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

(-)a/Koha/REST/V1/Checkouts.pm (+26 lines)
Lines 182-187 sub allows_renewal { Link Here
182
    );
182
    );
183
}
183
}
184
184
185
=head3 delete_history
186
187
Anonymize patron's checkout history.
188
189
=cut
190
191
sub delete_history {
192
    my $c = shift->openapi->valid_input or return;
193
194
    my $patron_id = $c->validation->param('patron_id');
195
196
    my $patrons = Koha::Patrons->search({
197
        'me.borrowernumber' => $patron_id
198
    });
199
200
    $patrons->anonymise_issue_history;
201
202
    unless ($patrons->count) {
203
        return $c->render( status => 404, openapi => {
204
            error => "Patron doesn't exist"
205
        });
206
    }
207
208
    return $c->render( status => 204, openapi => "" );
209
}
210
185
=head3 _to_api
211
=head3 _to_api
186
212
187
Helper function that maps a hashref of Koha::Checkout attributes into REST api
213
Helper function that maps a hashref of Koha::Checkout attributes into REST api
(-)a/api/v1/swagger/paths.json (+3 lines)
Lines 20-25 Link Here
20
  "/checkouts/{checkout_id}/renewal": {
20
  "/checkouts/{checkout_id}/renewal": {
21
    "$ref": "paths/checkouts.json#/~1checkouts~1{checkout_id}~1renewal"
21
    "$ref": "paths/checkouts.json#/~1checkouts~1{checkout_id}~1renewal"
22
  },
22
  },
23
  "/checkouts/history": {
24
    "$ref": "paths/checkouts.json#/~1checkouts~1history"
25
  },
23
  "/cities": {
26
  "/cities": {
24
    "$ref": "paths/cities.json#/~1cities"
27
    "$ref": "paths/cities.json#/~1cities"
25
  },
28
  },
(-)a/api/v1/swagger/paths/checkouts.json (+28 lines)
Lines 135-139 Link Here
135
        }
135
        }
136
      }
136
      }
137
    }
137
    }
138
  },
139
  "/checkouts/history": {
140
    "delete": {
141
      "x-mojo-to": "Checkouts#delete_history",
142
      "operationId": "delete_historyCheckouts",
143
      "tags": ["patrons", "checkouts"],
144
      "parameters": [{
145
        "$ref": "../parameters.json#/patron_id_qp"
146
      }],
147
      "produces": ["application/json"],
148
      "responses": {
149
        "204": {
150
          "description": "Checkout history deleted successfully",
151
          "schema": {
152
            "type": "string"
153
          }
154
        },
155
        "404": {
156
          "description": "Patron not found",
157
          "schema": { "$ref": "../definitions.json#/error" }
158
        }
159
      },
160
      "x-koha-authorization": {
161
        "permissions": {
162
          "circulate": "circulate_remaining_permissions"
163
        }
164
      }
165
    }
138
  }
166
  }
139
}
167
}
(-)a/t/db_dependent/api/v1/checkouts.t (-2 / +18 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 93;
20
use Test::More tests => 99;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Mojo;
22
use Test::Mojo;
23
use t::lib::Mocks;
23
use t::lib::Mocks;
Lines 216-218 $t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/all Link Here
216
        current_renewals => 1,
216
        current_renewals => 1,
217
        error            => 'too_many'
217
        error            => 'too_many'
218
    });
218
    });
219
- 
219
220
$t->delete_ok( "//$userid:$password@/api/v1/checkouts/history?patron_id=$patron_id")
221
  ->status_is(204)
222
  ->content_is('');
223
224
my $patron_to_delete = $builder->build_object({
225
    class => 'Koha::Patrons',
226
    value => { flags => 0 }
227
});
228
229
my $patron_to_delete_id = $patron_to_delete->borrowernumber;
230
231
$patron_to_delete->delete;
232
233
$t->delete_ok( "//$userid:$password@/api/v1/checkouts/history?patron_id=$patron_to_delete_id")
234
  ->status_is(404)
235
  ->json_is({error => "Patron doesn't exist"});

Return to bug 18795