Skip to content

Commit

Permalink
Raise ApprovalPermissionDenied for supporting files
Browse files Browse the repository at this point in the history
  • Loading branch information
rebkwok authored and madwort committed Mar 20, 2024
1 parent 79fa35b commit cae4b7d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 12 additions & 2 deletions airlock/business_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,14 @@ def all_files_set(self):
for request_file in filegroup.files.values()
}

def output_files_set(self):
"""Return the relpaths for output files on the request"""
return {
request_file.relpath
for filegroup in self.filegroups.values()
for request_file in filegroup.output_files
}

def is_supporting_file(self, urlpath: UrlPath):
try:
return self.get_request_file(urlpath).filetype == RequestFileType.SUPPORTING
Expand Down Expand Up @@ -646,8 +654,10 @@ def _verify_permission_to_review_file(
"only an output checker can approve a file"
)

if path not in release_request.file_set():
raise self.ApprovalPermissionDenied("file is not part of the request")
if path not in release_request.output_files_set():
raise self.ApprovalPermissionDenied(
"file is not an output file on this request"
)

def approve_file(self, release_request: ReleaseRequest, user: User, path: Path):
""" "Approve a file"""
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/test_business_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,20 @@ def test_approve_file_not_part_of_request(bll):
bll.approve_file(release_request, checker, bad_path)


def test_approve_supporting_file(bll):
release_request, path, author = setup_empty_release_request()
checker = factories.create_user("checker", [], True)

bll.add_file_to_request(
release_request, path, author, filetype=RequestFileType.SUPPORTING
)
bll.set_status(
release_request=release_request, to_status=RequestStatus.SUBMITTED, user=author
)
with pytest.raises(bll.ApprovalPermissionDenied):
bll.approve_file(release_request, checker, path)


def test_approve_file(bll):
release_request, path, author = setup_empty_release_request()
checker = factories.create_user("checker", [], True)
Expand Down

0 comments on commit cae4b7d

Please sign in to comment.