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

(-)a/Koha/REST/V1/AuthorisedValues.pm (-2 / +1 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use Mojo::Base 'Mojolicious::Controller';
20
use Mojo::Base 'Mojolicious::Controller';
21
21
22
use Koha::AuthorisedValues;
23
use Koha::AuthorisedValueCategories;
22
use Koha::AuthorisedValueCategories;
24
23
25
use Try::Tiny;
24
use Try::Tiny;
Lines 49-55 sub list_av_from_category { Link Here
49
    }
48
    }
50
49
51
    return try {
50
    return try {
52
        my $av_set = Koha::AuthorisedValues->search( { category => $category_name } )->search_with_library_limits;
51
        my $av_set = $category->authorised_values->search_with_library_limits;
53
        my $avs    = $c->objects->search($av_set);
52
        my $avs    = $c->objects->search($av_set);
54
        return $c->render( status => 200, openapi => $avs );
53
        return $c->render( status => 200, openapi => $avs );
55
    } catch {
54
    } catch {
(-)a/api/v1/swagger/paths/authorised_values.yaml (-1 / +1 lines)
Lines 1-5 Link Here
1
---
1
---
2
"/authorised_value_categories/{authorised_value_category_name}/values":
2
"/authorised_value_categories/{authorised_value_category_name}/authorised_values":
3
  get:
3
  get:
4
    x-mojo-to: AuthorisedValues#list_av_from_category
4
    x-mojo-to: AuthorisedValues#list_av_from_category
5
    operationId: listAuthorisedValues
5
    operationId: listAuthorisedValues
(-)a/api/v1/swagger/swagger.yaml (-2 / +2 lines)
Lines 145-152 paths: Link Here
145
    $ref: paths/auth.yaml#/~1auth~1identity_providers~1{identity_provider_id}~1domains~1{identity_provider_domain_id}
145
    $ref: paths/auth.yaml#/~1auth~1identity_providers~1{identity_provider_id}~1domains~1{identity_provider_domain_id}
146
  /authorised_value_categories:
146
  /authorised_value_categories:
147
    $ref: paths/authorised_value_categories.yaml#/~1authorised_value_categories
147
    $ref: paths/authorised_value_categories.yaml#/~1authorised_value_categories
148
  "/authorised_value_categories/{authorised_value_category_name}/values":
148
  "/authorised_value_categories/{authorised_value_category_name}/authorised_values":
149
    $ref: "./paths/authorised_values.yaml#/~1authorised_value_categories~1{authorised_value_category_name}~1values"
149
    $ref: "./paths/authorised_values.yaml#/~1authorised_value_categories~1{authorised_value_category_name}~1authorised_values"
150
  "/biblios/{biblio_id}":
150
  "/biblios/{biblio_id}":
151
    $ref: "./paths/biblios.yaml#/~1biblios~1{biblio_id}"
151
    $ref: "./paths/biblios.yaml#/~1biblios~1{biblio_id}"
152
  "/biblios/{biblio_id}/checkouts":
152
  "/biblios/{biblio_id}/checkouts":
(-)a/t/db_dependent/api/v1/authorised_values.t (-5 / +4 lines)
Lines 60-73 subtest 'list_av_from_category() tests' => sub { Link Here
60
60
61
    ## Authorized user tests
61
    ## Authorized user tests
62
    # No category, 404 expected
62
    # No category, 404 expected
63
    $t->get_ok("//$userid:$password@/api/v1/authorised_value_categories/NON_EXISTS/values")
63
    $t->get_ok("//$userid:$password@/api/v1/authorised_value_categories/NON_EXISTS/authorised_values")
64
      ->status_is(404)
64
      ->status_is(404)
65
      ->json_is( '/error' => 'Category not found' );
65
      ->json_is( '/error' => 'Category not found' );
66
66
67
    my $av_cat = $builder->build_object({ class => 'Koha::AuthorisedValueCategories' })->category_name;
67
    my $av_cat = $builder->build_object({ class => 'Koha::AuthorisedValueCategories' })->category_name;
68
68
69
    # No AVs, so empty array should be returned
69
    # No AVs, so empty array should be returned
70
    $t->get_ok("//$userid:$password@/api/v1/authorised_value_categories/$av_cat/values")
70
    $t->get_ok("//$userid:$password@/api/v1/authorised_value_categories/$av_cat/authorised_values")
71
      ->status_is(200)
71
      ->status_is(200)
72
      ->json_is( [] );
72
      ->json_is( [] );
73
73
Lines 75-86 subtest 'list_av_from_category() tests' => sub { Link Here
75
        { class => 'Koha::AuthorisedValues', value => { category => $av_cat } } );
75
        { class => 'Koha::AuthorisedValues', value => { category => $av_cat } } );
76
76
77
    # One av created, should get returned
77
    # One av created, should get returned
78
    $t->get_ok("//$userid:$password@/api/v1/authorised_value_categories/$av_cat/values")
78
    $t->get_ok("//$userid:$password@/api/v1/authorised_value_categories/$av_cat/authorised_values")
79
      ->status_is(200)
79
      ->status_is(200)
80
      ->json_is( [$av->to_api] );
80
      ->json_is( [$av->to_api] );
81
81
82
    # Unauthorized access
82
    # Unauthorized access
83
    $t->get_ok("//$unauth_userid:$password@/api/v1/authorised_value_categories/$av_cat/values")
83
    $t->get_ok("//$unauth_userid:$password@/api/v1/authorised_value_categories/$av_cat/authorised_values")
84
      ->status_is(403);
84
      ->status_is(403);
85
85
86
    $schema->storage->txn_rollback;
86
    $schema->storage->txn_rollback;
87
- 

Return to bug 32997