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

(-)a/Koha/REST/V1.pm (-3 / +11 lines)
Lines 3-17 package Koha::REST::V1; Link Here
3
use Modern::Perl;
3
use Modern::Perl;
4
use Mojo::Base 'Mojolicious';
4
use Mojo::Base 'Mojolicious';
5
5
6
use C4::Auth qw( check_cookie_auth get_session );
7
use Koha::Borrowers;
8
6
sub startup {
9
sub startup {
7
    my $self = shift;
10
    my $self = shift;
8
11
9
    my $route = $self->routes->under->to(
12
    my $route = $self->routes->under->to(
10
        cb => sub {
13
        cb => sub {
11
            my $c = shift;
14
            my $c = shift;
12
            my $user = $c->param('user');
15
13
            # Do the authentication stuff here...
16
            my ($status, $sessionID) = check_cookie_auth($c->cookie('CGISESSID'));
14
            $c->stash('user', $user);
17
            if ($status eq "ok") {
18
                my $session = get_session($sessionID);
19
                my $user = Koha::Borrowers->find($session->param('number'));
20
                $c->stash('koha.user' => $user);
21
            }
22
15
            return 1;
23
            return 1;
16
        }
24
        }
17
    );
25
    );
(-)a/Koha/REST/V1/Borrowers.pm (-4 / +18 lines)
Lines 4-14 use Modern::Perl; Link Here
4
4
5
use Mojo::Base 'Mojolicious::Controller';
5
use Mojo::Base 'Mojolicious::Controller';
6
6
7
use C4::Auth qw( haspermission );
7
use Koha::Borrowers;
8
use Koha::Borrowers;
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('koha.user');
14
    unless ($user && haspermission($user->userid, {borrowers => 1})) {
15
        return $c->$cb({error => "You don't have the required permission"}, 403);
16
    }
17
12
    my $borrowers = Koha::Borrowers->search;
18
    my $borrowers = Koha::Borrowers->search;
13
19
14
    $c->$cb($borrowers->unblessed, 200);
20
    $c->$cb($borrowers->unblessed, 200);
Lines 17-29 sub list_borrowers { Link Here
17
sub get_borrower {
23
sub get_borrower {
18
    my ($c, $args, $cb) = @_;
24
    my ($c, $args, $cb) = @_;
19
25
20
    my $borrower = Koha::Borrowers->find($args->{borrowernumber});
26
    my $user = $c->stash('koha.user');
21
27
22
    if ($borrower) {
28
    unless ( $user
23
        return $c->$cb($borrower->unblessed, 200);
29
        && ( $user->borrowernumber == $args->{borrowernumber}
30
            || haspermission($user->userid, {borrowers => 1}) ) )
31
    {
32
        return $c->$cb({error => "You don't have the required permission"}, 403);
33
    }
34
35
    my $borrower = Koha::Borrowers->find($args->{borrowernumber});
36
    unless ($borrower) {
37
        return $c->$cb({error => "Borrower not found"}, 404);
24
    }
38
    }
25
39
26
    $c->$cb({error => "Borrower not found"}, 404);
40
    return $c->$cb($borrower->unblessed, 200);
27
}
41
}
28
42
29
1;
43
1;
(-)a/api/v1/swagger.json (-1 / +12 lines)
Lines 31-36 Link Here
31
                "$ref": "#/definitions/borrower"
31
                "$ref": "#/definitions/borrower"
32
              }
32
              }
33
            }
33
            }
34
          },
35
          "403": {
36
            "description": "Access forbidden",
37
            "schema": {
38
              "$ref": "#/definitions/error"
39
            }
34
          }
40
          }
35
        }
41
        }
36
      }
42
      }
Lines 55-60 Link Here
55
              "$ref": "#/definitions/borrower"
61
              "$ref": "#/definitions/borrower"
56
            }
62
            }
57
          },
63
          },
64
          "403": {
65
            "description": "Access forbidden",
66
            "schema": {
67
              "$ref": "#/definitions/error"
68
            }
69
          },
58
          "404": {
70
          "404": {
59
            "description": "Borrower not found",
71
            "description": "Borrower not found",
60
            "schema": {
72
            "schema": {
61
- 

Return to bug 13799