From a037b80ee325e3828141ebc15533e8f3d159de5a 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. Signed-off-by: Signed-off-by: Jon McGowan Bug 18403: Fix patron creation memberentry.pl can be called to create a new patron, in that case the patron does not exist yet. Signed-off-by: Signed-off-by: Jon McGowan Signed-off-by: Jonathan Druart --- 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 | 8 +++++--- members/moremember.pl | 8 +++++--- 10 files changed, 23 insertions(+), 15 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 7903099bf4..f642264cfb 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -254,7 +254,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 27be4680e1..c43c23ea8e 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 5d88c6bb0d..38a61a4325 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 44bcc5dcca..a1f4942be1 100644 --- a/Koha/Patron/Discharge.pm +++ b/Koha/Patron/Discharge.pm @@ -184,7 +184,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 730056862a..5b424cd7d0 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 79d5ab8598..fe8dd524a1 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 a5fcae3323..1e980a90ff 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 21618e50e9..178415fb61 100755 --- a/members/member-flags.pl +++ b/members/member-flags.pl @@ -45,8 +45,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 b72f8daf2c..228bc5ed0f 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -76,7 +76,6 @@ 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); if ( C4::Context->preference('SMSSendDriver') eq 'Email' ) { @@ -107,7 +106,6 @@ my $borrower_data; my $NoUpdateLogin; my $userenv = C4::Context->userenv; - ## Deal with debarments $template->param( debarments => scalar GetDebarments( { borrowernumber => $borrowernumber } ) ); @@ -154,7 +152,11 @@ $template->param( "quickadd" => 1 ) if ( $quickadd ); $template->param( "duplicate" => 1 ) if ( $op eq 'duplicate' ); $template->param( "checked" => 1 ) if ( defined($nodouble) && $nodouble eq 1 ); if ( $op eq 'modify' or $op eq 'save' or $op eq 'duplicate' ) { - output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } ); + if ( $patron and $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 } ); + } + $borrower_data = $patron->unblessed; $borrower_data->{category_type} = $patron->category->category_type; } diff --git a/members/moremember.pl b/members/moremember.pl index 2f2e14234a..29eea1fe4e 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -121,9 +121,12 @@ $borrowernumber = HTML::Entities::encode($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; @@ -202,7 +205,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.39.5