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

(-)a/Koha/Borrower.pm (+14 lines)
Lines 23-28 use Carp; Link Here
23
23
24
use Koha::Database;
24
use Koha::Database;
25
25
26
use C4::Auth;
27
26
use base qw(Koha::Object);
28
use base qw(Koha::Object);
27
29
28
=head1 NAME
30
=head1 NAME
Lines 43-48 sub type { Link Here
43
    return 'Borrower';
45
    return 'Borrower';
44
}
46
}
45
47
48
=head2 Instance Methods
49
50
=head3 haspermission
51
52
=cut
53
54
sub haspermission {
55
    my ($self, $flags) = @_;
56
57
    return C4::Auth::haspermission($self->userid, $flags);
58
}
59
46
=head1 AUTHOR
60
=head1 AUTHOR
47
61
48
Kyle M Hall <kyle@bywatersolutions.com>
62
Kyle M Hall <kyle@bywatersolutions.com>
(-)a/Koha/REST/V1/Borrowers.pm (-1 / +27 lines)
Lines 5-14 use Modern::Perl; Link Here
5
use Mojo::Base 'Mojolicious::Controller';
5
use Mojo::Base 'Mojolicious::Controller';
6
6
7
use Koha::Borrowers;
7
use Koha::Borrowers;
8
use C4::Auth;
8
9
9
sub list_borrowers {
10
sub list_borrowers {
10
    my ($c, $args, $cb) = @_;
11
    my ($c, $args, $cb) = @_;
11
12
13
    my $user = $c->stash('user');
14
15
    unless ($user) {
16
        return $c->$cb({error => "Authentication required"}, 401);
17
    }
18
19
    unless ($user->haspermission({ borrowers => 1 })) {
20
        return $c->$cb({
21
            error => "You don't have permission to see users"
22
        }, 403 );
23
    }
24
12
    my $borrowers = Koha::Borrowers->search;
25
    my $borrowers = Koha::Borrowers->search;
13
26
14
    $c->$cb($borrowers->unblessed, 200);
27
    $c->$cb($borrowers->unblessed, 200);
Lines 17-23 sub list_borrowers { Link Here
17
sub get_borrower {
30
sub get_borrower {
18
    my ($c, $args, $cb) = @_;
31
    my ($c, $args, $cb) = @_;
19
32
20
    my $borrower = Koha::Borrowers->find($args->{borrowernumber});
33
    my $user = $c->stash('user');
34
    my $borrowernumber = $args->{borrowernumber};
35
36
    unless ($user) {
37
        return $c->$cb({error => "Authentication required"}, 401);
38
    }
39
40
    unless ($user->haspermission({ borrowers => 1 })) {
41
        return $c->$cb({
42
            error => "You don't have permission to see users"
43
        }, 403 );
44
    }
45
46
    my $borrower = Koha::Borrowers->find($borrowernumber);
21
47
22
    if ($borrower) {
48
    if ($borrower) {
23
        return $c->$cb($borrower->unblessed, 200);
49
        return $c->$cb($borrower->unblessed, 200);
(-)a/api/v1/swagger.json (-1 / +24 lines)
Lines 31-36 Link Here
31
                "$ref": "#/definitions/borrower"
31
                "$ref": "#/definitions/borrower"
32
              }
32
              }
33
            }
33
            }
34
          },
35
          "401": {
36
            "description": "Authentication required",
37
            "schema": {
38
              "$ref": "#/definitions/error"
39
            }
40
          },
41
          "403": {
42
            "description": "Missing permission",
43
            "schema": {
44
              "$ref": "#/definitions/error"
45
            }
34
          }
46
          }
35
        }
47
        }
36
      }
48
      }
Lines 55-60 Link Here
55
              "$ref": "#/definitions/borrower"
67
              "$ref": "#/definitions/borrower"
56
            }
68
            }
57
          },
69
          },
70
          "401": {
71
            "description": "Authentication required",
72
            "schema": {
73
              "$ref": "#/definitions/error"
74
            }
75
          },
76
          "403": {
77
            "description": "Missing permission",
78
            "schema": {
79
              "$ref": "#/definitions/error"
80
            }
81
          },
58
          "404": {
82
          "404": {
59
            "description": "Borrower not found",
83
            "description": "Borrower not found",
60
            "schema": {
84
            "schema": {
61
- 

Return to bug 13920