Bug 35197: Rename to 'Extended attribute types'
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
f8b8223353
commit
5cfc8b58a6
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
parameters: manage_additional_fields
|
||||
|
|
@ -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}":
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
Loading…
Reference in New Issue