diff --git a/invenio_records_resources/services/base/service.py b/invenio_records_resources/services/base/service.py index e5f877d8..d6bf2c6d 100644 --- a/invenio_records_resources/services/base/service.py +++ b/invenio_records_resources/services/base/service.py @@ -48,7 +48,7 @@ def require_permission(self, identity, action_name, **kwargs): Like `check_permission` but raises an error if not allowed. """ if not self.check_permission(identity, action_name, **kwargs): - raise PermissionDeniedError(action_name) + raise PermissionDeniedError(action_name, kwargs["record"]) # # Pluggable components diff --git a/invenio_records_resources/services/errors.py b/invenio_records_resources/services/errors.py index 7ae301db..e6b416ef 100644 --- a/invenio_records_resources/services/errors.py +++ b/invenio_records_resources/services/errors.py @@ -20,6 +20,12 @@ class PermissionDeniedError(PermissionDenied): description = "Permission denied." + def __init__(self, action_name=None, record=None, *args, **kwargs): + """Initialize exception.""" + self.record = record + self.action_name = action_name + super(PermissionDeniedError, self).__init__(*args, **kwargs) + class RevisionIdMismatchError(Exception): """Etag check exception."""