From 2ae4627085c5311ac10856550ccfc72548352d56 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Fri, 30 Jun 2017 15:30:12 +0000 Subject: [PATCH] Bug 18743 - Removed library filter in Acquisition suggestions when IndependentBranches enabled Also ensured that when a superlibrarian is logged in then suggestions from all branches are displayed with IndependentBranches being either on or off, as this syspref does not affect what suggestions superlibrarians can see. But when non-superlibrarian user with access to the acquisitions module visits it when IndependentBranches is enabled then only suggestions of the branch they are logged in with are displayed. If non-superlibrarian users log in when IndependentBranches is not enabled then suggestions from all branches are displayed. Note: The library filter in the 'Organize by' area (which is displayed when multiple branches suggestions are displayed according to the aforementioned logic) successfully splits the suggestions into different tabs with the correct number of suggestions for each branch displayed in each tab. Test plan: 1. Create 2 suggestions a library branch (which I will refer to in this test plan as branch A) 2. Create 1 suggestion for a different branch (which I will refer to as branch B) 3. Log into staff client as superlibrarian with either branch and ensure the IndependentBranches syspref is set to 'yes' 4. Go to Acquisitions->Suggestions Management 5. Notice that suggestions from branch A and B are displayed 6. In the Organize by are click to filter by library and click go 7. Notice that one tab says (2) whilst the other tab says (1) with each tab containing the relevant suggestions to that branch 8. Now change the IndependentBranches syspref to 'no' 9. Repeat steps 4, 5, 6, 7 noticing the same outcome in step 7 10. Log out and log back into staff client in branch A as a non-superlibrarian user who has access to the Acquisitions module 11. Currently IndependentBranches is set to 'no' so go to Acquisitions->Suggestions Management 12. Repeat steps 5, 6, 7 and notice the same outcome as step 7 13. Change IndependentBranches to 'yes' 14. Go to Acquisitions->Suggestions Management 15. Notice that only suggestions from branch A (the branch you are logged in with) are displayed. This is because when IndependentBranches is enabled non-superlibrarians do not need to see suggestions from other branches 16. Also noticethat there is no 'library' option in the 'Organized by' area. This is because only suggestions from the current branch are displayed and so organizing by library is redundant. Sponsored-by: Catalyst IT --- C4/Suggestions.pm | 15 +++++--- .../prog/en/modules/suggestion/suggestion.tt | 30 ++++++++------- suggestion/suggestion.pl | 45 +++++++++++++++++----- 3 files changed, 62 insertions(+), 28 deletions(-) diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm index 1ea2339..5d160f4 100644 --- a/C4/Suggestions.pm +++ b/C4/Suggestions.pm @@ -131,25 +131,30 @@ sub SearchSuggestion { } } + my $userenv = C4::Context->userenv; # filter on user branch if ( C4::Context->preference('IndependentBranches') ) { - my $userenv = C4::Context->userenv; - if ($userenv) { - if ( !C4::Context->IsSuperLibrarian() && !$suggestion->{branchcode} ) + if ( !C4::Context->IsSuperLibrarian() && $userenv ) { push @sql_params, $$userenv{branch}; push @query, q{ AND (suggestions.branchcode=? OR suggestions.branchcode='') }; + }else{ + if ( defined $suggestion->{branchcode} && $suggestion->{branchcode} ) { + unless ( $suggestion->{branchcode} eq '__ANY__' ) { + push @sql_params, $suggestion->{branchcode}; + push @query, qq{ AND suggestions.branchcode=? }; + } + } } - } } else { if ( defined $suggestion->{branchcode} && $suggestion->{branchcode} ) { unless ( $suggestion->{branchcode} eq '__ANY__' ) { push @sql_params, $suggestion->{branchcode}; push @query, qq{ AND suggestions.branchcode=? }; } - } + } } # filter on nillable fields diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt index 85b0821..bd57f79 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt @@ -715,10 +715,12 @@ h4.local_collapse a { font-size : 80%; text-decoration: none; } fieldset.brief o [% ELSE %] [% END %] - [% IF ( displayby == "branchcode" ) %] - - [% ELSE %] - + [% IF ( IndependentBranches == 0 ) || (SuperLibrarian) %] + [% IF ( displayby == "branchcode" ) %] + + [% ELSE %] + + [% END %] [% END %] [% IF ( displayby == "itemtype" ) %] @@ -837,15 +839,17 @@ h4.local_collapse a { font-size : 80%; text-decoration: none; } fieldset.brief o [% IF ( budgetid_loo.selected ) %] [% ELSE %][% END %] [% END %] -
  • -
  • + [% IF (IndependentBranches == 0 ) %] +
  • +
  • + [% END %] diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl index fb97762..6595cb4 100755 --- a/suggestion/suggestion.pl +++ b/suggestion/suggestion.pl @@ -94,6 +94,8 @@ my $tabcode = $input->param('tabcode'); # filter informations which are not suggestion related. my $suggestion_ref = $input->Vars; +my $IndependentBranches; +my $SuperLibrarian; # get only the columns of Suggestion my $schema = Koha::Database->new()->schema; @@ -117,6 +119,23 @@ my ( $template, $borrowernumber, $cookie, $userflags ) = get_template_and_user( $borrowernumber = $input->param('borrowernumber') if ( $input->param('borrowernumber') ); $template->param('borrowernumber' => $borrowernumber); +#Check if IndependentBranches syspref is enabled and if it is then return IndependentBranches variable of 1 so library +#filtering does not occur in suggestion.tt +if ( Koha::Config::SysPrefs->find( 'IndependentBranches')->value) { + $IndependentBranches = 1; + $template->param( + IndependentBranches => $IndependentBranches + ); +} + +if (C4::Context->IsSuperLibrarian()) { + $SuperLibrarian =1; + $template->param( + SuperLibrarian => $SuperLibrarian + ); +} + +# ######################################### ## Operations ## @@ -225,7 +244,7 @@ elsif ( $op eq 'show' ) { } if ($op=~/else/) { $op='else'; - + $displayby||="STATUS"; delete $$suggestion_ref{'branchcode'} if($displayby eq "branchcode"); # distinct values of display by @@ -245,29 +264,35 @@ if ($op=~/else/) { my $reasonsloop = GetAuthorisedValues("SUGGEST"); foreach my $criteriumvalue ( @criteria_dv ) { # By default, display suggestions from current working branch - unless ( exists $$suggestion_ref{'branchcode'} ) { - $$suggestion_ref{'branchcode'} = C4::Context->userenv->{'branch'}; + + if ( $IndependentBranches && !$SuperLibrarian) { + unless ( $$suggestion_ref{'branchcode'} ) { + $$suggestion_ref{'branchcode'} = C4::Context->userenv->{'branch'}; + } } + my $definedvalue = defined $$suggestion_ref{$displayby} && $$suggestion_ref{$displayby} ne ""; next if ( $definedvalue && $$suggestion_ref{$displayby} ne $criteriumvalue ); $$suggestion_ref{$displayby} = $criteriumvalue; my $suggestions = &SearchSuggestion($suggestion_ref); + + my $count = 0; foreach my $suggestion (@$suggestions) { if ($suggestion->{budgetid}){ my $bud = GetBudget( $suggestion->{budgetid} ); $suggestion->{budget_name} = $bud->{budget_name} if $bud; } + $count++; } push @allsuggestions,{ - "suggestiontype"=>$criteriumvalue||"suggest", - "suggestiontypelabel"=>GetCriteriumDesc($criteriumvalue,$displayby)||"", - "suggestionscount"=>scalar(@$suggestions), - 'suggestions_loop'=>$suggestions, - 'reasonsloop' => $reasonsloop, - }; - + "suggestiontype"=>$criteriumvalue||"suggest", + "suggestiontypelabel"=>GetCriteriumDesc($criteriumvalue,$displayby)||"", + "suggestionscount"=>scalar(@$suggestions), + 'suggestions_loop'=>$suggestions, + 'reasonsloop' => $reasonsloop, + }; delete $$suggestion_ref{$displayby} unless $definedvalue; } -- 2.1.4