Bugzilla – Attachment 41977 Details for
Bug 14544
Move the list related code to Koha::Virtualshelves
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14544: Get rid of ShelfPossibleAction
Bug-14544-Get-rid-of-ShelfPossibleAction.patch (text/plain), 10.06 KB, created by
Jonathan Druart
on 2015-08-26 13:09:29 UTC
(
hide
)
Description:
Bug 14544: Get rid of ShelfPossibleAction
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2015-08-26 13:09:29 UTC
Size:
10.06 KB
patch
obsolete
>From 065162bd1adeb9c44edf54dae18d0ccb89a62d63 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 17 Aug 2015 15:57:27 +0100 >Subject: [PATCH] Bug 14544: Get rid of ShelfPossibleAction > >Bug 14544: (follow-up) Get rid of ShelfPossibleAction >--- > C4/VirtualShelves.pm | 102 ----------------------------------------- > opac/opac-addbybiblionumber.pl | 66 +++++++++++++++----------- > opac/opac-downloadshelf.pl | 2 - > opac/opac-sendshelf.pl | 3 +- > opac/opac-shareshelf.pl | 13 +++--- > 5 files changed, 47 insertions(+), 139 deletions(-) > >diff --git a/C4/VirtualShelves.pm b/C4/VirtualShelves.pm >index 73786d1..3e8a686 100644 >--- a/C4/VirtualShelves.pm >+++ b/C4/VirtualShelves.pm >@@ -41,7 +41,6 @@ BEGIN { > @ISA = qw(Exporter); > @EXPORT = qw( > &GetShelfContents >- &ShelfPossibleAction > ); > @EXPORT_OK = qw( > &ShelvesMax >@@ -163,107 +162,6 @@ sub GetShelfContents { > # or newer, for your version of DBI. > } > >-=head2 ShelfPossibleAction >- >-ShelfPossibleAction($loggedinuser, $shelfnumber, $action); >- >-C<$loggedinuser,$shelfnumber,$action> >- >-$action can be "view", "add", "delete", "manage", "new_public", "new_private". >-New additional actions are: invite, acceptshare. >-Note that add/delete here refers to adding/deleting entries from the list. Deleting the list itself falls under manage. >-new_public and new_private refers to creating a new public or private list. >-The distinction between deleting your own entries from the list or entries from >-others is made when deleting a content from the shelf. >- >-Returns 1 if the user can do the $action in the $shelfnumber shelf. >-Returns 0 otherwise. >-For the actions invite and acceptshare a second errorcode is returned if the >-result is false. See opac-shareshelf.pl >- >-=cut >- >-sub ShelfPossibleAction { >- my ( $user, $shelfnumber, $action ) = @_; >- $action= 'view' unless $action; >- $user=0 unless $user; >- >- if($action =~ /^new/) { #no shelfnumber needed >- if($action eq 'new_private') { >- return $user>0; >- } >- elsif($action eq 'new_public') { >- return $user>0 && C4::Context->preference('OpacAllowPublicListCreation'); >- } >- return 0; >- } >- >- return 0 unless defined($shelfnumber); >- >- if ( $user > 0 and $action eq 'delete_shelf' ) { >- my $borrower = C4::Members::GetMember( borrowernumber => $user ); >- require C4::Auth; >- return 1 >- if C4::Auth::haspermission( $borrower->{userid}, { lists => 'delete_public_lists' } ); >- } >- >- my $dbh = C4::Context->dbh; >- my $query = q{ >- SELECT COALESCE(owner,0) AS owner, category, allow_add, allow_delete_own, allow_delete_other, COALESCE(sh.borrowernumber,0) AS borrowernumber >- FROM virtualshelves vs >- LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber >- AND sh.borrowernumber=? >- WHERE vs.shelfnumber=? >- }; >- my $sth = $dbh->prepare($query); >- $sth->execute($user, $shelfnumber); >- my $shelf= $sth->fetchrow_hashref; >- >- return 0 unless $shelf && ($shelf->{category}==2 || $shelf->{owner}==$user || ($user && $shelf->{borrowernumber}==$user)); >- if($action eq 'view') { >- #already handled in the above condition >- return 1; >- } >- elsif($action eq 'add') { >- return 0 if $user<=0; #should be logged in >- return 1 if $shelf->{allow_add}==1 || $shelf->{owner}==$user; >- #owner may always add >- } >- elsif($action eq 'delete') { >- #this answer is just diplomatic: it says that you may be able to delete >- #some items from that shelf >- #it does not answer the question about a specific biblio >- #Koha::Virtualshelf->remove_biblios checks the situation per biblio >- return 1 if $user>0 && ($shelf->{allow_delete_own}==1 || $shelf->{allow_delete_other}==1); >- } >- elsif($action eq 'invite') { >- #for sharing you must be the owner and the list must be private >- if( $shelf->{category}==1 ) { >- return 1 if $shelf->{owner}==$user; >- return (0, 4); # code 4: should be owner >- } >- else { >- return (0, 5); # code 5: should be private list >- } >- } >- elsif($action eq 'acceptshare') { >- #the key for accepting is checked later in Koha::Virtualshelf->share >- #you must not be the owner, list must be private >- if( $shelf->{category}==1 ) { >- return (0, 8) if $shelf->{owner}==$user; >- #code 8: should not be owner >- return 1; >- } >- else { >- return (0, 5); # code 5: should be private list >- } >- } >- elsif($action eq 'manage' or $action eq 'delete_shelf') { >- return 1 if $user && $shelf->{owner}==$user; >- } >- return 0; >-} >- > =head2 ShelvesMax > > $howmany= ShelvesMax($context); >diff --git a/opac/opac-addbybiblionumber.pl b/opac/opac-addbybiblionumber.pl >index 43d4489..b20702d 100755 >--- a/opac/opac-addbybiblionumber.pl >+++ b/opac/opac-addbybiblionumber.pl >@@ -87,47 +87,57 @@ sub AddBibliosToShelf { > } > > sub HandleNewVirtualShelf { >- if($authorized= ShelfPossibleAction($loggedinuser, undef, $category==1? 'new_private': 'new_public')) { >- my $shelf = eval { >- Koha::Virtualshelf->new( >- { >- shelfname => $newvirtualshelf, >- category => $category, >- owner => $loggedinuser, >- } >- ); >- }; >- if ( $@ or not $shelf ) { >- $authorized=0; >- $errcode=1; >- return; >- } >- AddBibliosToShelf($shelfnumber, @biblionumber); >- #Reload the page where you came from >- print $query->header; >- print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>"; >+ if ( $loggedinuser > 0 and >+ ( >+ $category == 1 >+ or $category == 2 and $loggedinuser>0 && C4::Context->preference('OpacAllowPublicListCreation') >+ ) >+ ) { >+ my $shelf = eval { >+ Koha::Virtualshelf->new( >+ { >+ shelfname => $newvirtualshelf, >+ category => $category, >+ owner => $loggedinuser, >+ } >+ ); >+ }; >+ if ( $@ or not $shelf ) { >+ $authorized = 0; >+ $errcode = 1; >+ return; >+ } >+ AddBibliosToShelf($shelfnumber, @biblionumber); >+ #Reload the page where you came from >+ print $query->header; >+ print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>"; > } > } > > sub HandleShelfNumber { >- if($authorized= ShelfPossibleAction($loggedinuser, $shelfnumber, 'add')) { >- AddBibliosToShelf($shelfnumber,@biblionumber); >- #Close this page and return >- print $query->header; >- print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>"; >+ my $shelfnumber = $query->param('shelfnumber'); >+ my $shelf = Koha::Virtualshelves->find( $shelfnumber ); >+ if ( $shelf->can_biblios_be_added( $loggedinuser ) ) { >+ AddBibliosToShelf($shelfnumber,@biblionumber); >+ #Close this page and return >+ print $query->header; >+ print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>"; >+ } else { >+ # TODO > } > } > > sub HandleSelectedShelf { >- if($authorized= ShelfPossibleAction( $loggedinuser, $selectedshelf, 'add')){ >- #adding to specific shelf >- my $shelfnumber = $query->param('selectedshelf'); >- my $shelf = Koha::Virtualshelves->find( $shelfnumber ); >+ my $shelfnumber = $query->param('selectedshelf'); >+ my $shelf = Koha::Virtualshelves->find( $shelfnumber ); >+ if ( $shelf->can_biblios_be_added( $loggedinuser ) ) { > $template->param( > singleshelf => 1, > shelfnumber => $shelf->shelfnumber, > shelfname => $shelf->shelfname, > ); >+ } else { >+ # TODO > } > } > >diff --git a/opac/opac-downloadshelf.pl b/opac/opac-downloadshelf.pl >index 4b932fc..f7e5571 100755 >--- a/opac/opac-downloadshelf.pl >+++ b/opac/opac-downloadshelf.pl >@@ -107,8 +107,6 @@ if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { > > } else { > >- my $shelf = Koha::Virtualshelves->find( $shelfid ); >- > # if modal context is passed set a variable so that page markup can be different > if($context eq "modal"){ > $template->param(modal => 1); >diff --git a/opac/opac-sendshelf.pl b/opac/opac-sendshelf.pl >index 07353ac..b0215cc 100755 >--- a/opac/opac-sendshelf.pl >+++ b/opac/opac-sendshelf.pl >@@ -52,7 +52,8 @@ my $email = $query->param('email'); > > my $dbh = C4::Context->dbh; > >-if ( ShelfPossibleAction( (defined($borrowernumber) ? $borrowernumber : -1), $shelfid, 'view' ) ) { >+my $shelf = Koha::Virtualshelves->find( $shelfid ); >+if ( $shelf->can_be_viewed( $borrowernumber ) ) { > > if ( $email ) { > my $message = Koha::Email->new(); >diff --git a/opac/opac-shareshelf.pl b/opac/opac-shareshelf.pl >index a75875c..ceafb33 100755 >--- a/opac/opac-shareshelf.pl >+++ b/opac/opac-shareshelf.pl >@@ -115,13 +115,14 @@ sub confirm_invite { > sub show_accept { > my ($param) = @_; > >- my @rv = ShelfPossibleAction( $param->{loggedinuser}, >- $param->{shelfnumber}, 'acceptshare' ); >- $param->{errcode} = $rv[1] if !$rv[0]; >- return if $param->{errcode}; >+ my $shelfnumber = $param->{shelfnumber}; >+ my $shelf = Koha::Virtualshelves->find( $shelfnumber ); > >- #errorcode 5: should be private list >- #errorcode 8: should not be owner >+ # The key for accepting is checked later in Koha::Virtualshelf->share >+ # You must not be the owner and the list must be private >+ if ( $shelf->category == 2 or $shelf->owner == $param->{loggedinuser} ) { >+ return; >+ } > > # We could have used ->find with the share id, but we don't want to change > # the url sent to the patron >-- >2.1.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14544
:
41034
|
41035
|
41036
|
41037
|
41038
|
41039
|
41040
|
41041
|
41042
|
41403
|
41404
|
41405
|
41406
|
41407
|
41408
|
41409
|
41410
|
41411
|
41412
|
41584
|
41585
|
41586
|
41587
|
41588
|
41589
|
41590
|
41591
|
41592
|
41593
|
41594
|
41595
|
41596
|
41597
|
41598
|
41599
|
41600
|
41601
|
41716
|
41717
|
41718
|
41719
|
41720
|
41721
|
41722
|
41723
|
41724
|
41725
|
41726
|
41727
|
41728
|
41729
|
41730
|
41731
|
41732
|
41733
|
41766
|
41909
|
41910
|
41913
|
41914
|
41915
|
41917
|
41918
|
41919
|
41924
|
41927
|
41931
|
41932
|
41953
|
41954
|
41955
|
41956
|
41957
|
41958
|
41959
|
41960
|
41961
|
41962
|
41963
|
41964
|
41965
|
41966
|
41967
|
41968
|
41969
|
41970
|
41973
|
41974
|
41975
|
41976
|
41977
|
41978
|
41979
|
41980
|
41981
|
41982
|
41983
|
41986
|
41988
|
42192
|
42199
|
42200
|
42201
|
42202
|
42203
|
42204
|
42205
|
42206
|
42207
|
42208
|
42209
|
42210
|
42211
|
42212
|
42213
|
42214
|
42215
|
42216
|
42217
|
42218
|
42219
|
42638
|
43223
|
43224
|
43225
|
43226
|
43227
|
43228
|
43229
|
43230
|
43231
|
43232
|
43233
|
43234
|
43235
|
43236
|
43237
|
43238
|
43239
|
43240
|
43241
|
43242
|
43243
|
43296
|
43334
|
43335
|
43403
|
43456
|
43457
|
43458
|
43459
|
43460
|
43461
|
43462
|
43463
|
43464
|
43465
|
43466
|
43467
|
43469
|
43470
|
43471
|
43472
|
43473
|
43474
|
43475
|
43476
|
43477
|
43478
|
43479
|
43480
|
43481
|
43482
|
43485
|
43486
|
43487
|
44467
|
44468
|
44469
|
44470
|
44471
|
44472
|
44473
|
44474
|
44475
|
44476
|
44477
|
44478
|
44479
|
44480
|
44481
|
44482
|
44483
|
44484
|
44485
|
44486
|
44487
|
44758
|
44845
|
44852
|
44863
|
44872