Skip to content

Commit

Permalink
add remote site revoking confirm dialogue (#817)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Jun 17, 2024
1 parent 426fd74 commit b6225dc
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
12 changes: 10 additions & 2 deletions projectroles/static/projectroles/js/project_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ $(document).ready(function() {
$('#div_id_public_guest_access').show();
$('div[id^="div_id_remote_site"]').show();
}

if ($('#sodar-pr-project-form-title').attr('data-project-type') === 'CATEGORY') {
$('div[id^="div_id_settings"]').each(function () {
var $parentDiv = $(this);
Expand All @@ -42,7 +41,6 @@ $(document).ready(function() {
}
});
}

// Show settings fields if selected type is project/category in update form
$('#div_id_type .form-control').change(function() {
if ($('#div_id_type .form-control').val() === 'PROJECT') {
Expand Down Expand Up @@ -81,4 +79,14 @@ $(document).ready(function() {
});
}
});

// Warn user of revoking remote site access
$('input[id^="id_remote_site"]').change(function() {
if (!$(this).is(':checked') && $(this).prop('defaultChecked')) {
const confirmMsg = 'This will revoke access to the project on ' +
'the site. Are you sure you want to proceed?'
if (!confirm(confirmMsg)) $(this).prop('checked', true);
else $(this).prop('checked', false);
}
});
})
49 changes: 48 additions & 1 deletion projectroles/tests/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from selenium.common.exceptions import (
NoSuchElementException,
StaleElementReferenceException,
TimeoutException,
)
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
Expand Down Expand Up @@ -1732,7 +1733,7 @@ def test_submit_button(self):
break


class TestProjectUpdateView(RemoteSiteMixin, UITestBase):
class TestProjectUpdateView(RemoteSiteMixin, RemoteProjectMixin, UITestBase):
"""Tests for ProjectUpdateView UI"""

def setUp(self):
Expand Down Expand Up @@ -1787,6 +1788,52 @@ def test_fields_category(self):
self.assert_displayed(By.ID, PROJECT_SETTING_ID, False)
self.assert_displayed(By.ID, CATEGORY_SETTING_ID, True)

def test_remote_field_enable(self):
"""Test enabling remote site field"""
self.login_and_redirect(self.superuser, self.url)
elem = self.selenium.find_element(By.ID, REMOTE_SITE_ID)
self.assertEqual(elem.is_selected(), False)
elem.click()
with self.assertRaises(TimeoutException):
WebDriverWait(self.selenium, 3).until(ec.alert_is_present())
self.assertEqual(elem.is_selected(), True)
elem.click() # Disable again
with self.assertRaises(TimeoutException):
WebDriverWait(self.selenium, 3).until(ec.alert_is_present())
self.assertEqual(elem.is_selected(), False)

def test_remote_field_disable(self):
"""Test disabling previously enabled remote site field"""
self.remote_project = self.make_remote_project(
project_uuid=self.project.sodar_uuid,
site=self.remote_site,
level=SODAR_CONSTANTS['REMOTE_LEVEL_READ_ROLES'],
project=self.project,
)
self.login_and_redirect(self.superuser, self.url)
elem = self.selenium.find_element(By.ID, REMOTE_SITE_ID)
self.assertEqual(elem.is_selected(), True)
elem.click()
WebDriverWait(self.selenium, 3).until(ec.alert_is_present())
self.selenium.switch_to.alert.accept()
self.assertEqual(elem.is_selected(), False)

def test_remote_field_disable_cancel(self):
"""Test canceling the disabling of previously enabled remote site field"""
self.remote_project = self.make_remote_project(
project_uuid=self.project.sodar_uuid,
site=self.remote_site,
level=SODAR_CONSTANTS['REMOTE_LEVEL_READ_ROLES'],
project=self.project,
)
self.login_and_redirect(self.superuser, self.url)
elem = self.selenium.find_element(By.ID, REMOTE_SITE_ID)
self.assertEqual(elem.is_selected(), True)
elem.click()
WebDriverWait(self.selenium, 3).until(ec.alert_is_present())
self.selenium.switch_to.alert.dismiss()
self.assertEqual(elem.is_selected(), True)


class TestProjectArchiveView(UITestBase):
"""Tests for ProjectArchiveView UI"""
Expand Down

0 comments on commit b6225dc

Please sign in to comment.