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

(-)a/Koha/REST/V1/AdvancedEditorMacro.pm (-3 / +3 lines)
Lines 72-78 sub get { Link Here
72
    }
72
    }
73
    if( $macro->shared ){
73
    if( $macro->shared ){
74
        return $c->render( status => 403, openapi => {
74
        return $c->render( status => 403, openapi => {
75
            error => "This macro is shared, you must access it via advancededitormacros/shared"
75
            error => "This macro is shared, you must access it via advanced_editor/macros/shared"
76
        });
76
        });
77
    }
77
    }
78
    warn $macro->borrowernumber;
78
    warn $macro->borrowernumber;
Lines 104-110 sub get_shared { Link Here
104
    }
104
    }
105
    unless( $macro->shared ){
105
    unless( $macro->shared ){
106
        return $c->render( status => 403, openapi => {
106
        return $c->render( status => 403, openapi => {
107
            error => "This macro is not shared, you must access it via advancededitormacros"
107
            error => "This macro is not shared, you must access it via advanced_editor/macros"
108
        });
108
        });
109
    }
109
    }
110
    return $c->render( status => 200, openapi => $macro->to_api );
110
    return $c->render( status => 200, openapi => $macro->to_api );
Lines 180-186 sub update { Link Here
180
180
181
    if( $macro->shared == 1 || defined $c->validation->param('body')->{shared} && $c->validation->param('body')->{shared} == 1 ){
181
    if( $macro->shared == 1 || defined $c->validation->param('body')->{shared} && $c->validation->param('body')->{shared} == 1 ){
182
        return $c->render( status  => 403,
182
        return $c->render( status  => 403,
183
                           openapi => { error => "To update a macro as shared you must use the advancededitormacros/shared endpoint" } );
183
                           openapi => { error => "To update a macro as shared you must use the advanced_editor/macros/shared endpoint" } );
184
    } else {
184
    } else {
185
        unless ( $macro->borrowernumber == $patron->borrowernumber ){
185
        unless ( $macro->borrowernumber == $patron->borrowernumber ){
186
            return $c->render( status  => 403,
186
            return $c->render( status  => 403,
(-)a/api/v1/swagger/paths.json (-8 / +8 lines)
Lines 68-84 Link Here
68
  "/checkouts/{checkout_id}/allows_renewal": {
68
  "/checkouts/{checkout_id}/allows_renewal": {
69
    "$ref": "paths/checkouts.json#/~1checkouts~1{checkout_id}~1allows_renewal"
69
    "$ref": "paths/checkouts.json#/~1checkouts~1{checkout_id}~1allows_renewal"
70
  },
70
  },
71
  "/advancededitormacros": {
71
  "/advanced_editor/macros": {
72
    "$ref": "paths/advancededitormacros.json#/~1advancededitormacros"
72
    "$ref": "paths/advancededitormacros.json#/~1advanced_editor~1macros"
73
  },
73
  },
74
  "/advancededitormacros/{advancededitormacro_id}": {
74
  "/advanced_editor/macros/{advancededitormacro_id}": {
75
    "$ref": "paths/advancededitormacros.json#/~1advancededitormacros~1{advancededitormacro_id}"
75
    "$ref": "paths/advancededitormacros.json#/~1advanced_editor~1macros~1{advancededitormacro_id}"
76
  },
76
  },
77
  "/advancededitormacros/shared": {
77
  "/advanced_editor/macros/shared": {
78
    "$ref": "paths/advancededitormacros.json#/~1advancededitormacros~1shared"
78
    "$ref": "paths/advancededitormacros.json#/~1advanced_editor~1macros~1shared"
79
  },
79
  },
80
  "/advancededitormacros/shared/{advancededitormacro_id}": {
80
  "/advanced_editor/macros/shared/{advancededitormacro_id}": {
81
    "$ref": "paths/advancededitormacros.json#/~1advancededitormacros~1shared~1{advancededitormacro_id}"
81
    "$ref": "paths/advancededitormacros.json#/~1advanced_editor~1macros~1shared~1{advancededitormacro_id}"
82
  },
82
  },
83
  "/patrons": {
83
  "/patrons": {
84
    "$ref": "paths/patrons.json#/~1patrons"
84
    "$ref": "paths/patrons.json#/~1patrons"
(-)a/api/v1/swagger/paths/advancededitormacros.json (-4 / +4 lines)
Lines 1-5 Link Here
1
{
1
{
2
  "/advancededitormacros": {
2
  "/advanced_editor/macros": {
3
    "get": {
3
    "get": {
4
      "x-mojo-to": "AdvancedEditorMacro#list",
4
      "x-mojo-to": "AdvancedEditorMacro#list",
5
      "operationId": "listMacro",
5
      "operationId": "listMacro",
Lines 127-133 Link Here
127
      }
127
      }
128
    }
128
    }
129
  },
129
  },
130
  "/advancededitormacros/shared": {
130
  "/advanced_editor/macros/shared": {
131
    "post": {
131
    "post": {
132
      "x-mojo-to": "AdvancedEditorMacro#add_shared",
132
      "x-mojo-to": "AdvancedEditorMacro#add_shared",
133
      "operationId": "addsharedAdvancedEditorMacro",
133
      "operationId": "addsharedAdvancedEditorMacro",
Lines 184-190 Link Here
184
      }
184
      }
185
    }
185
    }
186
  },
186
  },
187
  "/advancededitormacros/{advancededitormacro_id}": {
187
  "/advanced_editor/macros/{advancededitormacro_id}": {
188
    "get": {
188
    "get": {
189
      "x-mojo-to": "AdvancedEditorMacro#get",
189
      "x-mojo-to": "AdvancedEditorMacro#get",
190
      "operationId": "getAdvancedEditorMacro",
190
      "operationId": "getAdvancedEditorMacro",
Lines 350-356 Link Here
350
      }
350
      }
351
    }
351
    }
352
  },
352
  },
353
  "/advancededitormacros/shared/{advancededitormacro_id}": {
353
  "/advanced_editor/macros/shared/{advancededitormacro_id}": {
354
    "get": {
354
    "get": {
355
      "x-mojo-to": "AdvancedEditorMacro#get_shared",
355
      "x-mojo-to": "AdvancedEditorMacro#get_shared",
356
      "operationId": "getsharedAdvancedEditorMacro",
356
      "operationId": "getsharedAdvancedEditorMacro",
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc (-6 / +6 lines)
Lines 701-707 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
701
        var shared = macroEditor.activeMacroShared;
701
        var shared = macroEditor.activeMacroShared;
702
        var id = macroEditor.activeMacroId;
702
        var id = macroEditor.activeMacroId;
703
        macroEditor.activeMacroId = null;
703
        macroEditor.activeMacroId = null;
704
        api_url = "/api/v1/advancededitormacros/";
704
        api_url = "/api/v1/advanced_editor/macros/";
705
        if( shared ) { api_url += "shared/" }
705
        if( shared ) { api_url += "shared/" }
706
        let options = {
706
        let options = {
707
            url: api_url + id,
707
            url: api_url + id,
Lines 740-746 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
740
            return;
740
            return;
741
        }
741
        }
742
        $( '#macro-list li[data-name="' + name + '"][data-id="' + id + '"]' ).addClass( 'active' );
742
        $( '#macro-list li[data-name="' + name + '"][data-id="' + id + '"]' ).addClass( 'active' );
743
        api_url = "/api/v1/advancededitormacros/";
743
        api_url = "/api/v1/advanced_editor/macros/";
744
        if( shared ) { api_url += "shared/" }
744
        if( shared ) { api_url += "shared/" }
745
        let options = {
745
        let options = {
746
            url: api_url + id,
746
            url: api_url + id,
Lines 791-797 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
791
        } );
791
        } );
792
        $.each( macro_list, function( index, macro ) {
792
        $.each( macro_list, function( index, macro ) {
793
            let options = {
793
            let options = {
794
                url: "/api/v1/advancededitormacros/",
794
                url: "/api/v1/advanced_editor/macros/",
795
                method: "POST",
795
                method: "POST",
796
                contentType: "application/json",
796
                contentType: "application/json",
797
                data: JSON.stringify({
797
                data: JSON.stringify({
Lines 837-843 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
837
            $("#macro-toolbar").prepend($convert);
837
            $("#macro-toolbar").prepend($convert);
838
        }
838
        }
839
        let options = {
839
        let options = {
840
            url: "/api/v1/advancededitormacros/",
840
            url: "/api/v1/advanced_editor/macros/",
841
            method: "GET",
841
            method: "GET",
842
            contentType: "application/json",
842
            contentType: "application/json",
843
        };
843
        };
Lines 865-871 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
865
865
866
//            if ( !Preferences.user.macros[name] ) storeMacro( name, { format: "rancor", contents: "" } );
866
//            if ( !Preferences.user.macros[name] ) storeMacro( name, { format: "rancor", contents: "" } );
867
            let options = {
867
            let options = {
868
                url: "/api/v1/advancededitormacros/",
868
                url: "/api/v1/advanced_editor/macros/",
869
                method: "POST",
869
                method: "POST",
870
                contentType: "application/json",
870
                contentType: "application/json",
871
                data: JSON.stringify({
871
                data: JSON.stringify({
Lines 902-908 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
902
        if ( !name || macroEditor.savedGeneration == macroEditor.changeGeneration() && was_shared == shared ) return;
902
        if ( !name || macroEditor.savedGeneration == macroEditor.changeGeneration() && was_shared == shared ) return;
903
903
904
        macroEditor.savedGeneration = macroEditor.changeGeneration();
904
        macroEditor.savedGeneration = macroEditor.changeGeneration();
905
        api_url = "/api/v1/advancededitormacros/";
905
        api_url = "/api/v1/advanced_editor/macros/";
906
        if( shared || was_shared ) { api_url += "shared/" }
906
        if( shared || was_shared ) { api_url += "shared/" }
907
907
908
        let options = {
908
        let options = {
(-)a/t/db_dependent/api/v1/advanced_editor_macros.t (-44 / +43 lines)
Lines 85-91 subtest 'list() tests' => sub { Link Here
85
    my $macros_index = Koha::AdvancedEditorMacros->search({ -or => { shared => 1, borrowernumber => $patron_1->borrowernumber } })->count-1;
85
    my $macros_index = Koha::AdvancedEditorMacros->search({ -or => { shared => 1, borrowernumber => $patron_1->borrowernumber } })->count-1;
86
    ## Authorized user tests
86
    ## Authorized user tests
87
    # Make sure we are returned with the correct amount of macros
87
    # Make sure we are returned with the correct amount of macros
88
    $t->get_ok( "//$userid:$password@/api/v1/advancededitormacros" )
88
    $t->get_ok( "//$userid:$password@/api/v1/advanced_editor/macros" )
89
      ->status_is( 200, 'SWAGGER3.2.2' )
89
      ->status_is( 200, 'SWAGGER3.2.2' )
90
      ->json_has('/' . $macros_index . '/macro_id')
90
      ->json_has('/' . $macros_index . '/macro_id')
91
      ->json_hasnt('/' . ($macros_index + 1) . '/macro_id');
91
      ->json_hasnt('/' . ($macros_index + 1) . '/macro_id');
Lines 93-117 subtest 'list() tests' => sub { Link Here
93
    subtest 'query parameters' => sub {
93
    subtest 'query parameters' => sub {
94
94
95
        plan tests => 15;
95
        plan tests => 15;
96
        $t->get_ok("//$userid:$password@/api/v1/advancededitormacros?name=" . $macro_2->name)
96
        $t->get_ok("//$userid:$password@/api/v1/advanced_editor/macros?name=" . $macro_2->name)
97
          ->status_is(200)
97
          ->status_is(200)
98
          ->json_has( [ $macro_2 ] );
98
          ->json_has( [ $macro_2 ] );
99
        $t->get_ok("//$userid:$password@/api/v1/advancededitormacros?name=" . $macro_3->name)
99
        $t->get_ok("//$userid:$password@/api/v1/advanced_editor/macros?name=" . $macro_3->name)
100
          ->status_is(200)
100
          ->status_is(200)
101
          ->json_has( [ ] );
101
          ->json_has( [ ] );
102
        $t->get_ok("//$userid:$password@/api/v1/advancededitormacros?macro_text=delete 100")
102
        $t->get_ok("//$userid:$password@/api/v1/advanced_editor/macros?macro_text=delete 100")
103
          ->status_is(200)
103
          ->status_is(200)
104
          ->json_has( [ $macro_1, $macro_2, $macro_4 ] );
104
          ->json_has( [ $macro_1, $macro_2, $macro_4 ] );
105
        $t->get_ok("//$userid:$password@/api/v1/advancededitormacros?patron_id=" . $patron_1->borrowernumber)
105
        $t->get_ok("//$userid:$password@/api/v1/advanced_editor/macros?patron_id=" . $patron_1->borrowernumber)
106
          ->status_is(200)
106
          ->status_is(200)
107
          ->json_has( [ $macro_1, $macro_2 ] );
107
          ->json_has( [ $macro_1, $macro_2 ] );
108
        $t->get_ok("//$userid:$password@/api/v1/advancededitormacros?shared=1")
108
        $t->get_ok("//$userid:$password@/api/v1/advanced_editor/macros?shared=1")
109
          ->status_is(200)
109
          ->status_is(200)
110
          ->json_has( [ $macro_2, $macro_4 ] );
110
          ->json_has( [ $macro_2, $macro_4 ] );
111
    };
111
    };
112
112
113
    # Warn on unsupported query parameter
113
    # Warn on unsupported query parameter
114
    $t->get_ok( "//$userid:$password@/api/v1/advancededitormacros?macro_blah=blah" )
114
    $t->get_ok( "//$userid:$password@/api/v1/advanced_editor/macros?macro_blah=blah" )
115
      ->status_is(400)
115
      ->status_is(400)
116
      ->json_is( [{ path => '/query/macro_blah', message => 'Malformed query string'}] );
116
      ->json_is( [{ path => '/query/macro_blah', message => 'Malformed query string'}] );
117
117
Lines 143-168 subtest 'get() tests' => sub { Link Here
143
        }
143
        }
144
    });
144
    });
145
145
146
    $t->get_ok( "//$userid:$password@/api/v1/advancededitormacros/" . $macro_1->id )
146
    $t->get_ok( "//$userid:$password@/api/v1/advanced_editor/macros/" . $macro_1->id )
147
      ->status_is( 403, 'Cannot get a shared macro via regular endpoint' )
147
      ->status_is( 403, 'Cannot get a shared macro via regular endpoint' )
148
      ->json_is( '/error' => 'This macro is shared, you must access it via advancededitormacros/shared' );
148
      ->json_is( '/error' => 'This macro is shared, you must access it via advanced_editor/macros/shared' );
149
149
150
    $t->get_ok( "//$userid:$password@/api/v1/advancededitormacros/shared/" . $macro_1->id )
150
    $t->get_ok( "//$userid:$password@/api/v1/advanced_editor/macros/shared/" . $macro_1->id )
151
      ->status_is( 200, 'Can get a shared macro via shared endpoint' )
151
      ->status_is( 200, 'Can get a shared macro via shared endpoint' )
152
      ->json_is( '' => Koha::REST::V1::AdvancedEditorMacro::_to_api( $macro_1->TO_JSON ), 'Macro correctly retrieved' );
152
      ->json_is( '' => Koha::REST::V1::AdvancedEditorMacro::_to_api( $macro_1->TO_JSON ), 'Macro correctly retrieved' );
153
153
154
    $t->get_ok( "//$userid:$password@/api/v1/advancededitormacros/" . $macro_2->id )
154
    $t->get_ok( "//$userid:$password@/api/v1/advanced_editor/macros/" . $macro_2->id )
155
      ->status_is( 403, 'Cannot access another users macro' )
155
      ->status_is( 403, 'Cannot access another users macro' )
156
      ->json_is( '/error' => 'You do not have permission to access this macro' );
156
      ->json_is( '/error' => 'You do not have permission to access this macro' );
157
157
158
    $t->get_ok( "//$userid:$password@/api/v1/advancededitormacros/" . $macro_3->id )
158
    $t->get_ok( "//$userid:$password@/api/v1/advanced_editor/macros/" . $macro_3->id )
159
      ->status_is( 200, 'Can get your own private macro' )
159
      ->status_is( 200, 'Can get your own private macro' )
160
      ->json_is( '' => Koha::REST::V1::AdvancedEditorMacro::_to_api( $macro_3->TO_JSON ), 'Macro correctly retrieved' );
160
      ->json_is( '' => Koha::REST::V1::AdvancedEditorMacro::_to_api( $macro_3->TO_JSON ), 'Macro correctly retrieved' );
161
161
162
    my $non_existent_code = $macro_1->id;
162
    my $non_existent_code = $macro_1->id;
163
    $macro_1->delete;
163
    $macro_1->delete;
164
164
165
    $t->get_ok( "//$userid:$password@/api/v1/advancededitormacros/" . $non_existent_code )
165
    $t->get_ok( "//$userid:$password@/api/v1/advanced_editor/macros/" . $non_existent_code )
166
      ->status_is(404)
166
      ->status_is(404)
167
      ->json_is( '/error' => 'Macro not found' );
167
      ->json_is( '/error' => 'Macro not found' );
168
168
Lines 205-218 subtest 'add() tests' => sub { Link Here
205
    $macro->delete;
205
    $macro->delete;
206
206
207
    # Unauthorized attempt to write
207
    # Unauthorized attempt to write
208
    $t->post_ok( "//$unauth_userid:$password@/api/v1/advancededitormacros" => json => $macro_values )
208
    $t->post_ok( "//$unauth_userid:$password@/api/v1/advanced_editor/macros" => json => $macro_values )
209
      ->status_is(403);
209
      ->status_is(403);
210
210
211
    # Authorized attempt to write invalid data
211
    # Authorized attempt to write invalid data
212
    my $macro_with_invalid_field = { %$macro_values };
212
    my $macro_with_invalid_field = { %$macro_values };
213
    $macro_with_invalid_field->{'big_mac_ro'} = 'Mac attack';
213
    $macro_with_invalid_field->{'big_mac_ro'} = 'Mac attack';
214
214
215
    $t->post_ok( "//$auth_userid:$password@/api/v1/advancededitormacros" => json => $macro_with_invalid_field )
215
    $t->post_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros" => json => $macro_with_invalid_field )
216
      ->status_is(400)
216
      ->status_is(400)
217
      ->json_is(
217
      ->json_is(
218
        "/errors" => [
218
        "/errors" => [
Lines 224-237 subtest 'add() tests' => sub { Link Here
224
    );
224
    );
225
225
226
    # Authorized attempt to write
226
    # Authorized attempt to write
227
    $t->post_ok( "//$auth_userid:$password@/api/v1/advancededitormacros" => json => $macro_values )
227
    $t->post_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros" => json => $macro_values )
228
      ->status_is( 201, 'SWAGGER3.2.1' )
228
      ->status_is( 201, 'SWAGGER3.2.1' )
229
      ->json_has( '/macro_id', 'We generated a new id' )
229
      ->json_has( '/macro_id', 'We generated a new id' )
230
      ->json_is( '/name' => $macro_values->{name}, 'The name matches what we supplied' )
230
      ->json_is( '/name' => $macro_values->{name}, 'The name matches what we supplied' )
231
      ->json_is( '/macro_text' => $macro_values->{macro_text}, 'The text matches what we supplied' )
231
      ->json_is( '/macro_text' => $macro_values->{macro_text}, 'The text matches what we supplied' )
232
      ->json_is( '/patron_id' => $macro_values->{patron_id}, 'The borrower matches the borrower who submitted' )
232
      ->json_is( '/patron_id' => $macro_values->{patron_id}, 'The borrower matches the borrower who submitted' )
233
      ->json_is( '/shared' => 0, 'The macro is not shared' )
233
      ->json_is( '/shared' => Mojo::JSON->false, 'The macro is not shared' )
234
      ->header_like( Location => qr|^\/api\/v1\/advancededitormacros\/d*|, 'Correct location' );
234
      ->header_like( Location => qr|^\/api\/v1\/advanced_editor/macros\/d*|, 'Correct location' );
235
235
236
    # save the library_id
236
    # save the library_id
237
    my $macro_id = 999;
237
    my $macro_id = 999;
Lines 239-245 subtest 'add() tests' => sub { Link Here
239
    # Authorized attempt to create with existing id
239
    # Authorized attempt to create with existing id
240
    $macro_values->{macro_id} = $macro_id;
240
    $macro_values->{macro_id} = $macro_id;
241
241
242
    $t->post_ok( "//$auth_userid:$password@/api/v1/advancededitormacros" => json => $macro_values )
242
    $t->post_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros" => json => $macro_values )
243
      ->status_is(400)
243
      ->status_is(400)
244
      ->json_is( '/errors' => [
244
      ->json_is( '/errors' => [
245
            {
245
            {
Lines 249-262 subtest 'add() tests' => sub { Link Here
249
        ]
249
        ]
250
    );
250
    );
251
251
252
    $macro_values->{shared} = 1;
252
    $macro_values->{shared} = Mojo::JSON->true;
253
    delete $macro_values->{macro_id};
253
    delete $macro_values->{macro_id};
254
254
255
    # Unauthorized attempt to write a shared macro on private endpoint
255
    # Unauthorized attempt to write a shared macro on private endpoint
256
    $t->post_ok( "//$auth_userid:$password@/api/v1/advancededitormacros" => json => $macro_values )
256
    $t->post_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros" => json => $macro_values )
257
      ->status_is(403);
257
      ->status_is(403);
258
    # Unauthorized attempt to write a private macro on shared endpoint
258
    # Unauthorized attempt to write a private macro on shared endpoint
259
    $t->post_ok( "//$auth_userid:$password@/api/v1/advancededitormacros/shared" => json => $macro_values )
259
    $t->post_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros/shared" => json => $macro_values )
260
      ->status_is(403);
260
      ->status_is(403);
261
261
262
    $builder->build({
262
    $builder->build({
Lines 269-279 subtest 'add() tests' => sub { Link Here
269
    });
269
    });
270
270
271
    # Authorized attempt to write a shared macro on private endpoint
271
    # Authorized attempt to write a shared macro on private endpoint
272
    $t->post_ok( "//$auth_userid:$password@/api/v1/advancededitormacros" => json => $macro_values )
272
    $t->post_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros" => json => $macro_values )
273
      ->status_is(403);
273
      ->status_is(403);
274
274
275
    # Authorized attempt to write a shared macro on shared endpoint
275
    # Authorized attempt to write a shared macro on shared endpoint
276
    $t->post_ok( "//$auth_userid:$password@/api/v1/advancededitormacros/shared" => json => $macro_values )
276
    $t->post_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros/shared" => json => $macro_values )
277
      ->status_is(201);
277
      ->status_is(201);
278
278
279
};
279
};
Lines 319-325 subtest 'update() tests' => sub { Link Here
319
    delete $macro_values->{macro_id};
319
    delete $macro_values->{macro_id};
320
320
321
    # Unauthorized attempt to update
321
    # Unauthorized attempt to update
322
    $t->put_ok( "//$unauth_userid:$password@/api/v1/advancededitormacros/$macro_id"
322
    $t->put_ok( "//$unauth_userid:$password@/api/v1/advanced_editor/macros/$macro_id"
323
                    => json => { name => 'New unauthorized name change' } )
323
                    => json => { name => 'New unauthorized name change' } )
324
      ->status_is(403);
324
      ->status_is(403);
325
325
Lines 328-334 subtest 'update() tests' => sub { Link Here
328
        name => "Call it macro-roni",
328
        name => "Call it macro-roni",
329
    };
329
    };
330
330
331
    $t->put_ok( "//$auth_userid:$password@/api/v1/advancededitormacros/$macro_id" => json => $macro_with_missing_field )
331
    $t->put_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros/$macro_id" => json => $macro_with_missing_field )
332
      ->status_is(400)
332
      ->status_is(400)
333
      ->json_has( "/errors" =>
333
      ->json_has( "/errors" =>
334
          [ { message => "Missing property.", path => "/body/macro_text" } ]
334
          [ { message => "Missing property.", path => "/body/macro_text" } ]
Lines 338-347 subtest 'update() tests' => sub { Link Here
338
        name => "Macro-update",
338
        name => "Macro-update",
339
        macro_text => "delete 100",
339
        macro_text => "delete 100",
340
        patron_id => $authorized_patron->borrowernumber,
340
        patron_id => $authorized_patron->borrowernumber,
341
        shared => 0,
341
        shared => Mojo::JSON->false,
342
    };
342
    };
343
343
344
    my $test = $t->put_ok( "//$auth_userid:$password@/api/v1/advancededitormacros/$macro_id" => json => $macro_update )
344
    my $test = $t->put_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros/$macro_id" => json => $macro_update )
345
      ->status_is(200, 'Authorized user can update a macro')
345
      ->status_is(200, 'Authorized user can update a macro')
346
      ->json_is( '/macro_id' => $macro_id, 'We get the id back' )
346
      ->json_is( '/macro_id' => $macro_id, 'We get the id back' )
347
      ->json_is( '/name' => $macro_update->{name}, 'We get the name back' )
347
      ->json_is( '/name' => $macro_update->{name}, 'We get the name back' )
Lines 350-360 subtest 'update() tests' => sub { Link Here
350
      ->json_is( '/shared' => $macro_update->{shared}, 'It should still not be shared' );
350
      ->json_is( '/shared' => $macro_update->{shared}, 'It should still not be shared' );
351
351
352
    # Now try to make the macro shared
352
    # Now try to make the macro shared
353
    $macro_update->{shared} = 1;
353
    $macro_update->{shared} = Mojo::JSON->true;
354
354
355
    $t->put_ok( "//$auth_userid:$password@/api/v1/advancededitormacros/shared/$macro_id" => json => $macro_update )
355
    $t->put_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros/shared/$macro_id" => json => $macro_update )
356
      ->status_is(403, 'Cannot make your macro shared on private endpoint');
356
      ->status_is(403, 'Cannot make your macro shared on private endpoint');
357
    $t->put_ok( "//$auth_userid:$password@/api/v1/advancededitormacros/shared/$macro_id" => json => $macro_update )
357
    $t->put_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros/shared/$macro_id" => json => $macro_update )
358
      ->status_is(403, 'Cannot make your macro shared without permission');
358
      ->status_is(403, 'Cannot make your macro shared without permission');
359
359
360
    $builder->build({
360
    $builder->build({
Lines 366-387 subtest 'update() tests' => sub { Link Here
366
        },
366
        },
367
    });
367
    });
368
368
369
    $t->put_ok( "//$auth_userid:$password@/api/v1/advancededitormacros/$macro_id" => json => $macro_update )
369
    $t->put_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros/$macro_id" => json => $macro_update )
370
      ->status_is(403, 'Cannot make your macro shared on the private endpoint');
370
      ->status_is(403, 'Cannot make your macro shared on the private endpoint');
371
371
372
    $t->put_ok( "//$auth_userid:$password@/api/v1/advancededitormacros/shared/$macro_id" => json => $macro_update )
372
    $t->put_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros/shared/$macro_id" => json => $macro_update )
373
      ->status_is(200, 'Can update macro to shared with permission')
373
      ->status_is(200, 'Can update macro to shared with permission')
374
      ->json_is( '/macro_id' => $macro_id, 'We get back the id' )
374
      ->json_is( '/macro_id' => $macro_id, 'We get back the id' )
375
      ->json_is( '/name' => $macro_update->{name}, 'We get back the name' )
375
      ->json_is( '/name' => $macro_update->{name}, 'We get back the name' )
376
      ->json_is( '/macro_text' => $macro_update->{macro_text}, 'We get back the text' )
376
      ->json_is( '/macro_text' => $macro_update->{macro_text}, 'We get back the text' )
377
      ->json_is( '/patron_id' => $macro_update->{patron_id}, 'We get back our patron id' )
377
      ->json_is( '/patron_id' => $macro_update->{patron_id}, 'We get back our patron id' )
378
      ->json_is( '/shared' => 1, 'It is shared' );
378
      ->json_is( '/shared' => Mojo::JSON->true, 'It is shared' );
379
379
380
    # Authorized attempt to write invalid data
380
    # Authorized attempt to write invalid data
381
    my $macro_with_invalid_field = { %$macro_update };
381
    my $macro_with_invalid_field = { %$macro_update };
382
    $macro_with_invalid_field->{'big_mac_ro'} = 'Mac attack';
382
    $macro_with_invalid_field->{'big_mac_ro'} = 'Mac attack';
383
383
384
    $t->put_ok( "//$auth_userid:$password@/api/v1/advancededitormacros/$macro_id" => json => $macro_with_invalid_field )
384
    $t->put_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros/$macro_id" => json => $macro_with_invalid_field )
385
      ->status_is(400)
385
      ->status_is(400)
386
      ->json_is(
386
      ->json_is(
387
        "/errors" => [
387
        "/errors" => [
Lines 396-405 subtest 'update() tests' => sub { Link Here
396
    my $non_existent_code = $non_existent_macro->id;
396
    my $non_existent_code = $non_existent_macro->id;
397
    $non_existent_macro->delete;
397
    $non_existent_macro->delete;
398
398
399
    $t->put_ok("//$auth_userid:$password@/api/v1/advancededitormacros/$non_existent_code" => json => $macro_update)
399
    $t->put_ok("//$auth_userid:$password@/api/v1/advanced_editor/macros/$non_existent_code" => json => $macro_update)
400
      ->status_is(404);
400
      ->status_is(404);
401
401
402
    $t->put_ok("//$auth_userid:$password@/api/v1/advancededitormacros/$macro_2_id" => json => $macro_update)
402
    $t->put_ok("//$auth_userid:$password@/api/v1/advanced_editor/macros/$macro_2_id" => json => $macro_update)
403
      ->status_is(403, "Cannot update other borrowers private macro");
403
      ->status_is(403, "Cannot update other borrowers private macro");
404
};
404
};
405
405
Lines 442-459 subtest 'delete() tests' => sub { Link Here
442
    my $macro_2_id = $macro_2->id;
442
    my $macro_2_id = $macro_2->id;
443
443
444
    # Unauthorized attempt to delete
444
    # Unauthorized attempt to delete
445
    $t->delete_ok( "//$unauth_userid:$password@/api/v1/advancededitormacros/$macro_2_id")
445
    $t->delete_ok( "//$unauth_userid:$password@/api/v1/advanced_editor/macros/$macro_2_id")
446
      ->status_is(403, "Cannot delete macro without permission");
446
      ->status_is(403, "Cannot delete macro without permission");
447
447
448
    $t->delete_ok( "//$auth_userid:$password@/api/v1/advancededitormacros/$macro_id")
448
    $t->delete_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros/$macro_id")
449
      ->status_is(200, 'Can delete macro with permission');
449
      ->status_is(200, 'Can delete macro with permission');
450
450
451
    $t->delete_ok( "//$auth_userid:$password@/api/v1/advancededitormacros/$macro_2_id")
451
    $t->delete_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros/$macro_2_id")
452
      ->status_is(403, 'Cannot delete other users macro with permission');
452
      ->status_is(403, 'Cannot delete other users macro with permission');
453
453
454
    $macro_2->shared(1)->store();
454
    $macro_2->shared(1)->store();
455
455
456
    $t->delete_ok( "//$auth_userid:$password@/api/v1/advancededitormacros/shared/$macro_2_id")
456
    $t->delete_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros/shared/$macro_2_id")
457
      ->status_is(403, 'Cannot delete other users shared macro without permission');
457
      ->status_is(403, 'Cannot delete other users shared macro without permission');
458
458
459
    $builder->build({
459
    $builder->build({
Lines 464-472 subtest 'delete() tests' => sub { Link Here
464
            code           => 'delete_shared_macros',
464
            code           => 'delete_shared_macros',
465
        },
465
        },
466
    });
466
    });
467
    $t->delete_ok( "//$auth_userid:$password@/api/v1/advancededitormacros/$macro_2_id")
467
    $t->delete_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros/$macro_2_id")
468
      ->status_is(403, 'Cannot delete other users shared macro with permission on private endpoint');
468
      ->status_is(403, 'Cannot delete other users shared macro with permission on private endpoint');
469
    $t->delete_ok( "//$auth_userid:$password@/api/v1/advancededitormacros/shared/$macro_2_id")
469
    $t->delete_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros/shared/$macro_2_id")
470
      ->status_is(200, 'Can delete other users shared macro with permission');
470
      ->status_is(200, 'Can delete other users shared macro with permission');
471
471
472
};
472
};
473
- 

Return to bug 17268