From 4d65b8117581eedfa83b2d17733505db60d261a1 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 26 Aug 2015 14:24:25 +0100 Subject: [PATCH] Bug 14544: Fix regression on adding a new list The user should not be allowed to create a new list and get a friendly error message if he tries. The "New list" links are removed. --- .../opac-tmpl/bootstrap/en/modules/opac-shelves.tt | 13 ++++++- opac/opac-shelves.pl | 45 ++++++++++++---------- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt index 2f25d9c..84032a0 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt @@ -132,6 +132,8 @@ This item does not exist. [% CASE 'unauthorized_on_view' %] You do not have permission to view this list. + [% CASE 'unauthorized_on_insert' %] + You do not have permission to insert a new list. [% CASE 'unauthorized_on_update' %] You do not have permission to update this list. [% CASE 'unauthorized_on_delete' %] @@ -637,8 +639,15 @@
[% END %] - - [% IF shelves %] + [% IF loggedinusername %] + + [% ELSE %] + [% IF Koha.Preference( 'opacuserlogin' ) == 1 %] +
Log in to create new lists.
+ [% END %] + [% END %] + + [% IF shelves.count %] diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl index 63dc402..e4e4eaa 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -63,27 +63,32 @@ if ( $op eq 'add_form' ) { push @messages, { type => 'error', code => 'does_not_exist' }; } } elsif ( $op eq 'add' ) { - eval { - $shelf = Koha::Virtualshelf->new( - { shelfname => $query->param('shelfname'), - sortfield => $query->param('sortfield'), - category => $query->param('category') || 1, - allow_add => $query->param('allow_add'), - allow_delete_own => $query->param('allow_delete_own'), - allow_delete_other => $query->param('allow_delete_other'), - owner => $query->param('owner'), - } - ); - $shelf->store; - $shelfnumber = $shelf->shelfnumber; - }; - if ($@) { - push @messages, { type => 'error', code => ref($@), msg => $@ }; - } elsif ( not $shelf ) { - push @messages, { type => 'error', code => 'error_on_insert' }; + if ( $loggedinuser ) { + eval { + $shelf = Koha::Virtualshelf->new( + { shelfname => $query->param('shelfname'), + sortfield => $query->param('sortfield'), + category => $query->param('category') || 1, + allow_add => $query->param('allow_add'), + allow_delete_own => $query->param('allow_delete_own'), + allow_delete_other => $query->param('allow_delete_other'), + owner => $loggedinuser, + } + ); + $shelf->store; + $shelfnumber = $shelf->shelfnumber; + }; + if ($@) { + push @messages, { type => 'error', code => ref($@), msg => $@ }; + } elsif ( not $shelf ) { + push @messages, { type => 'error', code => 'error_on_insert' }; + } else { + push @messages, { type => 'message', code => 'success_on_insert' }; + $op = 'view'; + } } else { - push @messages, { type => 'message', code => 'success_on_insert' }; - $op = 'view'; + push @messages, { type => 'error', code => 'unauthorized_on_insert' }; + $op = 'list'; } } elsif ( $op eq 'edit' ) { $shelfnumber = $query->param('shelfnumber'); -- 2.1.0