Bugzilla – Attachment 160679 Details for
Bug 32105
Patron lists needs to share to specific people or groups
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 32105 - Add Library and Individual sharing modes to Patron Lists
0001-Bug-32105-Add-Library-and-Individual-sharing-modes-t.patch (text/plain), 52.75 KB, created by
Michael Hafen
on 2024-01-09 00:35:14 UTC
(
hide
)
Description:
Bug 32105 - Add Library and Individual sharing modes to Patron Lists
Filename:
MIME Type:
Creator:
Michael Hafen
Created:
2024-01-09 00:35:14 UTC
Size:
52.75 KB
patch
obsolete
>From 660dfabd8fd6addfcc3aa0d7ff255748521263f7 Mon Sep 17 00:00:00 2001 >From: Michael Hafen <michael.hafen@washk12.org> >Date: Tue, 11 Apr 2023 14:21:01 -0600 >Subject: [PATCH] Bug 32105 - Add Library and Individual sharing modes to > Patron Lists >Content-Type: text/plain; charset="utf-8" > >Test Plan: >1. apply patch, restart Plack, etc. >2. create or select three users, two at the same library and one not. >3. create or select a patron list owned by one of the users at the same library. >4. edit list and change sharing mode to 'Library and individuals'. >5. login as the other user at the same library and navigate to patron lists. >6. observe that the list is shared. >7. login as the third user and navigate to patron lists. >8. observe that the list is not shared with this user. >9. login as the owner of the list. >10. edit the list and add the third user as an individual. >11. login as the third user and navigate to patron lists. >12. observe that the list is now shared with the third user. >13. login as the owner of the list. >14. edit the list to change the sharing mode to 'Individuals'. >15. login as the second and third users. >16. observet that the list is not shared with the second user, but still is > with the third user. >--- > Koha/List/Patron.pm | 160 +++++++++++++++--- > Koha/Schema/Result/PatronList.pm | 152 +++++++++++++++++ > Koha/Schema/Result/PatronListUser.pm | 113 +++++++++++++ > .../bug_32105-add_patron_list_users_table.pl | 27 +++ > installer/data/mysql/kohastructure.sql | 22 ++- > .../en/modules/patron_lists/add-modify.tt | 128 +++++++++++++- > members/member.pl | 4 +- > members/members-home.pl | 4 +- > patron_lists/add-modify.pl | 37 +++- > patron_lists/delete.pl | 6 +- > patron_lists/list.pl | 14 +- > patron_lists/lists.pl | 4 +- > patron_lists/patron-lists-tab.pl | 12 +- > patron_lists/patrons.pl | 8 +- > patroncards/create-pdf.pl | 6 +- > patroncards/manage.pl | 4 +- > svc/members/add_to_list | 8 +- > t/db_dependent/Members.t | 8 +- > t/db_dependent/PatronLists.t | 93 ++++++---- > tools/cleanborrowers.pl | 4 +- > tools/import_borrowers.pl | 6 +- > tools/modborrowers.pl | 6 +- > 22 files changed, 705 insertions(+), 121 deletions(-) > create mode 100644 Koha/Schema/Result/PatronListUser.pm > create mode 100644 installer/data/mysql/atomicupdate/bug_32105-add_patron_list_users_table.pl > >diff --git a/Koha/List/Patron.pm b/Koha/List/Patron.pm >index cb91275d85..2c04419f3a 100644 >--- a/Koha/List/Patron.pm >+++ b/Koha/List/Patron.pm >@@ -36,29 +36,57 @@ BEGIN { > require Exporter; > @ISA = qw(Exporter); > @EXPORT_OK = qw( >- GetPatronLists >+ get_patron_list >+ get_patron_lists > >- DelPatronList >- AddPatronList >- ModPatronList >+ del_patron_list >+ add_patron_list >+ mod_patron_list > >- AddPatronsToList >- DelPatronsFromList >+ add_patrons_to_list >+ del_patrons_from_list >+ >+ grant_patrons_access_to_list >+ revoke_patrons_access_from_list > ); > } > >-=head2 GetPatronLists >+=head2 get_patron_list >+ >+ my $list = get_patron_list( { patron_list_id => 2 } ); >+ >+ Returns the patron list with patron_list_id. >+=cut >+ >+sub get_patron_list { >+ my ($params) = @_; >+ >+ unless ( $params->{'patron_list_id'} ) { >+ carp("No list id passed in or defined!"); >+ return; >+ } >+ >+ my $schema = Koha::Database->new()->schema(); >+ >+ my $patron_list = $schema->resultset('PatronList')->find($params->{'patron_list_id'}); >+ >+ return $patron_list; >+} >+ >+=head2 get_patron_lists > >- my @lists = GetPatronLists( $params ); >+ my @lists = get_patron_lists( $params ); > > Returns an array of lists created by the the given user > or the logged in user if none is passed in. > =cut > >-sub GetPatronLists { >+sub get_patron_lists { > my ($params) = @_; > > $params->{owner} ||= C4::Context->userenv->{'number'}; >+ my $user_branch = C4::Context->userenv->{'branch'}; >+ my $search_attrs = {}; > > unless ( $params->{owner} ) { > carp("No owner passed in or defined!"); >@@ -72,23 +100,35 @@ sub GetPatronLists { > $params->{'-or'} = [ > owner => $owner, > shared => 1, >+ '-and' => [ >+ shared => 2, >+ branchcode => $user_branch, >+ ], >+ '-and' => [ >+ shared => { 'IN' => [2,3] }, >+ 'patron_list_users.borrowernumber' => $owner, >+ ], > ]; >+ $search_attrs = { >+ join => [ 'owner', 'patron_list_users' ], >+ group_by => 'patron_list_id', >+ }; > } > > my $schema = Koha::Database->new()->schema(); > >- my @patron_lists = $schema->resultset('PatronList')->search($params); >+ my @patron_lists = $schema->resultset('PatronList')->search($params, $search_attrs); > > return wantarray() ? @patron_lists : \@patron_lists; > } > >-=head2 DelPatronList >+=head2 del_patron_list > >- DelPatronList( { patron_list_id => $list_id [, owner => $owner ] } ); >+ del_patron_list( { patron_list_id => $list_id [, owner => $owner ] } ); > > =cut > >-sub DelPatronList { >+sub del_patron_list { > my ($params) = @_; > > $params->{owner} ||= C4::Context->userenv->{'number'}; >@@ -107,13 +147,13 @@ sub DelPatronList { > ->search($params)->single()->delete(); > } > >-=head2 AddPatronList >+=head2 add_patron_list > >- AddPatronList( { name => $name [, owner => $owner ] } ); >+ add_patron_list( { name => $name [, owner => $owner ] } ); > > =cut > >-sub AddPatronList { >+sub add_patron_list { > my ($params) = @_; > > $params->{owner} ||= C4::Context->userenv->{'number'}; >@@ -132,13 +172,13 @@ sub AddPatronList { > ->create($params); > } > >-=head2 ModPatronList >+=head2 mod_patron_list > >- ModPatronList( { patron_list_id => $id, name => $name [, owner => $owner ] } ); >+ mod_patron_list( { patron_list_id => $id, name => $name [, owner => $owner ] } ); > > =cut > >-sub ModPatronList { >+sub mod_patron_list { > my ($params) = @_; > > unless ( $params->{patron_list_id} ) { >@@ -146,23 +186,22 @@ sub ModPatronList { > return; > } > >- my ($list) = GetPatronLists( >+ my $list = get_patron_list( > { > patron_list_id => $params->{patron_list_id}, >- owner => $params->{owner} > } > ); > > return $list->update($params); > } > >-=head2 AddPatronsToList >+=head2 add_patrons_to_list > >- AddPatronsToList({ list => $list, cardnumbers => \@cardnumbers }); >+ add_patrons_to_list({ list => $list, cardnumbers => \@cardnumbers }); > > =cut > >-sub AddPatronsToList { >+sub add_patrons_to_list { > my ($params) = @_; > > my $list = $params->{list}; >@@ -204,13 +243,13 @@ sub AddPatronsToList { > return wantarray() ? @results : \@results; > } > >-=head2 DelPatronsFromList >+=head2 del_patrons_from_list > >- DelPatronsFromList({ list => $list, patron_list_patrons => \@patron_list_patron_ids }); >+ del_patrons_from_list({ list => $list, patron_list_patrons => \@patron_list_patron_ids }); > > =cut > >-sub DelPatronsFromList { >+sub del_patrons_from_list { > my ($params) = @_; > > my $list = $params->{list}; >@@ -223,6 +262,73 @@ sub DelPatronsFromList { > ->delete(); > } > >+=head2 grant_patrons_access_to_list >+ >+ grant_patrons_access_to_list({ list => $list, cardnumbers => \@cardnumbers }); >+ >+=cut >+ >+sub grant_patrons_access_to_list { >+ my ($params) = @_; >+ >+ my $list = $params->{list}; >+ my $cardnumbers = $params->{'cardnumbers'}; >+ my $borrowernumbers = $params->{'borrowernumbers'}; >+ >+ return unless ( $list && ( $cardnumbers || $borrowernumbers ) ); >+ >+ my @borrowernumbers; >+ >+ my %search_param; >+ if ($cardnumbers) { >+ $search_param{cardnumber} = { 'IN' => $cardnumbers }; >+ } else { >+ $search_param{borrowernumber} = { 'IN' => $borrowernumbers }; >+ } >+ >+ @borrowernumbers = >+ Koha::Database->new()->schema()->resultset('Borrower')->search( >+ \%search_param, >+ { columns => [qw/ borrowernumber /] } >+ )->get_column('borrowernumber')->all(); >+ >+ my $patron_list_id = $list->patron_list_id(); >+ >+ my $plu_rs = Koha::Database->new()->schema()->resultset('PatronListUser'); >+ >+ my @results; >+ foreach my $borrowernumber (@borrowernumbers) { >+ my $result = $plu_rs->update_or_create( >+ { >+ patron_list_id => $patron_list_id, >+ borrowernumber => $borrowernumber >+ } >+ ); >+ push( @results, $result ); >+ } >+ >+ return wantarray() ? @results : \@results; >+} >+ >+=head2 revoke_patrons_access_from_list >+ >+ revoke_patrons_access_from_list({ list => $list, patron_list_users => \@patron_list_user_ids }); >+ >+=cut >+ >+sub revoke_patrons_access_from_list { >+ my ($params) = @_; >+ >+ my $list = $params->{list}; >+ my $patron_list_users = $params->{patron_list_users}; >+ >+ return unless ( $list && $patron_list_users ); >+ >+ return Koha::Database->new()->schema()->resultset('PatronListUser') >+ ->search( { patron_list_user_id => { 'IN' => $patron_list_users } } ) >+ ->delete(); >+} >+ > =head1 AUTHOR > > Kyle M Hall, E<lt>kyle@bywatersolutions.comE<gt> >diff --git a/Koha/Schema/Result/PatronList.pm b/Koha/Schema/Result/PatronList.pm >index ccb9fb1d5c..6c778e7cde 100644 >--- a/Koha/Schema/Result/PatronList.pm >+++ b/Koha/Schema/Result/PatronList.pm >@@ -23,6 +23,138 @@ __PACKAGE__->table("patron_lists"); > > =head1 ACCESSORS > >+=head2 patron_list_id >+ >+ data_type: 'integer' >+ is_auto_increment: 1 >+ is_nullable: 0 >+ >+=head2 name >+ >+ data_type: 'varchar' >+ is_nullable: 0 >+ size: 255 >+ >+=head2 owner >+ >+ data_type: 'integer' >+ is_foreign_key: 1 >+ is_nullable: 0 >+ >+=head2 shared >+ >+ data_type: 'tinyint' >+ default_value: 0 >+ is_nullable: 1 >+ >+=cut >+ >+__PACKAGE__->add_columns( >+ "patron_list_id", >+ { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, >+ "name", >+ { data_type => "varchar", is_nullable => 0, size => 255 }, >+ "owner", >+ { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, >+ "shared", >+ { data_type => "tinyint", default_value => 0, is_nullable => 1 }, >+); >+ >+=head1 PRIMARY KEY >+ >+=over 4 >+ >+=item * L</patron_list_id> >+ >+=back >+ >+=cut >+ >+__PACKAGE__->set_primary_key("patron_list_id"); >+ >+=head1 RELATIONS >+ >+=head2 owner >+ >+Type: belongs_to >+ >+Related object: L<Koha::Schema::Result::Borrower> >+ >+=cut >+ >+__PACKAGE__->belongs_to( >+ "owner", >+ "Koha::Schema::Result::Borrower", >+ { borrowernumber => "owner" }, >+ { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, >+); >+ >+=head2 patron_list_patrons >+ >+Type: has_many >+ >+Related object: L<Koha::Schema::Result::PatronListPatron> >+ >+=cut >+ >+__PACKAGE__->has_many( >+ "patron_list_patrons", >+ "Koha::Schema::Result::PatronListPatron", >+ { "foreign.patron_list_id" => "self.patron_list_id" }, >+ { cascade_copy => 0, cascade_delete => 0 }, >+); >+ >+=head2 patron_list_users >+ >+Type: has_many >+ >+Related object: L<Koha::Schema::Result::PatronListUser> >+ >+=cut >+ >+__PACKAGE__->has_many( >+ "patron_list_users", >+ "Koha::Schema::Result::PatronListUser", >+ { "foreign.patron_list_id" => "self.patron_list_id" }, >+ { cascade_copy => 0, cascade_delete => 0 }, >+); >+ >+ >+# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-02-28 16:35:34 >+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:YepHXHQHtxjorkGhef0rmQ >+# These lines were loaded from './Koha/Schema/Result/PatronList.pm' found in @INC. >+# They are now part of the custom portion of this file >+# for you to hand-edit. If you do not either delete >+# this section or remove that file from @INC, this section >+# will be repeated redundantly when you re-create this >+# file again via Loader! See skip_load_external to disable >+# this feature. >+ >+use utf8; >+package Koha::Schema::Result::PatronList; >+ >+# Created by DBIx::Class::Schema::Loader >+# DO NOT MODIFY THE FIRST PART OF THIS FILE >+ >+=head1 NAME >+ >+Koha::Schema::Result::PatronList >+ >+=cut >+ >+use strict; >+use warnings; >+ >+use base 'DBIx::Class::Core'; >+ >+=head1 TABLE: C<patron_lists> >+ >+=cut >+ >+__PACKAGE__->table("patron_lists"); >+ >+=head1 ACCESSORS >+ > =head2 patron_list_id > > data_type: 'integer' >@@ -114,6 +246,26 @@ __PACKAGE__->has_many( > # Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29 > # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+gAlf5GQ7YSgAtFIXgqVWw > >+=head2 patron_list_patrons >+ >+Type: has_many >+ >+Related object: L<Koha::Schema::Result::PatronListPatron> >+ >+=cut >+ >+__PACKAGE__->has_many( >+ "patron_list_users", >+ "Koha::Schema::Result::PatronListUser", >+ { "foreign.patron_list_id" => "self.patron_list_id" }, >+ { cascade_copy => 0, cascade_delete => 0 }, >+); >+ > > # You can replace this text with custom content, and it will be preserved on regeneration > 1; >+# End of lines loaded from './Koha/Schema/Result/PatronList.pm' >+ >+ >+# You can replace this text with custom code or comments, and it will be preserved on regeneration >+1; >diff --git a/Koha/Schema/Result/PatronListUser.pm b/Koha/Schema/Result/PatronListUser.pm >new file mode 100644 >index 0000000000..c3349458dc >--- /dev/null >+++ b/Koha/Schema/Result/PatronListUser.pm >@@ -0,0 +1,113 @@ >+use utf8; >+package Koha::Schema::Result::PatronListUser; >+ >+# Created by DBIx::Class::Schema::Loader >+# DO NOT MODIFY THE FIRST PART OF THIS FILE >+ >+=head1 NAME >+ >+Koha::Schema::Result::PatronListUser >+ >+=cut >+ >+use strict; >+use warnings; >+ >+use base 'DBIx::Class::Core'; >+ >+=head1 TABLE: C<patron_list_users> >+ >+=cut >+ >+__PACKAGE__->table("patron_list_users"); >+ >+=head1 ACCESSORS >+ >+=head2 patron_list_user_id >+ >+ data_type: 'integer' >+ is_auto_increment: 1 >+ is_nullable: 0 >+ >+=head2 patron_list_id >+ >+ data_type: 'integer' >+ is_foreign_key: 1 >+ is_nullable: 0 >+ >+=head2 borrowernumber >+ >+ data_type: 'integer' >+ is_foreign_key: 1 >+ is_nullable: 0 >+ >+=head2 can_edit >+ >+ data_type: 'tinyint' >+ default_value: 0 >+ is_nullable: 1 >+ >+=cut >+ >+__PACKAGE__->add_columns( >+ "patron_list_user_id", >+ { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, >+ "patron_list_id", >+ { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, >+ "borrowernumber", >+ { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, >+ "can_edit", >+ { data_type => "tinyint", default_value => 0, is_nullable => 1 }, >+); >+ >+=head1 PRIMARY KEY >+ >+=over 4 >+ >+=item * L</patron_list_user_id> >+ >+=back >+ >+=cut >+ >+__PACKAGE__->set_primary_key("patron_list_user_id"); >+ >+=head1 RELATIONS >+ >+=head2 borrowernumber >+ >+Type: belongs_to >+ >+Related object: L<Koha::Schema::Result::Borrower> >+ >+=cut >+ >+__PACKAGE__->belongs_to( >+ "borrowernumber", >+ "Koha::Schema::Result::Borrower", >+ { borrowernumber => "borrowernumber" }, >+ { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, >+); >+ >+=head2 patron_list >+ >+Type: belongs_to >+ >+Related object: L<Koha::Schema::Result::PatronList> >+ >+=cut >+ >+__PACKAGE__->belongs_to( >+ "patron_list", >+ "Koha::Schema::Result::PatronList", >+ { patron_list_id => "patron_list_id" }, >+ { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, >+); >+ >+ >+# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-02-28 16:35:34 >+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:3K+501CuiCeq6Jk7W6TE2w >+ >+ >+# You can replace this text with custom code or comments, and it will be preserved on regeneration >+1; >diff --git a/installer/data/mysql/atomicupdate/bug_32105-add_patron_list_users_table.pl b/installer/data/mysql/atomicupdate/bug_32105-add_patron_list_users_table.pl >new file mode 100644 >index 0000000000..fce28639d2 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_32105-add_patron_list_users_table.pl >@@ -0,0 +1,27 @@ >+use Modern::Perl; >+ >+return { >+ bug_number => "32105", >+ description => "Add patron list users table", >+ up => sub { >+ my ($args) = @_; >+ my ($dbh, $out) = @$args{qw(dbh out)}; >+ unless ( TableExists('patron_list_users') ) { >+ $dbh->do(q{CREATE TABLE `patron_list_users` ( >+ `patron_list_user_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier', >+ `patron_list_id` int(11) NOT NULL COMMENT 'the list this entry is part of', >+ `borrowernumber` int(11) NOT NULL COMMENT 'the borrower that is given access to this list', >+ `can_edit` tinyint(1) NOT NULL DEFAULt 0 COMMENT 'whether this borrower can edit the list and it''s patrons', >+ PRIMARY KEY (`patron_list_user_id`), >+ KEY `patron_list_id` (`patron_list_id`), >+ KEY `borrowernumber` (`borrowernumber`), >+ CONSTRAINT `patron_list_users_ibfk_1` FOREIGN KEY (`patron_list_id`) REFERENCES `patron_lists` (`patron_list_id`) ON DELETE CASCADE ON UPDATE CASCADE, >+ CONSTRAINT `patron_list_users_ibfk_2` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE >+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci}); >+ say $out "Added new table 'patron_list_users'"; >+ >+ $dbh->do(q{ALTER TABLE patron_lists MODIFY shared tinyint DEFAULT 0 COMMENT '1 for everyone, 2 for library and individuals, 3 for individuals'}); >+ say $out "Add additional share modes to patron_lists table comment"; >+ } >+ }, >+}; >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index 16310f0f44..bf2d51e40b 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -5003,6 +5003,26 @@ CREATE TABLE `patron_list_patrons` ( > ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; > /*!40101 SET character_set_client = @saved_cs_client */; > >+-- >+-- Table structure for table `patron_list_users` >+-- >+ >+DROP TABLE IF EXISTS `patron_list_users`; >+/*!40101 SET @saved_cs_client = @@character_set_client */; >+/*!40101 SET character_set_client = utf8 */; >+CREATE TABLE `patron_list_users` ( >+ `patron_list_user_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier', >+ `patron_list_id` int(11) NOT NULL COMMENT 'the list this entry is part of', >+ `borrowernumber` int(11) NOT NULL COMMENT 'the borrower that is given access to this list', >+ `can_edit` tinyint(1) NOT NULL DEFAULt 0 COMMENT 'whether this borrower can edit the list and it''s patrons', >+ PRIMARY KEY (`patron_list_user_id`), >+ KEY `patron_list_id` (`patron_list_id`), >+ KEY `borrowernumber` (`borrowernumber`), >+ CONSTRAINT `patron_list_users_ibfk_1` FOREIGN KEY (`patron_list_id`) REFERENCES `patron_lists` (`patron_list_id`) ON DELETE CASCADE ON UPDATE CASCADE, >+ CONSTRAINT `patron_list_users_ibfk_2` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE >+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; >+/*!40101 SET character_set_client = @saved_cs_client */; >+ > -- > -- Table structure for table `patron_lists` > -- >@@ -5014,7 +5034,7 @@ CREATE TABLE `patron_lists` ( > `patron_list_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier', > `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'the list''s name', > `owner` int(11) NOT NULL COMMENT 'borrowernumber of the list creator', >- `shared` tinyint(1) DEFAULT 0, >+ `shared` tinyint(1) DEFAULT 0 COMMENT '1 for everyone, 2 for library and individuals, 3 for individuals', > PRIMARY KEY (`patron_list_id`), > KEY `owner` (`owner`), > CONSTRAINT `patron_lists_ibfk_1` FOREIGN KEY (`owner`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/add-modify.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/add-modify.tt >index 7cc644537e..b8f60524f2 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/add-modify.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/add-modify.tt >@@ -1,6 +1,8 @@ > [% USE raw %] > [% USE Asset %] > [% PROCESS 'i18n.inc' %] >+[% USE Branches %] >+[% USE Categories %] > [% SET footerjs = 1 %] > [% INCLUDE 'doc-head-open.inc' %] > <title>[% FILTER collapse %] >@@ -13,6 +15,8 @@ > [% t("Tools") | html %] › > [% t("Koha") | html %] > [% END %]</title> >+ [% SET libraries = Branches.all %] >+[% SET categories = Categories.all.unblessed %] > [% INCLUDE 'doc-head-close.inc' %] > </head> > >@@ -62,16 +66,29 @@ > </li> > > <li> >- <label for="list-shared">Shared:</label> >- [% IF list.shared %] >- <input id="list-shared" name="shared" type="checkbox" checked="checked" /> >- [% ELSE %] >- <input id="list-shared" name="shared" type="checkbox" /> >- [% END %] >+ <label for="list-shared">Sharing mode:</label> >+ <select name="shared" id="list-shared"> >+ <option value="0">Not shared</option> >+ [% IF list.shared == 1 %] >+ <option value="1" selected="selected">Everyone</option> >+ [% ELSE %] >+ <option value="1">Everyone</option> >+ [% END %] >+ [% IF list.shared == 2 %] >+ <option value="2" selected="selected">Library staff and individuals</option> >+ [% ELSE %] >+ <option value="2">Library staff and individuals</option> >+ [% END %] >+ [% IF list.shared == 3 %] >+ <option value="3" selected="selected">Individuals</option> >+ [% ELSE %] >+ <option value="3">Individuals</option> >+ [% END %] >+ </select> > </li> > > <li> >- <span class="label">Owner: </span>[% logged_in_user.userid | html %] >+ <span class="label">Owner: </span>[% INCLUDE 'patron-title.inc' patron=list.owner %] > </li> > </ol> > >@@ -83,11 +100,108 @@ > <a href="lists.pl" class="cancel">Cancel</a> > </fieldset> > </form> >+ >+ <fieldset class="rows[% IF !list.shared || list.shared == 0 || list.shared == 1 %] hidden[% END %]" id="list-users"> >+ >+ <legend> >+ Manage individuals with access to list >+ </legend> >+ <span class="label">Users: </span> >+ <table id="patron_list_users"> >+ <thead> >+ <tr><th>Name</th><th>Library</th><th>Category</th><th></th></tr> >+ </thead> >+ <tbody> >+ [% FOREACH u IN list.patron_list_users %] >+ <tr> >+ <td>[% INCLUDE 'patron-title.inc' patron=u.borrowernumber | html %]</td> >+ <td>[% u.borrowernumber.library_id.name | html %]</td> >+ <td>[% u.borrowernumber.category_id.name | html %]</td> >+ <td><a href="add-modify.pl?patron_list_id=[% list.patron_list_id | html %]&revoke_list_users_id=[% u.patron_list_user_id | html %]">Remove</a> >+ </tr> >+ [% END %] >+ </tbody> >+ </table> >+ <div id="searchform"> >+ [% PROCESS patron_search_filters_simple %] >+ </div> >+ <div id="searchresults"> >+ <div class="searchheader fh-fixedHeader" id="searchheader" style="display:none"> >+ <div> >+ <a href="#" class="btn btn-link" id="select_all"><i class="fa fa-check"></i> Select all</a> >+ | >+ <a href="#" class="btn btn-link" id="clear_all"><i class="fa fa-remove"></i> Clear all</a> >+ <button id="add-patrons" class="btn btn-sm btn-default disabled" disabled="disabled"><i class="fa fa-compress" aria-hidden="true"></i> Add selected patrons to list</button> >+ </div> >+ [% PROCESS patron_search_table table_id => 'memberresultst' columns => ['checkbox','cardnumber','name','branch','category'] %] >+ </div> >+ </li> >+ </fieldset> >+ > </div> > </div> > > [% MACRO jsinclude BLOCK %] >+ [% INCLUDE 'datatables.inc' %] > [% Asset.js("js/tools-menu.js") | $raw %] >+ <script> >+ var patron_search_selections = []; >+ >+ $('#add-patrons').on('click', function() { >+ var merge_patrons_url = 'add-modify.pl?patron_list_id=[% list.patron_list_id | html %]&grant_borrowernumber=' + patron_search_selections.join("&grant_borrowernumber="); >+ window.location.href = merge_patrons_url; >+ }); >+ >+ $(document).ready(function() { >+ $(".browse").hide(); >+ >+ $('#memberresultst').on('change', 'input.selection', function() { >+ var borrowernumber = $(this).val(); >+ if( $(this).prop("checked") ){ >+ patron_search_selections.push( $(this).val() ); >+ $('#add-patrons').prop('disabled', false).removeClass("disabled"); >+ } else { >+ var filtered = patron_search_selections.filter(function( value ){ >+ return value !== borrowernumber; >+ }); >+ if( filtered.length > 0 ){ >+ patron_search_selections = filtered; >+ $('#add-patrons').prop('disabled', false).removeClass("disabled"); >+ } else { >+ patron_search_selections = []; >+ $('#add-patrons').prop('disabled', true).addClass("disabled"); >+ } >+ } >+ }); >+ >+ $("#select_all").on("click",function(e){ >+ e.preventDefault(); >+ patron_search_selections = []; >+ $(".selection").each(function(){ >+ if( $(this).prop("checked") == false ){ >+ $(this).prop( "checked", true ).change(); >+ } >+ patron_search_selections.push( $(this).val() ); >+ }); >+ $('#add-patrons').removeClass("disabled").prop('disabled', false); >+ }); >+ $("#clear_all").on("click",function(e){ >+ e.preventDefault(); >+ $(".selection").each(function(){ >+ if( $(this).prop("checked") ){ >+ $(this).prop("checked", false ).change(); >+ } >+ }); >+ patron_search_selections = []; >+ $('#add-patrons').prop('disabled', true).addClass("disabled"); >+ }); >+ >+ $("#searchheader").hide(); >+ $("#patron_search_form").on('submit', function(){$("#searchheader").show();}); >+ }); >+ </script> >+ [% PROCESS patron_search_js table_id => 'memberresultst', columns => ['checkbox','cardnumber','name','branch','category'], default_sort_column => 'name-address', display_search_description => 1, libraries => libraries, categories => categories %] >+ > [% END %] > > [% INCLUDE 'intranet-bottom.inc' %] >diff --git a/members/member.pl b/members/member.pl >index 30ba11bc8c..858eb076fe 100755 >--- a/members/member.pl >+++ b/members/member.pl >@@ -27,7 +27,7 @@ use Modern::Perl; > use C4::Auth qw( get_template_and_user ); > use C4::Output qw( output_html_with_http_headers ); > use CGI qw( -utf8 ); >-use Koha::List::Patron qw( GetPatronLists ); >+use Koha::List::Patron qw( get_patron_lists ); > use Koha::Patrons; > use Koha::Patron::Attribute::Types; > >@@ -72,7 +72,7 @@ $template->param( 'alphabet' => C4::Context->preference('alphabet') || join ' ', > my $defer_loading = $input->request_method() eq "GET" && !$circsearch ? 1 : 0; > > $template->param( >- patron_lists => [ GetPatronLists() ], >+ patron_lists => [ get_patron_lists() ], > searchmember => $searchmember, > branchcode_filter => scalar $input->param('branchcode_filter'), > categorycode_filter => scalar $input->param('categorycode_filter'), >diff --git a/members/members-home.pl b/members/members-home.pl >index 22d341bbbb..1e8ef14514 100755 >--- a/members/members-home.pl >+++ b/members/members-home.pl >@@ -25,7 +25,7 @@ use C4::Context; > use C4::Members; > use Koha::Patron::Modifications; > use Koha::Libraries; >-use Koha::List::Patron qw( GetPatronLists ); >+use Koha::List::Patron qw( get_patron_lists ); > use Koha::Patron::Categories; > use Koha::Patron::Attribute::Types; > >@@ -71,7 +71,7 @@ $template->param( > $template->param( > alphabet => C4::Context->preference('alphabet') || join (' ', 'A' .. 'Z'), > PatronAutoComplete => C4::Context->preference('PatronAutoComplete'), >- patron_lists => [ GetPatronLists() ], >+ patron_lists => [ get_patron_lists() ], > PatronsPerPage => C4::Context->preference("PatronsPerPage") || 20, > ); > >diff --git a/patron_lists/add-modify.pl b/patron_lists/add-modify.pl >index 95ff728707..72d7209910 100755 >--- a/patron_lists/add-modify.pl >+++ b/patron_lists/add-modify.pl >@@ -23,7 +23,7 @@ use CGI qw ( -utf8 ); > > use C4::Auth qw( get_template_and_user ); > use C4::Output qw( output_html_with_http_headers ); >-use Koha::List::Patron qw( AddPatronList GetPatronLists ModPatronList ); >+use Koha::List::Patron qw( get_patron_list add_patron_list mod_patron_list grant_patrons_access_to_list revoke_patrons_access_from_list ); > > my $cgi = CGI->new; > >@@ -38,24 +38,45 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > > my $id = $cgi->param('patron_list_id'); > my $name = $cgi->param('name'); >-my $shared = $cgi->param('shared') ? 1 : 0; >+my $shared = $cgi->param('shared'); >+my @grant_user = $cgi->multi_param('grant_borrowernumber'); >+my @revoke_user = $cgi->multi_param('revoke_list_users_id'); > > if ($id) { >- my ($list) = GetPatronLists( { patron_list_id => $id } ); >+ my $list = get_patron_list( { 'patron_list_id' => $id } ); > $template->param( list => $list ); > } > > if ($name) { >+ my $list; > if ($id) { >- ModPatronList( { patron_list_id => $id, name => $name, shared => $shared } ); >- print $cgi->redirect('lists.pl'); >+ mod_patron_list( { patron_list_id => $id, name => $name, shared => $shared } ); >+ $list = get_patron_list( { 'patron_list_id' => $id } ); > } > else { >- my $list = AddPatronList( { name => $name, shared => $shared } ); >- print $cgi->redirect( >- "list.pl?patron_list_id=" . $list->patron_list_id() ); >+ $list = add_patron_list( { name => $name, shared => $shared } ); > } > >+ $template->param( list => $list ); >+} >+ >+if (@grant_user) { >+ my $list = get_patron_list( { 'patron_list_id' => $id } ); >+ my $results = grant_patrons_access_to_list({ >+ list => $list, >+ borrowernumbers => \@grant_user, >+ }); >+ print $cgi->redirect("add-modify.pl?patron_list_id=" . $list->patron_list_id() ); >+ exit; >+} >+ >+if (@revoke_user) { >+ my $list = get_patron_list( { 'patron_list_id' => $id } ); >+ my $results = revoke_patrons_access_from_list({ >+ list => $list, >+ patron_list_users => \@revoke_user, >+ }); >+ print $cgi->redirect("add-modify.pl?patron_list_id=" . $list->patron_list_id() ); > exit; > } > >diff --git a/patron_lists/delete.pl b/patron_lists/delete.pl >index e7c227ea1f..4f3799be1d 100755 >--- a/patron_lists/delete.pl >+++ b/patron_lists/delete.pl >@@ -23,7 +23,7 @@ use CGI qw ( -utf8 ); > > use C4::Auth qw( get_template_and_user ); > use C4::Output; >-use Koha::List::Patron qw( DelPatronList ); >+use Koha::List::Patron qw( del_patron_list ); > > my $cgi = CGI->new; > >@@ -40,11 +40,11 @@ my $id = $cgi->param('patron_list_id'); > my @lists_ids = $cgi->multi_param('patron_lists_ids'); > > if ( defined $id && $id ne '' ) { >- DelPatronList( { patron_list_id => $id } ); >+ del_patron_list( { patron_list_id => $id } ); > } > if (@lists_ids) { > foreach my $list_id (@lists_ids) { >- DelPatronList( { patron_list_id => $list_id } ); >+ del_patron_list( { patron_list_id => $list_id } ); > } > } > >diff --git a/patron_lists/list.pl b/patron_lists/list.pl >index 45b11a1667..61ecc3f29c 100755 >--- a/patron_lists/list.pl >+++ b/patron_lists/list.pl >@@ -24,9 +24,9 @@ use CGI qw ( -utf8 ); > use C4::Auth qw( get_template_and_user ); > use C4::Output qw( output_html_with_http_headers ); > use Koha::List::Patron qw( >- AddPatronsToList >- DelPatronsFromList >- GetPatronLists >+ get_patron_list >+ add_patrons_to_list >+ del_patrons_from_list > ); > use List::MoreUtils qw( uniq ); > >@@ -42,7 +42,7 @@ my ( $template, $logged_in_user, $cookie ) = get_template_and_user( > ); > > my ($list) = >- GetPatronLists( { patron_list_id => scalar $cgi->param('patron_list_id') } ); >+ get_patron_list( { patron_list_id => scalar $cgi->param('patron_list_id') } ); > > my @existing = $list->patron_list_patrons; > >@@ -54,7 +54,7 @@ if ( $patrons_by_id ){ > my %add_params; > $add_params{list} = $list; > $add_params{ $id_column } = \@patrons_list; >- my @results = AddPatronsToList(\%add_params); >+ my @results = add_patrons_to_list(\%add_params); > my $id = $id_column eq 'borrowernumbers' ? 'borrowernumber' : 'cardnumber'; > my %found = map { $_->borrowernumber->$id => 1 } @results; > my %exist = map { $_->borrowernumber->$id => 1 } @existing; >@@ -72,12 +72,12 @@ if ( $patrons_by_id ){ > > my @patrons_to_add = $cgi->multi_param('patrons_to_add'); > if (@patrons_to_add) { >- AddPatronsToList( { list => $list, cardnumbers => \@patrons_to_add } ); >+ add_patrons_to_list( { list => $list, cardnumbers => \@patrons_to_add } ); > } > > my @patrons_to_remove = $cgi->multi_param('patrons_to_remove'); > if (@patrons_to_remove) { >- DelPatronsFromList( { list => $list, patron_list_patrons => \@patrons_to_remove } ); >+ del_patrons_from_list( { list => $list, patron_list_patrons => \@patrons_to_remove } ); > } > > $template->param( list => $list ); >diff --git a/patron_lists/lists.pl b/patron_lists/lists.pl >index f599cd164b..4ed88b248f 100755 >--- a/patron_lists/lists.pl >+++ b/patron_lists/lists.pl >@@ -23,7 +23,7 @@ use CGI qw ( -utf8 ); > > use C4::Auth qw( get_template_and_user ); > use C4::Output qw( output_html_with_http_headers ); >-use Koha::List::Patron qw( GetPatronLists ); >+use Koha::List::Patron qw( get_patron_lists ); > > my $cgi = CGI->new; > >@@ -36,7 +36,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > } > ); > >-my @lists = GetPatronLists(); >+my @lists = get_patron_lists(); > > $template->param( lists => \@lists ); > >diff --git a/patron_lists/patron-lists-tab.pl b/patron_lists/patron-lists-tab.pl >index c7c3e2a5f2..2dc45e91a3 100755 >--- a/patron_lists/patron-lists-tab.pl >+++ b/patron_lists/patron-lists-tab.pl >@@ -25,7 +25,7 @@ use C4::Auth qw( get_template_and_user ); > use C4::Output qw( output_html_with_http_headers ); > > use Koha::Patrons; >-use Koha::List::Patron qw( GetPatronLists AddPatronsToList DelPatronsFromList ); >+use Koha::List::Patron qw( get_patron_lists get_patron_list add_patrons_to_list del_patrons_from_list ); > > my $cgi = CGI->new; > >@@ -54,14 +54,14 @@ if ( !$logged_in_user->can_see_patron_infos($patron) ) { > } else { > my $has_perms = C4::Auth::haspermission( $logged_in_user->userid, { 'tools' => 'manage_patron_lists' } ); > if ( $list_id && $has_perms ) { >- my ($list) = GetPatronLists( { patron_list_id => $list_id } ); >+ my ($list) = get_patron_list( { patron_list_id => $list_id } ); > > if (@patrons_to_add) { >- AddPatronsToList( { list => $list, cardnumbers => \@patrons_to_add } ); >+ add_patrons_to_list( { list => $list, cardnumbers => \@patrons_to_add } ); > } > > if (@patrons_to_remove) { >- DelPatronsFromList( { list => $list, patron_list_patrons => \@patrons_to_remove } ); >+ del_patrons_from_list( { list => $list, patron_list_patrons => \@patrons_to_remove } ); > } > } > >@@ -77,8 +77,8 @@ if ( !$logged_in_user->can_see_patron_infos($patron) ) { > } > } > } >- @available_lists = GetPatronLists(); >- @available_lists = grep { !$list_id_lookup{ $_->patron_list_id } } @available_lists; >+ @available_lists = get_patron_lists(); >+ @available_lists = grep { ! $list_id_lookup{$_->patron_list_id} } @available_lists; > } > > $template->param( >diff --git a/patron_lists/patrons.pl b/patron_lists/patrons.pl >index f97fcf4662..c797e8a800 100755 >--- a/patron_lists/patrons.pl >+++ b/patron_lists/patrons.pl >@@ -23,7 +23,7 @@ use CGI qw ( -utf8 ); > > use C4::Auth qw( get_template_and_user ); > use C4::Output qw( output_html_with_http_headers ); >-use Koha::List::Patron qw( AddPatronList GetPatronLists ModPatronList ); >+use Koha::List::Patron qw( get_patron_list add_patron_list mod_patron_list ); > > my $cgi = CGI->new; > >@@ -40,16 +40,16 @@ my $id = $cgi->param('patron_list_id'); > my $name = $cgi->param('name'); > > if ($id) { >- my ($list) = GetPatronLists( { patron_list_id => $id } ); >+ my ($list) = get_patron_list( { patron_list_id => $id } ); > $template->param( list => $list ); > } > > if ($name) { > if ($id) { >- ModPatronList( { patron_list_id => $id, name => $name } ); >+ mod_patron_list( { patron_list_id => $id, name => $name } ); > } > else { >- AddPatronList( { name => $name } ); >+ add_patron_list( { name => $name } ); > } > > print $cgi->redirect('lists.pl'); >diff --git a/patroncards/create-pdf.pl b/patroncards/create-pdf.pl >index e994ddbbb2..4afd0897b2 100755 >--- a/patroncards/create-pdf.pl >+++ b/patroncards/create-pdf.pl >@@ -29,7 +29,7 @@ use autouse 'Data::Dumper' => qw(Dumper); > use C4::Context; > use C4::Creators; > use C4::Patroncards; >-use Koha::List::Patron qw( GetPatronLists ); >+use Koha::List::Patron qw( get_patron_list ); > use Koha::Patrons; > use Koha::Patron::Images; > >@@ -61,7 +61,7 @@ my $cardscount = 0; > > #Note fo bug 14138: Indenting follows in separate patch to ease review > eval { >-$pdf_file = (@label_ids || @borrower_numbers ? "card_single_" . scalar(@label_ids || @borrower_numbers) : "card_batch_$batch_id"); >+$pdf_file = (@label_ids || @borrower_numbers || $patronlist_id ? "card_single_" . scalar(@label_ids || @borrower_numbers || $patronlist_id) : "card_batch_$batch_id"); > > $pdf = C4::Creators::PDF->new(InitVars => 0); > my $batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id); >@@ -96,7 +96,7 @@ elsif (@borrower_numbers) { > } @borrower_numbers; > } > elsif ( $patronlist_id ) { >- my ($list) = GetPatronLists( { patron_list_id => $patronlist_id } ); >+ my $list = get_patron_list( { patron_list_id => $patronlist_id } ); > my @borrowerlist = $list->patron_list_patrons()->search_related('borrowernumber') > ->get_column('borrowernumber')->all(); > grep { >diff --git a/patroncards/manage.pl b/patroncards/manage.pl >index 4366955d87..f5a86a6ccf 100755 >--- a/patroncards/manage.pl >+++ b/patroncards/manage.pl >@@ -33,7 +33,7 @@ use C4::Creators qw( > html_table > ); > use C4::Labels; >-use Koha::List::Patron qw( GetPatronLists ); >+use Koha::List::Patron qw( get_patron_lists ); > > my $cgi = CGI->new; > my ( $template, $loggedinuser, $cookie ) = get_template_and_user( >@@ -117,7 +117,7 @@ else { # trap unsupported operations here > my $table = html_table($display_columns->{$card_element}, $db_rows); > > $template->param(print => 1) if ($card_element eq 'batch'); >-$template->param( patron_lists => [ GetPatronLists() ] ) if ($card_element eq 'batch'); >+$template->param( patron_lists => [ get_patron_lists() ] ) if ($card_element eq 'batch'); > > $template->param( > error => $errstr, >diff --git a/svc/members/add_to_list b/svc/members/add_to_list >index 2219717003..1642cec624 100755 >--- a/svc/members/add_to_list >+++ b/svc/members/add_to_list >@@ -22,7 +22,7 @@ use CGI; > > use C4::Auth qw( check_cookie_auth ); > use JSON qw( to_json ); >-use Koha::List::Patron qw( AddPatronList GetPatronLists AddPatronsToList ); >+use Koha::List::Patron qw( add_patron_list get_patron_lists add_patrons_to_list ); > > my $input = CGI->new; > >@@ -41,14 +41,14 @@ if ($add_to_patron_list) { > my $patron_list = []; > > if ( $add_to_patron_list eq 'new' ) { >- $patron_list = AddPatronList( { name => $new_patron_list } ); >+ $patron_list = add_patron_list( { name => $new_patron_list } ); > } > else { > $patron_list = >- [ GetPatronLists( { patron_list_id => $add_to_patron_list } ) ]->[0]; >+ [ get_patron_lists( { patron_list_id => $add_to_patron_list } ) ]->[0]; > } > >- my @patrons_added_to_list = AddPatronsToList( { list => $patron_list, borrowernumbers => \@borrowernumbers } ); >+ my @patrons_added_to_list = add_patrons_to_list( { list => $patron_list, borrowernumbers => \@borrowernumbers } ); > > $response->{patron_list} = { patron_list_id => $patron_list->patron_list_id, name => $patron_list->name }; > $response->{patrons_added_to_list} = scalar( @patrons_added_to_list ); >diff --git a/t/db_dependent/Members.t b/t/db_dependent/Members.t >index 70f4403cd5..a4c62237a4 100755 >--- a/t/db_dependent/Members.t >+++ b/t/db_dependent/Members.t >@@ -25,7 +25,7 @@ use Data::Dumper qw/Dumper/; > use C4::Context; > use Koha::Database; > use Koha::Holds; >-use Koha::List::Patron qw( AddPatronList AddPatronsToList ); >+use Koha::List::Patron qw( add_patron_list add_patrons_to_list ); > use Koha::Patrons; > use Koha::Patron::Relationship; > >@@ -214,14 +214,14 @@ my $anonymous_patron = Koha::Patron->new({ categorycode => 'CIVILIAN', branchcod > t::lib::Mocks::mock_preference('AnonymousPatron', $anonymous_patron); > > my $owner = Koha::Patron->new({ categorycode => 'STAFFER', branchcode => $library2->{branchcode} })->store->borrowernumber; >-my $list1 = AddPatronList( { name => 'Test List 1', owner => $owner } ); >+my $list1 = add_patron_list( { name => 'Test List 1', owner => $owner } ); > >-AddPatronsToList( { list => $list1, borrowernumbers => [$anonymous_patron] } ); >+add_patrons_to_list( { list => $list1, borrowernumbers => [$anonymous_patron] } ); > my $patstodel = GetBorrowersToExpunge( { patron_list_id => $list1->patron_list_id() } ); > is( scalar(@$patstodel), 0, 'Anonymous Patron not deleted from list' ); > > my @listpatrons = ($bor1inlist, $bor2inlist); >-AddPatronsToList( { list => $list1, borrowernumbers => \@listpatrons }); >+add_patrons_to_list( { list => $list1, borrowernumbers => \@listpatrons }); > $patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id() } ); > is( scalar(@$patstodel),0,'No staff deleted from list of all staff'); > Koha::Patrons->find($bor2inlist)->set({ categorycode => 'CIVILIAN' })->store; >diff --git a/t/db_dependent/PatronLists.t b/t/db_dependent/PatronLists.t >index b2edc8d8ff..a72fcfbf5b 100755 >--- a/t/db_dependent/PatronLists.t >+++ b/t/db_dependent/PatronLists.t >@@ -17,21 +17,22 @@ > > use Modern::Perl; > >-use Test::More tests => 12; >+use Test::More tests => 16; > use t::lib::TestBuilder; > use t::lib::Mocks; > > use Koha::Database; > use Koha::List::Patron >- qw( AddPatronList AddPatronsToList DelPatronList DelPatronsFromList GetPatronLists ModPatronList ); >+ qw( add_patron_list add_patrons_to_list del_patron_list del_patrons_from_list get_patron_list get_patron_lists mod_patron_list grant_patrons_access_to_list revoke_patrons_access_from_list ); > use Koha::Patrons; > > my $schema = Koha::Database->schema; > $schema->storage->txn_begin; > > my $builder = t::lib::TestBuilder->new; >+my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; > >-t::lib::Mocks::mock_userenv(); >+t::lib::Mocks::mock_userenv({branchcode => $branchcode}); > > # Create 10 sample borrowers > my @borrowers = (); >@@ -42,15 +43,24 @@ foreach (1..10) { > my $owner = $borrowers[0]->{borrowernumber}; > my $owner2 = $borrowers[1]->{borrowernumber}; > >-my @lists = GetPatronLists( { owner => $owner } ); >+my $owner3 = Koha::Patron->new( >+ { >+ surname => 'Test 1', >+ branchcode => $branchcode, >+ categorycode => $borrowers[0]->{categorycode} >+ } >+); >+$owner3->store(); >+ >+my @lists = get_patron_lists( { owner => $owner } ); > my $list_count_original = @lists; > >-my $list1 = AddPatronList( { name => 'Test List 1', owner => $owner } ); >-is( $list1->name(), 'Test List 1', 'AddPatronList works' ); >+my $list1 = add_patron_list( { name => 'Test List 1', owner => $owner } ); >+is( $list1->name(), 'Test List 1', 'add_patron_list works' ); > >-my $list2 = AddPatronList( { name => 'Test List 2', owner => $owner } ); >+my $list2 = add_patron_list( { name => 'Test List 2', owner => $owner } ); > >-ModPatronList( >+mod_patron_list( > { > patron_list_id => $list2->patron_list_id(), > name => 'Test List 3', >@@ -58,18 +68,22 @@ ModPatronList( > } > ); > $list2->discard_changes(); >-is( $list2->name(), 'Test List 3', 'ModPatronList works' ); >+is( $list2->name(), 'Test List 3', 'mod_patron_list works' ); >+ >+$list1 = >+ get_patron_list( { patron_list_id => $list1->patron_list_id() } ); >+is( $list1->name(), 'Test List 1', 'get_patron_list works' ); > >-AddPatronsToList( >+add_patrons_to_list( > { list => $list1, cardnumbers => [ map { $_->{cardnumber} } @borrowers ] } > ); > is( > scalar @borrowers, > $list1->patron_list_patrons()->search_related('borrowernumber')->all(), >- 'AddPatronsToList works for cardnumbers' >+ 'add_patrons_to_list works for cardnumbers' > ); > >-AddPatronsToList( >+add_patrons_to_list( > { > list => $list2, > borrowernumbers => [ map { $_->{borrowernumber} } @borrowers ] >@@ -78,49 +92,66 @@ AddPatronsToList( > is( > scalar @borrowers, > $list2->patron_list_patrons()->search_related('borrowernumber')->all(), >- 'AddPatronsToList works for borrowernumbers' >+ 'add_patrons_to_list works for borrowernumbers' > ); > > my $deleted_patron = $builder->build_object({ class => 'Koha::Patrons' }); > $deleted_patron->delete; >-my @result = AddPatronsToList({list => $list2,borrowernumbers => [ $deleted_patron->borrowernumber ]}); >+my @result = add_patrons_to_list({list => $list2,borrowernumbers => [ $deleted_patron->borrowernumber ]}); > is( scalar @result, 0,'Invalid borrowernumber not added'); >-@result = AddPatronsToList({list => $list2,cardnumbers => [ $deleted_patron->cardnumber ]}); >+@result = add_patrons_to_list({list => $list2,cardnumbers => [ $deleted_patron->cardnumber ]}); > is( scalar @result, 0,'Invalid cardnumber not added'); > > my @ids = > $list1->patron_list_patrons()->get_column('patron_list_patron_id')->all(); >-DelPatronsFromList( >+del_patrons_from_list( > { > list => $list1, > patron_list_patrons => \@ids, > } > ); > $list1->discard_changes(); >-is( $list1->patron_list_patrons()->count(), 0, 'DelPatronsFromList works.' ); >+is( $list1->patron_list_patrons()->count(), 0, 'del_patrons_from_list works.' ); > > my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >-AddPatronsToList({list => $list2,borrowernumbers => [ $patron->borrowernumber ]}); >+add_patrons_to_list({list => $list2,borrowernumbers => [ $patron->borrowernumber ]}); > @lists = $patron->get_lists_with_patron; > is( scalar @lists, 1, 'get_lists_with_patron works' ); > >-@lists = GetPatronLists( { owner => $owner } ); >-is( scalar @lists, $list_count_original + 2, 'GetPatronLists works' ); >+@lists = get_patron_lists( { owner => $owner } ); >+is( scalar @lists, $list_count_original + 2, 'get_patron_lists works' ); >+ >+my $list3 = add_patron_list( { name => 'Test List 3', owner => $owner2, shared => 0 } ); >+@lists = get_patron_lists( { owner => $owner } ); >+is( scalar @lists, $list_count_original + 2, 'get_patron_lists does not return non-shared list' ); >+ >+my $list4 = add_patron_list( { name => 'Test List 4', owner => $owner2, shared => 1 } ); >+@lists = get_patron_lists( { owner => $owner } ); >+is( scalar @lists, $list_count_original + 3, 'get_patron_lists does return shared list' ); >+ >+del_patron_list( { patron_list_id => $list1->patron_list_id(), owner => $owner } ); >+del_patron_list( { patron_list_id => $list2->patron_list_id(), owner => $owner } ); >+ >+$list1 = >+ get_patron_list( { patron_list_id => $list1->patron_list_id() } ); >+is( $list1, undef, 'del_patron_list works' ); > >-my $list3 = AddPatronList( { name => 'Test List 3', owner => $owner2, shared => 0 } ); >-@lists = GetPatronLists( { owner => $owner } ); >-is( scalar @lists, $list_count_original + 2, 'GetPatronLists does not return non-shared list' ); >+@lists = get_patron_lists(); >+my $lib_list_count = @lists; >+my $list5 = add_patron_list( { name => 'Test List 5', owner => $owner3->borrowernumber, shared => 2 } ); >+my $list6 = add_patron_list( { name => 'Test List 6', owner => $owner3->borrowernumber, shared => 3 } ); >+@lists = get_patron_lists(); >+is( scalar @lists, $lib_list_count + 1, 'get_patron_lists returns list shared with library' ); > >-my $list4 = AddPatronList( { name => 'Test List 4', owner => $owner2, shared => 1 } ); >-@lists = GetPatronLists( { owner => $owner } ); >-is( scalar @lists, $list_count_original + 3, 'GetPatronLists does return shared list' ); >+grant_patrons_access_to_list( { list => $list6, borrowernumbers => [ $patron->borrowernumber ] } ); > >-DelPatronList( { patron_list_id => $list1->patron_list_id(), owner => $owner } ); >-DelPatronList( { patron_list_id => $list2->patron_list_id(), owner => $owner } ); >+@lists = get_patron_lists({ owner => $patron->borrowernumber }); >+is( scalar @lists, $lib_list_count + 2, 'get_patron_lists returns list shared with individual, grant_patrons_access_to_list works' ); > >-@lists = >- GetPatronLists( { patron_list_id => $list1->patron_list_id(), owner => $owner } ); >-is( scalar @lists, 0, 'DelPatronList works' ); >+my @list_users = $list6->patron_list_users->get_column('patron_list_user_id')->all(); >+revoke_patrons_access_from_list({ list => $list6, patron_list_users => \@list_users }); >+@lists = get_patron_lists(); >+is( scalar @lists, $lib_list_count + 1, 'revoke_patrons_access_from_list works' ); > > $schema->storage->txn_rollback; > >diff --git a/tools/cleanborrowers.pl b/tools/cleanborrowers.pl >index 98ee38312e..fd05eb6f72 100755 >--- a/tools/cleanborrowers.pl >+++ b/tools/cleanborrowers.pl >@@ -40,7 +40,7 @@ use C4::Members qw( GetBorrowersToExpunge ); > use Koha::Old::Checkouts; > use Koha::Patron::Categories; > use Koha::Patrons; >-use Koha::List::Patron qw( GetPatronLists ); >+use Koha::List::Patron qw( get_patron_lists ); > > my $cgi = CGI->new; > >@@ -161,7 +161,7 @@ elsif ( $step == 3 ) { > testrun => ( $radio eq "testrun" ) ? 1: 0, > ); > } else { # $step == 1 >- my @all_lists = GetPatronLists(); >+ my @all_lists = get_patron_lists(); > my @non_empty_lists; > foreach my $list (@all_lists){ > my @patrons = $list->patron_list_patrons(); >diff --git a/tools/import_borrowers.pl b/tools/import_borrowers.pl >index a02f14dc40..09ea0cbb9b 100755 >--- a/tools/import_borrowers.pl >+++ b/tools/import_borrowers.pl >@@ -45,7 +45,7 @@ use Koha::Token; > use Koha::Libraries; > use Koha::Patron::Categories; > use Koha::Patron::Attribute::Types; >-use Koha::List::Patron qw( AddPatronList AddPatronsToList ); >+use Koha::List::Patron qw( add_patron_list add_patrons_to_list ); > > use Koha::Patrons::Import; > my $Import = Koha::Patrons::Import->new(); >@@ -139,8 +139,8 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) { > my $imported_borrowers = $return->{imported_borrowers}; > > if ( $imported && $createpatronlist ) { >- my $patronlist = AddPatronList({ name => $patronlistname }); >- AddPatronsToList({ list => $patronlist, borrowernumbers => $imported_borrowers }); >+ my $patronlist = add_patron_list({ name => $patronlistname }); >+ add_patrons_to_list({ list => $patronlist, borrowernumbers => $imported_borrowers }); > $template->param('patronlistname' => $patronlistname); > } > >diff --git a/tools/modborrowers.pl b/tools/modborrowers.pl >index 36c893b416..fe5e2e506f 100755 >--- a/tools/modborrowers.pl >+++ b/tools/modborrowers.pl >@@ -32,7 +32,7 @@ use C4::Koha qw( GetAuthorisedValues ); > use C4::Members; > use C4::Output qw( output_html_with_http_headers ); > use Koha::DateUtils qw( dt_from_string ); >-use Koha::List::Patron qw( GetPatronLists ); >+use Koha::List::Patron qw( get_patron_lists ); > use Koha::Libraries; > use Koha::Patron::Categories; > use Koha::Patron::Debarments qw( AddDebarment DelDebarment ); >@@ -89,7 +89,7 @@ if ( $op eq 'show' ) { > } > } elsif ( my $patron_list_id = $input->param('patron_list_id') ){ > # User selected a patron list >- my ($list) = GetPatronLists( { patron_list_id => $patron_list_id } ); >+ my ($list) = get_patron_lists( { patron_list_id => $patron_list_id } ); > @patronidnumbers = > $list->patron_list_patrons()->search_related('borrowernumber') > ->get_column('cardnumber')->all(); >@@ -459,7 +459,7 @@ if ( $op eq 'do' ) { > $template->param( errors => \@errors ); > } else { > >- $template->param( patron_lists => [ GetPatronLists() ] ); >+ $template->param( patron_lists => [ get_patron_lists() ] ); > } > > $template->param( >-- >2.34.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 32105
:
149475
|
160679
|
160783