diff --git a/airlock/views/request.py b/airlock/views/request.py index 654ab5e36..241b62325 100644 --- a/airlock/views/request.py +++ b/airlock/views/request.py @@ -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( diff --git a/tests/integration/views/test_request.py b/tests/integration/views/test_request.py index f5bd6b1a6..7470252b1 100644 --- a/tests/integration/views/test_request.py +++ b/tests/integration/views/test_request.py @@ -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)