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

(-)a/Koha/Exceptions/ArticleRequests.pm (-17 lines)
Lines 1-17 Link Here
1
package Koha::Exceptions::ArticleRequests;
2
3
use Modern::Perl;
4
5
use Exception::Class (
6
7
    'Koha::Exceptions::ArticleRequests' => {
8
        description => 'Something went wrong!',
9
    },
10
    'Koha::Exceptions::ArticleRequests::FailedCancel' => {
11
        isa => 'Koha::Exceptions::ArticleRequests',
12
        description => 'Failed to cancel article request'
13
    }
14
15
);
16
17
1;
(-)a/Koha/REST/V1/ArticleRequests.pm (-9 / +45 lines)
Lines 42-50 Controller function that handles cancelling a Koha::ArticleRequest object Link Here
42
sub cancel {
42
sub cancel {
43
    my $c = shift->openapi->valid_input or return;
43
    my $c = shift->openapi->valid_input or return;
44
44
45
    my $ar = Koha::ArticleRequests->find( $c->validation->param('ar_id') );
45
    my $article_request = Koha::ArticleRequests->find( $c->validation->param('article_request_id') );
46
46
47
    unless ( $ar ) {
47
    unless ( $article_request ) {
48
        return $c->render(
48
        return $c->render(
49
            status  => 404,
49
            status  => 404,
50
            openapi => { error => "Article request not found" }
50
            openapi => { error => "Article request not found" }
Lines 56-74 sub cancel { Link Here
56
56
57
    return try {
57
    return try {
58
58
59
        $ar->cancel($reason, $notes);
59
        $article_request->cancel($reason, $notes);
60
        return $c->render(
60
        return $c->render(
61
            status  => 204,
61
            status  => 204,
62
            openapi => q{}
62
            openapi => q{}
63
        );
63
        );
64
    } catch {
64
    } catch {
65
        if ( blessed $_ && $_->isa('Koha::Exceptions::ArticleRequests::FailedCancel') ) {
65
        $c->unhandled_exception($_);
66
            return $c->render(
66
    };
67
                status  => 403,
67
}
68
                openapi => { error => "Article request cannot be canceled" }
68
69
            );
69
=head3 patron_cancel
70
        }
70
71
Controller function that handles cancelling a patron's Koha::ArticleRequest object
72
73
=cut
74
75
sub patron_cancel {
76
    my $c = shift->openapi->valid_input or return;
77
78
    my $patron = Koha::Patrons->find( $c->validation->param('patron_id') );
79
80
    unless ( $patron ) {
81
        return $c->render(
82
            status  => 404,
83
            openapi => { error => "Patron not found" }
84
        );
85
    }
86
87
    my $article_request = $patron->article_requests->find( $c->validation->param('article_request_id') );
71
88
89
    unless ( $article_request ) {
90
        return $c->render(
91
            status  => 404,
92
            openapi => { error => "Article request not found" }
93
        );
94
    }
95
96
    my $reason = $c->validation->param('cancellation_reason');
97
    my $notes = $c->validation->param('notes');
98
99
    return try {
100
101
        $article_request->cancel( $reason, $notes );
102
        return $c->render(
103
            status  => 204,
104
            openapi => q{}
105
        );
106
    }
107
    catch {
72
        $c->unhandled_exception($_);
108
        $c->unhandled_exception($_);
73
    };
109
    };
74
}
110
}
(-)a/Koha/REST/V1/Patrons.pm (-49 lines)
Lines 419-471 sub guarantors_can_see_checkouts { Link Here
419
    };
419
    };
420
}
420
}
421
421
422
=head3 cancel_article_request
423
424
Controller function that handles cancelling a patron's Koha::ArticleRequest object
425
426
=cut
427
428
sub cancel_article_request {
429
    my $c = shift->openapi->valid_input or return;
430
431
    my $patron = Koha::Patrons->find( $c->validation->param('patron_id') );
432
433
    unless ( $patron ) {
434
        return $c->render(
435
            status  => 404,
436
            openapi => { error => "Patron not found" }
437
        );
438
    }
439
440
    my $ar = $patron->article_requests->find( $c->validation->param('ar_id') );
441
442
    unless ( $ar ) {
443
        return $c->render(
444
            status  => 404,
445
            openapi => { error => "Article request not found" }
446
        );
447
    }
448
449
    my $reason = $c->validation->param('cancellation_reason');
450
    my $notes = $c->validation->param('notes');
451
452
    return try {
453
454
        $ar->cancel($reason, $notes);
455
        return $c->render(
456
            status  => 204,
457
            openapi => q{}
458
        );
459
    } catch {
460
        if ( blessed $_ && $_->isa('Koha::Exceptions::ArticleRequests::FailedCancel') ) {
461
            return $c->render(
462
                status  => 403,
463
                openapi => { error => "Article request cannot be canceled" }
464
            );
465
        }
466
467
        $c->unhandled_exception($_);
468
    };
469
}
470
471
1;
422
1;
(-)a/api/v1/swagger/parameters.json (-9 lines)
Lines 56-70 Link Here
56
  "cashup_id_pp": {
56
  "cashup_id_pp": {
57
    "$ref": "parameters/cashup.json#/cashup_id_pp"
57
    "$ref": "parameters/cashup.json#/cashup_id_pp"
58
  },
58
  },
59
  "ar_id_pp": {
60
    "$ref": "parameters/article_request.json#/ar_id_pp"
61
  },
62
  "ar_reason_qp": {
63
    "$ref": "parameters/article_request.json#/ar_reason_qp"
64
  },
65
  "ar_notes_qp": {
66
    "$ref": "parameters/article_request.json#/ar_notes_qp"
67
  },
68
  "match": {
59
  "match": {
69
    "name": "_match",
60
    "name": "_match",
70
    "in": "query",
61
    "in": "query",
(-)a/api/v1/swagger/parameters/article_request.json (-23 lines)
Lines 1-23 Link Here
1
{
2
  "ar_id_pp": {
3
    "name": "ar_id",
4
    "in": "path",
5
    "description": "Article request identifier",
6
    "required": true,
7
    "type": "integer"
8
  },
9
  "ar_reason_qp": {
10
    "name": "cancellation_reason",
11
    "in": "query",
12
    "description": "Article request cancellation reason",
13
    "required": false,
14
    "type": "string"
15
  },
16
  "ar_notes_qp": {
17
    "name": "notes",
18
    "in": "query",
19
    "description": "Article request custom cancellation reason",
20
    "required": false,
21
    "type": "string"
22
  }
23
}
(-)a/api/v1/swagger/paths.json (-5 / +5 lines)
Lines 17-24 Link Here
17
  "/acquisitions/funds": {
17
  "/acquisitions/funds": {
18
    "$ref": "paths/acquisitions_funds.json#/~1acquisitions~1funds"
18
    "$ref": "paths/acquisitions_funds.json#/~1acquisitions~1funds"
19
  },
19
  },
20
  "/article_requests/{ar_id}": {
20
  "/article_requests/{article_request_id}": {
21
    "$ref": "paths/article_requests.json#/~1article_requests~1{ar_id}"
21
    "$ref": "paths/article_requests.yaml#/~1article_requests~1{article_request_id}"
22
  },
22
  },
23
  "/biblios/{biblio_id}": {
23
  "/biblios/{biblio_id}": {
24
    "$ref": "paths/biblios.json#/~1biblios~1{biblio_id}"
24
    "$ref": "paths/biblios.json#/~1biblios~1{biblio_id}"
Lines 164-169 Link Here
164
  "/public/biblios/{biblio_id}": {
164
  "/public/biblios/{biblio_id}": {
165
    "$ref": "paths/biblios.json#/~1public~1biblios~1{biblio_id}"
165
    "$ref": "paths/biblios.json#/~1public~1biblios~1{biblio_id}"
166
  },
166
  },
167
  "/public/patrons/{patron_id}/article_requests/{article_request_id}": {
168
    "$ref": "paths/article_requests.yaml#/~1public~1patrons~1{patron_id}~1article_requests~1{article_request_id}"
169
  },
167
  "/public/patrons/{patron_id}/password": {
170
  "/public/patrons/{patron_id}/password": {
168
    "$ref": "paths/public_patrons.json#/~1public~1patrons~1{patron_id}~1password"
171
    "$ref": "paths/public_patrons.json#/~1public~1patrons~1{patron_id}~1password"
169
  },
172
  },
Lines 173-181 Link Here
173
  "/public/patrons/{patron_id}/guarantors/can_see_checkouts": {
176
  "/public/patrons/{patron_id}/guarantors/can_see_checkouts": {
174
    "$ref": "paths/public_patrons.json#/~1public~1patrons~1{patron_id}~1guarantors~1can_see_checkouts"
177
    "$ref": "paths/public_patrons.json#/~1public~1patrons~1{patron_id}~1guarantors~1can_see_checkouts"
175
  },
178
  },
176
  "/public/patrons/{patron_id}/article_requests/{ar_id}": {
177
    "$ref": "paths/public_patrons.json#/~1public~1patrons~1{patron_id}~1article_requests~1{ar_id}"
178
  },
179
  "/quotes": {
179
  "/quotes": {
180
    "$ref": "paths/quotes.json#/~1quotes"
180
    "$ref": "paths/quotes.json#/~1quotes"
181
  },
181
  },
(-)a/api/v1/swagger/paths/article_requests.json (-70 lines)
Lines 1-70 Link Here
1
{
2
    "/article_requests/{ar_id}": {
3
        "delete": {
4
            "x-mojo-to": "ArticleRequests#cancel",
5
            "operationId": "cancelArticleRequest",
6
            "tags": [
7
                "article_requests"
8
            ],
9
            "summary": "Cancel article requests",
10
            "parameters": [
11
                {
12
                    "$ref": "../parameters.json#/ar_id_pp"
13
                },
14
                {
15
                    "$ref": "../parameters.json#/ar_reason_qp"
16
                },
17
                {
18
                    "$ref": "../parameters.json#/ar_notes_qp"
19
                }
20
            ],
21
            "produces": ["application/json"],
22
            "responses": {
23
                "204": {
24
                    "description": "Article request canceled"
25
                },
26
                "400": {
27
                    "description": "Bad request",
28
                    "schema": {
29
                        "$ref": "../definitions.json#/error"
30
                    }
31
                },
32
                "401": {
33
                    "description": "Authentication required",
34
                    "schema": {
35
                        "$ref": "../definitions.json#/error"
36
                    }
37
                },
38
                "403": {
39
                    "description": "Access forbidden",
40
                    "schema": {
41
                        "$ref": "../definitions.json#/error"
42
                    }
43
                },
44
                "404": {
45
                    "description": "Patron not found",
46
                    "schema": {
47
                        "$ref": "../definitions.json#/error"
48
                    }
49
                },
50
                "500": {
51
                    "description": "Internal server error",
52
                    "schema": {
53
                        "$ref": "../definitions.json#/error"
54
                    }
55
                },
56
                "503": {
57
                    "description": "Under maintenance",
58
                    "schema": {
59
                        "$ref": "../definitions.json#/error"
60
                    }
61
                }
62
            },
63
            "x-koha-authorization": {
64
                "permissions": {
65
                    "reserveforothers": "1"
66
                  }
67
            }
68
        }
69
    }
70
}
(-)a/api/v1/swagger/paths/article_requests.yaml (+111 lines)
Line 0 Link Here
1
---
2
"/article_requests/{article_request_id}":
3
  delete:
4
    x-mojo-to: ArticleRequests#cancel
5
    operationId: cancelArticleRequest
6
    tags:
7
      - article_requests
8
    summary: Cancel article requests
9
    parameters:
10
      - name: article_request_id
11
        in: path
12
        description: Article request identifier
13
        required: true
14
        type: integer
15
      - name: cancellation_reason
16
        in: query
17
        description: Article request cancellation reason
18
        required: false
19
        type: string
20
      - name: notes
21
        in: query
22
        description: Article request custom cancellation reason
23
        required: false
24
        type: string
25
    produces:
26
      - application/json
27
    responses:
28
      "204":
29
        description: Article request canceled
30
      "400":
31
        description: Bad request
32
        schema:
33
          $ref: ../definitions.json#/error
34
      "401":
35
        description: Authentication required
36
        schema:
37
          $ref: ../definitions.json#/error
38
      "403":
39
        description: Access forbidden
40
        schema:
41
          $ref: ../definitions.json#/error
42
      "404":
43
        description: Patron not found
44
        schema:
45
          $ref: ../definitions.json#/error
46
      "500":
47
        description: Internal server error
48
        schema:
49
          $ref: ../definitions.json#/error
50
      "503":
51
        description: Under maintenance
52
        schema:
53
          $ref: ../definitions.json#/error
54
    x-koha-authorization:
55
      permissions:
56
        reserveforothers: "1"
57
"/public/patrons/{patron_id}/article_requests/{article_request_id}":
58
  delete:
59
    x-mojo-to: ArticleRequests#patron_cancel
60
    operationId: publicCancelPatronArticleRequest
61
    tags:
62
      - article_requests
63
    summary: Cancel patron's article requests
64
    parameters:
65
      - $ref: ../parameters.json#/patron_id_pp
66
      - name: article_request_id
67
        in: path
68
        description: Article request identifier
69
        required: true
70
        type: integer
71
      - name: cancellation_reason
72
        in: query
73
        description: Article request cancellation reason
74
        required: false
75
        type: string
76
      - name: notes
77
        in: query
78
        description: Article request custom cancellation reason
79
        required: false
80
        type: string
81
    produces:
82
      - application/json
83
    responses:
84
      "204":
85
        description: Patron's article request canceled
86
      "400":
87
        description: Bad request
88
        schema:
89
          $ref: ../definitions.json#/error
90
      "401":
91
        description: Authentication required
92
        schema:
93
          $ref: ../definitions.json#/error
94
      "403":
95
        description: Access forbidden
96
        schema:
97
          $ref: ../definitions.json#/error
98
      "404":
99
        description: Patron not found
100
        schema:
101
          $ref: ../definitions.json#/error
102
      "500":
103
        description: Internal server error
104
        schema:
105
          $ref: ../definitions.json#/error
106
      "503":
107
        description: Under maintenance
108
        schema:
109
          $ref: ../definitions.json#/error
110
    x-koha-authorization:
111
      allow-owner: true
(-)a/api/v1/swagger/paths/public_patrons.json (-70 lines)
Lines 242-316 Link Here
242
                "allow-owner": true
242
                "allow-owner": true
243
            }
243
            }
244
        }
244
        }
245
    },
246
    "/public/patrons/{patron_id}/article_requests/{ar_id}": {
247
        "delete": {
248
            "x-mojo-to": "Patrons#cancel_article_request",
249
            "operationId": "cancelPatronArticleRequest",
250
            "tags": [
251
                "patrons",
252
                "article_requests"
253
            ],
254
            "summary": "Cancel patron's article requests",
255
            "parameters": [
256
                {
257
                    "$ref": "../parameters.json#/patron_id_pp"
258
                },
259
                {
260
                    "$ref": "../parameters.json#/ar_id_pp"
261
                },
262
                {
263
                    "$ref": "../parameters.json#/ar_reason_qp"
264
                },
265
                {
266
                    "$ref": "../parameters.json#/ar_notes_qp"
267
                }
268
            ],
269
            "produces": ["application/json"],
270
            "responses": {
271
                "204": {
272
                    "description": "Patron's article request canceled"
273
                },
274
                "400": {
275
                    "description": "Bad request",
276
                    "schema": {
277
                        "$ref": "../definitions.json#/error"
278
                    }
279
                },
280
                "401": {
281
                    "description": "Authentication required",
282
                    "schema": {
283
                        "$ref": "../definitions.json#/error"
284
                    }
285
                },
286
                "403": {
287
                    "description": "Access forbidden",
288
                    "schema": {
289
                        "$ref": "../definitions.json#/error"
290
                    }
291
                },
292
                "404": {
293
                    "description": "Patron not found",
294
                    "schema": {
295
                        "$ref": "../definitions.json#/error"
296
                    }
297
                },
298
                "500": {
299
                    "description": "Internal server error",
300
                    "schema": {
301
                        "$ref": "../definitions.json#/error"
302
                    }
303
                },
304
                "503": {
305
                    "description": "Under maintenance",
306
                    "schema": {
307
                        "$ref": "../definitions.json#/error"
308
                    }
309
                }
310
            },
311
            "x-koha-authorization": {
312
                "allow-owner": true
313
            }
314
        }
315
    }
245
    }
316
}
246
}
(-)a/api/v1/swagger/swagger.yaml (-1 / +4 lines)
Lines 56-61 info: Link Here
56
    context; If it is not included in the request, then the request context
56
    context; If it is not included in the request, then the request context
57
    will default to using your api comsumer's assigned home library.
57
    will default to using your api comsumer's assigned home library.
58
tags:
58
tags:
59
  - name: "article_requests"
60
    x-displayName: Article requests
61
    description: |
62
      Manage article requests
59
  - name: "biblios"
63
  - name: "biblios"
60
    x-displayName: Biblios
64
    x-displayName: Biblios
61
    description: |
65
    description: |
62
- 

Return to bug 27947