Bugzilla – Attachment 144472 Details for
Bug 31793
Add DELETE endpoint for Authorities
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31793: Add REST endpoint to delete authorities
Bug-31793-Add-REST-endpoint-to-delete-authorities.patch (text/plain), 5.75 KB, created by
Agustín Moyano
on 2022-12-07 15:21:46 UTC
(
hide
)
Description:
Bug 31793: Add REST endpoint to delete authorities
Filename:
MIME Type:
Creator:
Agustín Moyano
Created:
2022-12-07 15:21:46 UTC
Size:
5.75 KB
patch
obsolete
>From 73ff3c1be01bcf67aefcd492fa2c368daaa5d3c5 Mon Sep 17 00:00:00 2001 >From: Agustin Moyano <agustinmoyano@theke.io> >Date: Wed, 7 Dec 2022 12:05:35 -0300 >Subject: [PATCH] Bug 31793: Add REST endpoint to delete authorities > >To test: >1. Apply patch >2. Set RESTBasicAuth preference to true >3. Get the id of an authority >4. Make a DELETE request to /api/v1/authorities/{authid} >5. Check that the authority was deleted >6. Sign off >--- > Koha/REST/V1/Authorities.pm | 37 ++++++++++++++++++ > api/v1/swagger/paths/authorities.yaml | 42 +++++++++++++++++++++ > t/db_dependent/api/v1/authorities.t | 54 ++++++++++++++++++++++++++- > 3 files changed, 132 insertions(+), 1 deletion(-) > >diff --git a/Koha/REST/V1/Authorities.pm b/Koha/REST/V1/Authorities.pm >index 5266fab705..136e3134e6 100644 >--- a/Koha/REST/V1/Authorities.pm >+++ b/Koha/REST/V1/Authorities.pm >@@ -20,6 +20,7 @@ use Modern::Perl; > use Mojo::Base 'Mojolicious::Controller'; > > use Koha::Authorities; >+use C4::AuthoritiesMarc qw( DelAuthority ); > > use List::MoreUtils qw( any ); > use MARC::Record::MiJ; >@@ -99,4 +100,40 @@ sub get { > }; > } > >+=head3 delete >+ >+Controller function that handles deleting an authority object >+ >+=cut >+ >+sub delete { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $authority = Koha::Authorities->find( { authid => $c->validation->param('authority_id') } ); >+ >+ if ( not defined $authority ) { >+ return $c->render( >+ status => 404, >+ openapi => { error => "Object not found" } >+ ); >+ } >+ >+ return try { >+ my $error = DelAuthority( { authid => $authority->authid } ); >+ >+ if ($error) { >+ return $c->render( >+ status => 409, >+ openapi => { error => $error } >+ ); >+ } >+ else { >+ return $c->render( status => 204, openapi => "" ); >+ } >+ } >+ catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ > 1; >diff --git a/api/v1/swagger/paths/authorities.yaml b/api/v1/swagger/paths/authorities.yaml >index c5f1044b72..0b47d41389 100644 >--- a/api/v1/swagger/paths/authorities.yaml >+++ b/api/v1/swagger/paths/authorities.yaml >@@ -50,3 +50,45 @@ > x-koha-authorization: > permissions: > catalogue: "1" >+ delete: >+ x-mojo-to: Authorities#delete >+ operationId: deleteAuthority >+ tags: >+ - authorities >+ summary: Delete authority >+ parameters: >+ - $ref: "../swagger.yaml#/parameters/authority_id_pp" >+ produces: >+ - application/json >+ responses: >+ "204": >+ description: Authority deleted >+ schema: >+ type: string >+ "401": >+ description: Authentication required >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "403": >+ description: Access forbidden >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "404": >+ description: Biblio not found >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "409": >+ description: Unable to perform action on biblio >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "500": >+ description: Internal error >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "503": >+ description: Under maintenance >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ x-koha-authorization: >+ permissions: >+ editcatalogue: edit_catalogue >diff --git a/t/db_dependent/api/v1/authorities.t b/t/db_dependent/api/v1/authorities.t >index 5edc612838..13e101f951 100755 >--- a/t/db_dependent/api/v1/authorities.t >+++ b/t/db_dependent/api/v1/authorities.t >@@ -20,7 +20,7 @@ use Modern::Perl; > use utf8; > use Encode; > >-use Test::More tests => 1; >+use Test::More tests => 2; > use Test::MockModule; > use Test::Mojo; > use Test::Warn; >@@ -108,5 +108,57 @@ subtest 'get() tests' => sub { > ->status_is(404) > ->json_is( '/error', 'Object not found.' ); > >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'delete() tests' => sub { >+ >+ plan tests => 7; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 0 } # no permissions >+ } >+ ); >+ my $password = 'thePassword123'; >+ $patron->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $patron->userid; >+ >+ my $authority = $builder->build_object({ 'class' => 'Koha::Authorities', value => { >+ marcxml => q|<?xml version="1.0" encoding="UTF-8"?> >+<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/MARC21/slim" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"> >+ <controlfield tag="001">1001</controlfield> >+ <datafield tag="110" ind1=" " ind2=" "> >+ <subfield code="9">102</subfield> >+ <subfield code="a">My Corporation</subfield> >+ </datafield> >+</record>| >+ } }); >+ >+ $t->delete_ok("//$userid:$password@/api/v1/authorities/".$authority->authid) >+ ->status_is(403, 'Not enough permissions makes it return the right code'); >+ >+ # Add permissions >+ $builder->build( >+ { >+ source => 'UserPermission', >+ value => { >+ borrowernumber => $patron->borrowernumber, >+ module_bit => 9, >+ code => 'edit_catalogue' >+ } >+ } >+ ); >+ >+ $t->delete_ok("//$userid:$password@/api/v1/authorities/".$authority->authid) >+ ->status_is(204, 'SWAGGER3.2.4') >+ ->content_is('', 'SWAGGER3.3.4'); >+ >+ $t->delete_ok("//$userid:$password@/api/v1/authorities/".$authority->authid) >+ ->status_is(404); >+ > $schema->storage->txn_rollback; > }; >\ No newline at end of file >-- >2.25.1
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 31793
:
144472
|
144705
|
147808
|
147809
|
147810
|
147831
|
147832
|
147833