diff --git a/projectroles/static/projectroles/js/project_form.js b/projectroles/static/projectroles/js/project_form.js index e354867a..e4267e5b 100644 --- a/projectroles/static/projectroles/js/project_form.js +++ b/projectroles/static/projectroles/js/project_form.js @@ -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); @@ -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') { @@ -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); + } + }); }) diff --git a/projectroles/tests/test_ui.py b/projectroles/tests/test_ui.py index 444869c5..8d0fde87 100644 --- a/projectroles/tests/test_ui.py +++ b/projectroles/tests/test_ui.py @@ -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 @@ -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): @@ -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"""