From 8fa15d59a1e4b48e7f0af1bb43587123859ddcde Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 1 Aug 2013 13:56:21 +0200 Subject: [PATCH] Bug 10389: Remove an accepted share Content-Type: text/plain; charset=utf-8 If a user accepted a share, this patch allows him to remove it again. A new routine is added to VirtualShelves.pm. The Remove Share button is visible on OPAC when viewing Your lists or a particular shared list. Test plan: User 1 creates private list P3, sends a share. User 1 creates private list P4, adds one item, sends a share. User 2 accepts the share for P3. User 2 checks the shelves display, and removes share P3. User 2 accepts the share for P4. User 2 views shelf P4 with one item and confirms Remove share on that form. User 2 checks shelves display again. Run the adjusted test unit too. Did all 96 tests pass? Signed-off-by: Marcel de Rooy --- C4/VirtualShelves.pm | 24 +++++++++++++++++++- C4/VirtualShelves/Page.pm | 13 +++++++++- .../opac-tmpl/prog/en/modules/opac-shelves.tt | 18 +++++++++++++++ t/db_dependent/VirtualShelves.t | 13 ++++++++++- 4 files changed, 64 insertions(+), 4 deletions(-) diff --git a/C4/VirtualShelves.pm b/C4/VirtualShelves.pm index 4531564..f8afc58 100644 --- a/C4/VirtualShelves.pm +++ b/C4/VirtualShelves.pm @@ -44,7 +44,8 @@ BEGIN { &ModShelf &ShelfPossibleAction &DelFromShelf &DelShelf - &GetBibliosShelves &AddShare &AcceptShare &IsSharedList + &GetBibliosShelves + &AddShare &AcceptShare &RemoveShare &IsSharedList ); @EXPORT_OK = qw( &GetAllShelves &ShelvesMax @@ -740,6 +741,27 @@ sub IsSharedList { return defined($rv); } +=head2 RemoveShare + + RemoveShare( $user, $shelfnumber ); + +RemoveShare removes a share for specific shelf and borrower. +Returns true if a record could be deleted. + +=cut + +sub RemoveShare { + my ($user, $shelfnumber)= @_; + my $dbh = C4::Context->dbh; + my $sql=" +DELETE FROM virtualshelfshares +WHERE borrowernumber=? AND shelfnumber=? + "; + my $n= $dbh->do($sql,undef,($user, $shelfnumber)); + return if !defined($n) || !$n || $n eq '0E0'; #nothing removed + return 1; +} + # internal subs sub _shelf_count { diff --git a/C4/VirtualShelves/Page.pm b/C4/VirtualShelves/Page.pm index b2bd238..efaf69b 100644 --- a/C4/VirtualShelves/Page.pm +++ b/C4/VirtualShelves/Page.pm @@ -360,13 +360,22 @@ sub shelfpage { #Deleting a shelf (asking for confirmation if it has entries) foreach ( $query->param() ) { - /DEL-(\d+)/ or next; + /(DEL|REMSHR)-(\d+)/ or next; $delflag = 1; - my $number = $1; + my $number = $2; unless ( defined $shelflist->{$number} || defined $privshelflist->{$number} ) { push( @paramsloop, { unrecognized => $number } ); last; } + #remove a share + if(/REMSHR/) { + RemoveShare($loggedinuser, $number); + delete $shelflist->{$number} if exists $shelflist->{$number}; + delete $privshelflist->{$number} if exists $privshelflist->{$number}; + $stay=0; + next; + } + # unless ( ShelfPossibleAction( $loggedinuser, $number, 'manage' ) ) { push( @paramsloop, { nopermission => $shelfnumber } ); last; 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 b429717..4c77b9f 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tt @@ -8,6 +8,7 @@ // [% END %] +[%# When using the next block, add the parameter for shelfnumber and add a tag to end the form %] +[% BLOCK remove_share %] +
+ + + + +[% END %] + [% IF ( OpacNav ) %]
[% ELSIF ( loggedinusername ) %]
[% ELSE %]
[% END %]
[% INCLUDE 'masthead.inc' %] @@ -357,6 +367,10 @@ $(document).ready(function() { [% END %] + [% ELSIF showprivateshelves %] + [% INCLUDE remove_share %] + + [% END %] @@ -645,6 +659,10 @@ $(document).ready(function() { [% END %] + [% ELSIF shelveslooppri.shares %] + [% INCLUDE remove_share %] + + [% END %]  diff --git a/t/db_dependent/VirtualShelves.t b/t/db_dependent/VirtualShelves.t index 27bfd34..42f451a 100755 --- a/t/db_dependent/VirtualShelves.t +++ b/t/db_dependent/VirtualShelves.t @@ -5,7 +5,7 @@ # Larger modifications by Jonathan Druart and Marcel de Rooy use Modern::Perl; -use Test::More tests => 95; +use Test::More tests => 96; use MARC::Record; use C4::Biblio qw( AddBiblio DelBiblio ); @@ -229,6 +229,17 @@ for my $i (0..9) { is(IsSharedList($sh),$n? 1: '', "Checked IsSharedList for shelf $sh"); } +#----------------------- TEST RemoveShare -------------------------------------# + +my $remshr_test="select borrowernumber, shelfnumber from virtualshelfshares where borrowernumber is not null"; +my @remshr_shelf= $dbh->selectrow_array($remshr_test); +if(@remshr_shelf) { + is(RemoveShare(@remshr_shelf),1,'Removed a shelf share'); +} +else { + ok(1,'Skipped RemoveShare test'); +} + #----------------TEST DelShelf & DelFromShelf functions------------------------# for my $i (0..9){ -- 1.7.7.6