Skip to content

Commit

Permalink
create approve & reject file buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
madwort committed Mar 27, 2024
1 parent 0bbeea6 commit 0aec1ac
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 1 deletion.
18 changes: 18 additions & 0 deletions airlock/templates/file_browser/contents.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@
{% #button type="submit" tooltip="Remove this file from this request" variant="warning" %}Remove File from Request{% /button %}
</form>
{% elif is_output_checker %}
{% if file_approve_url %}
<form action="{{ file_approve_url }}" method="POST">
{% csrf_token %}
{% #button type="submit" variant="success" id="file-approve-button" %}Approve File{% /button %}
</form>
{% else %}
{% csrf_token %}
{% #button type="submit" variant="success" disabled=True id="file-approve-button" %}Approve File{% /button %}
{% endif %}
{% if file_reject_url %}
<form action="{{ file_reject_url }}" method="POST">
{% csrf_token %}
{% #button type="submit" variant="danger" href=file_reject_url id="file-reject-button" %}Reject File{% /button %}
</form>
{% else %}
{% csrf_token %}
{% #button type="submit" variant="danger" disabled=True href=file_reject_url id="file-reject-button" %}Reject File{% /button %}
{% endif %}
{% #button variant="primary" type="link" href=path_item.download_url id="download-button" %}Download file{% /button %}
{% endif %}
{% #button variant="primary" type="link" href=path_item.contents_url external=True id="view-button" %}View ↗{% /button %}
Expand Down
34 changes: 33 additions & 1 deletion airlock/views/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from django.views.decorators.vary import vary_on_headers
from opentelemetry import trace

from airlock.business_logic import RequestStatus, UrlPath, bll
from airlock.business_logic import FileReviewStatus, RequestStatus, UrlPath, bll
from airlock.file_browser_api import get_request_tree
from services.tracing import instrument

Expand Down Expand Up @@ -81,6 +81,36 @@ def request_view(request, request_id: str, path: str = ""):
"request_release_files",
kwargs={"request_id": request_id},
)

if is_directory_url:
file_approve_url = None
file_reject_url = None
else:
# get_path_item_from_tree_or_404() guarantees this file exists
group, request_file = release_request.get_request_group_and_file(path)

file_approve_url = reverse(
"file_approve",
kwargs={"request_id": request_id, "path": path},
)
file_reject_url = reverse(
"file_reject",
kwargs={"request_id": request_id, "path": path},
)

existing_reviews = [
r
for r in release_request.filegroups[group]
.files[request_file.relpath]
.reviews
if r.reviewer == request.user.username
]
if existing_reviews != []:
if existing_reviews[0].status == FileReviewStatus.APPROVED:
file_approve_url = None
else:
file_reject_url = None

context = {
"workspace": bll.get_workspace(release_request.workspace, request.user),
"release_request": release_request,
Expand All @@ -91,6 +121,8 @@ def request_view(request, request_id: str, path: str = ""):
# TODO file these in from user/models
"is_author": is_author,
"is_output_checker": request.user.output_checker,
"file_approve_url": file_approve_url,
"file_reject_url": file_reject_url,
"request_submit_url": request_submit_url,
"request_reject_url": request_reject_url,
"release_files_url": release_files_url,
Expand Down
56 changes: 56 additions & 0 deletions tests/integration/views/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,62 @@ def test_request_view_with_authored_request_file(airlock_client):
assert "Remove this file" in response.rendered_content


def test_request_view_with_submitted_file(airlock_client):
airlock_client.login(output_checker=True)
release_request = factories.create_release_request(
"workspace",
status=RequestStatus.SUBMITTED,
)
factories.write_request_file(release_request, "group", "file.txt", "foobar")
response = airlock_client.get(
f"/requests/view/{release_request.id}/group/file.txt", follow=True
)
assert "Remove this file" not in response.rendered_content
assert "Approve File" in response.rendered_content
assert "Reject File" in response.rendered_content
assert ' id="file-approve-button" type="submit"' in response.rendered_content
assert ' id="file-reject-button" type="submit"' in response.rendered_content


def test_request_view_with_submitted_file_approved(airlock_client):
airlock_client.login(output_checker=True)
release_request = factories.create_release_request(
"workspace",
status=RequestStatus.SUBMITTED,
)
factories.write_request_file(release_request, "group", "file.txt", "foobar")
airlock_client.post(f"/requests/approve/{release_request.id}/group/file.txt")
response = airlock_client.get(
f"/requests/view/{release_request.id}/group/file.txt", follow=True
)
print(response.rendered_content)
assert "Approve File" in response.rendered_content
assert "Reject File" in response.rendered_content
assert (
' disabled id="file-approve-button" type="submit"'
in response.rendered_content
)
assert ' id="file-reject-button" type="submit"' in response.rendered_content


def test_request_view_with_submitted_file_rejected(airlock_client):
airlock_client.login(output_checker=True)
release_request = factories.create_release_request(
"workspace",
status=RequestStatus.SUBMITTED,
)
factories.write_request_file(release_request, "group", "file.txt", "foobar")
airlock_client.post(f"/requests/reject/{release_request.id}/group/file.txt")
response = airlock_client.get(
f"/requests/view/{release_request.id}/group/file.txt", follow=True
)
assert ' id="file-approve-button" type="submit"' in response.rendered_content
assert (
' disabled id="file-reject-button" type="submit"'
in response.rendered_content
)


def test_request_view_with_404(airlock_client):
airlock_client.login(output_checker=True)
release_request = factories.create_release_request("workspace")
Expand Down

0 comments on commit 0aec1ac

Please sign in to comment.