From d7a7aaad7b66ecf63321b9c4c83703ac9faf0150 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 22 Mar 2012 11:59:01 +0100 Subject: [PATCH] Bug 7805: Exposing the new list permissions in opac and staff This report builds on 7310. Had to correct some lines in ModShelf and AddShelf as well in order to save 0 values correctly for the permission columns. Signed-off-by: Jared Camins-Esakov Signed-off-by: Paul Poulain --- C4/VirtualShelves.pm | 41 +++++++++---------- C4/VirtualShelves/Page.pm | 21 ++++++++-- .../prog/en/modules/virtualshelves/shelves.tt | 39 +++++++++++++++++- .../opac-tmpl/prog/en/modules/opac-shelves.tt | 30 ++++++++++++++ 4 files changed, 104 insertions(+), 27 deletions(-) diff --git a/C4/VirtualShelves.pm b/C4/VirtualShelves.pm index a02bb8e2ed..8ecb6039dc 100644 --- a/C4/VirtualShelves.pm +++ b/C4/VirtualShelves.pm @@ -215,19 +215,17 @@ sub GetSomeShelfNames { =head2 GetShelf - (shelfnumber,shelfname,owner,category,sortfield) = &GetShelf($shelfnumber); + (shelfnumber,shelfname,owner,category,sortfield,allow_add,allow_delete_own,allow_delete_other) = &GetShelf($shelfnumber); -Looks up information about the contents of virtual virtualshelves number -C<$shelfnumber> - -Returns the database's information on 'virtualshelves' table. +Returns the above-mentioned fields for passed virtual shelf number. =cut sub GetShelf ($) { my ($shelfnumber) = @_; my $query = qq( - SELECT shelfnumber, shelfname, owner, category, sortfield + SELECT shelfnumber, shelfname, owner, category, sortfield, + allow_add, allow_delete_own, allow_delete_other FROM virtualshelves WHERE shelfnumber=? ); @@ -311,7 +309,7 @@ sub AddShelf { #initialize missing hash values to silence warnings foreach('shelfname','category', 'sortfield', 'allow_add', 'allow_delete_own', 'allow_delete_other' ) { - $hashref->{$_}= exists $hashref->{$_}? $hashref->{$_}||'': ''; + $hashref->{$_}= undef unless exists $hashref->{$_}; } return -1 unless _CheckShelfName($hashref->{shelfname}, $hashref->{category}, $owner, 0); @@ -326,9 +324,9 @@ sub AddShelf { $owner, $hashref->{category}, $hashref->{sortfield}, - $hashref->{allow_add}||0, - $hashref->{allow_delete_own}||1, - $hashref->{allow_delete_other}||0 ); + $hashref->{allow_add}//0, + $hashref->{allow_delete_own}//1, + $hashref->{allow_delete_other}//0 ); my $shelfnumber = $dbh->{'mysql_insertid'}; return $shelfnumber; } @@ -393,16 +391,17 @@ sub ModShelf { #initialize missing hash values to silence warnings foreach('shelfname','category', 'sortfield', 'allow_add', 'allow_delete_own', 'allow_delete_other' ) { - $hashref->{$_}= exists $hashref->{$_}? $hashref->{$_}||'': ''; + $hashref->{$_}= undef unless exists $hashref->{$_}; } #if name or category changes, the name should be tested if($hashref->{shelfname} || $hashref->{category}) { unless(_CheckShelfName( - $hashref->{shelfname}||$oldrecord->{shelfname}, - $hashref->{category}||$oldrecord->{category}, - $oldrecord->{owner}, $shelfnumber )) { - return 0; #name check failed + $hashref->{shelfname}//$oldrecord->{shelfname}, + $hashref->{category}//$oldrecord->{category}, + $oldrecord->{owner}, + $shelfnumber )) { + return 0; #name check failed } } @@ -410,12 +409,12 @@ sub ModShelf { $query= "UPDATE virtualshelves SET shelfname=?, category=?, sortfield=?, allow_add=?, allow_delete_own=?, allow_delete_other=? WHERE shelfnumber=?"; $sth = $dbh->prepare($query); $sth->execute( - $hashref->{shelfname}||$oldrecord->{shelfname}, - $hashref->{category}||$oldrecord->{category}, - $hashref->{sortfield}||$oldrecord->{sortfield}, - $hashref->{allow_add}||$oldrecord->{allow_add}, - $hashref->{allow_delete_own}||$oldrecord->{allow_delete_own}, - $hashref->{allow_delete_other}||$oldrecord->{allow_delete_other}, + $hashref->{shelfname}//$oldrecord->{shelfname}, + $hashref->{category}//$oldrecord->{category}, + $hashref->{sortfield}//$oldrecord->{sortfield}, + $hashref->{allow_add}//$oldrecord->{allow_add}, + $hashref->{allow_delete_own}//$oldrecord->{allow_delete_own}, + $hashref->{allow_delete_other}//$oldrecord->{allow_delete_other}, $shelfnumber ); return $@? 0: 1; } diff --git a/C4/VirtualShelves/Page.pm b/C4/VirtualShelves/Page.pm index d32afed84d..09ec7c960a 100644 --- a/C4/VirtualShelves/Page.pm +++ b/C4/VirtualShelves/Page.pm @@ -185,8 +185,11 @@ sub shelfpage { last SWITCH; } my $shelf = { - 'shelfname' => $query->param('shelfname'), - 'sortfield' => $query->param('sortfield'), + shelfname => $query->param('shelfname'), + sortfield => $query->param('sortfield'), + allow_add => $query->param('allow_add'), + allow_delete_own => $query->param('allow_delete_own'), + allow_delete_other => $query->param('allow_delete_other'), }; if($query->param('category')) { #optional $shelf->{category}= $query->param('category'); @@ -207,7 +210,7 @@ sub shelfpage { } #Editing a shelf elsif ( $op eq 'modif' ) { - my ( $shelfnumber2, $shelfname, $owner, $category, $sortfield ) = GetShelf($shelfnumber); + my ( $shelfnumber2, $shelfname, $owner, $category, $sortfield, $allow_add, $allow_delete_own, $allow_delete_other) = GetShelf($shelfnumber); my $member = GetMember( 'borrowernumber' => $owner ); my $ownername = defined($member) ? $member->{firstname} . " " . $member->{surname} : ''; $edit = 1; @@ -222,6 +225,9 @@ sub shelfpage { "category$category" => 1, category => $category, "sort_$sortfield" => 1, + allow_add => $allow_add, + allow_delete_own => $allow_delete_own, + allow_delete_other => $allow_delete_other, ); } last SWITCH; @@ -322,7 +328,11 @@ sub shelfpage { my $shelfnumber = AddShelf( { shelfname => $newshelf, sortfield => $query->param('sortfield'), - category => $query->param('category') }, + category => $query->param('category'), + allow_add => $query->param('allow_add'), + allow_delete_own => $query->param('allow_delete_own'), + allow_delete_other => $query->param('allow_delete_other'), + }, $query->param('owner') ); $stay = 1; if ( $shelfnumber == -1 ) { #shelf already exists. @@ -454,6 +464,9 @@ sub shelfpage { $edit ) { $template->param( seflag => 1 ); + #This hack is just another argument for refactoring this script one day + #At this point you are adding or editing a list; if you add, then you add a private list (by default) with permissions as below; if you edit, do not pass these permissions, they must come from the database + $template->param( allow_add => 0, allow_delete_own => 1, allow_delete_other => 0) unless $shelfnumber; } #Next call updates the shelves for the Lists button. diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt index 650be11b1b..179e2c46ed 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt @@ -115,6 +115,32 @@ function placeHold () { [% INCLUDE 'header.inc' %] [% INCLUDE 'cat-search.inc' %] +[% BLOCK list_permissions %] +
  • + + +  anyone else to add entries. +
  • +
  • + + +  anyone to remove his own contributed entries. +
  • +
  • + + +  anyone to remove other contributed entries. +
  • +[% END %] @@ -153,6 +179,9 @@ function placeHold () { [% IF ( paramsloo.somedeleted) %]
    Warning: You could not delete all selected items from this shelf.
    [% END %] + [% IF ( paramsloo.modifyfailure) %] +
    ERROR: List could not be modified.
    + [% END %] [% END %] @@ -275,7 +304,9 @@ function placeHold () { + + [% INCLUDE list_permissions %] + [% END %] [% IF ( edit ) %] @@ -304,7 +335,9 @@ function placeHold () { [% ELSE %] [% END %] - + + [% INCLUDE list_permissions %] + [% END %] @@ -317,6 +350,8 @@ function placeHold () {
    • A Private list is managed by you and can be seen only by you.
    • A Public list can be seen by everybody, but managed only by you.
    • +
      +
    • The owner of a list is always allowed to add entries, but needs permission to remove.
    diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tt index b6a2954371..716f2e122c 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tt @@ -170,6 +170,34 @@ $(function() { [% IF ( loggedinusername ) %][% ELSE %][% END %] + +[% BLOCK list_permissions %] +
  • + + +  anyone else to add entries. (The owner of a list is always allowed to add entries, but needs permission to remove.) +
  • +
  • + + +  anyone to remove his own contributed entries. +
  • +
  • + + +  anyone to remove other contributed entries. +
  • +[% END %] + [% IF ( OpacNav ) %]
    [% ELSIF ( loggedinusername ) %]
    [% ELSE %]
    [% END %]
    [% INCLUDE 'masthead.inc' %] @@ -445,6 +473,7 @@ $(function() { [% END %] + [% INCLUDE list_permissions %]
    [% IF ( showprivateshelves ) %]Cancel[% ELSE %]Cancel[% END %]
    @@ -633,6 +662,7 @@ $(function() { [% END %] + [% INCLUDE list_permissions %]
    -- 2.39.5