From 4f96b7c330886c8213c7df7b21dd5fdf42b87537 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 24 Mar 2015 17:01:30 +0100 Subject: [PATCH] Bug 4137: Fix the OPACViewOthersSuggestions behavior This pref does not work at all, the interface let the user choose to list all suggestions, but whatever he chooses the suggestion list is the same. This patch cleans a bit the suggestedby management. There are a lot of cases to test, because linked to 2 prefs: AnonSuggestions and OPACViewOthersSuggestions. 1/ AnonSuggestions = 0 and OPACViewOthersSuggestions = 0 - A non logged in user is not able to make a suggestion. - A logged in user is not able to see suggestions made by someone else. 2/ AnonSuggestions = 0 and OPACViewOthersSuggestions = 1 - A non logged in user is not able to make a suggestion. - A logged in user is able to see suggestions made by someone else. 3/ AnonSuggestions = 1 and OPACViewOthersSuggestions = 0 - A non logged in user is able to make a suggestion. The suggestedby field will be filled with the AnonymousPatron pref value. He is not able to see suggestions, even the ones made by AnonymousPatron. - A logged in user is not able to see suggestions made by someone else. 4/ AnonSuggestions = 1 and OPACViewOthersSuggestions = 1 - A non logged in user is able to make a suggestion. He is able to see all suggestions. - A logged in user is able to see suggestions made by someone else. In all cases a logged in user should be able to search for suggestions (except if he is not able to see them). Signed-off-by: Bernardo Gonzalez Kriegel All use cases tested, work as expected No errors Only comment is perhaps (in the future) a gracefull failure when AnonymousPatron is not set, or has '0' value Message is DBIx::Class::ResultSet::create(): Column 'suggestedby' cannot be null at ... Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi (cherry picked from commit be35039b55a351c97f2c1f9a5b373cb26ac5e0b0) Signed-off-by: Chris Cormack Signed-off-by: Liz --- C4/Auth.pm | 1 - .../bootstrap/en/includes/usermenu.inc | 12 ++-- .../bootstrap/en/modules/opac-suggestions.tt | 57 +++++++++++-------- opac/opac-suggestions.pl | 46 ++++++++++----- 4 files changed, 72 insertions(+), 44 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 5ffab489c5..e5432b10c4 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -477,7 +477,6 @@ sub get_template_and_user { OPACShelfBrowser => "" . C4::Context->preference("OPACShelfBrowser"), OPACURLOpenInNewWindow => "" . C4::Context->preference("OPACURLOpenInNewWindow"), OPACUserCSS => "" . C4::Context->preference("OPACUserCSS"), - OPACViewOthersSuggestions => "" . C4::Context->preference("OPACViewOthersSuggestions"), OpacAuthorities => C4::Context->preference("OpacAuthorities"), OPACBaseURL => ( $using_https ? "https://" : "http://" ) . $opac_base_url, opac_css_override => $ENV{'OPAC_CSS_OVERRIDE'}, diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/usermenu.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/usermenu.inc index 182543b3b6..c509e374d8 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/usermenu.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/usermenu.inc @@ -68,14 +68,12 @@ [% END # / opacreadinghistory %] [% IF Koha.Preference( 'suggestion' ) == 1 %] - [% UNLESS ( Koha.Preference( 'AnonSuggestions' ) == 1 ) %] - [% IF ( suggestionsview ) %] -
  • - [% ELSE %] -
  • - [% END %] - your purchase suggestions
  • + [% IF ( suggestionsview ) %] +
  • + [% ELSE %] +
  • [% END %] + your purchase suggestions
  • [% END %] [% IF ( EnhancedMessagingPreferences ) %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt index 8ae921413f..e249709472 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt @@ -92,7 +92,7 @@
    - + Cancel
    @@ -127,29 +127,36 @@ [% IF ( deleted ) %]
    The selected suggestions have been deleted.
    [% END %] [% IF ( suggestions_loop ) %] - [% IF Koha.Preference( 'OPACViewOthersSuggestions' ) == 1 %] -
    -
    - - - -
    - - -
    -
    -
    - [% END %] +
    +
    + + + [% IF Koha.Preference( 'OPACViewOthersSuggestions' ) == 1 %] + [% IF loggedinusername %] + +
    + + +
    + [% END %] + [% END %] +
    +
    -
    - [% IF ( loggedinusername || ( Koha.Preference( 'AnonSuggestions' ) == 1 ) ) %] + [% IF ( loggedinusername || ( Koha.Preference( 'AnonSuggestions' ) == 1 ) ) %] +
    New purchase suggestion - [% END %] -
    +
    + [% END %] [% IF ( loggedinusername ) %]
    @@ -237,7 +244,11 @@ [% END %] [% ELSE %] -

    There are no pending purchase suggestions.

    + [% UNLESS Koha.Preference( 'OPACViewOthersSuggestions' ) or $loggedinusername %] +

    You are not authorized to see pending purchase suggestions.

    + [% ELSE %] +

    There are no pending purchase suggestions.

    + [% END %] [% IF ( loggedinusername || ( Koha.Preference( 'AnonSuggestions' ) == 1 ) ) %]

    New purchase suggestion

    [% END %] @@ -280,7 +291,7 @@ [% IF ( loggedinusername ) %]null,[% END %] { "sType": "anti-the" }, null, - [% IF ( OPACViewOthersSuggestions ) %]null,[% END %] + [% IF Koha.Preference( 'OPACViewOthersSuggestions' ) == 1 %]null,[% END %] [% IF Koha.Preference( 'OpacSuggestionManagedBy' ) %]null,[% END %] null ] diff --git a/opac/opac-suggestions.pl b/opac/opac-suggestions.pl index d55ef3dfac..cbdada24dd 100755 --- a/opac/opac-suggestions.pl +++ b/opac/opac-suggestions.pl @@ -32,11 +32,11 @@ use C4::Scrubber; use Koha::DateUtils qw( dt_from_string ); my $input = new CGI; -my $allsuggestions = $input->param('showall'); my $op = $input->param('op'); my $suggestion = $input->Vars; delete $suggestion->{negcap}; my $negcaptcha = $input->param('negcap'); +my $suggested_by_anyone = $input->param('suggested_by_anyone') || 0; # If a spambot accidentally populates the 'negcap' field in the sugesstions form, then silently skip and return. if ($negcaptcha ) { @@ -50,14 +50,14 @@ if ( ! C4::Context->preference('suggestion') ) { exit; } -delete $$suggestion{$_} foreach qw; +delete $suggestion->{$_} foreach qw; $op = 'else' unless $op; my ( $template, $borrowernumber, $cookie, @messages ); my $deleted = $input->param('deleted'); my $submitted = $input->param('submitted'); -if ( C4::Context->preference("AnonSuggestions") ) { +if ( C4::Context->preference("AnonSuggestions") or ( C4::Context->preference("OPACViewOthersSuggestions") and $op eq 'else' ) ) { ( $template, $borrowernumber, $cookie ) = get_template_and_user( { template_name => "opac-suggestions.tt", @@ -66,9 +66,6 @@ if ( C4::Context->preference("AnonSuggestions") ) { authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ), } ); - if ( !$$suggestion{suggestedby} ) { - $$suggestion{suggestedby} = C4::Context->preference("AnonymousPatron"); - } } else { ( $template, $borrowernumber, $cookie ) = get_template_and_user( @@ -80,13 +77,36 @@ else { } ); } -if ($allsuggestions){ - delete $$suggestion{suggestedby}; -} -else { - $$suggestion{suggestedby} ||= $borrowernumber unless ($allsuggestions); + +if ( $op eq 'else' ) { + if ( C4::Context->preference("OPACViewOthersSuggestions") ) { + if ( $borrowernumber ) { + # A logged in user is able to see suggestions from others + $suggestion->{suggestedby} = $suggested_by_anyone + ? undef + : $borrowernumber; + } + else { + # Non logged in user is able to see all suggestions + $suggestion->{suggestedby} = undef; + } + } + else { + if ( $borrowernumber ) { + $suggestion->{suggestedby} = $borrowernumber; + } + else { + $suggestion->{suggestedby} = -1; + } + } +} else { + if ( $borrowernumber ) { + $suggestion->{suggestedby} = $borrowernumber; + } + else { + $suggestion->{suggestedby} = C4::Context->preference("AnonymousPatron"); + } } -# warn "bornum:",$borrowernumber; my $suggestions_loop = &SearchSuggestion( $suggestion); @@ -170,11 +190,11 @@ $template->param( itemtypeloop=> $supportlist, suggestions_loop => $suggestions_loop, patron_reason_loop => $patron_reason_loop, - showall => $allsuggestions, "op_$op" => 1, $op => 1, messages => \@messages, suggestionsview => 1, + suggested_by_anyone => $suggested_by_anyone, ); output_html_with_http_headers $input, $cookie, $template->output; -- 2.39.5