Bugzilla – Attachment 58996 Details for
Bug 17371
Add routes for biblios [OMNIBUS]
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Added filtering OPAChiddenItems
Added-filtering-OPAChiddenItems.patch (text/plain), 2.74 KB, created by
Jiri Kozlovsky
on 2017-01-15 19:44:32 UTC
(
hide
)
Description:
Added filtering OPAChiddenItems
Filename:
MIME Type:
Creator:
Jiri Kozlovsky
Created:
2017-01-15 19:44:32 UTC
Size:
2.74 KB
patch
obsolete
>From 10ea8d538b892cc692ecd82b1e0a33794bc569f7 Mon Sep 17 00:00:00 2001 >From: Jiri Kozlovsky <mail@jkozlovsky.cz> >Date: Sun, 15 Jan 2017 17:07:48 +0000 >Subject: [PATCH] Added filtering OPAChiddenItems > >Test plan: > 1) Create OpacHiddenItems rules to hide chosen items > 2) Check that regular user doesn't see those items through the API > 3) Check that librarian can see them through the API > >https://bugs.koha-community.org/show_bug.cgi?id=17371 >--- > Koha/REST/V1/Biblio.pm | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 48 insertions(+), 2 deletions(-) > >diff --git a/Koha/REST/V1/Biblio.pm b/Koha/REST/V1/Biblio.pm >index d936530..c9bc4c8 100644 >--- a/Koha/REST/V1/Biblio.pm >+++ b/Koha/REST/V1/Biblio.pm >@@ -19,8 +19,11 @@ use Modern::Perl; > > use Mojo::Base 'Mojolicious::Controller'; > >+use C4::Auth qw( haspermission ); >+use C4::Context; >+ > use C4::Biblio qw( GetBiblioData AddBiblio ModBiblio DelBiblio ); >-use C4::Items qw ( AddItemBatchFromMarc ); >+use C4::Items qw ( AddItemBatchFromMarc GetHiddenItemnumbers ); > use Koha::Biblios; > use MARC::Record; > use MARC::Batch; >@@ -46,7 +49,15 @@ sub getitems { > unless ($biblio) { > return $c->$cb({error => "Biblio not found"}, 404); > } >- return $c->$cb({ biblio => $biblio->unblessed, items => $biblio->items->unblessed }, 200); >+ >+ my $items = $biblio->items->unblessed; >+ my $user = $c->stash('koha.user'); >+ >+ if (_hide_opac_hidden_items($user)) { >+ $items = _filter_hidden_items($items); >+ } >+ >+ return $c->$cb({ biblio => $biblio->unblessed, items => $items }, 200); > } > > sub getexpanded { >@@ -56,7 +67,14 @@ sub getexpanded { > unless ($biblio) { > return $c->$cb({error => "Biblio not found"}, 404); > } >+ > my $expanded = $biblio->items->unblessed; >+ my $user = $c->stash('koha.user'); >+ >+ if (_hide_opac_hidden_items($user)) { >+ $expanded = _filter_hidden_items($expanded); >+ } >+ > for my $item (@{$expanded}) { > > # we assume item is available by default >@@ -170,4 +188,32 @@ sub delete { > } > } > >+sub _hide_opac_hidden_items { >+ my ($user) = @_; >+ >+ my $isStaff = haspermission($user->userid, {borrowers => 1}); >+ >+ # Hide the hidden items from all but staff >+ my $hide_items = ! $isStaff && ( C4::Context->preference('OpacHiddenItems') !~ /^\s*$/ ); >+ >+ return $hide_items; >+} >+ >+sub _filter_hidden_items { >+ my ($items) = @_; >+ >+ my @hiddenitems = C4::Items::GetHiddenItemnumbers( @{$items} ); >+ >+ my @filteredItems = (); >+ >+ # Convert to a hash for quick searching >+ my %hiddenitems = map { $_ => 1 } @hiddenitems; >+ for my $item (@{$items}) { >+ next if $hiddenitems{$item->{itemnumber}}; >+ push @filteredItems, $item; >+ } >+ >+ return \@filteredItems; >+} >+ > 1; >-- >2.1.4
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 17371
:
55898
|
58995
|
58996
|
64842