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

(-)a/Koha/REST/V1/SearchFilter.pm (-3 / +1 lines)
Lines 59-67 Controller function that handles retrieving a single Koha::AdvancedEditorMacro Link Here
59
59
60
sub get {
60
sub get {
61
    my $c = shift->openapi->valid_input or return;
61
    my $c = shift->openapi->valid_input or return;
62
    my $filter = Koha::SearchFilters->find({
62
    my $filter = Koha::SearchFilters->find( $c->validation->param('search_filter_id') );
63
        id => $c->validation->param('search_filter_id'),
64
    });
65
    unless ($filter) {
63
    unless ($filter) {
66
        return $c->render( status  => 404,
64
        return $c->render( status  => 404,
67
                           openapi => { error => "Search filter not found" } );
65
                           openapi => { error => "Search filter not found" } );
(-)a/Koha/SearchFilter.pm (-12 lines)
Lines 29-46 Koha::SearchFilter - Koha Search filter object class Link Here
29
29
30
=head2 Class methods
30
=head2 Class methods
31
31
32
=head3 to_api_mapping
33
34
=cut
35
36
sub to_api_mapping {
37
    return {
38
        id                  => 'search_filter_id',
39
        query               => 'filter_query',
40
        limits              => 'filter_limits',
41
    };
42
}
43
44
=head3 expand_filter
32
=head3 expand_filter
45
33
46
    my ($expanded_limit, $query_limit) = $filter->expand_filter;
34
    my ($expanded_limit, $query_limit) = $filter->expand_filter;
(-)a/api/v1/swagger/definitions/search_filter.yaml (-2 / +2 lines)
Lines 8-19 properties: Link Here
8
  name:
8
  name:
9
    description: filter name
9
    description: filter name
10
    type: string
10
    type: string
11
  filter_query:
11
  query:
12
    description: filter query part
12
    description: filter query part
13
    type:
13
    type:
14
    - string
14
    - string
15
    - 'null'
15
    - 'null'
16
  filter_limits:
16
  limits:
17
    description: filter limits part
17
    description: filter limits part
18
    type:
18
    type:
19
    - string
19
    - string
(-)a/api/v1/swagger/paths/search_filters.yaml (-25 lines)
Lines 9-39 Link Here
9
    produces:
9
    produces:
10
      - application/json
10
      - application/json
11
    parameters:
11
    parameters:
12
      - name: name
13
        in: query
14
        description: Case insensitive search on filter name
15
        required: false
16
        type: string
17
      - name: filter_query
18
        in: query
19
        description: Search on filter query part
20
        required: false
21
        type: string
22
      - name: filter_limits
23
        in: query
24
        description: Search on filter limits
25
        required: false
26
        type: string
27
      - name: opac
28
        in: query
29
        description: Display in OPAC
30
        required: false
31
        type: boolean
32
      - name: staff_client
33
        in: query
34
        description: Display on staff client
35
        required: false
36
        type: boolean
37
      - $ref: "../swagger.yaml#/parameters/match"
12
      - $ref: "../swagger.yaml#/parameters/match"
38
      - $ref: "../swagger.yaml#/parameters/order_by"
13
      - $ref: "../swagger.yaml#/parameters/order_by"
39
      - $ref: "../swagger.yaml#/parameters/page"
14
      - $ref: "../swagger.yaml#/parameters/page"
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/search_filters.tt (-2 / +2 lines)
Lines 117-128 Link Here
117
                        "orderable": true
117
                        "orderable": true
118
                    },
118
                    },
119
                    {
119
                    {
120
                        "data": "filter_query",
120
                        "data": "query",
121
                        "searchable": true,
121
                        "searchable": true,
122
                        "orderable": true
122
                        "orderable": true
123
                    },
123
                    },
124
                    {
124
                    {
125
                        "data": "filter_limits",
125
                        "data": "limits",
126
                        "searchable": true,
126
                        "searchable": true,
127
                        "orderable": true
127
                        "orderable": true
128
                    },
128
                    },
(-)a/t/db_dependent/api/v1/search_filters.t (-35 / +26 lines)
Lines 33-42 t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); Link Here
33
33
34
my $t = Test::Mojo->new('Koha::REST::V1');
34
my $t = Test::Mojo->new('Koha::REST::V1');
35
35
36
$schema->storage->txn_begin;
37
38
subtest 'list() tests' => sub {
36
subtest 'list() tests' => sub {
39
    plan tests => 10;
37
38
    plan tests => 6;
39
40
    $schema->storage->txn_begin;
40
41
41
    Koha::SearchFilters->search()->delete();
42
    Koha::SearchFilters->search()->delete();
42
43
Lines 94-127 subtest 'list() tests' => sub { Link Here
94
      ->json_has('/2/search_filter_id')
95
      ->json_has('/2/search_filter_id')
95
      ->json_has('/3/search_filter_id');
96
      ->json_has('/3/search_filter_id');
96
97
97
    subtest 'query parameters' => sub {
98
    $schema->storage->txn_rollback;
98
99
        plan tests => 12;
100
        $t->get_ok("//$userid:$password@/api/v1/search_filters?name=" . $search_filter_2->name)
101
          ->status_is(200)
102
          ->json_is( [ $search_filter_2->to_api ] );
103
        $t->get_ok("//$userid:$password@/api/v1/search_filters?name=NotAName")
104
          ->status_is(200)
105
          ->json_is( [ ] );
106
        $t->get_ok("//$userid:$password@/api/v1/search_filters?filter_query=kw:any")
107
          ->status_is(200)
108
          ->json_is( [ $search_filter_3->to_api ] );
109
        $t->get_ok("//$userid:$password@/api/v1/search_filters?filter_limits=mc-itype,phr:BK")
110
          ->status_is(200)
111
          ->json_is( [ $search_filter_1->to_api, $search_filter_2->to_api ] );
112
    };
113
114
    # Warn on unsupported query parameter
115
    $t->get_ok( "//$userid:$password@/api/v1/search_filters?filter_blah=blah" )
116
      ->status_is(400)
117
      ->json_is( [{ path => '/query/filter_blah', message => 'Malformed query string'}] );
118
119
};
99
};
120
100
121
subtest 'get() tests' => sub {
101
subtest 'get() tests' => sub {
122
102
123
    plan tests => 9;
103
    plan tests => 9;
124
104
105
    $schema->storage->txn_begin;
106
125
    my $patron = $builder->build_object({
107
    my $patron = $builder->build_object({
126
        class => 'Koha::Patrons',
108
        class => 'Koha::Patrons',
127
        value => { flags => 3 }
109
        value => { flags => 3 }
Lines 150-161 subtest 'get() tests' => sub { Link Here
150
      ->status_is( 401, 'Cannot search filters without permission' )
132
      ->status_is( 401, 'Cannot search filters without permission' )
151
      ->json_is( '/error' => 'Authentication failure.' );
133
      ->json_is( '/error' => 'Authentication failure.' );
152
134
135
    $schema->storage->txn_rollback;
153
};
136
};
154
137
155
subtest 'add() tests' => sub {
138
subtest 'add() tests' => sub {
156
139
157
    plan tests => 17;
140
    plan tests => 17;
158
141
142
    $schema->storage->txn_begin;
143
159
    my $authorized_patron = $builder->build_object({
144
    my $authorized_patron = $builder->build_object({
160
        class => 'Koha::Patrons',
145
        class => 'Koha::Patrons',
161
        value => { flags => 0 }
146
        value => { flags => 0 }
Lines 231-241 subtest 'add() tests' => sub { Link Here
231
        ]
216
        ]
232
    );
217
    );
233
218
219
    $schema->storage->txn_rollback;
234
};
220
};
235
221
236
subtest 'update() tests' => sub {
222
subtest 'update() tests' => sub {
223
237
    plan tests => 15;
224
    plan tests => 15;
238
225
226
    $schema->storage->txn_begin;
227
239
    my $authorized_patron = $builder->build_object({
228
    my $authorized_patron = $builder->build_object({
240
        class => 'Koha::Patrons',
229
        class => 'Koha::Patrons',
241
        value => { flags => 0 }
230
        value => { flags => 0 }
Lines 271-288 subtest 'update() tests' => sub { Link Here
271
      ->status_is(403);
260
      ->status_is(403);
272
261
273
    my $search_filter_update = {
262
    my $search_filter_update = {
274
        name => "Filter update",
263
        name   => "Filter update",
275
        filter_query => "ti:The hobbit",
264
        query  => "ti:The hobbit",
276
        filter_limits => "mc-ccode:fantasy",
265
        limits => "mc-ccode:fantasy",
277
    };
266
    };
278
267
279
    my $test = $t->put_ok( "//$auth_userid:$password@/api/v1/search_filters/$search_filter_id" => json => $search_filter_update )
268
    my $test = $t->put_ok( "//$auth_userid:$password@/api/v1/search_filters/$search_filter_id" => json => $search_filter_update )
280
      ->status_is(200, 'Authorized user can update a macro')
269
      ->status_is(200, 'Authorized user can update a macro')
281
      ->json_is( '/search_filter_id' => $search_filter_id, 'We get back the id' )
270
      ->json_is( '/search_filter_id' => $search_filter_id, 'We get back the id' )
282
      ->json_is( '/name' => $search_filter_update->{name}, 'We get back the name' )
271
      ->json_is( '/name'   => $search_filter_update->{name}, 'We get back the name' )
283
      ->json_is( '/filter_query' => $search_filter_update->{filter_query}, 'We get back our query' )
272
      ->json_is( '/query'  => $search_filter_update->{query}, 'We get back our query' )
284
      ->json_is( '/filter_limits' => $search_filter_update->{filter_limits}, 'We get back our limits' )
273
      ->json_is( '/limits' => $search_filter_update->{limits}, 'We get back our limits' )
285
      ->json_is( '/opac' => 1, 'We get back our opac visibility unchanged' )
274
      ->json_is( '/opac'   => 1, 'We get back our opac visibility unchanged' )
286
      ->json_is( '/staff_client' => 1, 'We get back our staff client visibility unchanged' );
275
      ->json_is( '/staff_client' => 1, 'We get back our staff client visibility unchanged' );
287
276
288
    # Authorized attempt to write invalid data
277
    # Authorized attempt to write invalid data
Lines 307-317 subtest 'update() tests' => sub { Link Here
307
    $t->put_ok("//$auth_userid:$password@/api/v1/search_filters/$non_existent_code" => json => $search_filter_update)
296
    $t->put_ok("//$auth_userid:$password@/api/v1/search_filters/$non_existent_code" => json => $search_filter_update)
308
      ->status_is(404);
297
      ->status_is(404);
309
298
299
    $schema->storage->txn_rollback;
310
};
300
};
311
301
312
subtest 'delete() tests' => sub {
302
subtest 'delete() tests' => sub {
303
313
    plan tests => 4;
304
    plan tests => 4;
314
305
306
    $schema->storage->txn_begin;
307
315
    my $authorized_patron = $builder->build_object({
308
    my $authorized_patron = $builder->build_object({
316
        class => 'Koha::Patrons',
309
        class => 'Koha::Patrons',
317
        value => { flags => 0 }
310
        value => { flags => 0 }
Lines 348-353 subtest 'delete() tests' => sub { Link Here
348
    $t->delete_ok( "//$auth_userid:$password@/api/v1/search_filters/$search_filter_id")
341
    $t->delete_ok( "//$auth_userid:$password@/api/v1/search_filters/$search_filter_id")
349
      ->status_is( 204, 'Can delete search filter with permission');
342
      ->status_is( 204, 'Can delete search filter with permission');
350
343
344
    $schema->storage->txn_rollback;
351
};
345
};
352
353
$schema->storage->txn_rollback;
354
- 

Return to bug 17170