Skip to content

Commit

Permalink
merge 2 PR's
Browse files Browse the repository at this point in the history
  • Loading branch information
gromdimon committed Jun 19, 2023
1 parent b14ede0 commit 2d2611e
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 58 deletions.
22 changes: 20 additions & 2 deletions landingzones/static/landingzones/js/landingzones.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Init global variable
var isSuperuser = false;

/*****************************
Zone status updating function
*****************************/
Expand Down Expand Up @@ -56,7 +59,7 @@ var updateZoneStatus = function() {
statusTd.addClass(statusStyles[zoneStatus] + ' text-white');
statusInfoSpan.text(zoneStatusInfo);

if (['PREPARING', 'VALIDATING', 'MOVING'].includes(zoneStatus)) {
if (['PREPARING', 'VALIDATING', 'MOVING', 'DELETING'].includes(zoneStatus)) {
statusTd.append(
'<span class="pull-right"><i class="iconify" data-icon="mdi:lock"></i></span>'
);
Expand All @@ -80,7 +83,8 @@ var updateZoneStatus = function() {
}

// Button modification
if (zoneStatus !== 'ACTIVE' && zoneStatus !== 'FAILED') {
if (zoneStatus !== 'ACTIVE' && zoneStatus !== 'FAILED' && isSuperuser) {}
else if (zoneStatus !== 'ACTIVE' && zoneStatus !== 'FAILED') {
zoneTr.find('td.sodar-lz-zone-title').addClass('text-muted');
zoneTr.find('td.sodar-lz-zone-assay').addClass('text-muted');
zoneTr.find('td.sodar-lz-zone-status-info').addClass('text-muted');
Expand Down Expand Up @@ -114,6 +118,20 @@ var updateZoneStatus = function() {
};

$(document).ready(function() {
/*********************
Get superuser status
*********************/
$.ajax({
url: currentUserURL,
method: "GET",
success: function(response) {
isSuperuser = response.is_superuser;
},
error: function(response) {
isSuperuser = false;
}
});

/******************
Update zone status
******************/
Expand Down
2 changes: 2 additions & 0 deletions landingzones/templates/landingzones/project_zones.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ <h3><i class="iconify" data-icon="mdi:briefcase-upload"></i> Landing Zones</h3>
window.statusInterval = {{ zone_status_interval }} * 1000;
window.irodsShowChecksumCol = true;
var zoneStatusUrl = "{% url 'landingzones:ajax_status' project=project.sodar_uuid %}";
<!-- Superuser status variable -->
var currentUserURL = "{% url 'projectroles:ajax_user_current' %}";
</script>

<!-- Landingzones Javascript -->
Expand Down
157 changes: 101 additions & 56 deletions landingzones/tests/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _setup_investigation(self):
self.study = self.investigation.studies.first()
self.assay = self.study.assays.first()

def _assert_element(self, by, element, expected=True):
def assert_element(self, by, element, expected=True):
"""Assert element existence for an already logged in user"""
# TODO: Add this into TestUIBase (see bihealth/sodar-core#1104)
if expected:
Expand All @@ -47,7 +47,7 @@ def _assert_element(self, by, element, expected=True):
with self.assertRaises(NoSuchElementException):
self.selenium.find_element(by, element)

def _assert_btn_enabled(self, element, expected=True):
def assert_btn_enabled(self, element, expected=True):
"""Assert button is enabled"""
if expected:
self.assertNotIn('disabled', element.get_attribute('class'))
Expand All @@ -74,38 +74,38 @@ def test_render_no_sheets(self):
"""Test ProjectZoneView rendering with no sheets"""
# NOTE: Only testing with owner as this doesn't depend on user
self.login_and_redirect(self.user_owner, self.url)
self._assert_element(By.ID, 'sodar-lz-alert-archive', False)
self._assert_element(By.ID, 'sodar-lz-alert-disable', False)
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-zone-list-own', False)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', False)
self.assert_element(By.ID, 'sodar-lz-alert-archive', False)
self.assert_element(By.ID, 'sodar-lz-alert-disable', False)
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-zone-list-own', False)
self.assert_element(By.ID, 'sodar-lz-zone-list-other', False)

def test_render_no_colls(self):
"""Test ProjectZoneView with investigation but no colls"""
self._setup_investigation()
self.assertIsNotNone(self.investigation)
self.login_and_redirect(self.user_owner, self.url)
self._assert_element(By.ID, 'sodar-lz-alert-disable', False)
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-zone-list-own', False)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', False)
self.assert_element(By.ID, 'sodar-lz-alert-disable', False)
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-zone-list-own', False)
self.assert_element(By.ID, 'sodar-lz-zone-list-other', False)

def test_render_no_zones(self):
"""Test ProjectZoneView with iRODS enabled but no zones"""
self._setup_investigation()
self.investigation.irods_status = True
self.investigation.save()
self.login_and_redirect(self.user_owner, self.url)
self._assert_element(By.ID, 'sodar-lz-alert-disable', False)
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-zone-list-own', False)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', False)
self.assert_element(By.ID, 'sodar-lz-alert-disable', False)
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-zone-list-own', False)
self.assert_element(By.ID, 'sodar-lz-zone-list-other', False)

@override_settings(LANDINGZONES_DISABLE_FOR_USERS=True)
def test_render_disable(self):
Expand All @@ -114,12 +114,12 @@ def test_render_disable(self):
self.investigation.irods_status = True
self.investigation.save()
self.login_and_redirect(self.user_owner, self.url)
self._assert_element(By.ID, 'sodar-lz-alert-disable', True)
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-zone-list-own', False)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', False)
self.assert_element(By.ID, 'sodar-lz-alert-disable', True)
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-zone-list-own', False)
self.assert_element(By.ID, 'sodar-lz-zone-list-other', False)

@override_settings(LANDINGZONES_DISABLE_FOR_USERS=True)
def test_render_disable_superuser(self):
Expand All @@ -131,12 +131,12 @@ def test_render_disable_superuser(self):
'superuser_zone', self.project, self.superuser, self.assay
)
self.login_and_redirect(self.superuser, self.url)
self._assert_element(By.ID, 'sodar-lz-alert-disable', False)
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-zone-list-own', True)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', False)
self.assert_element(By.ID, 'sodar-lz-alert-disable', False)
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-zone-list-own', True)
self.assert_element(By.ID, 'sodar-lz-zone-list-other', False)

def test_render_own_zone(self):
"""Test ProjectZoneView as contributor with own zone"""
Expand All @@ -147,12 +147,12 @@ def test_render_own_zone(self):
'contrib_zone', self.project, self.user_contributor, self.assay
)
self.login_and_redirect(self.user_contributor, self.url)
self._assert_element(By.ID, 'sodar-lz-alert-disable', False)
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-zone-list-own', True)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', False)
self.assert_element(By.ID, 'sodar-lz-alert-disable', False)
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-zone-list-own', True)
self.assert_element(By.ID, 'sodar-lz-zone-list-other', False)
zones = self.selenium.find_elements(
By.CLASS_NAME, 'sodar-lz-zone-tr-existing'
)
Expand All @@ -172,8 +172,8 @@ def test_render_other_zone(self):
)
self.login_and_redirect(self.user_owner, self.url)
# NOTE: Element for own zones is visible while table is empty
self._assert_element(By.ID, 'sodar-lz-zone-list-own', True)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', True)
self.assert_element(By.ID, 'sodar-lz-zone-list-own', True)
self.assert_element(By.ID, 'sodar-lz-zone-list-other', True)
zones = self.selenium.find_elements(
By.CLASS_NAME, 'sodar-lz-zone-tr-existing'
)
Expand All @@ -195,8 +195,8 @@ def test_render_both_zones_contrib(self):
'contrib_zone', self.project, self.user_contributor, self.assay
)
self.login_and_redirect(self.user_contributor, self.url)
self._assert_element(By.ID, 'sodar-lz-zone-list-own', True)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', False)
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(
By.CLASS_NAME, 'sodar-lz-zone-tr-existing'
)
Expand All @@ -218,8 +218,8 @@ def test_render_both_zones_owner(self):
'contrib_zone', self.project, self.user_contributor, self.assay
)
self.login_and_redirect(self.user_owner, self.url)
self._assert_element(By.ID, 'sodar-lz-zone-list-own', True)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', True)
self.assert_element(By.ID, 'sodar-lz-zone-list-own', True)
self.assert_element(By.ID, 'sodar-lz-zone-list-other', True)
zones = self.selenium.find_elements(
By.CLASS_NAME, 'sodar-lz-zone-tr-existing'
)
Expand All @@ -232,7 +232,7 @@ def test_render_both_zones_owner(self):
zones[1].get_attribute('data-zone-uuid'),
str(contrib_zone.sodar_uuid),
)
self._assert_element(By.CLASS_NAME, 'sodar-lz-zone-warn-access', False)
self.assert_element(By.CLASS_NAME, 'sodar-lz-zone-warn-access', False)

def test_render_other_user_guest_access(self):
"""Test ProjectZoneView with guest access for other user"""
Expand All @@ -253,7 +253,7 @@ def test_render_other_user_guest_access(self):
By.CLASS_NAME, 'sodar-lz-zone-tr-existing'
)
self.assertEqual(len(zones), 2)
self._assert_element(By.CLASS_NAME, 'sodar-lz-zone-warn-access', True)
self.assert_element(By.CLASS_NAME, 'sodar-lz-zone-warn-access', True)

def test_render_other_user_no_access(self):
"""Test ProjectZoneView with no project access for other user"""
Expand All @@ -273,7 +273,7 @@ def test_render_other_user_no_access(self):
By.CLASS_NAME, 'sodar-lz-zone-tr-existing'
)
self.assertEqual(len(zones), 2)
self._assert_element(By.CLASS_NAME, 'sodar-lz-zone-warn-access', True)
self.assert_element(By.CLASS_NAME, 'sodar-lz-zone-warn-access', True)

def test_zone_buttons(self):
"""Test ProjectZoneView zone buttons"""
Expand All @@ -287,19 +287,19 @@ def test_zone_buttons(self):
zone = self.selenium.find_elements(
By.CLASS_NAME, 'sodar-lz-zone-tr-existing'
)[0]
self._assert_btn_enabled(
self.assert_btn_enabled(
zone.find_element(By.CLASS_NAME, 'sodar-lz-zone-btn-validate'),
True,
)
self._assert_btn_enabled(
self.assert_btn_enabled(
zone.find_element(By.CLASS_NAME, 'sodar-lz-zone-btn-move'),
True,
)
self._assert_btn_enabled(
self.assert_btn_enabled(
zone.find_element(By.CLASS_NAME, 'sodar-lz-zone-btn-copy'),
True,
)
self._assert_btn_enabled(
self.assert_btn_enabled(
zone.find_element(By.CLASS_NAME, 'sodar-lz-zone-btn-delete'),
True,
)
Expand All @@ -317,19 +317,64 @@ def test_zone_buttons_archive(self):
zone = self.selenium.find_elements(
By.CLASS_NAME, 'sodar-lz-zone-tr-existing'
)[0]
self._assert_btn_enabled(
self.assert_btn_enabled(
zone.find_element(By.CLASS_NAME, 'sodar-lz-zone-btn-validate'),
False,
)
self._assert_btn_enabled(
self.assert_btn_enabled(
zone.find_element(By.CLASS_NAME, 'sodar-lz-zone-btn-move'),
False,
)
self._assert_btn_enabled(
self.assert_btn_enabled(
zone.find_element(By.CLASS_NAME, 'sodar-lz-zone-btn-copy'),
True,
)
self._assert_btn_enabled(
self.assert_btn_enabled(
zone.find_element(By.CLASS_NAME, 'sodar-lz-zone-btn-delete'),
True,
)

def test_zone_locked_buttons_superuser(self):
"""Test ProjectZoneView zone buttons for locked zone as superuser"""
self._setup_investigation()
self.investigation.irods_status = True
self.investigation.save()
zone = self.make_landing_zone(
'contrib_zone', self.project, self.user_contributor, self.assay
)
# Set zone status to CREATING
zone.status = 'CREATING'
self.login_and_redirect(self.superuser, self.url)
zone = self.selenium.find_elements(
By.CLASS_NAME, 'sodar-lz-zone-tr-existing'
)[0]
dropdown_div = zone.find_element(By.CLASS_NAME, 'sodar-lz-zone-buttons')
try:
attr = dropdown_div.find_element(
By.CLASS_NAME, 'sodar-list-dropdown'
).get_attribute('disabled')
except AssertionError:
attr = None
self.assertIsNone(attr)
self.assertNotIn(
'text-muted',
zone.find_element(
By.CLASS_NAME, 'sodar-lz-zone-title'
).get_attribute('class'),
)
self.assertNotIn(
'text-muted',
zone.find_element(
By.CLASS_NAME, 'sodar-lz-zone-status-info'
).get_attribute('class'),
)
class_names = [
'sodar-lz-zone-btn-validate',
'sodar-lz-zone-btn-move',
'sodar-lz-zone-btn-copy',
'sodar-lz-zone-btn-delete',
]
for class_name in class_names:
self.assert_btn_enabled(
zone.find_element(By.CLASS_NAME, class_name), True
)

0 comments on commit 2d2611e

Please sign in to comment.