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

(-)a/Koha/REST/V1/Lists.pm (+71 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
    return $c->render(
43
        status  => 400,
44
        openapi => { error => "only_mine and only_public are mutually exclussive" }
45
    ) if $only_mine and $only_public;
46
47
    if ( !$user and $only_mine ) {
48
        $c->render(
49
            status  => 200,
50
            openapi => [],
51
        );
52
    }
53
54
    return try {
55
        my $lists_set = Koha::Virtualshelves->new;
56
        if ($only_mine) {
57
            $lists_set = $lists_set->search( { owner => $user->id } );
58
        } elsif ($only_public) {
59
            $lists_set = $lists_set->filter_by_public;
60
        } else {
61
            $lists_set = $lists_set->filter_by_readable( { patron_id => $user->id } );
62
        }
63
64
        my $lists = $c->objects->search($lists_set);
65
        return $c->render( status => 200, openapi => $lists );
66
    } catch {
67
        $c->unhandled_exception($_);
68
    };
69
}
70
71
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 (+38 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
additionalProperties: false
31
required:
32
    - list_id
33
    - name
34
    - creation_date
35
    - updated_on_date
36
    - allow_change_from_owner
37
    - allow_change_from_others
38
    - public
(-)a/api/v1/swagger/paths/lists.yaml (+52 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 transfer limits
33
        schema:
34
          type: array
35
      "400":
36
        description: Bad parameter
37
        schema:
38
          $ref: "../swagger.yaml#/definitions/error"
39
      "500":
40
        description: |
41
          Internal server error. Possible `error_code` attribute values:
42
43
          * `internal_server_error`
44
        schema:
45
          $ref: "../swagger.yaml#/definitions/error"
46
      "503":
47
        description: Under maintenance
48
        schema:
49
          $ref: "../swagger.yaml#/definitions/error"
50
    x-koha-authorization:
51
      permissions:
52
        catalogue: 1
(-)a/api/v1/swagger/swagger.yaml (-1 / +5 lines)
Lines 507-512 paths: Link Here
507
    $ref: ./paths/libraries.yaml#/~1public~1libraries
507
    $ref: ./paths/libraries.yaml#/~1public~1libraries
508
  "/public/libraries/{library_id}":
508
  "/public/libraries/{library_id}":
509
    $ref: "./paths/libraries.yaml#/~1public~1libraries~1{library_id}"
509
    $ref: "./paths/libraries.yaml#/~1public~1libraries~1{library_id}"
510
  "/public/lists":
511
    $ref: "./paths/lists.yaml#/~1public~1lists"
510
  "/public/oauth/login/{provider_code}/{interface}":
512
  "/public/oauth/login/{provider_code}/{interface}":
511
    $ref: ./paths/public_oauth.yaml#/~1public~1oauth~1login~1{provider_code}~1{interface}
513
    $ref: ./paths/public_oauth.yaml#/~1public~1oauth~1login~1{provider_code}~1{interface}
512
  "/public/patrons/{patron_id}/article_requests/{article_request_id}":
514
  "/public/patrons/{patron_id}/article_requests/{article_request_id}":
Lines 1230-1235 tags: Link Here
1230
  - description: "Manage libraries\n"
1232
  - description: "Manage libraries\n"
1231
    name: libraries
1233
    name: libraries
1232
    x-displayName: Libraries
1234
    x-displayName: Libraries
1235
  - description: "Manage lists"
1236
    name: "lists"
1237
    x-displayName: Lists
1233
  - description: "Manage macros\n"
1238
  - description: "Manage macros\n"
1234
    name: macros
1239
    name: macros
1235
    x-displayName: Macros
1240
    x-displayName: Macros
1236
- 

Return to bug 28965