From ae393577e228a5a8e9b6794d0a1b4cbd43ab9e95 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 26 Aug 2022 11:25:24 +0200 Subject: [PATCH] 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 Signed-off-by: Martin Renvoize --- Koha/Patron.pm | 8 +-- Koha/Patron/Attribute/Type.pm | 22 +++++++ admin/patron-attr-types.pl | 6 +- .../data/mysql/atomicupdate/bug-26573.pl | 54 ++++++++++++++++ installer/data/mysql/kohastructure.sql | 25 ++++++-- .../en/modules/admin/patron-attr-types.tt | 27 +++++--- .../prog/en/modules/members/memberentrygen.tt | 2 +- .../en/modules/reports/borrowers_stats.tt | 2 +- .../prog/en/modules/tools/modborrowers.tt | 2 +- koha-tmpl/intranet-tmpl/prog/js/members.js | 2 +- .../bootstrap/en/modules/opac-memberentry.tt | 2 +- members/memberentry.pl | 5 +- reports/borrowers_stats.pl | 11 ++-- t/db_dependent/Auth_with_ldap.t | 3 - t/db_dependent/Koha/Patron/Attribute.t | 9 ++- t/db_dependent/Koha/Patron/Attribute/Type.t | 37 +++++++++++ t/db_dependent/Koha/Patron/Attribute/Types.t | 12 ++-- t/db_dependent/api/v1/patrons.t | 14 ++--- .../api/v1/patrons_extended_attributes.t | 63 ++++++++----------- tools/modborrowers.pl | 15 ++--- 20 files changed, 220 insertions(+), 101 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug-26573.pl create mode 100755 t/db_dependent/Koha/Patron/Attribute/Type.t diff --git a/Koha/Patron.pm b/Koha/Patron.pm index ec7f6704983..3552db2f542 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -2272,9 +2272,9 @@ sub extended_attributes { # Check globally mandatory types my $interface = C4::Context->interface; my $params = { - mandatory => 1, - category_code => [ undef, $self->categorycode ], - 'borrower_attribute_types_branches.b_branchcode' => undef, + mandatory => 1, + 'borrower_attribute_types_categories.categorycode' => [ undef, $self->categorycode ], + 'borrower_attribute_types_branches.b_branchcode' => undef, }; if ( $interface eq 'opac' ) { @@ -2283,7 +2283,7 @@ sub extended_attributes { my @required_attribute_types = Koha::Patron::Attribute::Types->search( $params, - { join => 'borrower_attribute_types_branches' } + { join => [ 'borrower_attribute_types_branches', 'borrower_attribute_types_categories' ] } )->get_column('code'); for my $type (@required_attribute_types) { Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute->throw( diff --git a/Koha/Patron/Attribute/Type.pm b/Koha/Patron/Attribute/Type.pm index 75caa255d00..67eda5d6a9f 100644 --- a/Koha/Patron/Attribute/Type.pm +++ b/Koha/Patron/Attribute/Type.pm @@ -60,6 +60,28 @@ sub attributes { Koha::Patron::Attributes->_new_from_dbic($attributes_rs); } +=head3 categories + +Get or set attribute type's categories + + my @categories = $attribute_type->categories->as_list; + $attribute_type->categories(\@categories); + +=cut + +sub categories { + my ( $self, $categories ) = @_; + + if ($categories) { + my @categorycodes = map { $_->_result } @$categories; + $self->_result->set_categorycodes( \@categorycodes ); + return $self; + } + + my $rs = $self->_result->categorycodes; + return Koha::Patron::Categories->_new_from_dbic($rs); +} + =head2 Internal Methods =cut diff --git a/admin/patron-attr-types.pl b/admin/patron-attr-types.pl index 9b771b1ae3e..03e8b601ef5 100755 --- a/admin/patron-attr-types.pl +++ b/admin/patron-attr-types.pl @@ -118,7 +118,6 @@ sub add_update_attribute_type { my $mandatory = $input->param('mandatory') ? 1 : 0; my $authorised_value_category = $input->param('authorised_value_category'); my $display_checkout = $input->param('display_checkout') ? 1 : 0; - my $category_code = $input->param('category_code') || undef; my $class = $input->param('class'); my $attr_type = Koha::Patron::Attribute::Types->find($code); @@ -154,7 +153,6 @@ sub add_update_attribute_type { mandatory => $mandatory, authorised_value_category => $authorised_value_category, display_checkout => $display_checkout, - category_code => $category_code, class => $class, } )->store; @@ -162,6 +160,9 @@ sub add_update_attribute_type { my @branches = grep { !/^\s*$/ } $input->multi_param('branches'); $attr_type->library_limits( \@branches ); + my @categories = grep { !/^\s*$/ } $input->multi_param('category_code'); + $attr_type->categories( [ Koha::Patron::Categories->search( { categorycode => \@categories } )->as_list ] ); + if ( $op eq 'edit' ) { $template->param( edited_attribute_type => $attr_type->code() ); } else { @@ -235,6 +236,7 @@ sub edit_attribute_type_form { $can_be_set_to_unique = 0 if $@; $attr_type->unique_id(0); } + $template->param( attribute_type => $attr_type, attribute_type_form => 1, diff --git a/installer/data/mysql/atomicupdate/bug-26573.pl b/installer/data/mysql/atomicupdate/bug-26573.pl new file mode 100755 index 00000000000..b081280d551 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug-26573.pl @@ -0,0 +1,54 @@ +use Modern::Perl; + +return { + bug_number => '26573', + description => 'Add table borrower_attribute_types_categories', + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + $dbh->do( + q{ + CREATE TABLE IF NOT EXISTS `borrower_attribute_types_categories` ( + `borrower_attribute_type_code` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL, + `categorycode` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL, + KEY `borrower_attribute_type_code` (`borrower_attribute_type_code`), + KEY `categorycode` (`categorycode`), + CONSTRAINT `borrower_attribute_types_categories_borrower_attribute_type_code` FOREIGN KEY (`borrower_attribute_type_code`) REFERENCES `borrower_attribute_types` (`code`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `borrower_attribute_types_categories_categorycode` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) ON DELETE CASCADE ON UPDATE CASCADE, + PRIMARY KEY (`borrower_attribute_type_code`, `categorycode`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + } + ); + + say $out "Table 'borrower_attribute_types_categories' created"; + + if ( column_exists( 'borrower_attribute_types', 'category_code' ) ) { + $dbh->do( + q{ + INSERT IGNORE INTO borrower_attribute_types_categories (borrower_attribute_type_code, categorycode) + SELECT `code`, `category_code` FROM `borrower_attribute_types` + WHERE `category_code` IS NOT NULL + } + ); + + say $out + "Data migrated from 'borrower_attribute_types.category_code' to 'borrower_attribute_types_categories'"; + + $dbh->do( + q{ + ALTER TABLE `borrower_attribute_types` + DROP FOREIGN KEY `borrower_attribute_types_ibfk_1` + } + ); + $dbh->do( + q{ + ALTER TABLE `borrower_attribute_types` + DROP COLUMN `category_code` + } + ); + + say $out "Column 'borrower_attribute_types.category_code' deleted"; + } + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 3bf15c1007d..e21ee8a756e 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1257,14 +1257,11 @@ CREATE TABLE `borrower_attribute_types` ( `searched_by_default` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if this field is included in "Standard" patron searches in the staff interface (1 for yes, 0 for no)', `authorised_value_category` varchar(32) 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', - `category_code` varchar(10) DEFAULT NULL COMMENT 'defines a category for an attribute_type', `class` varchar(255) 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`), - KEY `category_code` (`category_code`), - CONSTRAINT `borrower_attribute_types_ibfk_1` FOREIGN KEY (`category_code`) REFERENCES `categories` (`categorycode`) + KEY `auth_val_cat_idx` (`authorised_value_category`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -1285,6 +1282,24 @@ CREATE TABLE `borrower_attribute_types_branches` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `borrower_attribute_types_categories` +-- + +DROP TABLE IF EXISTS `borrower_attribute_types_categories`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `borrower_attribute_types_categories` ( + `borrower_attribute_type_code` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL, + `categorycode` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL, + KEY `borrower_attribute_type_code` (`borrower_attribute_type_code`), + KEY `categorycode` (`categorycode`), + CONSTRAINT `borrower_attribute_types_categories_borrower_attribute_type_code` FOREIGN KEY (`borrower_attribute_type_code`) REFERENCES `borrower_attribute_types` (`code`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `borrower_attribute_types_categories_categorycode` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) ON DELETE CASCADE ON UPDATE CASCADE, + PRIMARY KEY (`borrower_attribute_type_code`, `categorycode`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `borrower_attributes` -- @@ -6755,4 +6770,4 @@ CREATE TABLE `zebraqueue` ( /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2024-11-25 12:13:27 +-- Dump completed on 2024-11-25 12:13:27 \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt index e3717155293..0d7f95b8383 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt @@ -235,17 +235,25 @@
  • - + + [% FOREACH category IN categories %] + [% SET selected = 0 %] + [% IF attribute_type %] + [% FOREACH cat IN attribute_type.categories %] + [% IF cat.categorycode == category.categorycode %] + [% SET selected = 1 %] + [% END %] + [% END %] + [% END %] + [% IF selected %] + [% ELSE %] - + [% END %] [% END %] -
    Choose one to limit this attribute to one patron type. Please leave blank if you want these attributes to be available for all types of patrons.
    +
    Select "All categories" if this attribute type should always be displayed. Otherwise select categories you want to associate with this value.
  • @@ -286,8 +294,6 @@ - -

    Patron attribute types

    [% IF ( added_attribute_type ) %]
    Added patron attribute type "[% added_attribute_type | html %]"
    [% END %] @@ -408,6 +414,9 @@ if ($("#branches option:selected").length < 1) { $("#branches option:first").attr("selected", "selected"); } + if ($("#category option:selected").length < 1) { + $("#category option:first").attr("selected", "selected"); + } $("#opac_display") .change(function () { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt index a4f415881b8..1e72a1b49a3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -1541,7 +1541,7 @@

    [% pa_loo.lib | html %]

    [% END %] [% FOREACH patron_attribute IN pa_loo.items %] -
  • +
  • [% IF patron_attribute.mandatory %] [% ELSE %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_stats.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_stats.tt index bf6c5904fac..ac7e5f35415 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_stats.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_stats.tt @@ -261,7 +261,7 @@ [% END %] [% FOREACH patron_attribute IN pa_loo.items %] - + [% patron_attribute.code | html %] ([% patron_attribute.description | html %]) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt index 4fc7daf7d70..522ad5e5288 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt @@ -593,7 +593,7 @@ information_category_node.html(""); if ( category && category.length > 0 ) { - information_category_node.html(_("This attribute will be only applied to the patron's category %s").format(category)); + information_category_node.html(_("This attribute will be only applied to the following patron categories: %s").format(category)); } var disable_input_node = $(li_node).find("input:checkbox[name='disable_input']"); if ( type == 'select' ) { diff --git a/koha-tmpl/intranet-tmpl/prog/js/members.js b/koha-tmpl/intranet-tmpl/prog/js/members.js index a20561cfe0b..e770b2c1d21 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/members.js +++ b/koha-tmpl/intranet-tmpl/prog/js/members.js @@ -77,7 +77,7 @@ function update_category_code(category_code) { var mytables = $(".attributes_table"); $(mytables).find("li").hide(); $(mytables) - .find(" li[data-category_code='" + category_code + "']") + .find(" li[data-category_code~='" + category_code + "']") .show(); $(mytables).find(" li[data-category_code='']").show(); diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt index c86f9f39e14..9927643f37c 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt @@ -1059,7 +1059,7 @@ [% FOREACH pa_value IN pa.values %] [% IF loop.first %][% END %] [% form_id = 'patron-attr-' _ Math.int( Math.rand(1000000) ) %] -
  • +
  • [% IF pa.type.mandatory && pa.type.opac_editable %] [% ELSE %] diff --git a/members/memberentry.pl b/members/memberentry.pl index c2df4523366..e428d3a2a9b 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -297,8 +297,7 @@ foreach my $guarantor (@guarantors) { if ( ( $op eq 'cud-save' || $op eq 'cud-insert' ) && ( $guarantor->is_child || $guarantor->is_guarantee || ( $patron && $patron->is_guarantor ) ) ) { - push @errors, 'ERROR_child_is_guarantor' if ( $guarantor->is_child ); - push @errors, 'ERROR_guarantor_is_guarantee' if ( !$guarantor->is_child ); + push @errors, 'ERROR_guarantor_is_guarantee'; } } @@ -986,7 +985,7 @@ sub patron_attributes_form { description => $attr_type->description(), repeatable => $attr_type->repeatable(), category => $attr_type->authorised_value_category(), - category_code => $attr_type->category_code(), + categorycodes => [ map { $_->categorycode } $attr_type->categories->as_list ], mandatory => $attr_type->mandatory(), is_date => $attr_type->is_date(), }; diff --git a/reports/borrowers_stats.pl b/reports/borrowers_stats.pl index fafd85ab26e..c6c84fdfb1d 100755 --- a/reports/borrowers_stats.pl +++ b/reports/borrowers_stats.pl @@ -506,12 +506,11 @@ sub patron_attributes_form { # TODO The following can be simplified easily my $entry = { - class => $attr_type->class(), - code => $attr_type->code(), - description => $attr_type->description(), - repeatable => $attr_type->repeatable(), - category => $attr_type->authorised_value_category(), - category_code => $attr_type->category_code(), + class => $attr_type->class(), + code => $attr_type->code(), + description => $attr_type->description(), + repeatable => $attr_type->repeatable(), + category => $attr_type->authorised_value_category(), }; my $newentry = {%$entry}; diff --git a/t/db_dependent/Auth_with_ldap.t b/t/db_dependent/Auth_with_ldap.t index 3b88d0e7a17..cd0309bc7bc 100755 --- a/t/db_dependent/Auth_with_ldap.t +++ b/t/db_dependent/Auth_with_ldap.t @@ -94,13 +94,11 @@ my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; my $attr_type = $builder->build( { source => 'BorrowerAttributeType', - value => { category_code => $categorycode } } ); my $attr_type2 = $builder->build( { source => 'BorrowerAttributeType', - value => { category_code => $categorycode } } ); @@ -708,4 +706,3 @@ sub is_admin_bind { } $schema->storage->txn_rollback(); - diff --git a/t/db_dependent/Koha/Patron/Attribute.t b/t/db_dependent/Koha/Patron/Attribute.t index e233a39050a..a04afc7c97f 100755 --- a/t/db_dependent/Koha/Patron/Attribute.t +++ b/t/db_dependent/Koha/Patron/Attribute.t @@ -328,11 +328,10 @@ subtest 'store() tests' => sub { { class => 'Koha::Patron::Attribute::Types', value => { - mandatory => 0, - repeatable => 0, - unique_id => 1, - is_date => 0, - category_code => undef + mandatory => 0, + repeatable => 0, + unique_id => 1, + is_date => 0, } } ); diff --git a/t/db_dependent/Koha/Patron/Attribute/Type.t b/t/db_dependent/Koha/Patron/Attribute/Type.t new file mode 100755 index 00000000000..d062cd32d81 --- /dev/null +++ b/t/db_dependent/Koha/Patron/Attribute/Type.t @@ -0,0 +1,37 @@ +#!/usr/bin/perl + +use Modern::Perl; + +use Test::More; +use Koha::Database; +use t::lib::TestBuilder; + +plan tests => 2; + +my $schema = Koha::Database->new->schema; +my $builder = t::lib::TestBuilder->new; + +use_ok('Koha::Patron::Attribute::Type'); + +subtest 'categories' => sub { + plan tests => 1; + + $schema->storage->txn_begin; + + my $category1 = $builder->build_object( { class => 'Koha::Patron::Categories' } ); + my $category2 = $builder->build_object( { class => 'Koha::Patron::Categories' } ); + Koha::Patron::Attribute::Types->delete(); + my $attribute_type = Koha::Patron::Attribute::Type->new( + { + code => 'TEST', + description => 'Test attribute type', + } + ); + $attribute_type->store(); + $attribute_type->categories( [ $category1, $category2 ] ); + $attribute_type->store(); + my @categories = $attribute_type->categories->as_list; + is( scalar @categories, 2 ); + + $schema->storage->txn_rollback; +}; diff --git a/t/db_dependent/Koha/Patron/Attribute/Types.t b/t/db_dependent/Koha/Patron/Attribute/Types.t index 222251a6dee..59c7cd0f710 100755 --- a/t/db_dependent/Koha/Patron/Attribute/Types.t +++ b/t/db_dependent/Koha/Patron/Attribute/Types.t @@ -55,14 +55,11 @@ subtest 'new() tests' => sub { 1, 'Only one object created' ); - my $cateogory_code = $builder->build( { source => 'Category' } )->{categorycode}; - - my $attribute_type_with_category = Koha::Patron::Attribute::Type->new( + my $attribute_type_2 = Koha::Patron::Attribute::Type->new( { - code => 'code_2', - description => 'description', - category_code => $cateogory_code, - repeatable => 0 + code => 'code_2', + description => 'description', + repeatable => 0 } )->store(); @@ -464,4 +461,3 @@ subtest 'search_with_library_limits() tests' => sub { $schema->storage->txn_rollback; }; - diff --git a/t/db_dependent/api/v1/patrons.t b/t/db_dependent/api/v1/patrons.t index 22b8cc5cc15..aab985fe111 100755 --- a/t/db_dependent/api/v1/patrons.t +++ b/t/db_dependent/api/v1/patrons.t @@ -626,10 +626,9 @@ subtest 'add() tests' => sub { { class => 'Koha::Patron::Attribute::Types', value => { - mandatory => 0, - repeatable => 1, - unique_id => 0, - category_code => 'ST' + mandatory => 0, + repeatable => 1, + unique_id => 0, } } ); @@ -637,10 +636,9 @@ subtest 'add() tests' => sub { { class => 'Koha::Patron::Attribute::Types', value => { - mandatory => 0, - repeatable => 1, - unique_id => 0, - category_code => 'ST' + mandatory => 0, + repeatable => 1, + unique_id => 0, } } ); diff --git a/t/db_dependent/api/v1/patrons_extended_attributes.t b/t/db_dependent/api/v1/patrons_extended_attributes.t index da7eeed122f..ef2ef0e3964 100755 --- a/t/db_dependent/api/v1/patrons_extended_attributes.t +++ b/t/db_dependent/api/v1/patrons_extended_attributes.t @@ -115,10 +115,9 @@ subtest 'add() tests' => sub { { class => 'Koha::Patron::Attribute::Types', value => { - mandatory => 1, - repeatable => 0, - unique_id => 0, - category_code => undef + mandatory => 1, + repeatable => 0, + unique_id => 0, } } ); @@ -126,10 +125,9 @@ subtest 'add() tests' => sub { { class => 'Koha::Patron::Attribute::Types', value => { - mandatory => 0, - repeatable => 1, - unique_id => 0, - category_code => undef + mandatory => 0, + repeatable => 1, + unique_id => 0, } } ); @@ -137,10 +135,9 @@ subtest 'add() tests' => sub { { class => 'Koha::Patron::Attribute::Types', value => { - mandatory => 0, - repeatable => 0, - unique_id => 1, - category_code => undef + mandatory => 0, + repeatable => 0, + unique_id => 1, } } ); @@ -238,10 +235,9 @@ subtest 'overwrite() tests' => sub { { class => 'Koha::Patron::Attribute::Types', value => { - mandatory => 1, - repeatable => 0, - unique_id => 0, - category_code => undef + mandatory => 1, + repeatable => 0, + unique_id => 0, } } ); @@ -249,10 +245,9 @@ subtest 'overwrite() tests' => sub { { class => 'Koha::Patron::Attribute::Types', value => { - mandatory => 0, - repeatable => 1, - unique_id => 0, - category_code => undef + mandatory => 0, + repeatable => 1, + unique_id => 0, } } ); @@ -260,10 +255,9 @@ subtest 'overwrite() tests' => sub { { class => 'Koha::Patron::Attribute::Types', value => { - mandatory => 0, - repeatable => 0, - unique_id => 1, - category_code => undef + mandatory => 0, + repeatable => 0, + unique_id => 1, } } ); @@ -380,10 +374,9 @@ subtest 'delete() tests' => sub { { class => 'Koha::Patron::Attribute::Types', value => { - mandatory => 0, - repeatable => 1, - unique_id => 0, - category_code => undef + mandatory => 0, + repeatable => 1, + unique_id => 0, } } ); @@ -426,10 +419,9 @@ subtest 'update() tests' => sub { { class => 'Koha::Patron::Attribute::Types', value => { - mandatory => 0, - repeatable => 1, - unique_id => 0, - category_code => undef + mandatory => 0, + repeatable => 1, + unique_id => 0, } } ); @@ -437,10 +429,9 @@ subtest 'update() tests' => sub { { class => 'Koha::Patron::Attribute::Types', value => { - mandatory => 0, - repeatable => 0, - unique_id => 1, - category_code => undef + mandatory => 0, + repeatable => 0, + unique_id => 1, } } ); diff --git a/tools/modborrowers.pl b/tools/modborrowers.pl index 9e1830ddb2f..3994a0f7d70 100755 --- a/tools/modborrowers.pl +++ b/tools/modborrowers.pl @@ -38,7 +38,7 @@ use Koha::Libraries; use Koha::Patron::Categories; use Koha::Patron::Debarments qw( AddDebarment DelDebarment ); use Koha::Patrons; -use List::MoreUtils qw(uniq); +use List::MoreUtils qw(uniq none); use Koha::Patron::Messages; my $input = CGI->new; @@ -164,10 +164,8 @@ if ( $op eq 'cud-show' || $op eq 'show' ) { options => $options, }; - my $category_code = $attr_type->category_code; - my ($category_lib) = - map { ( defined $category_code and $attr_type->category_code eq $_->categorycode ) ? $_->description : () } - @patron_categories; + my @categories = $attr_type->categories->as_list; + my ($category_lib) = join( ', ', map { $_->description } @categories ); push @patron_attributes_codes, { attribute_code => $attr_type->code, @@ -433,8 +431,11 @@ if ( $op eq 'cud-do' ) { next unless $attr_type; - # If this borrower is not in the category of this attribute, we don't want to modify this attribute - next if $attr_type->category_code and $attr_type->category_code ne $patron->categorycode; + # If this borrower is not in one of the categories of this attribute, we don't want to modify this attribute + my @attr_type_categories = $attr_type->categories->as_list; + if (@attr_type_categories) { + next if none { $patron->categorycode eq $_->categorycode } @attr_type_categories; + } if ( $attributes->{$code}->{disabled} ) { -- 2.48.1