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

(-)a/Koha/Patron.pm (-5 / +5 lines)
Lines 37-42 use Koha::Club::Enrollments; Link Here
37
use Koha::Database;
37
use Koha::Database;
38
use Koha::DateUtils qw( dt_from_string );
38
use Koha::DateUtils qw( dt_from_string );
39
use Koha::Encryption;
39
use Koha::Encryption;
40
use Koha::Exceptions;
40
use Koha::Exceptions::Password;
41
use Koha::Exceptions::Password;
41
use Koha::Holds;
42
use Koha::Holds;
42
use Koha::Old::Checkouts;
43
use Koha::Old::Checkouts;
Lines 1881-1891 Returns 0 if the I<user> parameter is missing. Link Here
1881
sub is_accessible {
1882
sub is_accessible {
1882
    my ( $self, $params ) = @_;
1883
    my ( $self, $params ) = @_;
1883
1884
1884
    # FIXME? It felt tempting to return 0 instead
1885
    unless ( defined( $params->{user} ) ) {
1885
    # but it would mean needing to explicitly add the 'user'
1886
        Koha::Exceptions::MissingParameter->throw(
1886
    # param in all tests...
1887
            error => "The `user` parameter is mandatory" );
1887
    return 1
1888
    }
1888
      unless $params->{user};
1889
1889
1890
    my $consumer = $params->{user};
1890
    my $consumer = $params->{user};
1891
    return $consumer->can_see_patron_infos($self);
1891
    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 218-223 Controller function that handles updating a Koha::Patron object Link Here
218
219
219
sub update {
220
sub update {
220
    my $c = shift->openapi->valid_input or return;
221
    my $c = shift->openapi->valid_input or return;
222
    my $current_user = $c->stash( 'koha.user' );
221
223
222
    my $patron_id = $c->validation->param('patron_id');
224
    my $patron_id = $c->validation->param('patron_id');
223
    my $patron    = Koha::Patrons->find( $patron_id );
225
    my $patron    = Koha::Patrons->find( $patron_id );
Lines 265-271 sub update { Link Here
265
267
266
        $patron->set_from_api($c->validation->param('body'))->store;
268
        $patron->set_from_api($c->validation->param('body'))->store;
267
        $patron->discard_changes;
269
        $patron->discard_changes;
268
        return $c->render( status => 200, openapi => $patron->to_api );
270
        return $c->render(
271
            status  => 200,
272
            openapi => $patron->to_api( { user => $current_user } )
273
        );
269
    }
274
    }
270
    catch {
275
    catch {
271
        unless ( blessed $_ && $_->can('rethrow') ) {
276
        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 336-343 subtest 'add() tests' => sub { Link Here
336
            }
342
            }
337
        );
343
        );
338
344
339
        my $patron = $builder->build_object({ class => 'Koha::Patrons' });
345
        my $librarian = $builder->build_object(
340
        my $newpatron = $patron->to_api;
346
            {
347
                class => 'Koha::Patrons',
348
                value => { flags => 2**4 }    # borrowers flag = 4
349
            }
350
        );
351
352
        my $patron    = $builder->build_object( { class => 'Koha::Patrons' } );
353
        my $newpatron = $patron->to_api({ user => $librarian });
341
        # delete RO attributes
354
        # delete RO attributes
342
        delete $newpatron->{patron_id};
355
        delete $newpatron->{patron_id};
343
        delete $newpatron->{restricted};
356
        delete $newpatron->{restricted};
Lines 349-360 subtest 'add() tests' => sub { Link Here
349
        # Delete library
362
        # Delete library
350
        $library_to_delete->delete;
363
        $library_to_delete->delete;
351
364
352
        my $librarian = $builder->build_object(
353
            {
354
                class => 'Koha::Patrons',
355
                value => { flags => 2**4 }    # borrowers flag = 4
356
            }
357
        );
358
        my $password = 'thePassword123';
365
        my $password = 'thePassword123';
359
        $librarian->set_password( { password => $password, skip_validation => 1 } );
366
        $librarian->set_password( { password => $password, skip_validation => 1 } );
360
        my $userid = $librarian->userid;
367
        my $userid = $librarian->userid;
Lines 390-396 subtest 'add() tests' => sub { Link Here
390
        delete $newpatron->{falseproperty};
397
        delete $newpatron->{falseproperty};
391
398
392
        my $patron_to_delete = $builder->build_object({ class => 'Koha::Patrons' });
399
        my $patron_to_delete = $builder->build_object({ class => 'Koha::Patrons' });
393
        $newpatron = $patron_to_delete->to_api;
400
        $newpatron = $patron_to_delete->to_api({ user => $librarian });
394
        # delete RO attributes
401
        # delete RO attributes
395
        delete $newpatron->{patron_id};
402
        delete $newpatron->{patron_id};
396
        delete $newpatron->{restricted};
403
        delete $newpatron->{restricted};
Lines 615-621 subtest 'update() tests' => sub { Link Here
615
622
616
        my $patron_1  = $authorized_patron;
623
        my $patron_1  = $authorized_patron;
617
        my $patron_2  = $unauthorized_patron;
624
        my $patron_2  = $unauthorized_patron;
618
        my $newpatron = $unauthorized_patron->to_api;
625
        my $newpatron = $unauthorized_patron->to_api({ user => $authorized_patron });
619
        # delete RO attributes
626
        # delete RO attributes
620
        delete $newpatron->{patron_id};
627
        delete $newpatron->{patron_id};
621
        delete $newpatron->{restricted};
628
        delete $newpatron->{restricted};
Lines 695-703 subtest 'update() tests' => sub { Link Here
695
          ->status_is(200, 'Patron updated successfully');
702
          ->status_is(200, 'Patron updated successfully');
696
703
697
        # Put back the RO attributes
704
        # Put back the RO attributes
698
        $newpatron->{patron_id} = $unauthorized_patron->to_api->{patron_id};
705
        $newpatron->{patron_id} = $unauthorized_patron->to_api({ user => $authorized_patron })->{patron_id};
699
        $newpatron->{restricted} = $unauthorized_patron->to_api->{restricted};
706
        $newpatron->{restricted} = $unauthorized_patron->to_api({ user => $authorized_patron })->{restricted};
700
        $newpatron->{anonymized} = $unauthorized_patron->to_api->{anonymized};
707
        $newpatron->{anonymized} = $unauthorized_patron->to_api({ user => $authorized_patron })->{anonymized};
701
708
702
        my $got = $result->tx->res->json;
709
        my $got = $result->tx->res->json;
703
        my $updated_on_got = delete $got->{updated_on};
710
        my $updated_on_got = delete $got->{updated_on};
704
- 

Return to bug 29523