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

(-)a/Koha/Patron.pm (-5 / +5 lines)
Lines 38-43 use Koha::Club::Enrollments; Link Here
38
use Koha::Database;
38
use Koha::Database;
39
use Koha::DateUtils qw( dt_from_string );
39
use Koha::DateUtils qw( dt_from_string );
40
use Koha::Encryption;
40
use Koha::Encryption;
41
use Koha::Exceptions;
41
use Koha::Exceptions::Password;
42
use Koha::Exceptions::Password;
42
use Koha::Holds;
43
use Koha::Holds;
43
use Koha::CurbsidePickups;
44
use Koha::CurbsidePickups;
Lines 2080-2090 Returns 0 if the I<user> parameter is missing. Link Here
2080
sub is_accessible {
2081
sub is_accessible {
2081
    my ( $self, $params ) = @_;
2082
    my ( $self, $params ) = @_;
2082
2083
2083
    # FIXME? It felt tempting to return 0 instead
2084
    unless ( defined( $params->{user} ) ) {
2084
    # but it would mean needing to explicitly add the 'user'
2085
        Koha::Exceptions::MissingParameter->throw(
2085
    # param in all tests...
2086
            error => "The `user` parameter is mandatory" );
2086
    return 1
2087
    }
2087
      unless $params->{user};
2088
2088
2089
    my $consumer = $params->{user};
2089
    my $consumer = $params->{user};
2090
    return $consumer->can_see_patron_infos($self);
2090
    return $consumer->can_see_patron_infos($self);
(-)a/Koha/REST/V1/Patrons.pm (-2 / +7 lines)
Lines 102-107 Controller function that handles adding a new Koha::Patron object Link Here
102
102
103
sub add {
103
sub add {
104
    my $c = shift->openapi->valid_input or return;
104
    my $c = shift->openapi->valid_input or return;
105
    my $current_user = $c->stash( 'koha.user' );
105
106
106
    return try {
107
    return try {
107
108
Lines 131-137 sub add { Link Here
131
                $c->res->headers->location($c->req->url->to_string . '/' . $patron->borrowernumber);
132
                $c->res->headers->location($c->req->url->to_string . '/' . $patron->borrowernumber);
132
                return $c->render(
133
                return $c->render(
133
                    status  => 201,
134
                    status  => 201,
134
                    openapi => $patron->to_api
135
                    openapi => $patron->to_api({ user => $current_user })
135
                );
136
                );
136
            }
137
            }
137
        );
138
        );
Lines 224-229 Controller function that handles updating a Koha::Patron object Link Here
224
225
225
sub update {
226
sub update {
226
    my $c = shift->openapi->valid_input or return;
227
    my $c = shift->openapi->valid_input or return;
228
    my $current_user = $c->stash( 'koha.user' );
227
229
228
    my $patron_id = $c->validation->param('patron_id');
230
    my $patron_id = $c->validation->param('patron_id');
229
    my $patron    = Koha::Patrons->find( $patron_id );
231
    my $patron    = Koha::Patrons->find( $patron_id );
Lines 271-277 sub update { Link Here
271
273
272
        $patron->set_from_api($c->validation->param('body'))->store;
274
        $patron->set_from_api($c->validation->param('body'))->store;
273
        $patron->discard_changes;
275
        $patron->discard_changes;
274
        return $c->render( status => 200, openapi => $patron->to_api );
276
        return $c->render(
277
            status  => 200,
278
            openapi => $patron->to_api( { user => $current_user } )
279
        );
275
    }
280
    }
276
    catch {
281
    catch {
277
        unless ( blessed $_ && $_->can('rethrow') ) {
282
        unless ( blessed $_ && $_->can('rethrow') ) {
(-)a/t/db_dependent/api/v1/acquisitions_baskets.t (-2 / +10 lines)
Lines 57-64 subtest 'list_managers() tests' => sub { Link Here
57
        }
57
        }
58
    );
58
    );
59
59
60
    $t->get_ok("//$userid:$password@/api/v1/acquisitions/baskets/managers?q=$api_filter")
60
    $t->get_ok(
61
      ->status_is(200)->json_is( [ $patron_with_permission->to_api, $superlibrarian->to_api ] );
61
        "//$userid:$password@/api/v1/acquisitions/baskets/managers?q=$api_filter"
62
    )->status_is(200)->json_is(
63
        [
64
            $patron_with_permission->to_api(
65
                { user => $patron_with_permission }
66
            ),
67
            $superlibrarian->to_api( { user => $superlibrarian } )
68
        ]
69
    );
62
70
63
    $schema->storage->txn_rollback;
71
    $schema->storage->txn_rollback;
64
};
72
};
(-)a/t/db_dependent/api/v1/acquisitions_funds.t (-5 / +21 lines)
Lines 113-123 subtest 'list_owners() and list_users() tests' => sub { Link Here
113
        }
113
        }
114
    );
114
    );
115
115
116
    $t->get_ok("//$userid:$password@/api/v1/acquisitions/funds/owners?q=$api_filter")
116
    $t->get_ok(
117
      ->status_is(200)->json_is( [ $patron_with_permission->to_api, $superlibrarian->to_api ] );
117
        "//$userid:$password@/api/v1/acquisitions/funds/owners?q=$api_filter")
118
118
      ->status_is(200)->json_is(
119
    $t->get_ok("//$userid:$password@/api/v1/acquisitions/funds/users?q=$api_filter")
119
        [
120
      ->status_is(200)->json_is( [ $patron_with_permission->to_api, $superlibrarian->to_api ] );
120
            $patron_with_permission->to_api(
121
                { user => $patron_with_permission }
122
            ),
123
            $superlibrarian->to_api( { user => $superlibrarian } )
124
        ]
125
      );
126
127
    $t->get_ok(
128
        "//$userid:$password@/api/v1/acquisitions/funds/users?q=$api_filter")
129
      ->status_is(200)->json_is(
130
        [
131
            $patron_with_permission->to_api(
132
                { user => $patron_with_permission }
133
            ),
134
            $superlibrarian->to_api( { user => $superlibrarian } )
135
        ]
136
      );
121
137
122
    $schema->storage->txn_rollback;
138
    $schema->storage->txn_rollback;
123
};
139
};
(-)a/t/db_dependent/api/v1/patrons.t (-15 / +21 lines)
Lines 295-301 subtest 'add() tests' => sub { Link Here
295
295
296
    $schema->storage->txn_begin;
296
    $schema->storage->txn_begin;
297
297
298
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } )->to_api;
298
    my $librarian = $builder->build_object(
299
        {
300
            class => 'Koha::Patrons',
301
            value => { flags => 2**4 }    # borrowers flag = 4
302
        }
303
    );
304
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } )->to_api({ user => $librarian });
299
305
300
    unauthorized_access_tests('POST', undef, $patron);
306
    unauthorized_access_tests('POST', undef, $patron);
301
307
Lines 339-346 subtest 'add() tests' => sub { Link Here
339
            }
345
            }
340
        );
346
        );
341
347
342
        my $patron = $builder->build_object({ class => 'Koha::Patrons' });
348
        my $librarian = $builder->build_object(
343
        my $newpatron = $patron->to_api;
349
            {
350
                class => 'Koha::Patrons',
351
                value => { flags => 2**4 }    # borrowers flag = 4
352
            }
353
        );
354
355
        my $patron    = $builder->build_object( { class => 'Koha::Patrons' } );
356
        my $newpatron = $patron->to_api({ user => $librarian });
344
        # delete RO attributes
357
        # delete RO attributes
345
        delete $newpatron->{patron_id};
358
        delete $newpatron->{patron_id};
346
        delete $newpatron->{restricted};
359
        delete $newpatron->{restricted};
Lines 352-363 subtest 'add() tests' => sub { Link Here
352
        # Delete library
365
        # Delete library
353
        $library_to_delete->delete;
366
        $library_to_delete->delete;
354
367
355
        my $librarian = $builder->build_object(
356
            {
357
                class => 'Koha::Patrons',
358
                value => { flags => 2**4 }    # borrowers flag = 4
359
            }
360
        );
361
        my $password = 'thePassword123';
368
        my $password = 'thePassword123';
362
        $librarian->set_password( { password => $password, skip_validation => 1 } );
369
        $librarian->set_password( { password => $password, skip_validation => 1 } );
363
        my $userid = $librarian->userid;
370
        my $userid = $librarian->userid;
Lines 391-397 subtest 'add() tests' => sub { Link Here
391
        delete $newpatron->{falseproperty};
398
        delete $newpatron->{falseproperty};
392
399
393
        my $patron_to_delete = $builder->build_object({ class => 'Koha::Patrons' });
400
        my $patron_to_delete = $builder->build_object({ class => 'Koha::Patrons' });
394
        $newpatron = $patron_to_delete->to_api;
401
        $newpatron = $patron_to_delete->to_api({ user => $librarian });
395
        # delete RO attributes
402
        # delete RO attributes
396
        delete $newpatron->{patron_id};
403
        delete $newpatron->{patron_id};
397
        delete $newpatron->{restricted};
404
        delete $newpatron->{restricted};
Lines 617-623 subtest 'update() tests' => sub { Link Here
617
624
618
        my $patron_1  = $authorized_patron;
625
        my $patron_1  = $authorized_patron;
619
        my $patron_2  = $unauthorized_patron;
626
        my $patron_2  = $unauthorized_patron;
620
        my $newpatron = $unauthorized_patron->to_api;
627
        my $newpatron = $unauthorized_patron->to_api({ user => $authorized_patron });
621
        # delete RO attributes
628
        # delete RO attributes
622
        delete $newpatron->{patron_id};
629
        delete $newpatron->{patron_id};
623
        delete $newpatron->{restricted};
630
        delete $newpatron->{restricted};
Lines 694-702 subtest 'update() tests' => sub { Link Here
694
          ->status_is(200, 'Patron updated successfully');
701
          ->status_is(200, 'Patron updated successfully');
695
702
696
        # Put back the RO attributes
703
        # Put back the RO attributes
697
        $newpatron->{patron_id} = $unauthorized_patron->to_api->{patron_id};
704
        $newpatron->{patron_id} = $unauthorized_patron->to_api({ user => $authorized_patron })->{patron_id};
698
        $newpatron->{restricted} = $unauthorized_patron->to_api->{restricted};
705
        $newpatron->{restricted} = $unauthorized_patron->to_api({ user => $authorized_patron })->{restricted};
699
        $newpatron->{anonymized} = $unauthorized_patron->to_api->{anonymized};
706
        $newpatron->{anonymized} = $unauthorized_patron->to_api({ user => $authorized_patron })->{anonymized};
700
707
701
        my $got = $result->tx->res->json;
708
        my $got = $result->tx->res->json;
702
        my $updated_on_got = delete $got->{updated_on};
709
        my $updated_on_got = delete $got->{updated_on};
703
- 

Return to bug 29523