Bugzilla – Attachment 152341 Details for
Bug 33996
Authority objects missing mapping
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33996: Add missing authority objects mapping
Bug-33996-Add-missing-authority-objects-mapping.patch (text/plain), 9.18 KB, created by
Sam Lau
on 2023-06-14 15:03:48 UTC
(
hide
)
Description:
Bug 33996: Add missing authority objects mapping
Filename:
MIME Type:
Creator:
Sam Lau
Created:
2023-06-14 15:03:48 UTC
Size:
9.18 KB
patch
obsolete
>From 1a04c116d91165e0c73574ab89aa6a50b00a3020 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 13 Jun 2023 10:13:40 -0300 >Subject: [PATCH] Bug 33996: Add missing authority objects mapping > >This patch adds a minimal mapping (i.e. some things get excluded from >the API objects for now). It makes some attributes consistent with the >current API names, and the rest can be added later when they become >needed and we discuss a proper name. But right now is a mess :-/ > >To test: >1. Apply this patch >2. Run: > $ ktd --shell > k$ prove t/db_dependent/api/v1/authorities.t >=> SUCCESS: Tests pass! >3. Sign off :-D > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: Sam Lau <samalau@gmail.com> >--- > Koha/Authority.pm | 27 +++++++++-- > t/db_dependent/api/v1/authorities.t | 71 +++++++++++++---------------- > 2 files changed, 56 insertions(+), 42 deletions(-) > >diff --git a/Koha/Authority.pm b/Koha/Authority.pm >index ee175c2244..d05192007a 100644 >--- a/Koha/Authority.pm >+++ b/Koha/Authority.pm >@@ -30,7 +30,7 @@ Koha::Authority - Koha Authority Object class > > =head1 API > >-=head2 Instance Methods >+=head2 Class methods > > =head3 get_usage_count > >@@ -168,9 +168,30 @@ sub record_schema { > : 'MARC21'; > } > >-=head2 Class Methods >+=head3 to_api_mapping > >-=head3 type >+This method returns the mapping for representing a Koha::Authority object >+on the API. >+ >+=cut >+ >+sub to_api_mapping { >+ return { >+ authid => 'authority_id', >+ authtrees => undef, >+ authtypecode => 'framework_id', >+ datecreated => 'creation_date', >+ linkid => undef, >+ marc => undef, >+ marcxml => undef, >+ modification_time => 'updated_on', >+ origincode => undef, >+ }; >+} >+ >+=head2 Internal methods >+ >+=head3 _type > > =cut > >diff --git a/t/db_dependent/api/v1/authorities.t b/t/db_dependent/api/v1/authorities.t >index ba6eaaf186..85da554eb1 100755 >--- a/t/db_dependent/api/v1/authorities.t >+++ b/t/db_dependent/api/v1/authorities.t >@@ -28,6 +28,8 @@ use Test::Warn; > use t::lib::Mocks; > use t::lib::TestBuilder; > >+use Mojo::JSON qw(encode_json); >+ > use C4::Auth; > > use Koha::Authorities; >@@ -67,34 +69,34 @@ subtest 'get() tests' => sub { > </record>| > } }); > >- $t->get_ok("//$userid:$password@/api/v1/authorities/" . $authority->authid) >+ $t->get_ok("//$userid:$password@/api/v1/authorities/" . $authority->id) > ->status_is(403); > > $patron->flags(4)->store; > >- $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->authid >+ $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id > => { Accept => 'application/weird+format' } ) > ->status_is(400); > >- $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->authid >+ $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id > => { Accept => 'application/json' } ) > ->status_is(200) >- ->json_is( '/authid', $authority->authid ) >- ->json_is( '/authtypecode', $authority->authtypecode ); >+ ->json_is( '/authority_id', $authority->id ) >+ ->json_is( '/framework_id', $authority->authtypecode ); > >- $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->authid >+ $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id > => { Accept => 'application/marcxml+xml' } ) > ->status_is(200); > >- $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->authid >+ $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id > => { Accept => 'application/marc-in-json' } ) > ->status_is(200); > >- $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->authid >+ $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id > => { Accept => 'application/marc' } ) > ->status_is(200); > >- $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->authid >+ $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id > => { Accept => 'text/plain' } ) > ->status_is(200) > ->content_is(q|LDR 00079 2200049 4500 >@@ -103,7 +105,7 @@ subtest 'get() tests' => sub { > _aMy Corporation|); > > $authority->delete; >- $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->authid >+ $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id > => { Accept => 'application/marc' } ) > ->status_is(404) > ->json_is( '/error', 'Object not found.' ); >@@ -138,16 +140,16 @@ subtest 'delete() tests' => sub { > </record>| > } }); > >- $t->delete_ok("//$userid:$password@/api/v1/authorities/".$authority->authid) >+ $t->delete_ok("//$userid:$password@/api/v1/authorities/".$authority->id) > ->status_is(403, 'Not enough permissions makes it return the right code'); > > $patron->flags( 2 ** 14 )->store; # 14 => editauthorities userflag > >- $t->delete_ok("//$userid:$password@/api/v1/authorities/".$authority->authid) >+ $t->delete_ok("//$userid:$password@/api/v1/authorities/".$authority->id) > ->status_is(204, 'SWAGGER3.2.4') > ->content_is('', 'SWAGGER3.3.4'); > >- $t->delete_ok("//$userid:$password@/api/v1/authorities/".$authority->authid) >+ $t->delete_ok("//$userid:$password@/api/v1/authorities/".$authority->id) > ->status_is(404); > > $schema->storage->txn_rollback; >@@ -261,7 +263,7 @@ subtest 'put() tests' => sub { > </record>| > } }); > >- my $authid = $authority->authid; >+ my $authid = $authority->id; > my $authtypecode = $authority->authtypecode; > > my $marcxml = q|<?xml version="1.0" encoding="UTF-8"?> >@@ -333,7 +335,7 @@ subtest 'list() tests' => sub { > $patron->discard_changes; > my $userid = $patron->userid; > >- my $authid1 = $builder->build_object({ 'class' => 'Koha::Authorities', value => { >+ my $auth_id_1 = $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> >@@ -344,7 +346,7 @@ subtest 'list() tests' => sub { > </record>| > } })->authid; > >- my $authid2 = $builder->build_object({ 'class' => 'Koha::Authorities', value => { >+ my $auth_id_2 = $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> >@@ -355,37 +357,28 @@ subtest 'list() tests' => sub { > </record>| > } })->authid; > >- my $search = >-"[{\"authid\": \"$authid1\"}, {\"authid\": \"$authid2\"}]"; >- $t->get_ok( >- "//$userid:$password@/api/v1/authorities/" => { 'x-koha-query' => $search } >- )->status_is(403); >+ my $query = encode_json( [ { authority_id => $auth_id_1 }, { authority_id => $auth_id_2 } ] ); >+ >+ $t->get_ok("//$userid:$password@/api/v1/authorities?q=$query")->status_is(403); > > $patron->flags(4)->store; > >- $t->get_ok( "//$userid:$password@/api/v1/authorities/" => >- { Accept => 'application/weird+format', 'x-koha-query' => $search } ) >- ->status_is(400); >+ $t->get_ok( "//$userid:$password@/api/v1/authorities?q=$query" => { Accept => 'application/weird+format' } ) >+ ->status_is(400); > >- $t->get_ok( "//$userid:$password@/api/v1/authorities/" => >- { Accept => 'application/json', 'x-koha-query' => $search } ) >- ->status_is(200); >+ $t->get_ok( "//$userid:$password@/api/v1/authorities?q=$query" => { Accept => 'application/json' } ) >+ ->status_is(200); > >- $t->get_ok( "//$userid:$password@/api/v1/authorities/" => >- { Accept => 'application/marcxml+xml', 'x-koha-query' => $search } ) >- ->status_is(200); >+ $t->get_ok( "//$userid:$password@/api/v1/authorities?q=$query" => { Accept => 'application/marcxml+xml' } ) >+ ->status_is(200); > >- $t->get_ok( "//$userid:$password@/api/v1/authorities/" => >- { Accept => 'application/marc-in-json', 'x-koha-query' => $search } ) >- ->status_is(200); >+ $t->get_ok( "//$userid:$password@/api/v1/authorities?q=$query" => { Accept => 'application/marc-in-json' } ) >+ ->status_is(200); > >- $t->get_ok( "//$userid:$password@/api/v1/authorities/" => >- { Accept => 'application/marc', 'x-koha-query' => $search } ) >- ->status_is(200); >+ $t->get_ok( "//$userid:$password@/api/v1/authorities?q=$query" => { Accept => 'application/marc' } ) >+ ->status_is(200); > >- $t->get_ok( "//$userid:$password@/api/v1/authorities/" => >- { Accept => 'text/plain', 'x-koha-query' => $search } ) >- ->status_is(200); >+ $t->get_ok( "//$userid:$password@/api/v1/authorities?q=$query" => { Accept => 'text/plain' } )->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 33996
:
152293
|
152341
|
152688
|
152689