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

(-)a/Koha/REST/V1/Checkouts.pm (-2 / +22 lines)
Lines 24-29 use C4::Auth qw( haspermission ); Link Here
24
use C4::Context;
24
use C4::Context;
25
use C4::Circulation;
25
use C4::Circulation;
26
use Koha::Checkouts;
26
use Koha::Checkouts;
27
use Koha::IssuingRules;
27
28
28
use Try::Tiny;
29
use Try::Tiny;
29
30
Lines 128-134 sub renew { Link Here
128
    );
129
    );
129
}
130
}
130
131
131
sub renewability {
132
=head3 allows_renewal
133
134
Checks if the checkout could be renewed and return the related information.
135
136
=cut
137
138
sub allows_renewal {
132
    my $c = shift->openapi->valid_input or return;
139
    my $c = shift->openapi->valid_input or return;
133
140
134
    my $checkout_id = $c->validation->param('checkout_id');
141
    my $checkout_id = $c->validation->param('checkout_id');
Lines 146-154 sub renewability { Link Here
146
153
147
    my $renewable = Mojo::JSON->false;
154
    my $renewable = Mojo::JSON->false;
148
    $renewable = Mojo::JSON->true if $can_renew;
155
    $renewable = Mojo::JSON->true if $can_renew;
156
157
    my $rule = Koha::IssuingRules->get_effective_issuing_rule(
158
        {
159
            categorycode => $checkout->patron->categorycode,
160
            itemtype     => $checkout->item->effective_itemtype,
161
            branchcode   => $checkout->branchcode,
162
        }
163
    );
149
    return $c->render(
164
    return $c->render(
150
        status => 200,
165
        status => 200,
151
        openapi => { renewable => $renewable, error => $error }
166
        openapi => {
167
            allows_renewal => $renewable,
168
            max_renewals => $rule->renewalsallowed,
169
            current_renewals => $checkout->renewals,
170
            error => $error
171
        }
152
    );
172
    );
153
}
173
}
154
174
(-)a/api/v1/swagger/definitions.json (-2 / +2 lines)
Lines 32-39 Link Here
32
  "patron_balance": {
32
  "patron_balance": {
33
    "$ref": "definitions/patron_balance.json"
33
    "$ref": "definitions/patron_balance.json"
34
  },
34
  },
35
  "renewability": {
35
  "allows_renewal": {
36
    "$ref": "definitions/renewability.json"
36
    "$ref": "definitions/allows_renewal.json"
37
  },
37
  },
38
  "vendor": {
38
  "vendor": {
39
    "$ref": "definitions/vendor.json"
39
    "$ref": "definitions/vendor.json"
(-)a/api/v1/swagger/definitions/allows_renewal.json (+21 lines)
Line 0 Link Here
1
{
2
  "type": "object",
3
  "properties": {
4
    "allows_renewal": {
5
      "type": "boolean",
6
      "description": "Renewability status; true = renewable, false = not renewable"
7
    },
8
    "max_renewals": {
9
      "type": "integer",
10
      "description": "Maximum number of possible renewals"
11
    },
12
     "current_renewals": {
13
      "type": "integer",
14
      "description": "Current used renewals"
15
    },
16
    "error": {
17
      "type": ["string", "null"],
18
      "description": "Description on false allows_renewal."
19
    }
20
  }
21
}
(-)a/api/v1/swagger/definitions/renewability.json (-13 lines)
Lines 1-13 Link Here
1
{
2
  "type": "object",
3
  "properties": {
4
    "renewable": {
5
      "type": "boolean",
6
      "description": "Renewability status; true = renewable, false = not renewable"
7
    },
8
    "error": {
9
      "type": ["string", "null"],
10
      "description": "Description on false renewability."
11
    }
12
  }
13
}
(-)a/api/v1/swagger/paths.json (-2 / +2 lines)
Lines 41-48 Link Here
41
  "/libraries/{library_id}": {
41
  "/libraries/{library_id}": {
42
    "$ref": "paths/libraries.json#/~1libraries~1{library_id}"
42
    "$ref": "paths/libraries.json#/~1libraries~1{library_id}"
43
  },
43
  },
44
  "/checkouts/{checkout_id}/renewability": {
44
  "/checkouts/{checkout_id}/allows_renewal": {
45
    "$ref": "paths/checkouts.json#/~1checkouts~1{checkout_id}~1renewability"
45
    "$ref": "paths/checkouts.json#/~1checkouts~1{checkout_id}~1allows_renewal"
46
  },
46
  },
47
  "/patrons": {
47
  "/patrons": {
48
    "$ref": "paths/patrons.json#/~1patrons"
48
    "$ref": "paths/patrons.json#/~1patrons"
(-)a/api/v1/swagger/paths/checkouts.json (-6 / +6 lines)
Lines 93-111 Link Here
93
      }
93
      }
94
    }
94
    }
95
  },
95
  },
96
  "/checkouts/{checkout_id}/renewability": {
96
  "/checkouts/{checkout_id}/allows_renewal": {
97
    "get": {
97
    "get": {
98
      "x-mojo-to": "Checkout#renewability",
98
      "x-mojo-to": "Checkouts#allows_renewal",
99
      "operationId": "renewabilityCheckout",
99
      "operationId": "allows_renewalCheckout",
100
      "tags": ["patrons", "checkouts"],
100
      "tags": ["patrons", "checkouts"],
101
      "parameters": [{
101
      "parameters": [{
102
        "$ref": "../parameters.json#/checkoutIdPathParam"
102
        "$ref": "../parameters.json#/checkout_id_pp"
103
      }],
103
      }],
104
      "produces": ["application/json"],
104
      "produces": ["application/json"],
105
      "responses": {
105
      "responses": {
106
        "200": {
106
        "200": {
107
          "description": "Checkout renewability",
107
          "description": "Checkout renewability information",
108
          "schema": { "$ref": "../definitions.json#/renewability" }
108
          "schema": { "$ref": "../definitions.json#/allows_renewal" }
109
        },
109
        },
110
        "403": {
110
        "403": {
111
          "description": "Forbidden",
111
          "description": "Forbidden",
(-)a/t/db_dependent/api/v1/checkouts.t (-5 / +14 lines)
Lines 144-152 $t->post_ok( "//$unauth_userid:$unauth_password@/api/v1/checkouts/" . $issue3->i Link Here
144
              required_permissions => { circulate => "circulate_remaining_permissions" }
144
              required_permissions => { circulate => "circulate_remaining_permissions" }
145
            });
145
            });
146
146
147
$t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/renewability")
147
$t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/allows_renewal")
148
  ->status_is(200)
148
  ->status_is(200)
149
  ->json_is({ renewable => Mojo::JSON->true, error => undef });
149
  ->json_is({
150
        allows_renewal   => Mojo::JSON->true,
151
        max_renewals     => 1,
152
        current_renewals => 0,
153
        error            => undef
154
    });
150
155
151
$t->post_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/renewal" )
156
$t->post_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/renewal" )
152
  ->status_is(201)
157
  ->status_is(201)
Lines 158-163 $t->post_ok( "//$userid:$password@/api/v1/checkouts/" . $issue1->issue_id . "/re Link Here
158
  ->status_is(403)
163
  ->status_is(403)
159
  ->json_is({ error => 'Renewal not authorized (too_many)' });
164
  ->json_is({ error => 'Renewal not authorized (too_many)' });
160
165
161
$t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/renewability")
166
$t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/allows_renewal")
162
  ->status_is(200)
167
  ->status_is(200)
163
  ->json_is({ renewable => Mojo::JSON->false, error => 'too_many' });
168
  ->json_is({
169
        allows_renewal   => Mojo::JSON->false,
170
        max_renewals     => 1,
171
        current_renewals => 1,
172
        error            => 'too_many'
173
    });
164
- 

Return to bug 17003