From 85bdc79b979f3abc4ca9df5cfc894d296a24b339 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 22 Mar 2012 11:59:01 +0100 Subject: [PATCH] 7805 Exposing the new list permissions in opac and staff Content-Type: text/plain; charset="utf-8" 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. --- C4/VirtualShelves.pm | 43 ++++++++++---------- C4/VirtualShelves/Page.pm | 21 ++++++++-- .../prog/en/modules/virtualshelves/shelves.tt | 42 ++++++++++++++++++- .../opac-tmpl/prog/en/modules/opac-shelves.tt | 30 ++++++++++++++ 4 files changed, 107 insertions(+), 29 deletions(-) diff --git a/C4/VirtualShelves.pm b/C4/VirtualShelves.pm index 85dbc9f..e67bd4c 100644 --- a/C4/VirtualShelves.pm +++ b/C4/VirtualShelves.pm @@ -219,19 +219,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=? ); @@ -315,7 +313,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); @@ -330,9 +328,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; } @@ -397,16 +395,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 } } @@ -414,13 +413,13 @@ 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}, - $shelfnumber ); + $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 125a1e6..c1eb5f2 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 0eb0d02..8117150 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,33 @@ 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 +180,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 +305,9 @@ function placeHold () { + + [% INCLUDE list_permissions %] + [% END %] [% IF ( edit ) %] @@ -304,7 +336,9 @@ function placeHold () { [% ELSE %] [% END %] - + + [% INCLUDE list_permissions %] + [% END %] @@ -316,7 +350,9 @@ 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.
    • +
    • 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 9e201d0..0cef9a8 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 %]
    -- 1.6.0.6