Bugzilla – Attachment 165050 Details for
Bug 31791
Add the ability to lock records to prevent modification through the Koha staff interface
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31791: Add x-record-source-id header to POST /biblios
Bug-31791-Add-x-record-source-id-header-to-POST-bi.patch (text/plain), 5.66 KB, created by
Arthur Suzuki
on 2024-04-18 08:06:40 UTC
(
hide
)
Description:
Bug 31791: Add x-record-source-id header to POST /biblios
Filename:
MIME Type:
Creator:
Arthur Suzuki
Created:
2024-04-18 08:06:40 UTC
Size:
5.66 KB
patch
obsolete
>From 54bfa81ff6cc9e3da2c455e6f7ad2ec1319a4f60 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 8 Feb 2024 20:18:35 -0300 >Subject: [PATCH] Bug 31791: Add x-record-source-id header to POST /biblios > >This patch adds support for setting the record source on the API. It >does so by adding support for a new header `x-record-source-id`. > >Setting the record source is restricted to patrons with the >`set_record_sources` permission. > >A 403 error is returned on an attempt to set it without the correct >permissions. > >The feature is documented on the spec. > >To test: >1. Apply this patch >2. Run: > $ ktd --shell > k$ prove t/db_dependent/api/v1/biblios.t >=> SUCCESS: Tests pass! Tests cover the right use cases! >3. Play with Postman (or similar) >4. Sign off :-D > >Sponsored-by: ByWater Solutions >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Signed-off-by: Lucas Gass <lucas@bywatersolutions.com> >Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> >--- > Koha/REST/V1/Biblios.pm | 19 +++++++++++++--- > api/v1/swagger/paths/biblios.yaml | 1 + > api/v1/swagger/swagger.yaml | 6 ++++++ > t/db_dependent/api/v1/biblios.t | 36 ++++++++++++++++++++++++++++++- > 4 files changed, 58 insertions(+), 4 deletions(-) > >diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm >index edb51653146..b892c8c0e22 100644 >--- a/Koha/REST/V1/Biblios.pm >+++ b/Koha/REST/V1/Biblios.pm >@@ -26,6 +26,7 @@ use Koha::RecordProcessor; > use C4::Biblio qw( DelBiblio AddBiblio ModBiblio ); > use C4::Search qw( FindDuplicate ); > >+use C4::Auth qw( haspermission ); > use C4::Barcodes::ValueBuilder; > use C4::Context; > >@@ -714,6 +715,19 @@ sub add { > my $flavour = $headers->header('x-record-schema'); > $flavour //= C4::Context->preference('marcflavour'); > >+ my $record_source_id = $headers->header('x-record-source-id'); >+ >+ if ($record_source_id) { >+ >+ # We've been passed a record source. Verify they are allowed to >+ unless ( haspermission( $c->stash('koha.user')->userid, { editcatalogue => 'set_record_sources' } ) ) { >+ return $c->render( >+ status => 403, >+ openapi => { error => 'You do not have permission to set the record source' } >+ ); >+ } >+ } >+ > my $record; > > my $frameworkcode = $headers->header('x-framework-id'); >@@ -751,12 +765,11 @@ sub add { > } > ) unless !$duplicatebiblionumber || $confirm_not_duplicate; > >- my ( $biblionumber, $oldbibitemnum ); >- ( $biblionumber, $oldbibitemnum ) = AddBiblio( $record, $frameworkcode ); >+ my ( $biblio_id ) = AddBiblio( $record, $frameworkcode, { record_source_id => $record_source_id } ); > > $c->render( > status => 200, >- openapi => { id => $biblionumber } >+ openapi => { id => $biblio_id } > ); > } > catch { >diff --git a/api/v1/swagger/paths/biblios.yaml b/api/v1/swagger/paths/biblios.yaml >index 10b2b42820b..f41a08363e7 100644 >--- a/api/v1/swagger/paths/biblios.yaml >+++ b/api/v1/swagger/paths/biblios.yaml >@@ -22,6 +22,7 @@ > - $ref: "../swagger.yaml#/parameters/framework_id_header" > - $ref: "../swagger.yaml#/parameters/marc_schema_header" > - $ref: "../swagger.yaml#/parameters/confirm_not_duplicate_header" >+ - $ref: "../swagger.yaml#/parameters/record_source_id_header" > produces: > - application/json > responses: >diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml >index c83ea8c20f9..e432d54c339 100644 >--- a/api/v1/swagger/swagger.yaml >+++ b/api/v1/swagger/swagger.yaml >@@ -847,6 +847,12 @@ parameters: > name: quote_id > required: true > type: integer >+ record_source_id_header: >+ description: Internal record source identifier. >+ name: x-record-source-id >+ in: header >+ required: false >+ type: string > request_id_header: > description: Request id header > in: header >diff --git a/t/db_dependent/api/v1/biblios.t b/t/db_dependent/api/v1/biblios.t >index b7e51a046f7..e65e930bac0 100755 >--- a/t/db_dependent/api/v1/biblios.t >+++ b/t/db_dependent/api/v1/biblios.t >@@ -857,7 +857,7 @@ subtest 'set_rating() tests' => sub { > > subtest 'post() tests' => sub { > >- plan tests => 13; >+ plan tests => 14; > > $schema->storage->txn_begin; > >@@ -1280,6 +1280,40 @@ subtest 'post() tests' => sub { > ->status_is(200) > ->json_has('/id'); > >+ subtest 'x-record-source-id header tests' => sub { >+ >+ plan tests => 5; >+ >+ my $record_source = >+ $builder->build_object( { class => 'Koha::RecordSources', value => { can_be_edited => 0 } } ); >+ >+ $t->post_ok( >+ "//$userid:$password@/api/v1/biblios" => { >+ 'Content-Type' => 'application/marc', 'x-framework-id' => $frameworkcode, >+ 'x-record-source-id' => $record_source->id >+ } => $marc >+ )->status_is(403)->json_is( '/error' => 'You do not have permission to set the record source' ); >+ >+ # Add required subpermission >+ $builder->build( >+ { >+ source => 'UserPermission', >+ value => { >+ borrowernumber => $patron->id, >+ module_bit => 9, >+ code => 'set_record_sources' >+ } >+ } >+ ); >+ >+ $t->post_ok( >+ "//$userid:$password@/api/v1/biblios" => { >+ 'Content-Type' => 'application/marc', 'x-framework-id' => $frameworkcode, >+ 'x-record-source-id' => $record_source->id >+ } => $marc >+ )->status_is(200); >+ }; >+ > $schema->storage->txn_rollback; > }; > >-- >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 31791
:
163371
|
163372
|
163373
|
163374
|
163375
|
163376
|
163377
|
163378
|
163405
|
163408
|
163410
|
163411
|
163413
|
163414
|
163415
|
163416
|
163426
|
163427
|
163428
|
163429
|
163430
|
163431
|
163432
|
163433
|
163434
|
163531
|
163532
|
163533
|
163534
|
163535
|
163536
|
163537
|
163538
|
163539
|
163545
|
164193
|
164194
|
164195
|
164196
|
164197
|
164696
|
164697
|
164698
|
164699
|
164700
|
164701
|
164702
|
164703
|
164704
|
164705
|
165044
|
165045
|
165046
|
165047
|
165048
|
165049
| 165050 |
165051
|
165052
|
165053
|
165697