View | Details | Raw Unified | Return to bug 41994
Collapse All | Expand All

(-)a/Koha/REST/V1/Sysprefs.pm (+49 lines)
Line 0 Link Here
1
package Koha::REST::V1::Sysprefs;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <https://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use Koha::Config::SysPrefs;
23
24
use Try::Tiny;
25
26
=head1 API
27
28
=head2 Methods
29
30
=head3 list_sysprefs
31
32
This routine returns the system preferences
33
34
=cut
35
36
sub list_sysprefs {
37
    my $c = shift->openapi->valid_input or return;
38
39
    return try {
40
        my $rs       = Koha::Config::SysPrefs->search;
41
        my $sysprefs = $c->objects->search_rs($rs);
42
        return $c->render( status => 200, openapi => $sysprefs );
43
    } catch {
44
        $c->unhandled_exception($_);
45
    };
46
47
}
48
49
1;
(-)a/api/v1/swagger/definitions/syspref.yaml (+29 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  variable:
5
    type: string
6
    description: name of the syspref
7
  value:
8
    description: value of the syspref
9
    type: string
10
  options:
11
    description: the possible values
12
    type:
13
      - string
14
      - "null"
15
  explanation:
16
    description: explanation of the pref
17
    type:
18
      - string
19
      - "null"
20
  type:
21
    description: type of the pref
22
    type:
23
      - string
24
      - "null"
25
additionalProperties: false
26
27
required:
28
  - variable
29
  - value
(-)a/api/v1/swagger/paths/sysprefs.yaml (+58 lines)
Line 0 Link Here
1
---
2
"/sysprefs":
3
  get:
4
    x-mojo-to: Sysprefs#list_sysprefs
5
    operationId: listSysprefs
6
    tags:
7
      - sysprefs
8
    summary: List system preferences
9
    produces:
10
      - application/json
11
    parameters:
12
      - description: variable
13
        in: query
14
        name: variable
15
        required: false
16
        type: string
17
      - $ref: "../swagger.yaml#/parameters/match"
18
      - $ref: "../swagger.yaml#/parameters/order_by"
19
      - $ref: "../swagger.yaml#/parameters/page"
20
      - $ref: "../swagger.yaml#/parameters/per_page"
21
      - $ref: "../swagger.yaml#/parameters/q_param"
22
      - $ref: "../swagger.yaml#/parameters/q_body"
23
      - $ref: "../swagger.yaml#/parameters/request_id_header"
24
    responses:
25
      200:
26
        description: A list of system preferences
27
        schema:
28
          items:
29
            $ref: "../swagger.yaml#/definitions/syspref"
30
          type: array
31
      400:
32
        description: |
33
          Bad request. Possible `error_code` attribute values:
34
35
            * `invalid_query`
36
        schema:
37
          $ref: "../swagger.yaml#/definitions/error"
38
      403:
39
        description: Access forbidden
40
        schema:
41
          $ref: "../swagger.yaml#/definitions/error"
42
      404:
43
        description: Ressource not found
44
        schema:
45
          $ref: "../swagger.yaml#/definitions/error"
46
      500:
47
        description: |-
48
          Internal server error. Possible `error_code` attribute values:
49
          * `internal_server_error`
50
        schema:
51
          $ref: "../swagger.yaml#/definitions/error"
52
      503:
53
        description: Under maintenance
54
        schema:
55
          $ref: "../swagger.yaml#/definitions/error"
56
    x-koha-authorization:
57
      permissions:
58
        parameters: manage_sysprefs
(-)a/api/v1/swagger/swagger.yaml (+7 lines)
Lines 192-197 definitions: Link Here
192
    $ref: ./definitions/file_transport.yaml
192
    $ref: ./definitions/file_transport.yaml
193
  suggestion:
193
  suggestion:
194
    $ref: ./definitions/suggestion.yaml
194
    $ref: ./definitions/suggestion.yaml
195
  syspref:
196
    $ref: ./definitions/syspref.yaml
195
  ticket:
197
  ticket:
196
    $ref: ./definitions/ticket.yaml
198
    $ref: ./definitions/ticket.yaml
197
  ticket_update:
199
  ticket_update:
Lines 623-628 paths: Link Here
623
    $ref: "./paths/suggestions.yaml#/~1suggestions~1{suggestion_id}"
625
    $ref: "./paths/suggestions.yaml#/~1suggestions~1{suggestion_id}"
624
  /suggestions/managers:
626
  /suggestions/managers:
625
    $ref: "./paths/suggestions.yaml#/~1suggestions~1managers"
627
    $ref: "./paths/suggestions.yaml#/~1suggestions~1managers"
628
  /sysprefs:
629
    $ref: ./paths/sysprefs.yaml#/~1sysprefs
626
  "/tickets":
630
  "/tickets":
627
    $ref: "./paths/tickets.yaml#/~1tickets"
631
    $ref: "./paths/tickets.yaml#/~1tickets"
628
  "/tickets/{ticket_id}":
632
  "/tickets/{ticket_id}":
Lines 1401-1406 tags: Link Here
1401
  - description: "Manage SMTP servers configurations\n"
1405
  - description: "Manage SMTP servers configurations\n"
1402
    name: smtp_servers
1406
    name: smtp_servers
1403
    x-displayName: SMTP servers
1407
    x-displayName: SMTP servers
1408
  - description: "Manage system preferences\n"
1409
    name: sysprefs
1410
    x-displayName: System preferences
1404
  - description: "Manage file transport configurations\n"
1411
  - description: "Manage file transport configurations\n"
1405
    name: file_transports
1412
    name: file_transports
1406
    x-displayName: File transports
1413
    x-displayName: File transports
(-)a/t/db_dependent/api/v1/sysprefs.t (-1 / +68 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/env perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <https://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::NoWarnings;
21
use Test::More tests => 2;
22
use Test::Mojo;
23
24
use t::lib::TestBuilder;
25
use t::lib::Mocks;
26
27
use Koha::Database;
28
29
my $schema  = Koha::Database->new->schema;
30
my $builder = t::lib::TestBuilder->new;
31
32
my $t = Test::Mojo->new('Koha::REST::V1');
33
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
34
35
subtest 'list() tests' => sub {
36
37
    plan tests => 4;
38
39
    $schema->storage->txn_begin;
40
41
    my $librarian = $builder->build_object(
42
        {
43
            class => 'Koha::Patrons',
44
            value => { flags => 3**2 }    # parameters flag = 3
45
        }
46
    );
47
    my $password = 'thePassword123';
48
    $librarian->set_password( { password => $password, skip_validation => 1 } );
49
    my $userid = $librarian->userid;
50
51
    my $patron = $builder->build_object(
52
        {
53
            class => 'Koha::Patrons',
54
            value => { flags => 0 }
55
        }
56
    );
57
58
    $patron->set_password( { password => $password, skip_validation => 1 } );
59
    my $unauth_userid = $patron->userid;
60
61
    ## Authorized user tests
62
    $t->get_ok("//$userid:$password@/api/v1/sysprefs")->status_is(200);
63
64
    # Unauthorized access
65
    $t->get_ok("//$unauth_userid:$password@/api/v1/sysprefs")->status_is(403);
66
67
    $schema->storage->txn_rollback;
68
};

Return to bug 41994