Skip to content

Commit

Permalink
Move all of user_can_withdraw_file check to permissions.py
Browse files Browse the repository at this point in the history
The check for whether a file is withdrawable uses
WorkspaceFileStatus (to check if it's already been withdrawn).
This is dependent on the current user's requests, so this check
belongs in permissions.py, not policies.py
  • Loading branch information
rebkwok committed Sep 4, 2024
1 parent 4fd14dd commit e4caa1d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
12 changes: 11 additions & 1 deletion airlock/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from airlock.enums import (
RequestStatus,
RequestStatusOwner,
WorkspaceFileStatus,
)
from airlock.types import UrlPath
from airlock.users import User
Expand Down Expand Up @@ -231,12 +232,21 @@ def check_user_can_withdraw_file_from_request(
user: User, request: "ReleaseRequest", workspace: "Workspace", relpath: UrlPath
):
assert workspace.name == request.workspace
policies.check_can_withdraw_file_from_request(workspace, relpath)

if not user_can_edit_request(user, request):
raise exceptions.RequestPermissionDenied(
f"Cannot withdraw file {relpath} from request"
)

# If the user has permission to withdraw, check that the file
# is withdrawable; i.e. it has not already been withdrawn
# Note this is dependent on the user's current request
status = workspace.get_workspace_file_status(relpath)
if status == WorkspaceFileStatus.WITHDRAWN:
raise exceptions.RequestPermissionDenied(
"File has already been withdrawn from request"
)


def user_can_withdraw_file_from_request(
user: User, request: "ReleaseRequest", workspace: "Workspace", relpath: UrlPath
Expand Down
11 changes: 0 additions & 11 deletions airlock/policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,6 @@ def check_can_update_file_on_request(workspace: "Workspace", relpath: UrlPath):
)


def check_can_withdraw_file_from_request(workspace: "Workspace", relpath: UrlPath):
"""
This file is withdrawable; i.e. it has not already been withdrawn
"""
status = workspace.get_workspace_file_status(relpath)
if status == WorkspaceFileStatus.WITHDRAWN:
raise exceptions.RequestPermissionDenied(
"file has already been withdrawn from request"
)


def check_can_review_request(request: "ReleaseRequest"):
"""
This request is in a reviewable state
Expand Down

0 comments on commit e4caa1d

Please sign in to comment.