Skip to content

Commit

Permalink
fix ZoneCreateView access with no irods colls (#2066)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Feb 17, 2025
1 parent 5a6584e commit b741688
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ Fixed
- iRODS file list modal content overflow with long file paths (#2056)
- **Landingzones**
- Timeline link active for ``DELETED`` and ``NOT_CREATED`` zones (#2005)
- Create Zone button visible with iRODS collections not created (#2066)
- ``ZoneCreateView`` access with iRODS collections not created (#2066)
- **Samplesheets**
- Timeline event status not updated in ``SheetDeleteVieW`` with iRODS collections enabled (#1798)
- Assay plugin ``update_row()`` setting links for empty file names (#2017)
Expand Down
17 changes: 13 additions & 4 deletions landingzones/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@
# Predicates -------------------------------------------------------------------


@rules.predicate
def can_create_zone(user, obj):
"""Allow creating a new landing zone"""
inv = obj.investigations.filter(active=True).first()
return (
inv is not None
and inv.irods_status
and (user.is_superuser or not settings.LANDINGZONES_DISABLE_FOR_USERS)
)


@rules.predicate
def can_modify_zone(user, obj):
"""
Whether or not user can modify landing zones.
"""
"""Allow modifying an existing landing zone"""
return user.is_superuser or not settings.LANDINGZONES_DISABLE_FOR_USERS


Expand Down Expand Up @@ -44,7 +53,7 @@ def can_modify_zone(user, obj):
rules.add_perm(
'landingzones.create_zone',
pr_rules.can_modify_project_data
& can_modify_zone
& can_create_zone
& (
pr_rules.is_project_owner
| pr_rules.is_project_delegate
Expand Down
12 changes: 6 additions & 6 deletions landingzones/templates/landingzones/project_zones.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

<div class="row sodar-subtitle-container bg-white sticky-top">
<h3><i class="iconify" data-icon="mdi:briefcase-upload"></i> Landing Zones</h3>
{% if not zone_access_disabled and investigation and can_create_zone %}
{% if not zone_access_disabled and can_create_zone %}
<div class="ml-auto">
<a href="{% url 'landingzones:create' project=project.sodar_uuid %}"
class="btn btn-primary" role="button" id="sodar-lz-btn-create-zone">
Expand Down Expand Up @@ -121,11 +121,11 @@ <h3><i class="iconify" data-icon="mdi:briefcase-upload"></i> Landing Zones</h3>

{% elif investigation and not investigation.irods_status %}
<div class="alert alert-danger" role="alert" id="sodar-lz-alert-no-colls">
The iRODS collections for the project sample sheets are not available. A
user authorized for sample sheet editing must enable iRODS access by
selecting <cite>"Create in iRODS"</cite> in the
<a href="{% url 'samplesheets:project_sheets' project=project.sodar_uuid %}">Sample Sheets</a> app.
After that landing zones can be created for the project.
The iRODS collections for the project sample sheets have not been created.
A user authorized for sample sheet editing must enable iRODS access by
selecting <a href="{% url 'samplesheets:collections' project=project.sodar_uuid %}">Create iRODS Collections</a>
in the <a href="{% url 'samplesheets:project_sheets' project=project.sodar_uuid %}">Sample Sheets</a>
app. After that landing zones can be created for the project.
</div>

{% elif zones_own.count == 0 and not zones_other %}
Expand Down
62 changes: 60 additions & 2 deletions landingzones/tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,69 @@ def test_get_disable(self):
class TestZoneCreateView(LandingzonesPermissionTestBase):
"""Tests for ZoneCreateView permissions"""

def _set_up_investigation(self, colls=False):
"""set up investigation and optional iRODS colls"""
self.investigation = self.import_isa_from_file(SHEET_PATH, self.project)
if colls:
self.investigation.irods_status = True
self.investigation.save()

def setUp(self):
super().setUp()
self.url = reverse(
'landingzones:create', kwargs={'project': self.project.sodar_uuid}
)

def test_get(self):
"""Test ZoneCreateView GET"""
def test_get_no_sheets(self):
"""Test ZoneCreateView GET with no sheets"""
good_users = [self.superuser]
bad_users = [
self.user_owner_cat,
self.user_delegate_cat,
self.user_contributor_cat,
self.user_guest_cat,
self.user_finder_cat,
self.user_owner,
self.user_delegate,
self.user_contributor,
self.user_guest,
self.user_no_roles,
self.anonymous,
]
self.assert_response(self.url, good_users, 200)
self.assert_response(self.url, bad_users, 302)
self.project.set_public()
self.assert_response(
self.url, [self.user_no_roles, self.anonymous], 302
)

def test_get_investigation(self):
"""Test GET with investigation"""
self._set_up_investigation()
good_users = [self.superuser]
bad_users = [
self.user_owner_cat,
self.user_delegate_cat,
self.user_contributor_cat,
self.user_guest_cat,
self.user_finder_cat,
self.user_owner,
self.user_delegate,
self.user_contributor,
self.user_guest,
self.user_no_roles,
self.anonymous,
]
self.assert_response(self.url, good_users, 200)
self.assert_response(self.url, bad_users, 302)
self.project.set_public()
self.assert_response(
self.url, [self.user_no_roles, self.anonymous], 302
)

def test_get_colls(self):
"""Test GET with investigation and collections"""
self._set_up_investigation(True)
good_users = [
self.superuser,
self.user_owner_cat,
Expand All @@ -164,11 +219,13 @@ def test_get(self):
@override_settings(PROJECTROLES_ALLOW_ANONYMOUS=True)
def test_get_anon(self):
"""Test GET with anonymous access"""
self._set_up_investigation(True)
self.project.set_public()
self.assert_response(self.url, self.anonymous, 302)

def test_get_archive(self):
"""Test GET with archived project"""
self._set_up_investigation(True)
self.project.set_archive()
good_users = [self.superuser]
bad_users = [
Expand All @@ -194,6 +251,7 @@ def test_get_archive(self):
@override_settings(LANDINGZONES_DISABLE_FOR_USERS=True)
def test_get_disable(self):
"""Test ZoneCreateView with disabled non-superuser access"""
self._set_up_investigation(True)
good_users = [self.superuser]
bad_users = [
self.user_owner_cat,
Expand Down
6 changes: 6 additions & 0 deletions landingzones/tests/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def test_render_no_sheets(self):
self._assert_element(By.ID, 'sodar-lz-alert-no-sheets', True)
self._assert_element(By.ID, 'sodar-lz-alert-no-colls', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-zones', False)
self._assert_element(By.ID, 'sodar-lz-btn-create-zone', False)
self._assert_element(By.ID, 'sodar-lz-zone-list-own', False)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', False)

Expand All @@ -124,6 +125,7 @@ def test_render_no_colls(self):
self._assert_element(By.ID, 'sodar-lz-alert-no-sheets', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-colls', True)
self._assert_element(By.ID, 'sodar-lz-alert-no-zones', False)
self._assert_element(By.ID, 'sodar-lz-btn-create-zone', False)
self._assert_element(By.ID, 'sodar-lz-zone-list-own', False)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', False)

Expand All @@ -137,6 +139,7 @@ def test_render_no_zones(self):
self._assert_element(By.ID, 'sodar-lz-alert-no-sheets', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-colls', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-zones', True)
self._assert_element(By.ID, 'sodar-lz-btn-create-zone', True)
self._assert_element(By.ID, 'sodar-lz-zone-list-own', False)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', False)

Expand All @@ -151,6 +154,7 @@ def test_render_disable(self):
self._assert_element(By.ID, 'sodar-lz-alert-no-sheets', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-colls', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-zones', False)
self._assert_element(By.ID, 'sodar-lz-btn-create-zone', False)
self._assert_element(By.ID, 'sodar-lz-zone-list-own', False)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', False)

Expand All @@ -168,6 +172,7 @@ def test_render_disable_superuser(self):
self._assert_element(By.ID, 'sodar-lz-alert-no-sheets', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-colls', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-zones', False)
self._assert_element(By.ID, 'sodar-lz-btn-create-zone', True)
self._assert_element(By.ID, 'sodar-lz-zone-list-own', True)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', False)

Expand All @@ -184,6 +189,7 @@ def test_render_own_zone(self):
self._assert_element(By.ID, 'sodar-lz-alert-no-sheets', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-colls', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-zones', False)
self._assert_element(By.ID, 'sodar-lz-btn-create-zone', True)
self._assert_element(By.ID, 'sodar-lz-zone-list-own', True)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', False)
zones = self.selenium.find_elements(
Expand Down

0 comments on commit b741688

Please sign in to comment.