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: Chris Cormack <chrisc@catalyst.net.nz>
This commit is contained in:
Marcel de Rooy 2012-03-22 11:59:01 +01:00 committed by Chris Cormack
parent d392831756
commit bb3c997c20
4 changed files with 104 additions and 27 deletions

View File

@ -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;
}

View File

@ -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.

View File

@ -115,6 +115,32 @@ function placeHold () {
[% INCLUDE 'header.inc' %]
[% INCLUDE 'cat-search.inc' %]
[% BLOCK list_permissions %]
<li>
<label for="permissions">Permissions: </label>
<select name="allow_add" id="allow_add">
[% IF allow_add %]<option value="0">Do not allow</option>[% ELSE %]<option value="0" selected="selected">Do not allow</option>[% END %]
[% IF allow_add %]<option value="1" selected="selected">Allow</option>[% ELSE %]<option value="1">Allow</option>[% END %]
</select>
&nbsp;<span>anyone else to add entries.</span>
</li>
<li>
<label>&nbsp;</label>
<select name="allow_delete_own" id="allow_delete_own">
[% IF allow_delete_own %]<option value="0">Do not allow</option>[% ELSE %]<option value="0" selected="selected">Do not allow</option>[% END %]
[% IF allow_delete_own %]<option value="1" selected="selected">Allow</option>[% ELSE %]<option value="1">Allow</option>[% END %]
</select>
&nbsp;<span>anyone to remove his own contributed entries.</span>
</li>
<li>
<label>&nbsp;</label>
<select name="allow_delete_other" id="allow_delete_other">
[% IF allow_delete_other %]<option value="0">Do not allow</option>[% ELSE %]<option value="0" selected="selected">Do not allow</option>[% END %]
[% IF allow_delete_other %]<option value="1" selected="selected">Allow</option>[% ELSE %]<option value="1">Allow</option>[% END %]
</select>
&nbsp;<span>anyone to remove other contributed entries.</span>
</li>
[% END %]
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/virtualshelves/shelves.pl">Lists</a> [% IF ( category1 ) %] &rsaquo; [% IF ( viewshelf || edit ) %] <a href="/cgi-bin/koha/virtualshelves/shelves.pl?display=privateshelves">Your lists</a> [% ELSE %] Your lists [% END %] [% ELSIF ( category2 ) %] &rsaquo; [% IF ( viewshelf ) %] <a href="/cgi-bin/koha/virtualshelves/shelves.pl?display=publicshelves">Public lists</a> [% ELSE %] Public lists [% END %] [% ELSIF ( showprivateshelves ) %] &rsaquo; [% IF ( viewshelf || edit ) %] <a href="/cgi-bin/koha/virtualshelves/shelves.pl?display=privateshelves">Your lists</a> [% ELSE %] Your lists [% END %] [% ELSIF ( showpublicshelves ) %] &rsaquo; [% IF ( viewshelf || edit ) %] <a href="/cgi-bin/koha/virtualshelves/shelves.pl?display=publicshelves">Public lists</a> [% ELSE %] Public lists [% END %] [% END %]
[% IF ( viewshelf ) %]&rsaquo; Contents of <i>[% shelfname | html %]</i>[% END %][% IF ( shelves ) %] &rsaquo; Create new list[% END %][% IF ( edit ) %] &rsaquo; Edit list <i>[% shelfname | html %]</i>[% END %]</div>
@ -153,6 +179,9 @@ function placeHold () {
[% IF ( paramsloo.somedeleted) %]
<div class="dialog message">Warning: You could not delete all selected items from this shelf.</div>
[% END %]
[% IF ( paramsloo.modifyfailure) %]
<div class="dialog message">ERROR: List could not be modified.</div>
[% END %]
</div>
</div>
[% END %]
@ -275,7 +304,9 @@ function placeHold () {
<select name="category" id="category">
<option value="1">Private</option>
<option value="2">Public</option>
</select></li></ol>
</select></li>
[% INCLUDE list_permissions %]
</ol>
[% END %]
[% IF ( edit ) %]
@ -304,7 +335,9 @@ function placeHold () {
[% ELSE %]
<option value="2">Public</option>
[% END %]
</select></li></ol>
</select></li>
[% INCLUDE list_permissions %]
</ol>
[% END %]
</fieldset>
@ -317,6 +350,8 @@ function placeHold () {
<div class="help"><ul>
<li>A <b>Private</b> list is managed by you and can be seen only by you.</li>
<li> A <b>Public</b> list can be seen by everybody, but managed only by you.</li>
<br/>
<li>The owner of a list is always allowed to add entries, but needs permission to remove.</li>
</ul>
</div>
</div>

View File

@ -170,6 +170,34 @@ $(function() {
</script>
</head>
[% IF ( loggedinusername ) %]<body id="opac-userlists">[% ELSE %]<body id="opac-lists">[% END %]
[% BLOCK list_permissions %]
<li>
<label for="permissions">Permissions: </label>
<select name="allow_add" id="allow_add">
[% IF allow_add %]<option value="0">Do not allow</option>[% ELSE %]<option value="0" selected="selected">Do not allow</option>[% END %]
[% IF allow_add %]<option value="1" selected="selected">Allow</option>[% ELSE %]<option value="1">Allow</option>[% END %]
</select>
&nbsp;<span>anyone else to add entries. (The owner of a list is always allowed to add entries, but needs permission to remove.)</span>
</li>
<li>
<label>&nbsp;</label>
<select name="allow_delete_own" id="allow_delete_own">
[% IF allow_delete_own %]<option value="0">Do not allow</option>[% ELSE %]<option value="0" selected="selected">Do not allow</option>[% END %]
[% IF allow_delete_own %]<option value="1" selected="selected">Allow</option>[% ELSE %]<option value="1">Allow</option>[% END %]
</select>
&nbsp;<span>anyone to remove his own contributed entries.</span>
</li>
<li>
<label>&nbsp;</label>
<select name="allow_delete_other" id="allow_delete_other">
[% IF allow_delete_other %]<option value="0">Do not allow</option>[% ELSE %]<option value="0" selected="selected">Do not allow</option>[% END %]
[% IF allow_delete_other %]<option value="1" selected="selected">Allow</option>[% ELSE %]<option value="1">Allow</option>[% END %]
</select>
&nbsp;<span>anyone to remove other contributed entries.</span>
</li>
[% END %]
[% IF ( OpacNav ) %]<div id="doc3" class="yui-t1">[% ELSIF ( loggedinusername ) %]<div id="doc3" class="yui-t1">[% ELSE %]<div id="doc3" class="yui-t7">[% END %]
<div id="bd">
[% INCLUDE 'masthead.inc' %]
@ -445,6 +473,7 @@ $(function() {
</select>
[% END %]
</li>
[% INCLUDE list_permissions %]
</ol>
</fieldset>
<fieldset class="action"><input type="submit" value="Save" class="submit" /> [% IF ( showprivateshelves ) %]<a class="cancel" href="/cgi-bin/koha/opac-shelves.pl?shelfnumber=[% shelfnumber %]&amp;display=privateshelves">Cancel</a>[% ELSE %]<a class="cancel" href="/cgi-bin/koha/opac-shelves.pl?shelfnumber=[% shelfnumber %]">Cancel</a>[% END %]</fieldset>
@ -633,6 +662,7 @@ $(function() {
[% END %]
</select>
</li>
[% INCLUDE list_permissions %]
</ol>
</fieldset>
<fieldset class="action">