From 5cfc8b58a658b2df60623dc2e716d12342fa71f6 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 29 Apr 2024 14:38:54 -0300 Subject: [PATCH] Bug 35197: Rename to 'Extended attribute types' Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- Koha/AdditionalField.pm | 29 +++++++++++++-- ...nalFields.pm => ExtendedAttributeTypes.pm} | 24 +++++++++---- .../swagger/definitions/additional_field.yaml | 35 ------------------- .../definitions/extended_attribute_type.yaml | 35 +++++++++++++++++++ ...lds.yaml => extended_attribute_types.yaml} | 20 ++++++----- api/v1/swagger/swagger.yaml | 8 ++--- ...al_fields.t => extended_attribute_types.t} | 14 ++++---- 7 files changed, 102 insertions(+), 63 deletions(-) rename Koha/REST/V1/{AdditionalFields.pm => ExtendedAttributeTypes.pm} (63%) delete mode 100644 api/v1/swagger/definitions/additional_field.yaml create mode 100644 api/v1/swagger/definitions/extended_attribute_type.yaml rename api/v1/swagger/paths/{additional_fields.yaml => extended_attribute_types.yaml} (73%) rename t/db_dependent/api/v1/{additional_fields.t => extended_attribute_types.t} (82%) diff --git a/Koha/AdditionalField.pm b/Koha/AdditionalField.pm index 19f93c7cd9..e3b675bc62 100644 --- a/Koha/AdditionalField.pm +++ b/Koha/AdditionalField.pm @@ -42,6 +42,31 @@ sub effective_authorised_value_category { return $category; } +=head3 to_api + + my $json = $additional_field_type->to_api; + +Overloaded method that returns a JSON representation of the Koha::AdditionalField +object, suitable for API output. + +=cut + +sub to_api { + my ( $self, $params ) = @_; + + my $table_to_resource = { + 'aqbasket' => 'basket', + 'aqinvoices' => 'invoice', + 'aqorders' => 'order', + }; + + my $json = $self->SUPER::to_api($params); + + $json->{resource_type} = $table_to_resource->{ $self->tablename }; + + return $json; +} + =head3 to_api_mapping This method returns the mapping for representing an AdditionalField object @@ -51,8 +76,8 @@ on the API. sub to_api_mapping { return { - id => 'additional_field_id', - tablename => 'table_name', + id => 'extended_attribute_type_id', + tablename => 'resource_type', authorised_value_category => 'authorised_value_category_name', marcfield => 'marc_field', marcfield_mode => 'marc_field_mode' diff --git a/Koha/REST/V1/AdditionalFields.pm b/Koha/REST/V1/ExtendedAttributeTypes.pm similarity index 63% rename from Koha/REST/V1/AdditionalFields.pm rename to Koha/REST/V1/ExtendedAttributeTypes.pm index 21f4b899d5..f44164c628 100644 --- a/Koha/REST/V1/AdditionalFields.pm +++ b/Koha/REST/V1/ExtendedAttributeTypes.pm @@ -1,4 +1,4 @@ -package Koha::REST::V1::AdditionalFields; +package Koha::REST::V1::ExtendedAttributeTypes; # This file is part of Koha. # @@ -34,19 +34,29 @@ use Try::Tiny qw( catch try ); sub list { my $c = shift->openapi->valid_input or return; - my $tablename = $c->param('table_name'); + my $resource_type = $c->param('resource_type'); + + # FIXME: Maybe not the best place for this mapping + my $resource_to_table = { + basket => 'aqbasket', + invoice => 'aqinvoices', + order => 'aqorders', + }; return try { my $additional_fields_set = Koha::AdditionalFields->new; - if ($tablename) { - $additional_fields_set = $additional_fields_set->search( { tablename => $tablename } ); + if ($resource_type) { + $additional_fields_set = + $additional_fields_set->search( { tablename => $resource_to_table->{$resource_type} } ); } - my $additional_fields = $c->objects->search($additional_fields_set); - return $c->render( status => 200, openapi => $additional_fields ); + + return $c->render( + status => 200, + openapi => $c->objects->search($additional_fields_set) + ); } catch { $c->unhandled_exception($_); }; - } 1; diff --git a/api/v1/swagger/definitions/additional_field.yaml b/api/v1/swagger/definitions/additional_field.yaml deleted file mode 100644 index 35d5097c45..0000000000 --- a/api/v1/swagger/definitions/additional_field.yaml +++ /dev/null @@ -1,35 +0,0 @@ ---- -type: object -properties: - additional_field_id: - type: integer - description: internally assigned additional field identifier - readOnly: true - table_name: - description: name of the table this additional field corresponds to - type: string - name: - description: name of the additional field - type: string - authorised_value_category_name: - description: authorised value category of the additional field - type: - - string - - "null" - marc_field: - description: marc field of the additional field - type: string - marc_field_mode: - description: marc field mode of the additional field - type: string - enum: - - get - - set - searchable: - description: is the additional field searchable - type: boolean - -additionalProperties: false -required: - - additional_field_id - - table_name diff --git a/api/v1/swagger/definitions/extended_attribute_type.yaml b/api/v1/swagger/definitions/extended_attribute_type.yaml new file mode 100644 index 0000000000..eb7145065f --- /dev/null +++ b/api/v1/swagger/definitions/extended_attribute_type.yaml @@ -0,0 +1,35 @@ +--- +type: object +properties: + extended_attribute_type_id: + type: integer + description: internally assigned extended attribute type identifier + readOnly: true + resource_type: + description: name of the resource type this extended attribute type corresponds to + type: string + name: + description: name of the extended attribute type + type: string + authorised_value_category_name: + description: authorised value category of the extended attribute type values + type: + - string + - "null" + marc_field: + description: marc field of the extended attribute type + type: string + marc_field_mode: + description: marc field mode of the extended attribute type + type: string + enum: + - get + - set + searchable: + description: is the extended attribute type searchable + type: boolean + +additionalProperties: false +required: + - extended_attribute_type_id + - resource_type diff --git a/api/v1/swagger/paths/additional_fields.yaml b/api/v1/swagger/paths/extended_attribute_types.yaml similarity index 73% rename from api/v1/swagger/paths/additional_fields.yaml rename to api/v1/swagger/paths/extended_attribute_types.yaml index d90183df4c..f96049f1ed 100644 --- a/api/v1/swagger/paths/additional_fields.yaml +++ b/api/v1/swagger/paths/extended_attribute_types.yaml @@ -1,18 +1,22 @@ --- -/additional_fields: +/extended_attribute_types: get: - x-mojo-to: AdditionalFields#list + x-mojo-to: ExtendedAttributeTypes#list operationId: listAdditionalFields tags: - additional_fields - summary: List additional fields + summary: List extended attribute types produces: - application/json parameters: - - description: filter by table name + - description: filter by resource type in: query - name: table_name + name: resource_type type: string + enum: + - basket + - invoice + - order - $ref: "../swagger.yaml#/parameters/match" - $ref: "../swagger.yaml#/parameters/order_by" - $ref: "../swagger.yaml#/parameters/page" @@ -21,10 +25,10 @@ - $ref: "../swagger.yaml#/parameters/q_body" responses: 200: - description: A list of additional_fields + description: A list of extended attribute types schema: items: - $ref: "../swagger.yaml#/definitions/additional_field" + $ref: "../swagger.yaml#/definitions/extended_attribute_type" type: array 400: description: Bad request @@ -46,4 +50,4 @@ $ref: "../swagger.yaml#/definitions/error" x-koha-authorization: permissions: - parameters: manage_additional_fields \ No newline at end of file + parameters: manage_additional_fields diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml index efd70d3288..05e77b4c22 100644 --- a/api/v1/swagger/swagger.yaml +++ b/api/v1/swagger/swagger.yaml @@ -4,8 +4,6 @@ basePath: /api/v1 definitions: account_line: $ref: ./definitions/account_line.yaml - additional_field: - $ref: ./definitions/additional_field.yaml advancededitormacro: $ref: ./definitions/advancededitormacro.yaml allows_renewal: @@ -86,6 +84,8 @@ definitions: $ref: ./definitions/erm_usage_yus.yaml error: $ref: ./definitions/error.yaml + extended_attribute_type: + $ref: ./definitions/extended_attribute_type.yaml fund: $ref: ./definitions/fund.yaml hold: @@ -199,8 +199,6 @@ paths: $ref: "./paths/acquisitions_vendors.yaml#/~1acquisitions~1vendors~1{vendor_id}" "/acquisitions/vendors/{vendor_id}/issues": $ref: "./paths/acquisitions_vendor_issues.yaml#/~1acquisitions~1vendors~1{vendor_id}~1issues" - /additional_fields: - $ref: ./paths/additional_fields.yaml#/~1additional_fields /advanced_editor/macros: $ref: ./paths/advancededitormacros.yaml#/~1advanced_editor~1macros /advanced_editor/macros/shared: @@ -375,6 +373,8 @@ paths: $ref: ./paths/erm_usage_titles.yaml#/~1erm~1usage_titles /erm/users: $ref: ./paths/erm_users.yaml#/~1erm~1users + /extended_attribute_types: + $ref: ./paths/extended_attribute_types.yaml#/~1extended_attribute_types /holds: $ref: ./paths/holds.yaml#/~1holds "/holds/{hold_id}": diff --git a/t/db_dependent/api/v1/additional_fields.t b/t/db_dependent/api/v1/extended_attribute_types.t similarity index 82% rename from t/db_dependent/api/v1/additional_fields.t rename to t/db_dependent/api/v1/extended_attribute_types.t index 15aba4c77e..38e62ffd6f 100755 --- a/t/db_dependent/api/v1/additional_fields.t +++ b/t/db_dependent/api/v1/extended_attribute_types.t @@ -62,7 +62,7 @@ subtest 'list() tests' => sub { ## Authorized user tests # No additional fields, so empty array should be returned - $t->get_ok("//$userid:$password@/api/v1/additional_fields")->status_is(200)->json_is( [] ); + $t->get_ok("//$userid:$password@/api/v1/extended_attribute_types")->status_is(200)->json_is( [] ); my $additional_field = $builder->build_object( { @@ -72,7 +72,7 @@ subtest 'list() tests' => sub { ); # One additional_field created, should get returned - $t->get_ok("//$userid:$password@/api/v1/additional_fields")->status_is(200) + $t->get_ok("//$userid:$password@/api/v1/extended_attribute_types")->status_is(200) ->json_is( [ $additional_field->to_api ] ); my $another_additional_field = $builder->build_object( @@ -90,7 +90,7 @@ subtest 'list() tests' => sub { ); # Three additional fields created, they should both be returned - $t->get_ok("//$userid:$password@/api/v1/additional_fields")->status_is(200)->json_is( + $t->get_ok("//$userid:$password@/api/v1/extended_attribute_types")->status_is(200)->json_is( [ $additional_field->to_api, $another_additional_field->to_api, @@ -99,15 +99,15 @@ subtest 'list() tests' => sub { ); # Filtering works, two existing additional fields returned for the queried table name - $t->get_ok( "//$userid:$password@/api/v1/additional_fields?table_name=" . $additional_field->tablename ) - ->status_is(200)->json_is( [ $additional_field->to_api, $another_additional_field->to_api ] ); + $t->get_ok("//$userid:$password@/api/v1/extended_attribute_types?resource_type=invoice")->status_is(200) + ->json_is( [ $additional_field->to_api, $another_additional_field->to_api ] ); # Warn on unsupported query parameter - $t->get_ok("//$userid:$password@/api/v1/additional_fields?blah=blah")->status_is(400) + $t->get_ok("//$userid:$password@/api/v1/extended_attribute_types?blah=blah")->status_is(400) ->json_is( [ { path => '/query/blah', message => 'Malformed query string' } ] ); # Unauthorized access - $t->get_ok("//$unauth_userid:$password@/api/v1/additional_fields")->status_is(403); + $t->get_ok("//$unauth_userid:$password@/api/v1/extended_attribute_types")->status_is(403); $schema->storage->txn_rollback; }; -- 2.39.5