Skip to content

Commit

Permalink
errors: rework PermissionDeniedError
Browse files Browse the repository at this point in the history
  • Loading branch information
anikachurilova committed May 14, 2024
1 parent 878b9f7 commit 03726ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion invenio_records_resources/services/base/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions invenio_records_resources/services/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit 03726ae

Please sign in to comment.