Bug 38262: (bug 38446 follow-up) Use a dedicated endpoint
Following what has been done on bug 38262 we need a separate endpoint to retrieve additional fields for vendors. We add another proxy for acquisition in acquisition-api-client: we do not want to retrieve all the fields for acquisition as we have more granular permissions than ERM. Signed-off-by: Michaela <michaela.sieber@kit.edu> Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
52c3b54269
commit
e8f4637f84
|
|
@ -112,4 +112,26 @@ sub list_erm {
|
|||
};
|
||||
}
|
||||
|
||||
=head3 list_acq_vendors
|
||||
|
||||
List the vendors-related additional fields, can be filtered using the resource_type parameter.
|
||||
|
||||
=cut
|
||||
|
||||
sub list_acq_vendors {
|
||||
my ($self) = @_;
|
||||
my $c = shift->openapi->valid_input or return;
|
||||
my @resource_types = qw(vendor);
|
||||
|
||||
return try {
|
||||
my $additional_fields_set = $self->_list(@resource_types);
|
||||
return $c->render(
|
||||
status => 200,
|
||||
openapi => $c->objects->search($additional_fields_set)
|
||||
);
|
||||
} catch {
|
||||
$c->unhandled_exception($_);
|
||||
};
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
---
|
||||
/acquisitions/vendors/extended_attribute_types:
|
||||
get:
|
||||
x-mojo-to: ExtendedAttributeTypes#list_acq_vendors
|
||||
operationId: listAcquisitionVendorsAdditionalFields
|
||||
tags:
|
||||
- additional_fields
|
||||
summary: List acquisition vendors extended attribute types
|
||||
produces:
|
||||
- application/json
|
||||
parameters:
|
||||
- description: filter by resource type
|
||||
in: query
|
||||
name: resource_type
|
||||
type: string
|
||||
enum:
|
||||
- vendor
|
||||
- $ref: "../swagger.yaml#/parameters/match"
|
||||
- $ref: "../swagger.yaml#/parameters/order_by"
|
||||
- $ref: "../swagger.yaml#/parameters/page"
|
||||
- $ref: "../swagger.yaml#/parameters/per_page"
|
||||
- $ref: "../swagger.yaml#/parameters/q_param"
|
||||
- $ref: "../swagger.yaml#/parameters/q_body"
|
||||
responses:
|
||||
200:
|
||||
description: A list of extended attribute types for acquisition vendors
|
||||
schema:
|
||||
items:
|
||||
$ref: "../swagger.yaml#/definitions/extended_attribute_type"
|
||||
type: array
|
||||
"400":
|
||||
description: |
|
||||
Bad request. Possible `error_code` attribute values:
|
||||
|
||||
* `invalid_query`
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/error"
|
||||
403:
|
||||
description: Access forbidden
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/error"
|
||||
500:
|
||||
description: |-
|
||||
Internal server error. Possible `error_code` attribute values:
|
||||
* `internal_server_error`
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/error"
|
||||
503:
|
||||
description: Under maintenance
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/error"
|
||||
x-koha-authorization:
|
||||
permissions:
|
||||
- acquisition: vendors_manage
|
||||
|
|
@ -227,6 +227,8 @@ paths:
|
|||
$ref: "./paths/acquisitions_orders.yaml#/~1acquisitions~1orders~1{order_id}"
|
||||
/acquisitions/vendors:
|
||||
$ref: ./paths/acquisitions_vendors.yaml#/~1acquisitions~1vendors
|
||||
/acquisitions/vendors/extended_attribute_types:
|
||||
$ref: ./paths/acquisitions_vendors_extended_attribute_types.yaml#/~1acquisitions~1vendors~1extended_attribute_types
|
||||
/acquisitions/vendors/config:
|
||||
$ref: ./paths/acquisitions_vendors_config.yaml#/~1acquisitions~1vendors~1config
|
||||
"/acquisitions/vendors/{vendor_id}":
|
||||
|
|
|
|||
|
|
@ -57,6 +57,11 @@ export class AcquisitionAPIClient {
|
|||
...(query && { q: JSON.stringify(query) }),
|
||||
}),
|
||||
}),
|
||||
additional_fields: resource_type =>
|
||||
this.httpClient.getAll({
|
||||
endpoint: "vendors/extended_attribute_types",
|
||||
params: { resource_type },
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -74,6 +79,20 @@ export class AcquisitionAPIClient {
|
|||
}),
|
||||
};
|
||||
}
|
||||
|
||||
get additional_fields() {
|
||||
return {
|
||||
getAll: resource_type => {
|
||||
if (resource_type == "vendor") {
|
||||
return this.vendors.additional_fields(resource_type);
|
||||
}
|
||||
// Use fetch/additional-fields-api-client.js instead
|
||||
throw new Error(
|
||||
"resource_type %s does not have a dedicated endpoint to fetch additional fields."
|
||||
);
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default AcquisitionAPIClient;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import ERMAPIClient from "@fetch/erm-api-client";
|
||||
import AcquisitionAPIClient from "@fetch/acquisition-api-client.js";
|
||||
|
||||
export class AdditionalFieldsAPIClient {
|
||||
constructor(HttpClient) {
|
||||
|
|
@ -23,6 +24,7 @@ export class AdditionalFieldsAPIClientWrapper {
|
|||
this.clients = {
|
||||
admin: new AdditionalFieldsAPIClient(HttpClient),
|
||||
erm: new ERMAPIClient(HttpClient),
|
||||
acquisition: new AcquisitionAPIClient(HttpClient),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -40,6 +42,7 @@ export class AdditionalFieldsAPIClientWrapper {
|
|||
getModuleName(resource_type) {
|
||||
const moduleMappings = {
|
||||
erm: ["agreement", "license", "package"],
|
||||
acquisition: ["vendor"],
|
||||
};
|
||||
|
||||
for (const [module, resourceTypes] of Object.entries(moduleMappings)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue