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 2039-2049 Returns 0 if the I<user> parameter is missing. Link Here
2039
sub is_accessible {
2040
sub is_accessible {
2040
    my ( $self, $params ) = @_;
2041
    my ( $self, $params ) = @_;
2041
2042
2042
    # FIXME? It felt tempting to return 0 instead
2043
    unless ( defined( $params->{user} ) ) {
2043
    # but it would mean needing to explicitly add the 'user'
2044
        Koha::Exceptions::MissingParameter->throw(
2044
    # param in all tests...
2045
            error => "The `user` parameter is mandatory" );
2045
    return 1
2046
    }
2046
      unless $params->{user};
2047
2047
2048
    my $consumer = $params->{user};
2048
    my $consumer = $params->{user};
2049
    return $consumer->can_see_patron_infos($self);
2049
    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 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 393-399 subtest 'add() tests' => sub { Link Here
393
        delete $newpatron->{falseproperty};
400
        delete $newpatron->{falseproperty};
394
401
395
        my $patron_to_delete = $builder->build_object({ class => 'Koha::Patrons' });
402
        my $patron_to_delete = $builder->build_object({ class => 'Koha::Patrons' });
396
        $newpatron = $patron_to_delete->to_api;
403
        $newpatron = $patron_to_delete->to_api({ user => $librarian });
397
        # delete RO attributes
404
        # delete RO attributes
398
        delete $newpatron->{patron_id};
405
        delete $newpatron->{patron_id};
399
        delete $newpatron->{restricted};
406
        delete $newpatron->{restricted};
Lines 618-624 subtest 'update() tests' => sub { Link Here
618
625
619
        my $patron_1  = $authorized_patron;
626
        my $patron_1  = $authorized_patron;
620
        my $patron_2  = $unauthorized_patron;
627
        my $patron_2  = $unauthorized_patron;
621
        my $newpatron = $unauthorized_patron->to_api;
628
        my $newpatron = $unauthorized_patron->to_api({ user => $authorized_patron });
622
        # delete RO attributes
629
        # delete RO attributes
623
        delete $newpatron->{patron_id};
630
        delete $newpatron->{patron_id};
624
        delete $newpatron->{restricted};
631
        delete $newpatron->{restricted};
Lines 698-706 subtest 'update() tests' => sub { Link Here
698
          ->status_is(200, 'Patron updated successfully');
705
          ->status_is(200, 'Patron updated successfully');
699
706
700
        # Put back the RO attributes
707
        # Put back the RO attributes
701
        $newpatron->{patron_id} = $unauthorized_patron->to_api->{patron_id};
708
        $newpatron->{patron_id} = $unauthorized_patron->to_api({ user => $authorized_patron })->{patron_id};
702
        $newpatron->{restricted} = $unauthorized_patron->to_api->{restricted};
709
        $newpatron->{restricted} = $unauthorized_patron->to_api({ user => $authorized_patron })->{restricted};
703
        $newpatron->{anonymized} = $unauthorized_patron->to_api->{anonymized};
710
        $newpatron->{anonymized} = $unauthorized_patron->to_api({ user => $authorized_patron })->{anonymized};
704
711
705
        my $got = $result->tx->res->json;
712
        my $got = $result->tx->res->json;
706
        my $updated_on_got = delete $got->{updated_on};
713
        my $updated_on_got = delete $got->{updated_on};
707
- 

Return to bug 29523