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

(-)a/Koha/REST/V1/Lists.pm (+74 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->validation->output->{only_mine};
40
    my $only_public = delete $c->validation->output->{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
        }
59
        elsif ( $only_public ) {
60
            $lists_set = $lists_set->filter_by_public;
61
        }
62
        else {
63
            $lists_set = $lists_set->filter_by_readable({ patron_id => $user->id });
64
        }
65
66
        my $lists = $c->objects->search( $lists_set );
67
        return $c->render( status => 200, openapi => $lists );
68
    }
69
    catch {
70
        $c->unhandled_exception($_);
71
    };
72
}
73
74
1;
(-)a/Koha/Schema/Result/Virtualshelve.pm (-1 / +3 lines)
Lines 210-216 sub koha_objects_class { Link Here
210
}
210
}
211
211
212
__PACKAGE__->add_columns(
212
__PACKAGE__->add_columns(
213
    '+public' => { is_boolean => 1 },
213
    '+allow_change_from_others' => { is_boolean => 1 },
214
    '+allow_change_from_owner'  => { is_boolean => 1 },
215
    '+public'                   => { is_boolean => 1 },
214
);
216
);
215
217
216
1;
218
1;
(-)a/Koha/Virtualshelf.pm (+32 lines)
Lines 255-260 sub can_biblios_be_removed { Link Here
255
    # Same answer since bug 18228
255
    # Same answer since bug 18228
256
}
256
}
257
257
258
=head3 to_api_mapping
259
260
This method returns the mapping for representing a Koha::Virtualshelf object
261
on the API.
262
263
=cut
264
265
sub to_api_mapping {
266
    return {
267
        created_on   => 'creation_date',
268
        lastmodified => 'updated_on_date',
269
        owner        => 'owner_id',
270
        shelfname    => 'name',
271
        shelfnumber  => 'list_id',
272
        sortfield    => 'default_sort_field',
273
    };
274
}
275
276
=head3 public_read_list
277
278
This method returns the list of publicly readable database fields for both API and UI output purposes
279
280
=cut
281
282
sub public_read_list {
283
    return [
284
        'created_on',  'lastmodified', 'shelfname',
285
        'shelfnumber', 'public',       'sortfield',
286
        'allow_change_from_owner', 'allow_change_from_others'
287
    ];
288
}
289
258
=head2 Internal methods
290
=head2 Internal methods
259
291
260
=head3 _type
292
=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.json (+3 lines)
Lines 167-172 Link Here
167
  "/public/libraries/{library_id}": {
167
  "/public/libraries/{library_id}": {
168
    "$ref": "paths/libraries.json#/~1public~1libraries~1{library_id}"
168
    "$ref": "paths/libraries.json#/~1public~1libraries~1{library_id}"
169
  },
169
  },
170
  "/public/lists": {
171
    "$ref": "paths/lists.yaml#/~1public~1lists"
172
  },
170
  "/public/patrons/{patron_id}/password": {
173
  "/public/patrons/{patron_id}/password": {
171
    "$ref": "paths/public_patrons.json#/~1public~1patrons~1{patron_id}~1password"
174
    "$ref": "paths/public_patrons.json#/~1public~1patrons~1{patron_id}~1password"
172
  },
175
  },
(-)a/api/v1/swagger/paths/lists.yaml (+49 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": "../parameters.json#/match"
22
    - "$ref": "../parameters.json#/order_by"
23
    - "$ref": "../parameters.json#/page"
24
    - "$ref": "../parameters.json#/per_page"
25
    - "$ref": "../parameters.json#/q_param"
26
    - "$ref": "../parameters.json#/q_body"
27
    - "$ref": "../parameters.json#/q_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": "../definitions.json#/error"
39
      '500':
40
        description: Internal error
41
        schema:
42
          "$ref": "../definitions.json#/error"
43
      '503':
44
        description: Under maintenance
45
        schema:
46
          "$ref": "../definitions.json#/error"
47
    x-koha-authorization:
48
      permissions:
49
        catalogue: 1
(-)a/api/v1/swagger/swagger.yaml (-1 / +4 lines)
Lines 79-84 tags: Link Here
79
    x-displayName: Libraries
79
    x-displayName: Libraries
80
    description: |
80
    description: |
81
      Manage libraries
81
      Manage libraries
82
  - name: "lists"
83
    x-displayName: Lists
84
    description: |
85
      Manage lists
82
  - name: "macros"
86
  - name: "macros"
83
    x-displayName: Macros
87
    x-displayName: Macros
84
    description: |
88
    description: |
85
- 

Return to bug 28965