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

(-)a/Koha/REST/V1/Lists.pm (+75 lines)
Line 0 Link Here
1
package Koha::REST::V1::Lists;
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 <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use Koha::Virtualshelves;
23
24
use Try::Tiny qw( catch try );
25
26
=head1 API
27
28
=head2 Methods
29
30
=head3 list_public
31
32
=cut
33
34
sub list_public {
35
    my $c = shift->openapi->valid_input or return;
36
37
    my $user = $c->stash('koha.user');
38
39
    my $only_mine   = delete $c->param('only_mine');
40
    my $only_public = delete $c->param('only_public');
41
42
    if ( !$user && $only_mine ) {
43
        return $c->render(
44
            status  => 400,
45
            openapi => {
46
                error      => "Bad request - only_mine can only be passed by logged in users",
47
                error_code => "only_mine_forbidden",
48
            },
49
        );
50
    }
51
52
    return try {
53
54
        my $lists_set = Koha::Virtualshelves->new;
55
56
        if ($only_mine) {
57
            $lists_set = $lists_set->search( { owner => $user->id } );
58
        }
59
60
        if ( $only_public || !$user ) {
61
            $lists_set = $lists_set->filter_by_public;
62
        } else {
63
            $lists_set = $lists_set->filter_by_readable( { patron_id => $user->id } );
64
        }
65
66
        return $c->render(
67
            status  => 200,
68
            openapi => $c->objects->search($lists_set),
69
        );
70
    } catch {
71
        $c->unhandled_exception($_);
72
    };
73
}
74
75
1;
(-)a/Koha/Schema/Result/Virtualshelve.pm (-1 / +3 lines)
Lines 230-236 sub koha_objects_class { Link Here
230
}
230
}
231
231
232
__PACKAGE__->add_columns(
232
__PACKAGE__->add_columns(
233
    '+public' => { is_boolean => 1 },
233
    '+allow_change_from_others' => { is_boolean => 1 },
234
    '+allow_change_from_owner'  => { is_boolean => 1 },
235
    '+public'                   => { is_boolean => 1 },
234
);
236
);
235
237
236
__PACKAGE__->add_columns(
238
__PACKAGE__->add_columns(
(-)a/Koha/Virtualshelf.pm (+32 lines)
Lines 398-403 sub transfer_ownership { Link Here
398
    return $self;
398
    return $self;
399
}
399
}
400
400
401
=head3 to_api_mapping
402
403
This method returns the mapping for representing a Koha::Virtualshelf object
404
on the API.
405
406
=cut
407
408
sub to_api_mapping {
409
    return {
410
        created_on   => 'creation_date',
411
        lastmodified => 'updated_on_date',
412
        owner        => 'owner_id',
413
        shelfname    => 'name',
414
        shelfnumber  => 'list_id',
415
        sortfield    => 'default_sort_field',
416
    };
417
}
418
419
=head3 public_read_list
420
421
This method returns the list of publicly readable database fields for both API and UI output purposes
422
423
=cut
424
425
sub public_read_list {
426
    return [
427
        'created_on',  'lastmodified', 'shelfname',
428
        'shelfnumber', 'public',       'sortfield',
429
        'allow_change_from_owner', 'allow_change_from_others'
430
    ];
431
}
432
401
=head2 Internal methods
433
=head2 Internal methods
402
434
403
=head3 _type
435
=head3 _type
(-)a/api/v1/swagger/definitions/list.yaml (+41 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
    list_id:
5
        description: Interal identifier for the list
6
        type: integer
7
    name:
8
        description: List name
9
        type: string
10
    creation_date:
11
        description: Date the list was created
12
        type: string
13
        format: date-time
14
    updated_on_date:
15
        description: Date the list was last updated
16
        type: string
17
        format: date-time
18
    owner_id:
19
        description: Internal identifier for the owning patron
20
        type: integer
21
    allow_change_from_owner:
22
        description: If the owner can change the contents
23
        type: boolean
24
    allow_change_from_others:
25
        description: If others can change the contents
26
        type: boolean
27
    public:
28
        description: If the list is public
29
        type: boolean
30
    default_sort_field:
31
        description: The field this list is sorted on by default
32
        type: string
33
additionalProperties: false
34
required:
35
    - list_id
36
    - name
37
    - creation_date
38
    - updated_on_date
39
    - allow_change_from_owner
40
    - allow_change_from_others
41
    - public
(-)a/api/v1/swagger/paths/lists.yaml (+60 lines)
Line 0 Link Here
1
---
2
"/public/lists":
3
  get:
4
    x-mojo-to: Lists#list_public
5
    operationId: listListsPublic
6
    description: "This resource returns a list of existing bibliographic lists."
7
    summary: List bibliographic lists
8
    tags:
9
      - lists
10
    parameters:
11
      - name: only_mine
12
        in: query
13
        description: Only return the users' lists
14
        required: false
15
        type: string
16
      - name: only_public
17
        in: query
18
        description: Only return public lists
19
        required: false
20
        type: string
21
      - $ref: "../swagger.yaml#/parameters/match"
22
      - $ref: "../swagger.yaml#/parameters/order_by"
23
      - $ref: "../swagger.yaml#/parameters/page"
24
      - $ref: "../swagger.yaml#/parameters/per_page"
25
      - $ref: "../swagger.yaml#/parameters/q_param"
26
      - $ref: "../swagger.yaml#/parameters/q_body"
27
      - $ref: "../swagger.yaml#/parameters/request_id_header"
28
    produces:
29
      - application/json
30
    responses:
31
      "200":
32
        description: A list of lists
33
        schema:
34
          type: array
35
          items:
36
            $ref: "../swagger.yaml#/definitions/list"
37
      "400":
38
        description: |
39
          Bad request. Possible `error_code` attribute values:
40
41
            * `bad_request`
42
            * `invalid_query`
43
            * `only_mine_forbidden`
44
        schema:
45
          $ref: "../swagger.yaml#/definitions/error"
46
      "403":
47
        description: Access forbidden
48
        schema:
49
          $ref: "../swagger.yaml#/definitions/error"
50
      "500":
51
        description: |
52
          Internal server error. Possible `error_code` attribute values:
53
54
          * `internal_server_error`
55
        schema:
56
          $ref: "../swagger.yaml#/definitions/error"
57
      "503":
58
        description: Under maintenance
59
        schema:
60
          $ref: "../swagger.yaml#/definitions/error"
(-)a/api/v1/swagger/swagger.yaml (-1 / +7 lines)
Lines 132-137 definitions: Link Here
132
    $ref: ./definitions/job.yaml
132
    $ref: ./definitions/job.yaml
133
  library:
133
  library:
134
    $ref: ./definitions/library.yaml
134
    $ref: ./definitions/library.yaml
135
  list:
136
    $ref: ./definitions/list.yaml
135
  merge_biblios:
137
  merge_biblios:
136
    $ref: ./definitions/merge_biblios.yaml
138
    $ref: ./definitions/merge_biblios.yaml
137
  order:
139
  order:
Lines 507-512 paths: Link Here
507
    $ref: ./paths/libraries.yaml#/~1public~1libraries
509
    $ref: ./paths/libraries.yaml#/~1public~1libraries
508
  "/public/libraries/{library_id}":
510
  "/public/libraries/{library_id}":
509
    $ref: "./paths/libraries.yaml#/~1public~1libraries~1{library_id}"
511
    $ref: "./paths/libraries.yaml#/~1public~1libraries~1{library_id}"
512
  "/public/lists":
513
    $ref: "./paths/lists.yaml#/~1public~1lists"
510
  "/public/oauth/login/{provider_code}/{interface}":
514
  "/public/oauth/login/{provider_code}/{interface}":
511
    $ref: ./paths/public_oauth.yaml#/~1public~1oauth~1login~1{provider_code}~1{interface}
515
    $ref: ./paths/public_oauth.yaml#/~1public~1oauth~1login~1{provider_code}~1{interface}
512
  "/public/patrons/{patron_id}/article_requests/{article_request_id}":
516
  "/public/patrons/{patron_id}/article_requests/{article_request_id}":
Lines 1230-1235 tags: Link Here
1230
  - description: "Manage libraries\n"
1234
  - description: "Manage libraries\n"
1231
    name: libraries
1235
    name: libraries
1232
    x-displayName: Libraries
1236
    x-displayName: Libraries
1237
  - description: "Manage lists"
1238
    name: "lists"
1239
    x-displayName: Lists
1233
  - description: "Manage macros\n"
1240
  - description: "Manage macros\n"
1234
    name: macros
1241
    name: macros
1235
    x-displayName: Macros
1242
    x-displayName: Macros
1236
- 

Return to bug 28965