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

(-)a/Koha/REST/V1/Checkouts.pm (-2 / +22 lines)
Lines 22-27 use C4::Auth qw( haspermission ); Link Here
22
use C4::Context;
22
use C4::Context;
23
use C4::Circulation;
23
use C4::Circulation;
24
use Koha::Checkouts;
24
use Koha::Checkouts;
25
use Koha::IssuingRules;
25
26
26
use Try::Tiny;
27
use Try::Tiny;
27
28
Lines 126-132 sub renew { Link Here
126
    );
127
    );
127
}
128
}
128
129
129
sub renewability {
130
=head3 allows_renewal
131
132
Checks if the checkout could be renewed and return the related information.
133
134
=cut
135
136
sub allows_renewal {
130
    my $c = shift->openapi->valid_input or return;
137
    my $c = shift->openapi->valid_input or return;
131
138
132
    my $checkout_id = $c->validation->param('checkout_id');
139
    my $checkout_id = $c->validation->param('checkout_id');
Lines 144-152 sub renewability { Link Here
144
151
145
    my $renewable = Mojo::JSON->false;
152
    my $renewable = Mojo::JSON->false;
146
    $renewable = Mojo::JSON->true if $can_renew;
153
    $renewable = Mojo::JSON->true if $can_renew;
154
155
    my $rule = Koha::IssuingRules->get_effective_issuing_rule(
156
        {
157
            categorycode => $checkout->patron->categorycode,
158
            itemtype     => $checkout->item->effective_itemtype,
159
            branchcode   => $checkout->branchcode,
160
        }
161
    );
147
    return $c->render(
162
    return $c->render(
148
        status => 200,
163
        status => 200,
149
        openapi => { renewable => $renewable, error => $error }
164
        openapi => {
165
            allows_renewal => $renewable,
166
            max_renewals => $rule->renewalsallowed,
167
            current_renewals => $checkout->renewals,
168
            error => $error
169
        }
150
    );
170
    );
151
}
171
}
152
172
(-)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