From 9d5c7909408274b33db7ac3ffde3b24561633675 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 12 Apr 2017 09:56:22 -0300 Subject: [PATCH] Bug 18403: Deal with the DB user On first login, Koha explodes before the logged in user does not exist in DB. This patch deals with that by adding several checks when it's needed. Test plan: Use the DB user to create a superlibrarian user. The DB user should no be allowed to do anything else. --- C4/Auth.pm | 2 +- Koha/ArticleRequests.pm | 2 +- Koha/Libraries.pm | 3 ++- Koha/Patron/Discharge.pm | 2 +- Koha/Patron/Modifications.pm | 2 +- Koha/Patrons.pm | 2 +- Koha/Reviews.pm | 2 +- members/member-flags.pl | 7 +++++-- members/memberentry.pl | 9 +++++---- members/moremember.pl | 8 +++++--- 10 files changed, 23 insertions(+), 16 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 61b7cfc..99a6dee 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -256,7 +256,7 @@ sub get_template_and_user { ); } - $template->param( "USER_INFO" => $patron->unblessed ); + $template->param( "USER_INFO" => $patron->unblessed ) if $borrowernumber != 0; my $all_perms = get_all_subpermissions(); diff --git a/Koha/ArticleRequests.pm b/Koha/ArticleRequests.pm index 27be468..c43c23e 100644 --- a/Koha/ArticleRequests.pm +++ b/Koha/ArticleRequests.pm @@ -51,7 +51,7 @@ sub search_limited { my $userenv = C4::Context->userenv; my @restricted_branchcodes; - if ( $userenv ) { + if ( $userenv and $userenv->{number} ) { my $logged_in_user = Koha::Patrons->find( $userenv->{number} ); @restricted_branchcodes = $logged_in_user->libraries_where_can_see_patrons; } diff --git a/Koha/Libraries.pm b/Koha/Libraries.pm index 5d88c6b..38a61a4 100644 --- a/Koha/Libraries.pm +++ b/Koha/Libraries.pm @@ -46,7 +46,8 @@ sub search_filtered { my ( $self, $params, $attributes ) = @_; my @branchcodes; - if ( my $userenv = C4::Context->userenv ) { + my $userenv = C4::Context->userenv; + if ( $userenv and $userenv->{number} ) { my $only_from_group = $params->{only_from_group}; if ( $only_from_group ) { my $logged_in_user = Koha::Patrons->find( $userenv->{number} ); diff --git a/Koha/Patron/Discharge.pm b/Koha/Patron/Discharge.pm index 52d3abf..81d73a6 100644 --- a/Koha/Patron/Discharge.pm +++ b/Koha/Patron/Discharge.pm @@ -183,7 +183,7 @@ sub search_limited { my ( $params, $attributes ) = @_; my $userenv = C4::Context->userenv; my @restricted_branchcodes; - if ( $userenv ) { + if ( $userenv and $userenv->{number} ) { my $logged_in_user = Koha::Patrons->find( $userenv->{number} ); @restricted_branchcodes = $logged_in_user->libraries_where_can_see_patrons; } diff --git a/Koha/Patron/Modifications.pm b/Koha/Patron/Modifications.pm index 1a35894..6419796 100644 --- a/Koha/Patron/Modifications.pm +++ b/Koha/Patron/Modifications.pm @@ -54,7 +54,7 @@ sub pending_count { my $userenv = C4::Context->userenv; my @branchcodes; - if ( $userenv ) { + if ( $userenv and $userenv->{number} ) { my $logged_in_user = Koha::Patrons->find( $userenv->{number} ); if ($branchcode) { return 0 unless $logged_in_user->can_see_patrons_from($branchcode); diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm index 9ae5efd..22ba83a 100644 --- a/Koha/Patrons.pm +++ b/Koha/Patrons.pm @@ -54,7 +54,7 @@ sub search_limited { my $userenv = C4::Context->userenv; my @restricted_branchcodes; - if ( $userenv ) { + if ( $userenv and $userenv->{number} ) { my $logged_in_user = Koha::Patrons->find( $userenv->{number} ); @restricted_branchcodes = $logged_in_user->libraries_where_can_see_patrons; } diff --git a/Koha/Reviews.pm b/Koha/Reviews.pm index a5fcae3..1e980a9 100644 --- a/Koha/Reviews.pm +++ b/Koha/Reviews.pm @@ -48,7 +48,7 @@ sub search_limited { my $userenv = C4::Context->userenv; my @restricted_branchcodes; - if ( $userenv ) { + if ( $userenv and $userenv->{number} ) { my $logged_in_user = Koha::Patrons->find( $userenv->{number} ); @restricted_branchcodes = $logged_in_user->libraries_where_can_see_patrons; } diff --git a/members/member-flags.pl b/members/member-flags.pl index 95723d1..857f2ad 100755 --- a/members/member-flags.pl +++ b/members/member-flags.pl @@ -41,8 +41,11 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user({ debug => 1, }); -my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in"; -output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } ); +my $userenv = C4::Context->userenv; +if ( $userenv and $userenv->{number} ) { # Allow DB user to create a superlibrarian patron + my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in"; + output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } ); +} my %member2; $member2{'borrowernumber'}=$member; diff --git a/members/memberentry.pl b/members/memberentry.pl index 755c4f2..bda4f96 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -76,9 +76,12 @@ my ($template, $loggedinuser, $cookie) }); my $borrowernumber = $input->param('borrowernumber'); -my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in"; 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 } ); +my $userenv = C4::Context->userenv; +if ( $userenv and $userenv->{number} ) { # Allow DB user to create a superlibrarian patron + my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in"; + output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } ); +} if ( C4::Context->preference('SMSSendDriver') eq 'Email' ) { my @providers = Koha::SMS::Providers->search(); @@ -106,8 +109,6 @@ my $step = $input->param('step') || 0; my @errors; my $borrower_data; my $NoUpdateLogin; -my $userenv = C4::Context->userenv; - ## Deal with debarments $template->param( diff --git a/members/moremember.pl b/members/moremember.pl index 6b08ef6..5e1dcd0 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -119,9 +119,12 @@ my $borrowernumber = $input->param('borrowernumber'); my $error = $input->param('error'); $template->param( error => $error ) if ( $error ); -my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in"; 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 } ); +my $userenv = C4::Context->userenv; +if ( $userenv and $userenv->{number} ) { # Allow DB user to create a superlibrarian patron + my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in"; + output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } ); +} my $issues = $patron->checkouts; my $balance = $patron->account->balance; @@ -196,7 +199,6 @@ $bor{'borrowernumber'} = $borrowernumber; # Converts the branchcode to the branch name my $samebranch; if ( C4::Context->preference("IndependentBranches") ) { - my $userenv = C4::Context->userenv; if ( C4::Context->IsSuperLibrarian() ) { $samebranch = 1; } -- 2.9.3