Bug 26573 - Limit patron attribute types to more than one patron category
Summary: Limit patron attribute types to more than one patron category
Status: Failed QA
Alias: None
Product: Koha
Classification: Unclassified
Component: System Administration (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Julian Maurice
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-09-29 19:18 UTC by Caroline Cyr La Rose
Modified: 2024-03-12 14:40 UTC (History)
13 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 26573: Limit patron attribute types to more than one patron category (25.79 KB, patch)
2022-08-26 11:50 UTC, Julian Maurice
Details | Diff | Splinter Review
[DO NOT PUSH] DBIX schema update (8.88 KB, patch)
2022-11-03 13:34 UTC, Victor Grousset/tuxayo
Details | Diff | Splinter Review
DBIX schema update (8.92 KB, patch)
2022-11-03 14:03 UTC, PTFS Europe Sandboxes
Details | Diff | Splinter Review
Bug 26573: Limit patron attribute types to more than one patron category (25.85 KB, patch)
2022-11-03 14:19 UTC, PTFS Europe Sandboxes
Details | Diff | Splinter Review
DBIX schema update (8.99 KB, patch)
2022-11-03 14:19 UTC, PTFS Europe Sandboxes
Details | Diff | Splinter Review
Bug 26573: Limit patron attribute types to more than one patron category (25.83 KB, patch)
2022-12-07 15:01 UTC, Julian Maurice
Details | Diff | Splinter Review
Bug 26573: Remove remaining reference to category_code column (1.32 KB, patch)
2022-12-07 15:01 UTC, Julian Maurice
Details | Diff | Splinter Review
Bug 26573: Limit patron attribute types to more than one patron category (25.86 KB, patch)
2023-11-23 16:48 UTC, Shi Yao Wang
Details | Diff | Splinter Review
Bug 26573: Remove remaining reference to category_code column (1.32 KB, patch)
2023-11-23 16:48 UTC, Shi Yao Wang
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Caroline Cyr La Rose 2020-09-29 19:18:45 UTC
Currently, Koha doesn't allow to limit a patron attribute type to more than one patron category.

Let's say I have a patron attribute type STUDENTID, and I want to limit this attribute to the categories "undergrad students" and "grad students". I have to create two different patron attribute types.

To replicate:
1) Go to Administration > Patron attribute types
2) Create a new patron attribute
3) Note that the "Category" field is a dropdown and you can't choose more than one patron category to assign this attribute type to.
Comment 1 George Williams (NEKLS) 2020-10-01 14:24:49 UTC
The ability to limit a patron extended attribute to more than 1 category at a time would be great.
Comment 2 Barbara Johnson 2021-05-11 14:57:04 UTC
I had to create a whole duplicate set of attributes for a different patron category.  It took me awhile to figure that out and now if feels clunky to have these 'near duplicate' attributes in the system. This functionality is really needed.
Comment 3 Andrew Fuerste-Henry 2022-02-23 16:20:53 UTC
Agreed, this would be helpful!
Comment 4 Julian Maurice 2022-08-26 11:50:23 UTC
Created attachment 139823 [details] [review]
Bug 26573: Limit patron attribute types to more than one patron category

Test plan:
1. Create patron attribute types, some with a category limit, some
   without
2. Apply patch
3. Run installer/data/mysql/updatedatabase.pl
4. Run misc/devel/update_dbix_class_files.pl --koha-conf
5. Restart koha
6. Verify that existing category limits were kept
7. Create a new patron attribute type and select multiple category
   limits. Verify that they have been saved correctly.
8. Edit this patron attribute type and modify category limits. Verify
   that the changes have been saved correctly
9. Go to the patron creation form, and verify that patron attributes are
   shown/hidden accordingly when categorycode is changed.
10. Go to patron batch modification tool, enter a cardnumber (or a
    borrowernumber) and submit the form to go to the next step.
    Now select a patron attribute type that has category limits and
    verify that the message shown to the right is correct
Comment 5 Victor Grousset/tuxayo 2022-11-03 13:34:06 UTC
Created attachment 143113 [details] [review]
[DO NOT PUSH] DBIX schema update
Comment 6 PTFS Europe Sandboxes 2022-11-03 14:03:38 UTC
Created attachment 143114 [details] [review]
DBIX schema update

https://bugs.koha-community.org/show_bug.cgi?id=26573

Signed-off-by: Aude Charillon <aude-charillon@ptfs-europe.com>
Comment 7 PTFS Europe Sandboxes 2022-11-03 14:19:13 UTC
Created attachment 143115 [details] [review]
Bug 26573: Limit patron attribute types to more than one patron category

Test plan:
1. Create patron attribute types, some with a category limit, some
   without
2. Apply patch
3. Run installer/data/mysql/updatedatabase.pl
4. Run misc/devel/update_dbix_class_files.pl --koha-conf
5. Restart koha
6. Verify that existing category limits were kept
7. Create a new patron attribute type and select multiple category
   limits. Verify that they have been saved correctly.
8. Edit this patron attribute type and modify category limits. Verify
   that the changes have been saved correctly
9. Go to the patron creation form, and verify that patron attributes are
   shown/hidden accordingly when categorycode is changed.
10. Go to patron batch modification tool, enter a cardnumber (or a
    borrowernumber) and submit the form to go to the next step.
    Now select a patron attribute type that has category limits and
    verify that the message shown to the right is correct

Signed-off-by: Aude Charillon <aude-charillon@ptfs-europe.com>
Comment 8 PTFS Europe Sandboxes 2022-11-03 14:19:18 UTC
Created attachment 143116 [details] [review]
DBIX schema update

https://bugs.koha-community.org/show_bug.cgi?id=26573

Signed-off-by: Aude Charillon <aude-charillon@ptfs-europe.com>

Signed-off-by: Aude Charillon <aude-charillon@ptfs-europe.com>
Comment 9 Aude Charillon 2022-11-03 14:23:19 UTC
All works! A lot of library colleagues will find this useful.
Comment 10 Kyle M Hall 2022-11-04 18:37:22 UTC
Something went wrong loading file /kohadevbox/koha/installer/data/mysql/kohastructure.sql ([SQL ERROR]: CREATE TABLE `borrower_attribute_types` (
  `code` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'unique key used to identify each custom field',
  `description` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'description for each custom field',
  `repeatable` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines whether one patron/borrower can have multiple values for this custom field  (1 for yes, 0 for no)',
  `unique_id` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if this value needs to be unique (1 for yes, 0 for no)',
  `opac_display` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if this field is visible to patrons on their account in the OPAC (1 for yes, 0 for no)',
  `opac_editable` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if this field is editable by patrons on their account in the OPAC (1 for yes, 0 for no)',
  `staff_searchable` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if this field is searchable via the patron search in the staff interface (1 for yes, 0 for no)',
  `authorised_value_category` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'foreign key from authorised_values that links this custom field to an authorized value category',
  `display_checkout` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if this field displays in checkout screens',
  `class` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'defines a class for an attribute_type',
  `keep_for_pseudonymization` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if this field is copied to anonymized_borrower_attributes (1 for yes, 0 for no)',
  `mandatory` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if the attribute is mandatory or not',
  PRIMARY KEY (`code`),
  KEY `auth_val_cat_idx` (`authorised_value_category`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
) at /kohadevbox/koha/C4/Installer.pm line 583.
Comment 11 Julian Maurice 2022-12-07 15:01:08 UTC
Created attachment 144470 [details] [review]
Bug 26573: Limit patron attribute types to more than one patron category

Test plan:
1. Create patron attribute types, some with a category limit, some
   without
2. Apply patch
3. Run installer/data/mysql/updatedatabase.pl
4. Run misc/devel/update_dbix_class_files.pl --koha-conf
5. Restart koha
6. Verify that existing category limits were kept
7. Create a new patron attribute type and select multiple category
   limits. Verify that they have been saved correctly.
8. Edit this patron attribute type and modify category limits. Verify
   that the changes have been saved correctly
9. Go to the patron creation form, and verify that patron attributes are
   shown/hidden accordingly when categorycode is changed.
10. Go to patron batch modification tool, enter a cardnumber (or a
    borrowernumber) and submit the form to go to the next step.
    Now select a patron attribute type that has category limits and
    verify that the message shown to the right is correct

Signed-off-by: Aude Charillon <aude-charillon@ptfs-europe.com>
Comment 12 Julian Maurice 2022-12-07 15:01:14 UTC
Created attachment 144471 [details] [review]
Bug 26573: Remove remaining reference to category_code column
Comment 13 Julian Maurice 2022-12-07 15:03:02 UTC
Patch rebased on master (with the offending comma removed from kohastructure.sql)
+ a fix in the latest patch
Back to needs signoff
Comment 14 Shi Yao Wang 2022-12-09 21:39:39 UTC
Patch doesn't apply.

Bug 26573 - Limit patron attribute types to more than one patron category

143113 - [DO NOT PUSH] DBIX schema update
144470 - Bug 26573: Limit patron attribute types to more than one patron category
144471 - Bug 26573: Remove remaining reference to category_code column

Apply? [(y)es, (n)o, (i)nteractive] y
Applying: DBIX schema update
Using index info to reconstruct a base tree...
M	Koha/Schema/Result/Category.pm
M	Koha/Schema/Result/TmpHoldsqueue.pm
Falling back to patching base and 3-way merge...
Auto-merging Koha/Schema/Result/TmpHoldsqueue.pm
CONFLICT (content): Merge conflict in Koha/Schema/Result/TmpHoldsqueue.pm
Auto-merging Koha/Schema/Result/Category.pm
CONFLICT (content): Merge conflict in Koha/Schema/Result/Category.pm
error: Failed to merge in the changes.
Patch failed at 0001 DBIX schema update
Comment 15 Julian Maurice 2023-03-03 09:35:03 UTC
Comment on attachment 143113 [details] [review]
[DO NOT PUSH] DBIX schema update

Patches apply correctly without the DBIx schema patch, so I'm removing this one. Do not forget to run update_dbix_class_files.pl when testing.
Comment 16 Benjamin Daeuber 2023-03-30 22:00:19 UTC
Patches apply for me, but after running 

installer/data/mysql/updatedatabase.pl and misc/devel/update_dbix_class_files.pl --koha-conf

And after restarting koha I get an error when loading patron-attr-types.pl. The trace is quite long, but begins with: 

DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception: DBD::mysql::st execute failed: Unknown column 'me.category_code' in 'field list' at /kohadevbox/koha/Koha/Objects.pm line 394
 at /usr/share/perl5/DBIx/Class/Exception.pm line 77
Comment 17 Benjamin Daeuber 2023-03-31 14:06:12 UTC
Never mind, I was in the wrong branch. However, patches to not seem to apply to master at the moment.
Comment 18 Laura Escamilla 2023-04-07 12:15:20 UTC
Marking as "Patch doesn't apply" per Benjamin's comment.
Comment 19 Shi Yao Wang 2023-11-23 16:48:36 UTC
Created attachment 159210 [details] [review]
Bug 26573: Limit patron attribute types to more than one patron category

Test plan:
1. Create patron attribute types, some with a category limit, some
   without
2. Apply patch
3. Run installer/data/mysql/updatedatabase.pl
4. Run misc/devel/update_dbix_class_files.pl --koha-conf
5. Restart koha
6. Verify that existing category limits were kept
7. Create a new patron attribute type and select multiple category
   limits. Verify that they have been saved correctly.
8. Edit this patron attribute type and modify category limits. Verify
   that the changes have been saved correctly
9. Go to the patron creation form, and verify that patron attributes are
   shown/hidden accordingly when categorycode is changed.
10. Go to patron batch modification tool, enter a cardnumber (or a
    borrowernumber) and submit the form to go to the next step.
    Now select a patron attribute type that has category limits and
    verify that the message shown to the right is correct

Signed-off-by: Aude Charillon <aude-charillon@ptfs-europe.com>
Comment 20 Shi Yao Wang 2023-11-23 16:48:39 UTC
Created attachment 159211 [details] [review]
Bug 26573: Remove remaining reference to category_code column
Comment 21 Shi Yao Wang 2023-11-23 16:48:55 UTC
rebase
Comment 22 Anneli Österman 2023-12-15 12:20:11 UTC
I tested this in PTFS Europe's sandbox. Everything works according to the test plan but if I try to actually make batch modification from the step 10 I get this error message:

The method Koha::Patron::Attribute::Type->category_code is not covered by tests!

Trace begun at /kohadevbox/koha/Koha/Object.pm line 964
Koha::Object::AUTOLOAD('Koha::Patron::Attribute::Type=HASH(0x557cbecdce30)') called at /kohadevbox/koha/tools/modborrowers.pl line 408
eval {...} at /kohadevbox/koha/tools/modborrowers.pl line 2
CGI::Compile::ROOT::kohadevbox_koha_tools_modborrowers_2epl::__ANON__('CGI::Compile=HASH(0x557cbec1b4f8)', '', '/kohadevbox/koha/tools/modborrowers.pl', '/kohadevbox/koha/tools', 'ARRAY(0x557cbf067bc8)') called at /usr/share/perl5/CGI/Compile.pm line 151
CGI::Compile::ROOT::kohadevbox_koha_tools_modborrowers_2epl::modborrowers_2epl at /usr/share/perl5/CGI/Emulate/PSGI.pm line 30
CGI::Emulate::PSGI::__ANON__('HASH(0x557cbf1c69d8)') called at /usr/share/perl5/Plack/App/WrapCGI.pm line 95.....

I also tested without the patch and batch modification works without it.