Skip to content

Commit

Permalink
ACQUI-142: Add patron embedding to tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
mblenk committed Apr 11, 2024
1 parent 4713ab4 commit b37016c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 18 deletions.
13 changes: 0 additions & 13 deletions Koha/Plugin/Acquire/Controllers/ControllerUtils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) = @_;

Expand Down
4 changes: 0 additions & 4 deletions Koha/Plugin/Acquire/Controllers/TaskManagement/Tasks.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 } );

Expand Down
15 changes: 15 additions & 0 deletions Koha/Plugin/Acquire/api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
28 changes: 28 additions & 0 deletions Koha/Plugin/Acquire/lib/Koha/Acquire/TaskManagement/Task.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/TaskManagement/TaskShow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b37016c

Please sign in to comment.