Skip to content

Commit

Permalink
Only show the complete-review reminder where there are files to review
Browse files Browse the repository at this point in the history
If there are no output files on a request, there's nothing to be
reviewed. The method for all_files_reviewed_for_user returns True,
but we don't want to remind users to complete their review when
there was nothing to review.

We also don't want to show this to authors at all.
  • Loading branch information
rebkwok committed Jun 28, 2024
1 parent 8b56d16 commit a1be757
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 6 deletions.
17 changes: 11 additions & 6 deletions airlock/views/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,17 @@ def request_view(request, request_id: str, path: str = ""):
request=release_request.id, group=group, exclude_readonly=True, size=20
)

user_has_completed_review = (
request.user.username in release_request.completed_reviews
)
user_has_reviewed_all_files = release_request.all_files_reviewed_by_reviewer(
request.user
)
if not is_author:
user_has_completed_review = (
request.user.username in release_request.completed_reviews
)
user_has_reviewed_all_files = (
release_request.output_files()
and release_request.all_files_reviewed_by_reviewer(request.user)
)
else:
user_has_completed_review = False
user_has_reviewed_all_files = False

if user_has_reviewed_all_files and not user_has_completed_review:
messages.success(
Expand Down
47 changes: 47 additions & 0 deletions tests/integration/views/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,53 @@ def test_request_view_with_submitted_request(airlock_client):
assert "Complete review" in response.rendered_content


@pytest.mark.parametrize(
"files,has_message",
[
([], False),
([factories.request_file()], False),
([factories.request_file(filetype=RequestFileType.SUPPORTING)], False),
(
[
factories.request_file(approved=True),
factories.request_file(path="unapproved.txt"),
],
False,
),
([factories.request_file(rejected=True)], True),
(
[
factories.request_file(approved=True),
factories.request_file(
path="supporting.txt", filetype=RequestFileType.SUPPORTING
),
],
True,
),
],
)
def test_request_view_complete_review_message(airlock_client, files, has_message):
checker = factories.get_default_output_checkers()[0]
airlock_client.login(checker.username, output_checker=True)
release_request = factories.create_request_at_status(
"workspace", status=RequestStatus.SUBMITTED, files=files
)

response = airlock_client.get(f"/requests/view/{release_request.id}", follow=True)

# The all-files-reviewed reminder message is only shown if the request has
# output files and all have been reviewed
if has_message:
assert "All files reviewed" in list(response.context["messages"])[0].message
else:
assert not list(response.context["messages"])

# The all-files-reviewed reminder message is never shown to an author
airlock_client.login(release_request.author, workspaces=["workspace"])
response = airlock_client.get(f"/requests/view/{release_request.id}", follow=True)
assert not list(response.context["messages"])


def test_request_view_with_reviewed_request(airlock_client):
# Login as 1st default output-checker
airlock_client.login("output-checker-0", output_checker=True)
Expand Down

0 comments on commit a1be757

Please sign in to comment.