Bugzilla – Attachment 194491 Details for
Bug 41994
REST API route to list system preferences
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 41994: Implement /sysprefs route to list system preferences
06d8104.patch (text/plain), 8.79 KB, created by
Jonathan Druart
on 2026-03-05 10:41:44 UTC
(
hide
)
Description:
Bug 41994: Implement /sysprefs route to list system preferences
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2026-03-05 10:41:44 UTC
Size:
8.79 KB
patch
obsolete
>From 06d810435df810f50a7de6d02f597aa61a3303ce Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 12 Feb 2026 13:22:36 +0100 >Subject: [PATCH] Bug 41994: Implement /sysprefs route to list system > preferences > >This new route will be used in a follow-up bug to auto-complete sysprefs >when using the header to search for sysprefs. > >Note that this is based on top of bug 41834 that NULL options, >explanation and type in DB, but a future enhancement will populate the >response to return the values present in the yaml files. > >Test plan: >1. Bundle the swagger specs and reload plack: > yarn api:bundle && koha-plack --reload kohadev >2. Fetch the sysprefs using the new route: > curl -u koha:koha --request GET 'http://${INSTANCE}-intra.localhost/api/v1/sysprefs' --header "Content-Type: application/json" | jq >3. Confirm that the tests pass > prove t/db_dependent/api/v1/sysprefs.t >--- > Koha/REST/V1/Sysprefs.pm | 49 ++++++++++++++++++ > api/v1/swagger/definitions/syspref.yaml | 29 +++++++++++ > api/v1/swagger/paths/sysprefs.yaml | 58 +++++++++++++++++++++ > api/v1/swagger/swagger.yaml | 7 +++ > t/db_dependent/api/v1/sysprefs.t | 68 +++++++++++++++++++++++++ > 5 files changed, 211 insertions(+) > create mode 100644 Koha/REST/V1/Sysprefs.pm > create mode 100644 api/v1/swagger/definitions/syspref.yaml > create mode 100644 api/v1/swagger/paths/sysprefs.yaml > create mode 100755 t/db_dependent/api/v1/sysprefs.t > >diff --git a/Koha/REST/V1/Sysprefs.pm b/Koha/REST/V1/Sysprefs.pm >new file mode 100644 >index 00000000000..b56854b2424 >--- /dev/null >+++ b/Koha/REST/V1/Sysprefs.pm >@@ -0,0 +1,49 @@ >+package Koha::REST::V1::Sysprefs; >+ >+# 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 <https://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Mojo::Base 'Mojolicious::Controller'; >+ >+use Koha::Config::SysPrefs; >+ >+use Try::Tiny; >+ >+=head1 API >+ >+=head2 Methods >+ >+=head3 list_sysprefs >+ >+This routine returns the system preferences >+ >+=cut >+ >+sub list_sysprefs { >+ my $c = shift->openapi->valid_input or return; >+ >+ return try { >+ my $rs = Koha::Config::SysPrefs->search; >+ my $sysprefs = $c->objects->search_rs($rs); >+ return $c->render( status => 200, openapi => $sysprefs ); >+ } catch { >+ $c->unhandled_exception($_); >+ }; >+ >+} >+ >+1; >diff --git a/api/v1/swagger/definitions/syspref.yaml b/api/v1/swagger/definitions/syspref.yaml >new file mode 100644 >index 00000000000..4a617419e5e >--- /dev/null >+++ b/api/v1/swagger/definitions/syspref.yaml >@@ -0,0 +1,29 @@ >+--- >+type: object >+properties: >+ variable: >+ type: string >+ description: name of the syspref >+ value: >+ description: value of the syspref >+ type: string >+ options: >+ description: the possible values >+ type: >+ - string >+ - "null" >+ explanation: >+ description: explanation of the pref >+ type: >+ - string >+ - "null" >+ type: >+ description: type of the pref >+ type: >+ - string >+ - "null" >+additionalProperties: false >+ >+required: >+ - variable >+ - value >diff --git a/api/v1/swagger/paths/sysprefs.yaml b/api/v1/swagger/paths/sysprefs.yaml >new file mode 100644 >index 00000000000..ed26122ce21 >--- /dev/null >+++ b/api/v1/swagger/paths/sysprefs.yaml >@@ -0,0 +1,58 @@ >+--- >+"/sysprefs": >+ get: >+ x-mojo-to: Sysprefs#list_sysprefs >+ operationId: listSysprefs >+ tags: >+ - sysprefs >+ summary: List system preferences >+ produces: >+ - application/json >+ parameters: >+ - description: variable >+ in: query >+ name: variable >+ 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 system preferences >+ schema: >+ items: >+ $ref: "../swagger.yaml#/definitions/syspref" >+ 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" >+ 404: >+ description: Ressource not found >+ 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: >+ parameters: manage_sysprefs >diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml >index 9a9b7af7565..8dea00655e1 100644 >--- a/api/v1/swagger/swagger.yaml >+++ b/api/v1/swagger/swagger.yaml >@@ -192,6 +192,8 @@ definitions: > $ref: ./definitions/file_transport.yaml > suggestion: > $ref: ./definitions/suggestion.yaml >+ syspref: >+ $ref: ./definitions/syspref.yaml > ticket: > $ref: ./definitions/ticket.yaml > ticket_update: >@@ -623,6 +625,8 @@ paths: > $ref: "./paths/suggestions.yaml#/~1suggestions~1{suggestion_id}" > /suggestions/managers: > $ref: "./paths/suggestions.yaml#/~1suggestions~1managers" >+ /sysprefs: >+ $ref: ./paths/sysprefs.yaml#/~1sysprefs > "/tickets": > $ref: "./paths/tickets.yaml#/~1tickets" > "/tickets/{ticket_id}": >@@ -1401,6 +1405,9 @@ tags: > - description: "Manage SMTP servers configurations\n" > name: smtp_servers > x-displayName: SMTP servers >+ - description: "Manage system preferences\n" >+ name: sysprefs >+ x-displayName: System preferences > - description: "Manage file transport configurations\n" > name: file_transports > x-displayName: File transports >diff --git a/t/db_dependent/api/v1/sysprefs.t b/t/db_dependent/api/v1/sysprefs.t >new file mode 100755 >index 00000000000..e4881a50ce3 >--- /dev/null >+++ b/t/db_dependent/api/v1/sysprefs.t >@@ -0,0 +1,68 @@ >+#!/usr/bin/env perl >+ >+# 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 <https://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::NoWarnings; >+use Test::More tests => 2; >+use Test::Mojo; >+ >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+ >+use Koha::Database; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+my $t = Test::Mojo->new('Koha::REST::V1'); >+t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); >+ >+subtest 'list() tests' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ my $librarian = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 3**2 } # parameters flag = 3 >+ } >+ ); >+ my $password = 'thePassword123'; >+ $librarian->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $librarian->userid; >+ >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 0 } >+ } >+ ); >+ >+ $patron->set_password( { password => $password, skip_validation => 1 } ); >+ my $unauth_userid = $patron->userid; >+ >+ ## Authorized user tests >+ $t->get_ok("//$userid:$password@/api/v1/sysprefs")->status_is(200); >+ >+ # Unauthorized access >+ $t->get_ok("//$unauth_userid:$password@/api/v1/sysprefs")->status_is(403); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.43.0 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 41994
:
194491
|
194496