]> git.koha-community.org Git - koha.git/commit
Bug 28907: REST - Drop support for allow-owner functionality
authorLari Taskula <lari.taskula@hypernova.fi>
Wed, 18 Sep 2024 13:35:06 +0000 (13:35 +0000)
committerFridolin Somers <fridolin.somers@biblibre.com>
Mon, 24 Feb 2025 13:19:22 +0000 (14:19 +0100)
commit7ba53849d525759dbca0609205e2450adf9df3f4
tree2481923eb659972370b5d8797150b23ce2d6b934
parent824e7991c19bffc39c54a5c277f7405c350fc94e
Bug 28907: REST - Drop support for allow-owner functionality

...and allow-guarantor functionality. Replaced by $c->auth->public($patron_id)
and/or $c->auth->public_guarantor($patron_id), where $patron_id is the patron's
id that owns the requested resource.

Old method, was applicable to both privileged and public routes:

  api/v1/swagger/paths/route.yaml

  x-koha-authorization:
    allow-owner: true
    allow-guarantor: true

New method, use public routes with no x-koha-authorization:

  GET /public/route/{patron_id}
  Koha/REST/V1/Controller#public_action:

  sub public_action {
      my $c = shift->openapi->valid_input or return;
      my $patron_id = $c->param( 'patron_id' );
      try {
          # Throws an exception that will render a response of 401 if not
          # authenticated and 403 if trying to access another user's resources
          $c->auth->public($patron_id); #or $c->auth->public_guarantor($patron_id)
          ...
          # other code
          ...
      }
      catch {
          $c->unhandled_exception($_);
      }
  }

  Another example of retrieving $patron_id when patron_id is not a request
  parameter:
  GET /public/another/object/{another_object_id}

  my $patron_id = Another::Object->find($another_object_id)->borrowernumber;
  try {
      # 403 if $another_object_id does not belong to API user
      $c->auth->public($patron_id);
      ...

Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Alex Buckley <alexbuckley@catalyst.net.nz>
(cherry picked from commit 8a1c0af3e49ecf0921121f410ca7bcff5350a983)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Koha/REST/V1/Auth.pm