From e62d08c5a27fcdf9bef7f5bbf47d8796fd11a6e5 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 7 May 2018 07:10:28 -0400 Subject: [PATCH] Bug 20718: Add ability to have lists that are available to all list editors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some librarians would like to have lists that can be shared among staff that have the lists permission. Test Plan: 1) Apply this patch 2) Create some private, public and 'staff' lists 3) Note only staff that can edit lists have access to the 'staff' lists Signed-off-by: Christian Stelzenmüller --- C4/Utils/DataTables/VirtualShelves.pm | 21 +++++++++++- Koha/Virtualshelf.pm | 40 +++++++++++++++++++++- Koha/Virtualshelves.pm | 38 +++++++++++++++++--- .../en/modules/virtualshelves/addbybiblionumber.tt | 1 + .../prog/en/modules/virtualshelves/shelves.tt | 28 +++++++++++++-- virtualshelves/shelves.pl | 4 +++ 6 files changed, 123 insertions(+), 9 deletions(-) diff --git a/C4/Utils/DataTables/VirtualShelves.pm b/C4/Utils/DataTables/VirtualShelves.pm index 5a349326b1..a6c1798c2e 100644 --- a/C4/Utils/DataTables/VirtualShelves.pm +++ b/C4/Utils/DataTables/VirtualShelves.pm @@ -15,12 +15,30 @@ sub search { my $dt_params = $params->{dt_params}; # public is default - $type = 2 if not $type or $type != 1; + $type = 2 unless $type && ( $type == 1 || $type == 3 ); # If not logged in user, be carreful and set the borrowernumber to 0 # to prevent private lists lack my $loggedinuser = C4::Context->userenv->{'number'} || 0; + if ( $type == 3 ) { + my $permissions = + C4::Auth::haspermission( C4::Context->userenv->{id}, { lists => '*' } ); + + unless ( + $permissions + && ( $permissions->{superlibrarian} == 1 + || $permissions->{lists} == 1 ) + ) + { + return { + iTotalRecords => 0, + iTotalDisplayRecords => 0, + shelves => [], + }; + } + } + my ($iTotalRecords, $iTotalDisplayRecords); my $dbh = C4::Context->dbh; @@ -125,6 +143,7 @@ sub search { $shelf->{can_delete_shelf} = $s->can_be_deleted( $loggedinuser ); $shelf->{is_shared} = $s->is_shared; } + return { iTotalRecords => $iTotalRecords, iTotalDisplayRecords => $iTotalDisplayRecords, diff --git a/Koha/Virtualshelf.pm b/Koha/Virtualshelf.pm index c27c695ada..185e2b6608 100644 --- a/Koha/Virtualshelf.pm +++ b/Koha/Virtualshelf.pm @@ -47,7 +47,8 @@ Koha::Virtualshelf - Koha Virtualshelf Object class =cut our $PRIVATE = 1; -our $PUBLIC = 2; +our $PUBLIC = 2; +our $STAFF = 3; sub store { my ( $self ) = @_; @@ -71,16 +72,45 @@ sub store { return $self->SUPER::store( $self ); } +=head3 is_public + + my $bool = $shelf->is_public; + + Returns true if shelf has been made public. + +=cut + sub is_public { my ( $self ) = @_; return $self->category == $PUBLIC; } +=head3 is_private + + my $bool = $shelf->is_private; + + Returns true if shelf is a private shelf. + +=cut + sub is_private { my ( $self ) = @_; return $self->category == $PRIVATE; } +=head3 is_staff + + my $bool = $shelf->is_staff; + + Returns true if shelf is available to staff only. + +=cut + +sub is_staff { + my ( $self ) = @_; + return $self->category == $STAFF; +} + sub is_shelfname_valid { my ( $self ) = @_; @@ -221,6 +251,7 @@ sub can_be_viewed { return 1 if $self->is_public; return 0 unless $borrowernumber; return 1 if $self->owner == $borrowernumber; + return 1 if $self->category == 3; return $self->get_shares->search( { borrowernumber => $borrowernumber, @@ -243,8 +274,15 @@ sub can_be_deleted { sub can_be_managed { my ( $self, $borrowernumber ) = @_; + return 1 if $borrowernumber and $self->owner == $borrowernumber; + + my $patron = Koha::Patrons->find( $borrowernumber ); + my $permissions = C4::Auth::haspermission( $patron->userid, { lists => '*' } ); + return 1 + if $borrowernumber and $self->category == 3 and $permissions and $permissions->{lists} == 1; + return 0; } diff --git a/Koha/Virtualshelves.pm b/Koha/Virtualshelves.pm index 3dde3c35da..7678cc0de9 100644 --- a/Koha/Virtualshelves.pm +++ b/Koha/Virtualshelves.pm @@ -35,10 +35,6 @@ Koha::Virtualshelf - Koha Virtualshelf Object class =cut -=head3 type - -=cut - sub get_private_shelves { my ( $self, $params ) = @_; my $page = $params->{page}; @@ -62,7 +58,6 @@ sub get_private_shelves { ); } - sub get_public_shelves { my ( $self, $params ) = @_; my $page = $params->{page}; @@ -80,6 +75,31 @@ sub get_public_shelves { ); } +=head3 get_staff_shelves + + my $shelves = $virtual_shelves->get_staff_shelves( { page => $page, rows => $rowss ); + + Returns item lists that are visible to all staff that can manage patron lists + +=cut + +sub get_staff_shelves { + my ( $self, $params ) = @_; + my $page = $params->{page}; + my $rows = $params->{rows}; + + $self->search( + { + category => 3, + }, + { + group_by => 'shelfnumber', + order_by => 'shelfname', + ( ( $page and $rows ) ? ( page => $page, rows => $rows ) : () ), + } + ); +} + sub get_some_shelves { my ( $self, $params ) = @_; my $borrowernumber = $params->{borrowernumber} || 0; @@ -160,10 +180,18 @@ sub get_shelves_containing_record { ); } +=head3 _type + +=cut + sub _type { return 'Virtualshelve'; } +=head3 object_class + +=cut + sub object_class { return 'Koha::Virtualshelf'; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/addbybiblionumber.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/addbybiblionumber.tt index e43c50ed1f..35a14d7727 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/addbybiblionumber.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/addbybiblionumber.tt @@ -97,6 +97,7 @@ diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt index 076206554b..85607cb186 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt @@ -3,7 +3,8 @@ [% USE Koha %] [% USE KohaDates %] [% SET PRIVATE = 1 %] -[% SET PUBLIC = 2 %] +[% SET PUBLIC = 2 %] +[% SET STAFF = 3 %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] Koha › [% IF op == 'view' %]Lists › Contents of [% shelf.shelfname | html %][% ELSE %]Lists[% END %][% IF op == 'add_form' %] › Create new list[% END %][% IF op == 'edit_form' %] › Edit list [% shelf.shelfname | html %][% END %] @@ -48,6 +49,12 @@ [% ELSE %] Your lists [% END %] + [% ELSIF shelf AND shelf.is_staff %] › + [% IF op == 'view' %] + Staff lists + [% ELSE %] + Public lists + [% END %] [% ELSIF shelf AND shelf.is_public %] › [% IF op == 'view' %] Public lists @@ -301,6 +308,13 @@ [% ELSE %] [% END %] + + [% IF shelf.is_staff %] + + [% ELSE %] + + [% END %] + [% IF shelf.is_public %] [% ELSE %] @@ -335,6 +349,9 @@
@@ -451,6 +468,8 @@ $(document).ready(function(){ [% IF category == PUBLIC %] var type = [% PUBLIC | html %]; + [% ELSIF category == STAFF %] + var type = [% STAFF %]; [% ELSE %] var type = [% PRIVATE | html %]; [% END %] @@ -510,7 +529,9 @@ dtListResults.fnAddFilters("filter", 750); var tabs = $("#tabs").tabs({ - [% IF category == PUBLIC %] + [% IF category == STAFF %] + active: 2, + [% ELSIF category == PUBLIC %] active: 1, [% ELSE %] active: 0, @@ -523,6 +544,9 @@ } else if ( active == 1 ) { type = [% PUBLIC | html %]; dtListResults.fnDraw(); + } else if ( active == 2 ) { + type = [% STAFF %]; + dtListResults.fnDraw(); } } }); diff --git a/virtualshelves/shelves.pl b/virtualshelves/shelves.pl index d233eb1355..6d4c89f09b 100755 --- a/virtualshelves/shelves.pl +++ b/virtualshelves/shelves.pl @@ -346,6 +346,9 @@ if ( $op eq 'view' ) { } } +my $permissions = C4::Auth::haspermission( C4::Context->userenv->{id}, { lists => '*' } ); +my $can_manage_lists = $permissions && ( $permissions->{superlibrarian} == 1 || $permissions->{lists} == 1 ); + $template->param( op => $op, referer => $referer, @@ -354,6 +357,7 @@ $template->param( category => $category, print => scalar $query->param('print') || 0, csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc', used_for => 'export_records' }) ], + can_manage_lists => $can_manage_lists, ); output_html_with_http_headers $query, $cookie, $template->output; -- 2.11.0