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 353-358 sub transfer_ownership { Link Here
353
    return $self->set({ owner => $patron_id })->store;
353
    return $self->set({ owner => $patron_id })->store;
354
}
354
}
355
355
356
=head3 to_api_mapping
357
358
This method returns the mapping for representing a Koha::Virtualshelf object
359
on the API.
360
361
=cut
362
363
sub to_api_mapping {
364
    return {
365
        created_on   => 'creation_date',
366
        lastmodified => 'updated_on_date',
367
        owner        => 'owner_id',
368
        shelfname    => 'name',
369
        shelfnumber  => 'list_id',
370
        sortfield    => 'default_sort_field',
371
    };
372
}
373
374
=head3 public_read_list
375
376
This method returns the list of publicly readable database fields for both API and UI output purposes
377
378
=cut
379
380
sub public_read_list {
381
    return [
382
        'created_on',  'lastmodified', 'shelfname',
383
        'shelfnumber', 'public',       'sortfield',
384
        'allow_change_from_owner', 'allow_change_from_others'
385
    ];
386
}
387
356
=head2 Internal methods
388
=head2 Internal methods
357
389
358
=head3 _type
390
=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 493-498 paths: Link Here
493
    $ref: ./paths/libraries.yaml#/~1public~1libraries
493
    $ref: ./paths/libraries.yaml#/~1public~1libraries
494
  "/public/libraries/{library_id}":
494
  "/public/libraries/{library_id}":
495
    $ref: "./paths/libraries.yaml#/~1public~1libraries~1{library_id}"
495
    $ref: "./paths/libraries.yaml#/~1public~1libraries~1{library_id}"
496
  "/public/lists": 
497
    $ref: "./paths/lists.yaml#/~1public~1lists"
496
  "/public/oauth/login/{provider_code}/{interface}":
498
  "/public/oauth/login/{provider_code}/{interface}":
497
    $ref: ./paths/public_oauth.yaml#/~1public~1oauth~1login~1{provider_code}~1{interface}
499
    $ref: ./paths/public_oauth.yaml#/~1public~1oauth~1login~1{provider_code}~1{interface}
498
  "/public/patrons/{patron_id}/article_requests/{article_request_id}":
500
  "/public/patrons/{patron_id}/article_requests/{article_request_id}":
Lines 1189-1194 tags: Link Here
1189
  - description: "Manage libraries\n"
1191
  - description: "Manage libraries\n"
1190
    name: libraries
1192
    name: libraries
1191
    x-displayName: Libraries
1193
    x-displayName: Libraries
1194
  - description: "Manage lists"
1195
    name: "lists"
1196
    x-displayName: Lists
1192
  - description: "Manage macros\n"
1197
  - description: "Manage macros\n"
1193
    name: macros
1198
    name: macros
1194
    x-displayName: Macros
1199
    x-displayName: Macros
1195
- 

Return to bug 28965