From 591dfabdf3180e02089e18b3529ca4c6a8fb2da1 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Tue, 9 Aug 2022 14:43:33 +0000 Subject: [PATCH] Bug 31333: Add ability to make purchase suggestions by borrower type Introduce a suggestionPatronCategoryExceptions system preference. If the suggestion syspref is enabled then libraries can stop specific borrower types from making suggestions by ticking the type in the suggestionPatronCategoryExceptions syspref. Test plan: 1. Apply patches, update database, re-start services 2. Set 'suggestion' syspref = 'Allow' 3. Confirm you can view the purchase suggestion links on OPAC biblio detail page & 'your summary' page. As well as successfully submit a suggestion. 4. Select the patron category you're logged in as in suggestionPatronCategoryExceptions syspref 5. Confirm the purchase suggestion links are hidden in the OPAC biblio detail page & 'your summary' page 6. In your browser enter the link: /cgi-bin/koha/opac-suggestions.pl e.g. http://localhost:8080/cgi-bin/koha/opac-suggestions.pl 7. Confirm a 404 page loads 8. Confirm you can view/moderate suggestions in the staff client - even though your patron is selected in the suggestionPatronCategoryExceptions syspref 9. Untick your patron category in the suggestionPatronCategoryExceptions syspref 10. Confirm you can view the purchase suggestion links on the OPAC, as well as successfully submit a suggestion. 11. Set 'suggestion' syspref = "Don't allow" 12. Confirm the purchase suggestion links are hidden in the OPAC 13. Select all patron categories in suggestPatronCategoryExceptions syspref. View the OPAC without logging in and confirm you can perform searches and view OPAC biblio detail pages. Sponsored-by: Catalyst IT, New Zealand Signed-off-by: Owen Leonard Signed-off-by: Katrin Fischer --- C4/Auth.pm | 10 ++++++-- Koha/Patron/Category.pm | 25 +++++++++++++++++++ .../en/modules/admin/preferences/opac.pref | 7 +++++- .../en/includes/opac-detail-sidebar.inc | 2 +- .../bootstrap/en/includes/usermenu.inc | 2 +- opac/opac-suggestions.pl | 12 ++++----- 6 files changed, 47 insertions(+), 11 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index a2b1b84aea..612aeb4fe2 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -499,6 +499,12 @@ sub get_template_and_user { # these template parameters are set the same regardless of $in->{'type'} + # Decide if the patron can make suggestions in the OPAC + my $can_make_suggestions; + if ( C4::Context->userenv && C4::Context->userenv->{'number'} ) { + $can_make_suggestions = Koha::Patrons->find(C4::Context->userenv->{'number'})->category->can_make_suggestions; + } + my $minPasswordLength = C4::Context->preference('minPasswordLength'); $minPasswordLength = 3 if not $minPasswordLength or $minPasswordLength < 3; $template->param( @@ -537,7 +543,7 @@ sub get_template_and_user { intranetstylesheet => C4::Context->preference("intranetstylesheet"), IntranetUserCSS => C4::Context->preference("IntranetUserCSS"), IntranetUserJS => C4::Context->preference("IntranetUserJS"), - suggestion => C4::Context->preference("suggestion"), + suggestion => $can_make_suggestions, virtualshelves => C4::Context->preference("virtualshelves"), StaffSerialIssueDisplayCount => C4::Context->preference("StaffSerialIssueDisplayCount"), EasyAnalyticalRecords => C4::Context->preference('EasyAnalyticalRecords'), @@ -627,7 +633,7 @@ sub get_template_and_user { OpenLibrarySearch => C4::Context->preference("OpenLibrarySearch"), ShowReviewer => C4::Context->preference("ShowReviewer"), ShowReviewerPhoto => C4::Context->preference("ShowReviewerPhoto"), - suggestion => "" . C4::Context->preference("suggestion"), + suggestion => $can_make_suggestions, virtualshelves => "" . C4::Context->preference("virtualshelves"), OPACSerialIssueDisplayCount => C4::Context->preference("OPACSerialIssueDisplayCount"), SyndeticsClientCode => C4::Context->preference("SyndeticsClientCode"), diff --git a/Koha/Patron/Category.pm b/Koha/Patron/Category.pm index c6837ca00f..39c56be14a 100644 --- a/Koha/Patron/Category.pm +++ b/Koha/Patron/Category.pm @@ -205,6 +205,31 @@ sub override_hidden_items { split( /\|/, C4::Context->preference('OpacHiddenItemsExceptions') ); } +=head3 can_make_suggestions + + + if ( $patron->category->can_make_suggestions ) { + ... + } + +Returns if the OPAC logged-in user is allowed to make OPAC purchase suggestions. + +=cut + +sub can_make_suggestions { + my ( $self ) = @_; + + if ( C4::Context->preference('suggestion') ) { + my @patron_categories = split ',', C4::Context->preference('suggestionPatronCategoryExceptions'); + if ( @patron_categories ) { + my $categorycode = $self->categorycode; + return if grep {$_ eq $categorycode } @patron_categories; + } + return 1; + } + return; +} + =head2 Internal methods =head3 _library_limits diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index c74d5c9d49..258a819458 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -427,7 +427,12 @@ OPAC: choices: 1: Allow 0: "Don't allow" - - patrons to make purchase suggestions on the OPAC. + - 'Patron categories allowed to make purchase suggestions on the OPAC:' + - + - 'Patron categories not affected by suggestion:' + - pref: suggestionPatronCategoryExceptions + choices: patron-categories + class: multiple - - pref: OPACComments choices: diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc index a3cbb23590..2602ad7502 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc @@ -38,7 +38,7 @@ [% END %] [% END %] - [% IF Koha.Preference('suggestion') %] + [% IF ( suggestion ) %]
  • Suggest for purchase
  • [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/usermenu.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/usermenu.inc index d172132cb7..1c23e01181 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/usermenu.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/usermenu.inc @@ -83,7 +83,7 @@ your holds history [% END %] - [% IF Koha.Preference( 'suggestion' ) == 1 %] + [% IF ( suggestion ) %] [% IF ( suggestionsview ) %]
  • [% ELSE %] diff --git a/opac/opac-suggestions.pl b/opac/opac-suggestions.pl index ec3ced7f9f..b6942d6753 100755 --- a/opac/opac-suggestions.pl +++ b/opac/opac-suggestions.pl @@ -69,12 +69,6 @@ if ($negcaptcha ) { exit; } -#If suggestions are turned off we redirect to 404 error. This will also redirect guest suggestions -if ( ! C4::Context->preference('suggestion') ) { - print $input->redirect("/cgi-bin/koha/errors/404.pl"); - exit; -} - my ( $template, $borrowernumber, $cookie, @messages ); my $deleted = $input->param('deleted'); my $submitted = $input->param('submitted'); @@ -99,6 +93,12 @@ else { ); } +# If suggestions are turned off, or this patron belongs to a category not allowed to make suggestions (suggestionPatronCategoryExceptions syspref) we redirect to 404 error. This will also redirect guest suggestions +if ( !Koha::Patrons->find( $borrowernumber )->category->can_make_suggestions ) { + print $input->redirect("/cgi-bin/koha/errors/404.pl"); + exit; +} + my $suggested_by; if ( $op eq 'else' ) { if ( C4::Context->preference("OPACViewOthersSuggestions") ) { -- 2.30.2