<<

NAME

Koha::REST::Plugin::Policy - Mojolicious plugin for module policies

SYNOPSIS

    # In the Koha REST app startup
    $self->plugin('Koha::REST::Plugin::Policy');

    # In any controller, when refusing a request because of the policy
    return $c->render(
        status  => 403,
        openapi => {
            error      => 'Return date override is not enabled',
            error_code => 'return_date_not_allowed',
            policy     => $c->module_policy( 'Checkin', { library => $library_id } ),
        }
    );

DESCRIPTION

Provides helpers for returning module policies in API responses. The policy represents the current capabilities available to the authenticated user at the given library for a specific module.

When a request is refused because of the module policy, the error object carries the current policy in its policy attribute so the client can refresh its view of it. It follows the module_policy API definition. It is informational, for the client to update the UI: the server keeps validating every action.

API

Helper methods

register

module_policy

    my $policy = $c->module_policy('Checkin');
    my $policy = $c->module_policy( 'Checkin', { library => 'CPL' } );

Returns the current policy for the given module, for the authenticated user, as a hashref matching the module_policy API definition (see "to_hashref" in Koha::Module::Policy).

Parameters:

Throws an exception if there is no policy class for $scope.

<<