From cfa349ccaf244d8bc3977eed064c75231f0645f6 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 26 Mar 2026 11:55:17 -0400 Subject: [PATCH] Bug 29016: Add REST API for action logs Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Lucas Gass --- Koha/REST/V1/ActionLogs.pm | 45 +++++++++++ api/v1/swagger/definitions/action_log.yaml | 55 +++++++++++++ api/v1/swagger/paths/action_logs.yaml | 91 ++++++++++++++++++++++ api/v1/swagger/swagger.yaml | 4 + 4 files changed, 195 insertions(+) create mode 100644 Koha/REST/V1/ActionLogs.pm create mode 100644 api/v1/swagger/definitions/action_log.yaml create mode 100644 api/v1/swagger/paths/action_logs.yaml diff --git a/Koha/REST/V1/ActionLogs.pm b/Koha/REST/V1/ActionLogs.pm new file mode 100644 index 0000000000..68c68c8fd2 --- /dev/null +++ b/Koha/REST/V1/ActionLogs.pm @@ -0,0 +1,45 @@ +package Koha::REST::V1::ActionLogs; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Mojo::Base 'Mojolicious::Controller'; + +use Koha::ActionLogs; + +use Try::Tiny qw( catch try ); + +=head1 API + +=head2 Methods + +=head3 list + +=cut + +sub list { + my $c = shift->openapi->valid_input or return; + + return try { + my $logs = $c->objects->search( Koha::ActionLogs->new ); + return $c->render( status => 200, openapi => $logs ); + } catch { + $c->unhandled_exception($_); + }; +} + +1; diff --git a/api/v1/swagger/definitions/action_log.yaml b/api/v1/swagger/definitions/action_log.yaml new file mode 100644 index 0000000000..b4d72726f0 --- /dev/null +++ b/api/v1/swagger/definitions/action_log.yaml @@ -0,0 +1,55 @@ +--- +type: object +properties: + action_id: + type: integer + description: Internal action log identifier + readOnly: true + timestamp: + type: string + format: date-time + description: The date and time the action took place + user: + type: integer + description: The staff member who performed the action (borrowernumber) + module: + type: + - string + - "null" + description: The module this action was taken against + action: + type: + - string + - "null" + description: The action performed (e.g. ADD, DELETE, MODIFY) + object: + type: + - integer + - "null" + description: The object that the action was taken against + info: + type: + - string + - "null" + description: Information about the action + interface: + type: + - string + - "null" + description: The context this action was taken in (INTRANET, OPAC, SIP, etc.) + script: + type: + - string + - "null" + description: The name of the cron script that caused this change + trace: + type: + - string + - "null" + description: An optional stack trace + diff: + type: + - string + - "null" + description: A diff of the changed object +additionalProperties: false diff --git a/api/v1/swagger/paths/action_logs.yaml b/api/v1/swagger/paths/action_logs.yaml new file mode 100644 index 0000000000..e236092993 --- /dev/null +++ b/api/v1/swagger/paths/action_logs.yaml @@ -0,0 +1,91 @@ +--- +/action_logs: + get: + x-mojo-to: ActionLogs#list + operationId: listActionLogs + tags: + - action_logs + summary: List action logs + produces: + - application/json + parameters: + - name: action_id + in: query + description: Search on action log id + required: false + type: integer + - name: timestamp + in: query + description: Search on timestamp + required: false + type: string + format: date-time + - name: user + in: query + description: Search on user (borrowernumber) + required: false + type: integer + - name: module + in: query + description: Search on module + required: false + type: string + - name: action + in: query + description: Search on action + required: false + type: string + - name: object + in: query + description: Search on object + required: false + type: integer + - name: info + in: query + description: Search on info + required: false + type: string + - name: interface + in: query + description: Search on interface + required: false + type: string + - $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" + - $ref: "../swagger.yaml#/parameters/request_id_header" + responses: + "200": + description: A list of action logs + schema: + type: array + items: + $ref: "../swagger.yaml#/definitions/action_log" + "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: + tools: view_system_logs diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml index bb825fc1b2..7f9dda188f 100644 --- a/api/v1/swagger/swagger.yaml +++ b/api/v1/swagger/swagger.yaml @@ -4,6 +4,8 @@ basePath: /api/v1 definitions: account_line: $ref: ./definitions/account_line.yaml + action_log: + $ref: ./definitions/action_log.yaml additional_content: $ref: ./definitions/additional_content.yaml advancededitormacro: @@ -215,6 +217,8 @@ definitions: vendors_config: $ref: ./definitions/vendors_config.yaml paths: + /action_logs: + $ref: ./paths/action_logs.yaml#/~1action_logs /acquisitions/baskets: $ref: ./paths/acquisitions_baskets.yaml#/~1acquisitions~1baskets /acquisitions/baskets/managers: