Skip to content

Commit

Permalink
Enable multiselect update for updated files (#620)
Browse files Browse the repository at this point in the history
* Revert "Hide multiselect for updated files (#595)"
* Add basic update files button
* Test both ways of updating a file
* Show default "already in group" message for files needing update
  • Loading branch information
madwort authored Aug 14, 2024
1 parent e071309 commit e562520
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 16 deletions.
3 changes: 0 additions & 3 deletions airlock/file_browser_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,6 @@ def is_withdrawn(self):
def is_valid(self):
return is_valid_file_type(Path(self.relpath))

def is_updated(self):
return self.workspace_status == WorkspaceFileStatus.CONTENT_UPDATED

def html_classes(self):
"""Semantic html classes for this PathItem.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<td>{{ path.modified_at|date:"Y-m-d H:i" }}</td>
{% if workspace.is_active and multiselect_add %}
<td>
{% if not path.is_directory and not path.is_updated %}
{% if not path.is_directory %}
{% form_checkbox name="selected" value=path.relpath custom_field=True %}
{% endif %}
</td>
Expand Down
7 changes: 6 additions & 1 deletion airlock/templates/file_browser/directory.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@
{% if multiselect_add %}
<div class="div flex flex-col items-start gap-4">
<div class="flex items-center gap-2">
{% #button type="submit" name="action" value="add_files" variant="success" form="multiselect_form"%}Add Files to Request{% /button %}
{% #button type="submit" name="action" value="add_files" variant="success" form="multiselect_form"%}
Add Files to Request
{% /button %}
{% #button type="submit" name="action" value="update_files" variant="success" form="multiselect_form"%}
Update Files in Request
{% /button %}
</div>
<div id="multiselect_modal"></div>
</div>
Expand Down
2 changes: 0 additions & 2 deletions airlock/views/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,6 @@ def multiselect_add_files(request, multiform, workspace):
state = workspace.get_workspace_file_status(relpath)
if policies.can_add_file_to_request(workspace, relpath):
files_to_add.append(f)
elif state == WorkspaceFileStatus.CONTENT_UPDATED:
files_ignored[f] = "cannot update using the add dialogue"
elif state == WorkspaceFileStatus.RELEASED:
files_ignored[f] = "already released"
else:
Expand Down
25 changes: 18 additions & 7 deletions tests/functional/test_e2e.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re

import pytest
from playwright.sync_api import expect

from airlock.business_logic import bll
Expand Down Expand Up @@ -454,7 +455,11 @@ def test_e2e_release_files(
expect(page.locator("body")).not_to_contain_text("test-workspace by researcher")


def test_e2e_update_file(page, live_server, dev_users):
@pytest.mark.parametrize(
"multiselect",
[True, False],
)
def test_e2e_update_file(page, live_server, dev_users, multiselect):
"""
Test researcher updates a modified file in a returned request
"""
Expand All @@ -471,20 +476,26 @@ def test_e2e_update_file(page, live_server, dev_users):
],
)

# change the file on disk
# Log in as researcher
login_as(live_server, page, "researcher")

workspace = bll.get_workspace("test-workspace", author)

# change the file on disk
factories.write_workspace_file(workspace, path, contents="changed")

# Log in as researcher
login_as(live_server, page, "researcher")
if multiselect:
page.goto(live_server.url + workspace.get_url("subdir/"))

page.goto(live_server.url + workspace.get_url("subdir/file.txt"))
# click on the multi-select checkbox
find_and_click(page.locator('input[name="selected"]'))
else:
page.goto(live_server.url + workspace.get_url("subdir/file.txt"))

# Update file in request
# Find the add file button and click on it to open the modal
find_and_click(page.locator("button[value=update_files]"))

# Click the button to add the file to a release request
# Click the button to update the file in the release request
find_and_click(page.get_by_role("form").locator("#update-file-button"))

expect(page.locator("body")).to_contain_text("file has been updated in request")
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/views/test_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,7 @@ def test_workspace_multiselect_add_files_updated_file(airlock_client, bll):
assert response.status_code == 200
assert "test/path1.txt" in response.rendered_content
assert "test/path2.txt" in response.rendered_content
assert response.rendered_content.count("cannot update using the add dialogue") == 1
assert response.rendered_content.count("already in group") == 1
assert response.rendered_content.count("already in group") == 2
assert 'name="filegroup"' not in response.rendered_content


Expand Down

0 comments on commit e562520

Please sign in to comment.