From d89b3a2a6957951137117daa366f0649a4429b8c Mon Sep 17 00:00:00 2001 From: Mikko Nieminen Date: Fri, 26 Apr 2024 12:00:08 +0200 Subject: [PATCH] add additional email gui (wip) (#874) --- userprofile/templates/userprofile/detail.html | 92 +++++++++++++++++++ userprofile/tests/test_ui.py | 41 ++++++++- userprofile/tests/test_views.py | 19 +++- userprofile/views.py | 5 +- 4 files changed, 151 insertions(+), 6 deletions(-) diff --git a/userprofile/templates/userprofile/detail.html b/userprofile/templates/userprofile/detail.html index c7d3a0d1..214b99fc 100644 --- a/userprofile/templates/userprofile/detail.html +++ b/userprofile/templates/userprofile/detail.html @@ -4,6 +4,11 @@ {% block title %}User Profile for {{ request.user.get_full_name }}{% endblock %} +{% block css %} + {{ block.super }} + {# TODO: Add styles for email table #} +{% endblock %} + {% block projectroles %}
@@ -91,6 +96,75 @@

+ +
+
+

+ Additional Email Addresses + {% if local_user %} + + + Add Email + + + {% endif %} +

+
+
+ + + + + + + + + + + + {% if add_emails.count > 0 %} + {% for email in add_emails %} + + + + + + + + {% endfor %} + {% else %} + + + + {% endif %} + +
AddressStatusCreatedModified
{{ email.email }} + {% if email.verified %}Verified{% else %}Unverified{% endif %} + {{ email.date_created | date:'Y-m-d H:i'}}{{ email.date_modified | date:'Y-m-d H:i'}} + + +
+ No additional email addresses set. +
+
+
{% endblock projectroles %} @@ -143,5 +217,23 @@

showCancelLink: true }); } + tour.addStep('additional_email', { + title: 'Additional Email Addresses Card', + text: 'This card displays additional email addresses set for the ' + + 'user and the ability to manage those addresses.', + attachTo: '#sodar-user-email-card top', + advanceOn: '.docs-link click', + showCancelLink: true + }); + tour.addStep('additional_email_add', { + title: 'Add Email', + text: 'If you want email notifications sent to one or more ' + + 'addresses other than your primary address, add those here. ' + + 'Addresses must be validated by following a link received in ' + + 'the initial email.', + attachTo: '#sodar-user-btn-email-add left', + advanceOn: '.docs-link click', + showCancelLink: true + }); {% endblock javascript %} diff --git a/userprofile/tests/test_ui.py b/userprofile/tests/test_ui.py index 8943fe67..03cdf702 100644 --- a/userprofile/tests/test_ui.py +++ b/userprofile/tests/test_ui.py @@ -9,6 +9,7 @@ # Projectroles dependency from projectroles.forms import SETTING_DISABLE_LABEL from projectroles.models import SODAR_CONSTANTS +from projectroles.tests.test_models import SODARUserAdditionalEmailMixin from projectroles.tests.test_ui import UITestBase @@ -17,7 +18,7 @@ @override_settings(AUTH_LDAP_USERNAME_DOMAIN='EXAMPLE') -class TestUserDetails(UITestBase): +class TestUserDetails(SODARUserAdditionalEmailMixin, UITestBase): """Tests for user details page""" def setUp(self): @@ -25,12 +26,46 @@ def setUp(self): # Create users self.local_user = self.make_user('local_user', False) self.ldap_user = self.make_user('user@EXAMPLE', False) + self.url = reverse('userprofile:detail') def test_update_button(self): """Test existence of user update button""" - url = reverse('userprofile:detail') expected = [(self.local_user, 1), (self.ldap_user, 0)] - self.assert_element_count(expected, url, 'sodar-user-btn-update') + self.assert_element_count(expected, self.url, 'sodar-user-btn-update') + + def test_add_email_unset(self): + """Test existence of additional email elements without email""" + self.assert_element_count( + [(self.local_user, 0)], + self.url, + 'sodar-user-email-table-row', + 'class', + ) + self.assert_element_exists( + [self.local_user], + self.url, + 'sodar-user-email-table-not-found', + True, + ) + + def test_add_email_set(self): + """Test existence of additional email elements with email""" + self.make_email(self.local_user, 'add1@example.com') + self.make_email(self.local_user, 'add2@example.com', verified=False) + # Another user, should not be visible + self.make_email(self.ldap_user, 'add3@example.com') + self.assert_element_count( + [(self.local_user, 2)], + self.url, + 'sodar-user-email-table-row', + 'class', + ) + self.assert_element_exists( + [self.local_user], + self.url, + 'sodar-user-email-table-not-found', + False, + ) class TestUserSettings(UITestBase): diff --git a/userprofile/tests/test_views.py b/userprofile/tests/test_views.py index 81eb098c..3ee035a6 100644 --- a/userprofile/tests/test_views.py +++ b/userprofile/tests/test_views.py @@ -8,7 +8,11 @@ # Projectroles dependency from projectroles.app_settings import AppSettingAPI -from projectroles.tests.test_models import EXAMPLE_APP_NAME, AppSettingMixin +from projectroles.tests.test_models import ( + EXAMPLE_APP_NAME, + AppSettingMixin, + SODARUserAdditionalEmailMixin, +) from projectroles.views import MSG_FORM_INVALID from userprofile.views import SETTING_UPDATE_MSG @@ -36,7 +40,7 @@ def setUp(self): # View tests ------------------------------------------------------------------- -class TestUserDetailView(UserViewTestBase): +class TestUserDetailView(SODARUserAdditionalEmailMixin, UserViewTestBase): """Tests for UserDetailView""" def test_get(self): @@ -45,6 +49,17 @@ def test_get(self): response = self.client.get(reverse('userprofile:detail')) self.assertEqual(response.status_code, 200) self.assertIsNotNone(response.context['user_settings']) + self.assertEqual(response.context['add_emails'].count(), 0) + + def test_get_additional_email(self): + """Test GET with additional email""" + self.make_email(self.user, 'add@example.com') + self.make_email(self.user, 'add_unverified@example.com', verified=False) + with self.login(self.user): + response = self.client.get(reverse('userprofile:detail')) + self.assertEqual(response.status_code, 200) + self.assertIsNotNone(response.context['user_settings']) + self.assertEqual(response.context['add_emails'].count(), 2) class TestUserSettingsView(AppSettingMixin, UserViewTestBase): diff --git a/userprofile/views.py b/userprofile/views.py index 159a92ad..ece23d1b 100644 --- a/userprofile/views.py +++ b/userprofile/views.py @@ -7,7 +7,7 @@ # Projectroles dependency from projectroles.app_settings import AppSettingAPI -from projectroles.models import SODAR_CONSTANTS +from projectroles.models import SODARUserAdditionalEmail, SODAR_CONSTANTS from projectroles.plugins import get_active_plugins from projectroles.views import ( LoggedInPermissionMixin, @@ -64,6 +64,9 @@ def get_context_data(self, **kwargs): result = super().get_context_data(**kwargs) result['user_settings'] = list(self._get_user_settings()) result['local_user'] = self.request.user.is_local() + result['add_emails'] = SODARUserAdditionalEmail.objects.filter( + user=self.request.user + ).order_by('email') return result