Bugzilla – Attachment 140888 Details for
Bug 30982
Use the REST API for background job list view
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30982: Make code more re-usable
Bug-30982-Make-code-more-re-usable.patch (text/plain), 2.77 KB, created by
Marcel de Rooy
on 2022-09-23 09:45:15 UTC
(
hide
)
Description:
Bug 30982: Make code more re-usable
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2022-09-23 09:45:15 UTC
Size:
2.77 KB
patch
obsolete
>From d3c345dbefc4040fd0e7eb500a371f1519ce8c46 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Wed, 29 Jun 2022 15:14:41 +0100 >Subject: [PATCH] Bug 30982: Make code more re-usable >Content-Type: text/plain; charset=utf-8 > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > Koha/BackgroundJobs.pm | 28 ++++++++++++++++++++++++++++ > Koha/REST/V1/BackgroundJobs.pm | 16 ++-------------- > 2 files changed, 30 insertions(+), 14 deletions(-) > >diff --git a/Koha/BackgroundJobs.pm b/Koha/BackgroundJobs.pm >index d2ff22347f..194123020d 100644 >--- a/Koha/BackgroundJobs.pm >+++ b/Koha/BackgroundJobs.pm >@@ -29,6 +29,34 @@ Koha::BackgroundJobs - Koha BackgroundJob Object set class > > =cut > >+=head2 search_limited >+ >+ my $background_jobs = Koha::BackgroundJobs->search_limited( $params, $attributes ); >+ >+Returns all background jobs the logged in user should be allowed to see >+ >+=cut >+ >+sub search_limited { >+ my ( $self, $params, $attributes ) = @_; >+ >+ # Assume permission if context has no user >+ my $can_manage_background_jobs = 1; >+ >+ my $logged_in_user; >+ my $userenv = C4::Context->userenv; >+ if ( $userenv and $userenv->{number} ) { >+ $logged_in_user = Koha::Patrons->find( $userenv->{number} ); >+ $can_manage_background_jobs = $logged_in_user->has_permission( >+ { parameters => 'manage_background_jobs' } ); >+ } >+ >+ return $can_manage_background_jobs >+ ? $self->search( $params, $attributes ) >+ : $self->search( { borrowernumber => $logged_in_user->borrowernumber } ) >+ ->search( $params, $attributes ); >+} >+ > =head3 _type > > =cut >diff --git a/Koha/REST/V1/BackgroundJobs.pm b/Koha/REST/V1/BackgroundJobs.pm >index 55f121b403..251d5657f3 100644 >--- a/Koha/REST/V1/BackgroundJobs.pm >+++ b/Koha/REST/V1/BackgroundJobs.pm >@@ -35,24 +35,13 @@ sub list { > my $c = shift->openapi->valid_input or return; > > return try { >- my $patron = $c->stash('koha.user'); >- >- my $can_manage_background_jobs = >- $patron->has_permission( { parameters => 'manage_background_jobs' } ); >- >- my $background_jobs_set = >- $can_manage_background_jobs >- ? Koha::BackgroundJobs->new >- : Koha::BackgroundJobs->search( >- { borrowernumber => $patron->borrowernumber } ); >- >- my $background_jobs = $c->objects->search( $background_jobs_set ); >+ my $background_jobs_set = Koha::BackgroundJobs->new; >+ my $background_jobs = $c->objects->search($background_jobs_set); > return $c->render( status => 200, openapi => $background_jobs ); > } > catch { > $c->unhandled_exception($_); > }; >- > } > > sub get { >@@ -90,5 +79,4 @@ sub get { > }; > } > >- > 1; >-- >2.30.2
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 30982
:
136245
|
136246
|
136670
|
136671
|
136672
|
136707
|
136708
|
136715
|
138114
|
139636
|
139637
|
139638
|
139639
|
139640
|
139641
|
140488
|
140489
|
140490
|
140491
|
140492
|
140493
|
140494
|
140495
|
140496
|
140497
|
140498
|
140589
|
140590
|
140591
|
140592
|
140593
|
140594
|
140595
|
140596
|
140597
|
140598
|
140599
|
140789
|
140884
|
140885
|
140886
|
140887
| 140888 |
140889
|
140890
|
140891
|
140892
|
140893
|
140894
|
140895
|
140896
|
140897
|
142859