From b37016c064fd245221438b14f29f36ab661e5d2c Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Thu, 11 Apr 2024 14:17:27 +0200 Subject: [PATCH] ACQUI-142: Add patron embedding to tasks --- .../Acquire/Controllers/ControllerUtils.pm | 13 --------- .../Controllers/TaskManagement/Tasks.pm | 4 --- Koha/Plugin/Acquire/api/openapi.json | 15 ++++++++++ .../lib/Koha/Acquire/TaskManagement/Task.pm | 28 +++++++++++++++++++ src/components/TaskManagement/TaskShow.vue | 2 +- 5 files changed, 44 insertions(+), 18 deletions(-) diff --git a/Koha/Plugin/Acquire/Controllers/ControllerUtils.pm b/Koha/Plugin/Acquire/Controllers/ControllerUtils.pm index 7b127e9..6b9cb24 100644 --- a/Koha/Plugin/Acquire/Controllers/ControllerUtils.pm +++ b/Koha/Plugin/Acquire/Controllers/ControllerUtils.pm @@ -71,19 +71,6 @@ sub _get_unblessed { return blessed $data ? $data->unblessed : $data; } -sub add_patron_data { - my ( $self, $args ) = @_; - - my $data = _get_unblessed( $args->{data} ); - my $field = $args->{field}; - my $key = $args->{key}; - - my $patron = Koha::Patrons->find( { borrowernumber => $data->{$key} } ); - $data->{$field} = $patron->unblessed; - - return $data; -} - sub add_lib_group_data { my ( $self, $args ) = @_; diff --git a/Koha/Plugin/Acquire/Controllers/TaskManagement/Tasks.pm b/Koha/Plugin/Acquire/Controllers/TaskManagement/Tasks.pm index dd90d21..e5a0eba 100644 --- a/Koha/Plugin/Acquire/Controllers/TaskManagement/Tasks.pm +++ b/Koha/Plugin/Acquire/Controllers/TaskManagement/Tasks.pm @@ -71,10 +71,6 @@ sub get { ); } - $task = Koha::Plugin::Acquire::Controllers::ControllerUtils->add_patron_data( - { data => $task, field => 'owned_by', key => 'owner' } ); - $task = Koha::Plugin::Acquire::Controllers::ControllerUtils->add_patron_data( - { data => $task, field => 'creator', key => 'created_by' } ); $task = Koha::Plugin::Acquire::Controllers::ControllerUtils->add_lib_group_data( { data => $task } ); diff --git a/Koha/Plugin/Acquire/api/openapi.json b/Koha/Plugin/Acquire/api/openapi.json index db7b0ac..4da83fc 100644 --- a/Koha/Plugin/Acquire/api/openapi.json +++ b/Koha/Plugin/Acquire/api/openapi.json @@ -354,6 +354,21 @@ "description": "ID of task to fetch", "required": true, "type": "integer" + }, + { + "name": "x-koha-embed", + "in": "header", + "description": "Embed", + "required": false, + "type": "array", + "items": { + "type": "string", + "enum": [ + "owner", + "created_by" + ] + }, + "collectionFormat": "csv" } ], "produces": [ diff --git a/Koha/Plugin/Acquire/lib/Koha/Acquire/TaskManagement/Task.pm b/Koha/Plugin/Acquire/lib/Koha/Acquire/TaskManagement/Task.pm index 3be6d56..faed10c 100644 --- a/Koha/Plugin/Acquire/lib/Koha/Acquire/TaskManagement/Task.pm +++ b/Koha/Plugin/Acquire/lib/Koha/Acquire/TaskManagement/Task.pm @@ -29,6 +29,34 @@ use JSON qw ( encode_json ); =cut + +=head3 owner + +Method to embed the owner to a given task + +=cut + +sub owner { + my ($self) = @_; + my $owner_rs = $self->_result->owner; + return Koha::Patron->_new_from_dbic($owner_rs); +} + + +=head3 created_by + +Method to embed the patron who created the task + +=cut + +sub created_by { + my ($self) = @_; + my $created_by_rs = $self->_result->created_by; + return Koha::Patron->_new_from_dbic($created_by_rs); +} + + + sub _type { return 'KohaPluginAcquireWorkflowTask'; } diff --git a/src/components/TaskManagement/TaskShow.vue b/src/components/TaskManagement/TaskShow.vue index bd48b0e..6489532 100644 --- a/src/components/TaskManagement/TaskShow.vue +++ b/src/components/TaskManagement/TaskShow.vue @@ -59,7 +59,7 @@ export default { methods: { async getTask(task_id) { const client = APIClient.acquisition - await client.tasks.get(task_id).then( + await client.tasks.get(task_id, { "x-koha-embed": "owner,created_by" }).then( task => { this.task = task this.initialized = true