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 44-51 Link Here
44
  "/libraries/{library_id}": {
44
  "/libraries/{library_id}": {
45
    "$ref": "paths/libraries.json#/~1libraries~1{library_id}"
45
    "$ref": "paths/libraries.json#/~1libraries~1{library_id}"
46
  },
46
  },
47
  "/checkouts/{checkout_id}/renewability": {
47
  "/checkouts/{checkout_id}/allows_renewal": {
48
    "$ref": "paths/checkouts.json#/~1checkouts~1{checkout_id}~1renewability"
48
    "$ref": "paths/checkouts.json#/~1checkouts~1{checkout_id}~1allows_renewal"
49
  },
49
  },
50
  "/patrons": {
50
  "/patrons": {
51
    "$ref": "paths/patrons.json#/~1patrons"
51
    "$ref": "paths/patrons.json#/~1patrons"
(-)a/api/v1/swagger/paths/checkouts.json (-6 / +6 lines)
Lines 97-115 Link Here
97
      }
97
      }
98
    }
98
    }
99
  },
99
  },
100
  "/checkouts/{checkout_id}/renewability": {
100
  "/checkouts/{checkout_id}/allows_renewal": {
101
    "get": {
101
    "get": {
102
      "x-mojo-to": "Checkout#renewability",
102
      "x-mojo-to": "Checkouts#allows_renewal",
103
      "operationId": "renewabilityCheckout",
103
      "operationId": "allows_renewalCheckout",
104
      "tags": ["patrons", "checkouts"],
104
      "tags": ["patrons", "checkouts"],
105
      "parameters": [{
105
      "parameters": [{
106
        "$ref": "../parameters.json#/checkoutIdPathParam"
106
        "$ref": "../parameters.json#/checkout_id_pp"
107
      }],
107
      }],
108
      "produces": ["application/json"],
108
      "produces": ["application/json"],
109
      "responses": {
109
      "responses": {
110
        "200": {
110
        "200": {
111
          "description": "Checkout renewability",
111
          "description": "Checkout renewability information",
112
          "schema": { "$ref": "../definitions.json#/renewability" }
112
          "schema": { "$ref": "../definitions.json#/allows_renewal" }
113
        },
113
        },
114
        "403": {
114
        "403": {
115
          "description": "Forbidden",
115
          "description": "Forbidden",
(-)a/t/db_dependent/api/v1/checkouts.t (-5 / +14 lines)
Lines 169-177 $t->post_ok( "//$unauth_userid:$unauth_password@/api/v1/checkouts/" . $issue3->i Link Here
169
              required_permissions => { circulate => "circulate_remaining_permissions" }
169
              required_permissions => { circulate => "circulate_remaining_permissions" }
170
            });
170
            });
171
171
172
$t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/renewability")
172
$t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/allows_renewal")
173
  ->status_is(200)
173
  ->status_is(200)
174
  ->json_is({ renewable => Mojo::JSON->true, error => undef });
174
  ->json_is({
175
        allows_renewal   => Mojo::JSON->true,
176
        max_renewals     => 1,
177
        current_renewals => 0,
178
        error            => undef
179
    });
175
180
176
$t->post_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/renewal" )
181
$t->post_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/renewal" )
177
  ->status_is(201)
182
  ->status_is(201)
Lines 183-188 $t->post_ok( "//$userid:$password@/api/v1/checkouts/" . $issue1->issue_id . "/re Link Here
183
  ->status_is(403)
188
  ->status_is(403)
184
  ->json_is({ error => 'Renewal not authorized (too_many)' });
189
  ->json_is({ error => 'Renewal not authorized (too_many)' });
185
190
186
$t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/renewability")
191
$t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/allows_renewal")
187
  ->status_is(200)
192
  ->status_is(200)
188
  ->json_is({ renewable => Mojo::JSON->false, error => 'too_many' });
193
  ->json_is({
194
        allows_renewal   => Mojo::JSON->false,
195
        max_renewals     => 1,
196
        current_renewals => 1,
197
        error            => 'too_many'
198
    });
189
- 

Return to bug 17003