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

(-)a/t/db_dependent/api/v1/patrons.t (-10 / +21 lines)
Lines 222-228 subtest 'update() tests' => sub { Link Here
222
    $schema->storage->txn_rollback;
222
    $schema->storage->txn_rollback;
223
223
224
    subtest 'librarian access tests' => sub {
224
    subtest 'librarian access tests' => sub {
225
        plan tests => 40;
225
        plan tests => 42;
226
226
227
        $schema->storage->txn_begin;
227
        $schema->storage->txn_begin;
228
228
Lines 340-345 subtest 'update() tests' => sub { Link Here
340
        $newpatron->{cardnumber} = $superlibrarian->cardnumber;
340
        $newpatron->{cardnumber} = $superlibrarian->cardnumber;
341
        $newpatron->{userid}     = $superlibrarian->userid;
341
        $newpatron->{userid}     = $superlibrarian->userid;
342
        $newpatron->{email}      = 'nosense@no.no';
342
        $newpatron->{email}      = 'nosense@no.no';
343
        # delete RO attributes
344
        delete $newpatron->{patron_id};
345
        delete $newpatron->{restricted};
346
        delete $newpatron->{anonymized};
343
347
344
        # attempt to update
348
        # attempt to update
345
        $authorized_patron->flags( 2**4 )->store; # borrowers flag = 4
349
        $authorized_patron->flags( 2**4 )->store; # borrowers flag = 4
Lines 350-357 subtest 'update() tests' => sub { Link Here
350
        # attempt to unset
354
        # attempt to unset
351
        $newpatron->{email} = undef;
355
        $newpatron->{email} = undef;
352
        $t->put_ok( "//$userid:$password@/api/v1/patrons/" . $superlibrarian->borrowernumber => json => $newpatron )
356
        $t->put_ok( "//$userid:$password@/api/v1/patrons/" . $superlibrarian->borrowernumber => json => $newpatron )
353
          ->status_is(403, "Non-superlibrarian user change of superlibrarian email forbidden")
357
          ->status_is(403, "Non-superlibrarian user change of superlibrarian email to undefined forbidden")
354
          ->json_is( { error => "Not enough privileges to change a superlibrarian's email to undefined" } );
358
          ->json_is( { error => "Not enough privileges to change a superlibrarian's email" } );
355
359
356
        $newpatron->{email}           = $superlibrarian->email;
360
        $newpatron->{email}           = $superlibrarian->email;
357
        $newpatron->{secondary_email} = 'nonsense@no.no';
361
        $newpatron->{secondary_email} = 'nonsense@no.no';
Lines 359-371 subtest 'update() tests' => sub { Link Here
359
        # attempt to update
363
        # attempt to update
360
        $t->put_ok( "//$userid:$password@/api/v1/patrons/" . $superlibrarian->borrowernumber => json => $newpatron )
364
        $t->put_ok( "//$userid:$password@/api/v1/patrons/" . $superlibrarian->borrowernumber => json => $newpatron )
361
          ->status_is(403, "Non-superlibrarian user change of superlibrarian secondary_email forbidden")
365
          ->status_is(403, "Non-superlibrarian user change of superlibrarian secondary_email forbidden")
362
          ->json_is( { error => "Not enough privileges to change a superlibrarian's secondary_email" } );
366
          ->json_is( { error => "Not enough privileges to change a superlibrarian's email" } );
363
367
364
        # attempt to unset
368
        # attempt to unset
365
        $newpatron->{secondary_email} = undef;
369
        $newpatron->{secondary_email} = undef;
366
        $t->put_ok( "//$userid:$password@/api/v1/patrons/" . $superlibrarian->borrowernumber => json => $newpatron )
370
        $t->put_ok( "//$userid:$password@/api/v1/patrons/" . $superlibrarian->borrowernumber => json => $newpatron )
367
          ->status_is(403, "Non-superlibrarian user change of superlibrarian secondary_email forbidden")
371
          ->status_is(403, "Non-superlibrarian user change of superlibrarian secondary_email to undefined forbidden")
368
          ->json_is( { error => "Not enough privileges to change a superlibrarian's secondary_email to undefined" } );
372
          ->json_is( { error => "Not enough privileges to change a superlibrarian's email" } );
369
373
370
        $newpatron->{secondary_email}  = $superlibrarian->emailpro;
374
        $newpatron->{secondary_email}  = $superlibrarian->emailpro;
371
        $newpatron->{altaddress_email} = 'nonsense@no.no';
375
        $newpatron->{altaddress_email} = 'nonsense@no.no';
Lines 373-385 subtest 'update() tests' => sub { Link Here
373
        # attempt to update
377
        # attempt to update
374
        $t->put_ok( "//$userid:$password@/api/v1/patrons/" . $superlibrarian->borrowernumber => json => $newpatron )
378
        $t->put_ok( "//$userid:$password@/api/v1/patrons/" . $superlibrarian->borrowernumber => json => $newpatron )
375
          ->status_is(403, "Non-superlibrarian user change of superlibrarian altaddress_email forbidden")
379
          ->status_is(403, "Non-superlibrarian user change of superlibrarian altaddress_email forbidden")
376
          ->json_is( { error => "Not enough privileges to change a superlibrarian's altaddress_email" } );
380
          ->json_is( { error => "Not enough privileges to change a superlibrarian's email" } );
377
381
378
        # attempt to unset
382
        # attempt to unset
379
        $newpatron->{altaddress_email} = undef;
383
        $newpatron->{altaddress_email} = undef;
380
        $t->put_ok( "//$userid:$password@/api/v1/patrons/" . $superlibrarian->borrowernumber => json => $newpatron )
384
        $t->put_ok( "//$userid:$password@/api/v1/patrons/" . $superlibrarian->borrowernumber => json => $newpatron )
381
          ->status_is(403, "Non-superlibrarian user change of superlibrarian altaddress_email forbidden")
385
          ->status_is(403, "Non-superlibrarian user change of superlibrarian altaddress_email to undefined forbidden")
382
          ->json_is( { error => "Not enough privileges to change a superlibrarian's altaddress_email to undefined" } );
386
          ->json_is( { error => "Not enough privileges to change a superlibrarian's email" } );
387
388
        # update patron without sending email
389
        delete $newpatron->{email};
390
        delete $newpatron->{secondary_email};
391
        delete $newpatron->{altaddress_email};
392
        $t->put_ok( "//$userid:$password@/api/v1/patrons/" . $superlibrarian->borrowernumber => json => $newpatron )
393
          ->status_is(200, "Non-superlibrarian user can edit superlibrarian successfully if not changing email");
394
#  ->json_is( { error => "Not enough privileges to change a superlibrarian's email" } );
383
395
384
        $schema->storage->txn_rollback;
396
        $schema->storage->txn_rollback;
385
    };
397
    };
386
- 

Return to bug 23634