Bugzilla – Attachment 122341 Details for
Bug 26383
Koha::Patron->is_superlibrarian is not optimal
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26383: WIP Replace C4::Context->IsSuperLibrarian with Koha::Patron->is_superlibrarian
Bug-26383-WIP-Replace-C4Context-IsSuperLibrarian-w.patch (text/plain), 11.85 KB, created by
Jonathan Druart
on 2021-06-23 14:29:59 UTC
(
hide
)
Description:
Bug 26383: WIP Replace C4::Context->IsSuperLibrarian with Koha::Patron->is_superlibrarian
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2021-06-23 14:29:59 UTC
Size:
11.85 KB
patch
obsolete
>From a06bd071abf54e5a62860ae55306adc6ff0e40dd Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 23 Jun 2021 16:28:48 +0200 >Subject: [PATCH] Bug 26383: WIP Replace C4::Context->IsSuperLibrarian with > Koha::Patron->is_superlibrarian > >--- > C4/Acquisition.pm | 11 +++++++---- > C4/Circulation.pm | 8 +++++--- > Koha/Patron.pm | 3 ++- > acqui/basket.pl | 2 +- > catalogue/detail.pl | 6 +++--- > catalogue/moredetail.pl | 10 ++++++---- > catalogue/search.pl | 1 + > cataloguing/additem.pl | 10 ++++++---- > circ/branchtransfers.pl | 3 ++- > members/deletemem.pl | 2 +- > members/discharges.pl | 4 ++-- > members/member-flags.pl | 2 +- > 12 files changed, 37 insertions(+), 25 deletions(-) > >diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm >index 1d6f350487c..03fda80f99d 100644 >--- a/C4/Acquisition.pm >+++ b/C4/Acquisition.pm >@@ -1777,8 +1777,9 @@ sub SearchOrders { > } > > my $userenv = C4::Context->userenv; >- if ( C4::Context->preference("IndependentBranches") ) { >- unless ( C4::Context->IsSuperLibrarian() ) { >+ if ( C4::Context->preference("IndependentBranches") && $userenv ) { >+ my $logged_in_user = Koha::Patrons->find($userenv->{number}); >+ unless ( $logged_in_user->is_superlibrarian ) { > $query .= q{ > AND ( > borrowers.branchcode = ? >@@ -2286,8 +2287,10 @@ sub GetHistory { > $query .= ' AND aqbasket.basketno IN ( ' . join( ',', map { $_->basketno } @baskets ) . ' )'; > } > >- if ( C4::Context->preference("IndependentBranches") ) { >- unless ( C4::Context->IsSuperLibrarian() ) { >+ my $userenv = C4::Context->userenv; >+ if ( C4::Context->preference("IndependentBranches") && $userenv ) { >+ my $logged_in_user = Koha::Patrons->find($userenv->{number}); >+ unless ( $logged_in_user->is_superlibrarian ) { > $query .= " AND (borrowers.branchcode = ? OR borrowers.branchcode ='' ) "; > push @query_params, C4::Context->userenv->{branch}; > } >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index 89e2737f56a..f77c5704914 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -1070,9 +1070,11 @@ sub CanBookBeIssued { > $needsconfirmation{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'confirm' ); > $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' ); > } >- if ( C4::Context->preference("IndependentBranches") ) { >- my $userenv = C4::Context->userenv; >- unless ( C4::Context->IsSuperLibrarian() ) { >+ >+ my $userenv = C4::Context->userenv; >+ if ( C4::Context->preference("IndependentBranches") && $userenv ) { >+ my $logged_in_user = Koha::Patrons->find($userenv->{number}); >+ unless ( $logged_in_user->is_superlibrarian ) { > my $HomeOrHoldingBranch = C4::Context->preference("HomeOrHoldingBranch"); > if ( $item_object->$HomeOrHoldingBranch ne $userenv->{branch} ){ > $issuingimpossible{ITEMNOTSAMEBRANCH} = 1; >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index a8379f62281..b3a6dad4d07 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -1475,7 +1475,8 @@ Return true if the patron is a superlibrarian. > > sub is_superlibrarian { > my ($self) = @_; >- return $self->has_permission( { superlibrarian => 1 } ) ? 1 : 0; >+ >+ return ( $self->flags // 0 ) % 2; > } > > =head3 is_adult >diff --git a/acqui/basket.pl b/acqui/basket.pl >index 09545ee3cc4..9b1c83d7adf 100755 >--- a/acqui/basket.pl >+++ b/acqui/basket.pl >@@ -252,7 +252,7 @@ if ( $op eq 'list' ) { > # get librarian branch... > if ( C4::Context->preference("IndependentBranches") ) { > my $userenv = C4::Context->userenv; >- unless ( C4::Context->IsSuperLibrarian() ) { >+ unless ( $logged_in_patron->is_superlibrarian ) { > my $validtest = ( $basket->{creationdate} eq '' ) > || ( $userenv->{branch} eq $basket->{branch} ) > || ( $userenv->{branch} eq '' ) >diff --git a/catalogue/detail.pl b/catalogue/detail.pl >index 0ba37e7253c..44b35794337 100755 >--- a/catalogue/detail.pl >+++ b/catalogue/detail.pl >@@ -182,9 +182,9 @@ my $dbh = C4::Context->dbh; > > my @all_items = GetItemsInfo( $biblionumber ); > my @items; >-my $patron = Koha::Patrons->find( $borrowernumber ); >+my $logged_in_patron = Koha::Patrons->find( $borrowernumber ); > for my $itm (@all_items) { >- push @items, $itm unless ( $itm->{itemlost} && $patron->category->hidelostitems && !$showallitems); >+ push @items, $itm unless ( $itm->{itemlost} && $logged_in_patron->category->hidelostitems && !$showallitems); > } > > # flag indicating existence of at least one item linked via a host record >@@ -380,7 +380,7 @@ foreach my $item (@items) { > > if ( C4::Context->preference('IndependentBranches') ) { > my $userenv = C4::Context->userenv(); >- if ( not C4::Context->IsSuperLibrarian() >+ if ( not $logged_in_patron->is_superlibrarian > and $userenv->{branch} ne $item->{homebranch} ) { > $item->{cannot_be_edited} = 1; > } >diff --git a/catalogue/moredetail.pl b/catalogue/moredetail.pl >index 94a7eab12f5..93316dde24c 100755 >--- a/catalogue/moredetail.pl >+++ b/catalogue/moredetail.pl >@@ -108,10 +108,10 @@ my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber); > my $fw = GetFrameworkCode($biblionumber); > my @all_items= GetItemsInfo($biblionumber); > my @items; >-my $patron = Koha::Patrons->find( $loggedinuser ); >+my $logged_in_patron = Koha::Patrons->find( $loggedinuser ); > for my $itm (@all_items) { > push @items, $itm unless ( $itm->{itemlost} && >- $patron->category->hidelostitems && >+ $logged_in_patron->category->hidelostitems && > !$showallitems && > ($itemnumber != $itm->{itemnumber})); > } >@@ -230,8 +230,10 @@ foreach my $item (@items){ > if (C4::Context->preference("IndependentBranches")) { > #verifying rights > my $userenv = C4::Context->userenv(); >- unless (C4::Context->IsSuperLibrarian() or ($userenv->{'branch'} eq $item->{'homebranch'})) { >- $item->{'nomod'}=1; >+ unless ( $logged_in_patron->is_superlibrarian() >+ or ( $userenv->{'branch'} eq $item->{'homebranch'} ) ) >+ { >+ $item->{'nomod'} = 1; > } > } > if ($item->{'datedue'}) { >diff --git a/catalogue/search.pl b/catalogue/search.pl >index cd098beac2d..788f7f4b9cb 100755 >--- a/catalogue/search.pl >+++ b/catalogue/search.pl >@@ -186,6 +186,7 @@ my ($template, $borrowernumber, $cookie) = get_template_and_user({ > } > ); > >+my $logged_in_patron = Koha::Patrons->find($borrowernumber); > my $lang = C4::Languages::getlanguage($cgi); > > if (C4::Context->preference("marcflavour") eq "UNIMARC" ) { >diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl >index b1e03573988..b6e447e8f42 100755 >--- a/cataloguing/additem.pl >+++ b/cataloguing/additem.pl >@@ -425,7 +425,7 @@ if (not defined $userflags) { > $userflags = ($frameworkcode eq 'FA') ? "fast_cataloging" : "edit_items"; > } > >-my ($template, $loggedinuser, $cookie) >+my ($template, $borrowernumber, $cookie) > = get_template_and_user({template_name => "cataloguing/additem.tt", > query => $input, > type => "intranet", >@@ -434,10 +434,12 @@ my ($template, $loggedinuser, $cookie) > > > # Does the user have a restricted item editing permission? >-my $uid = Koha::Patrons->find( $loggedinuser )->userid; >+my $logged_in_patron = Koha::Patrons->find( $borrowernumber ); >+my $is_superlibrarian = $logged_in_patron->is_superlibrarian; >+my $uid = $logged_in_patron->userid; > my $restrictededition = $uid ? haspermission($uid, {'editcatalogue' => 'edit_items_restricted'}) : undef; > # In case user is a superlibrarian, editing is not restricted >-$restrictededition = 0 if ($restrictededition != 0 && C4::Context->IsSuperLibrarian()); >+$restrictededition = 0 if ($restrictededition != 0 && $is_superlibrarian); > # In case user has fast cataloging permission (and we're in fast cataloging), editing is not restricted > $restrictededition = 0 if ($restrictededition != 0 && $frameworkcode eq 'FA' && haspermission($uid, {'editcatalogue' => 'fast_cataloging'})); > >@@ -855,7 +857,7 @@ foreach my $field (@fields) { > if (($field->tag eq $branchtagfield) && ($subfieldcode eq $branchtagsubfield) && C4::Context->preference("IndependentBranches")) { > #verifying rights > my $userenv = C4::Context->userenv(); >- unless (C4::Context->IsSuperLibrarian() or (($userenv->{'branch'} eq $subfieldvalue))){ >+ unless ($is_super_librarian or (($userenv->{'branch'} eq $subfieldvalue))){ > $this_row{'nomod'} = 1; > } > } >diff --git a/circ/branchtransfers.pl b/circ/branchtransfers.pl >index 9a652750de9..a8bfc8f515f 100755 >--- a/circ/branchtransfers.pl >+++ b/circ/branchtransfers.pl >@@ -63,8 +63,9 @@ my ($template, $user, $cookie, $flags ) = get_template_and_user( > } > ); > >+my $logged_in_patron = Koha::Patrons->find($user); > # Check transfers is allowed from system preference >-if ( C4::Context->preference("IndependentBranchesTransfers") && !C4::Context->IsSuperLibrarian() ) { >+if ( C4::Context->preference("IndependentBranchesTransfers") && !$logged_in_patron->is_superlibrarian() ) { > print $query->redirect("/cgi-bin/koha/errors/403.pl"); > exit; > } >diff --git a/members/deletemem.pl b/members/deletemem.pl >index 78fd7f1dca8..48667cff622 100755 >--- a/members/deletemem.pl >+++ b/members/deletemem.pl >@@ -78,7 +78,7 @@ if ($patron->category->category_type eq "S") { > > if (C4::Context->preference("IndependentBranches")) { > my $userenv = C4::Context->userenv; >- if ( !C4::Context->IsSuperLibrarian() && $patron->branchcode){ >+ if ( !$logged_in_patron->is_superlibrarian && $patron->branchcode){ > unless ($userenv->{branch} eq $patron->branchcode){ > print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_OTHERLIBRARY"); > exit 0; # Exit without error >diff --git a/members/discharges.pl b/members/discharges.pl >index de19751ee08..5aeb04b6769 100755 >--- a/members/discharges.pl >+++ b/members/discharges.pl >@@ -35,15 +35,15 @@ my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user({ > flagsrequired => { borrowers => 'edit_borrowers' }, > }); > >+my $logged_in_user = Koha::Patrons->find( $loggedinuser ); > my $branchcode = > ( C4::Context->preference("IndependentBranches") >- and not C4::Context->IsSuperLibrarian() ) >+ and not $logged_in_user->is_superlibrarian ) > ? C4::Context->userenv()->{'branch'} > : undef; > > if( $op eq 'allow' ) { > my $borrowernumber = $input->param('borrowernumber'); >- my $logged_in_user = Koha::Patrons->find( $loggedinuser ); > my $patron = Koha::Patrons->find($borrowernumber); > output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } ); > Koha::Patron::Discharge::discharge({ >diff --git a/members/member-flags.pl b/members/member-flags.pl >index e34384044c2..5e4363a9db5 100755 >--- a/members/member-flags.pl >+++ b/members/member-flags.pl >@@ -84,7 +84,7 @@ if ($input->param('newflags')) { > my $old_flags = $patron->flags // 0; > if( ( $old_flags == 1 || $module_flags == 1 ) && > $old_flags != $module_flags ) { >- die "Non-superlibrarian is changing superlibrarian privileges" if !C4::Context->IsSuperLibrarian && C4::Context->preference('ProtectSuperlibrarianPrivileges'); # Interface should not allow this, so we can just die here >+ die "Non-superlibrarian is changing superlibrarian privileges" if !$logged_in_user->is_superlibrarian() && C4::Context->preference('ProtectSuperlibrarianPrivileges'); # Interface should not allow this, so we can just die here > } > $sth->execute($module_flags, $member); > >-- >2.20.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 26383
: 122341