-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
permissions: add self-checkout #1222
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,25 +134,27 @@ def patron_owner_permission(record): | |
def loan_checkout_permission(*args, **kwargs): | ||
"""Return permission to allow admins and librarians to checkout and patrons to self-checkout if enabled.""" | ||
if not has_request_context(): | ||
# If from CLI, don't allow self-checkout | ||
# CLI or Celery task | ||
return backoffice_permission() | ||
|
||
if current_user.is_anonymous: | ||
abort(401) | ||
|
||
is_admin_or_librarian = backoffice_permission().allows(g.identity) | ||
if is_admin_or_librarian: | ||
return backoffice_permission() | ||
|
||
# ensure that only the loan's patron can do operations on this loan | ||
if len(args): | ||
loan = args[0] | ||
else: | ||
loan = kwargs.get("record", {}) | ||
is_patron_current_user = current_user.id == int(loan.get("patron_pid")) | ||
if ( | ||
current_app.config.get("ILS_SELF_CHECKOUT_ENABLED", False) | ||
and is_patron_current_user | ||
): | ||
loan = kwargs["record"] | ||
is_patron_current_user = current_user.id == int(loan["patron_pid"]) | ||
|
||
if current_app.config["ILS_SELF_CHECKOUT_ENABLED"] and is_patron_current_user: | ||
return authenticated_user_permission() | ||
raise LoanCheckoutByPatronForbidden(int(loan.get("patron_pid")), current_user.id) | ||
|
||
raise LoanCheckoutByPatronForbidden(int(loan["patron_pid"]), current_user.id) | ||
|
||
|
||
class PatronOwnerPermission(Permission): | ||
|
@@ -163,36 +165,42 @@ def __init__(self, record): | |
super().__init__(UserNeed(int(record["patron_pid"])), backoffice_access_action) | ||
|
||
|
||
_is_authenticated_user = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved outside to declare them once, and not on each func call. |
||
"circulation-loan-request", | ||
"patron-loans", | ||
"bulk-loan-extension", | ||
] | ||
_is_backoffice_permission = [ | ||
"circulation-loan-force-checkout", | ||
"circulation-overdue-loan-notification", | ||
"circulation-loan-update-dates", | ||
"relations-create", | ||
"relations-delete", | ||
"stats-most-loaned", | ||
"document-request-actions", | ||
"bucket-create", | ||
"ill-brwreq-patron-loan-create", | ||
"ill-brwreq-patron-loan-extension-accept", | ||
"ill-brwreq-patron-loan-extension-decline", | ||
"send-notification-to-patron", | ||
] | ||
_is_patron_owner_permission = [ | ||
"document-request-decline", | ||
"ill-brwreq-patron-loan-extension-request", | ||
] | ||
|
||
|
||
def views_permissions_factory(action): | ||
"""Return ILS views permissions factory.""" | ||
is_authenticated_user = [ | ||
"circulation-loan-request", | ||
"patron-loans", | ||
"bulk-loan-extension", | ||
] | ||
is_backoffice_permission = [ | ||
"circulation-loan-checkout", | ||
"circulation-loan-force-checkout", | ||
"circulation-overdue-loan-notification", | ||
"circulation-loan-update-dates", | ||
"relations-create", | ||
"relations-delete", | ||
"stats-most-loaned", | ||
"document-request-actions", | ||
"bucket-create", | ||
"ill-brwreq-patron-loan-create", | ||
"ill-brwreq-patron-loan-extension-accept", | ||
"ill-brwreq-patron-loan-extension-decline", | ||
"send-notification-to-patron", | ||
] | ||
is_patron_owner_permission = [ | ||
"document-request-decline", | ||
"ill-brwreq-patron-loan-extension-request", | ||
] | ||
if action in is_authenticated_user: | ||
if action in _is_authenticated_user: | ||
return authenticated_user_permission() | ||
elif action in is_backoffice_permission: | ||
elif action in _is_backoffice_permission: | ||
return backoffice_permission() | ||
elif action in is_patron_owner_permission: | ||
elif action in _is_patron_owner_permission: | ||
return PatronOwnerPermission | ||
elif action == "circulation-loan-checkout": | ||
if current_app.config["ILS_SELF_CHECKOUT_ENABLED"]: | ||
return authenticated_user_permission() | ||
else: | ||
return backoffice_permission() | ||
return deny_all() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should really avoid using
.get
when the dict field is required. We need to fail early in these cases.