Skip to content

Commit

Permalink
add additional email gui (wip) (#874)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Apr 26, 2024
1 parent 0e50861 commit d89b3a2
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 6 deletions.
92 changes: 92 additions & 0 deletions userprofile/templates/userprofile/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

<div class="row sodar-pr-content-title pt-2">
Expand Down Expand Up @@ -91,6 +96,75 @@ <h4>
</dl>
</div>
</div>

<div class="card" id="sodar-user-email-card">
<div class="card-header">
<h4>
<i class="iconify" data-icon="mdi:email-multiple"></i> Additional Email Addresses
{% if local_user %}
<span class="sodar-header-input-group pull-right">
<a role="button"
class="btn btn-primary"
id="sodar-user-btn-email-add"
href="#">
<i class="iconify" data-icon="mdi:plus-thick"></i> Add Email
</a>
</span>
{% endif %}
</h4>
</div>
<div class="card-body p-0">
<table class="table table-striped sodar-card-table"
id="sodar-user-email-table">
<thead>
<tr>
<th>Address</th>
<th>Status</th>
<th>Created</th>
<th>Modified</th>
<th></th>
</tr>
</thead>
<tbody>
{% if add_emails.count > 0 %}
{% for email in add_emails %}
<tr class="sodar-user-email-table-row">
<td><a href="mailto:{{ email.email }}">{{ email.email }}</a></td>
<td class="text-{% if email.verified %}success{% else %}danger{% endif %}">
{% if email.verified %}Verified{% else %}Unverified{% endif %}
</td>
<td>{{ email.date_created | date:'Y-m-d H:i'}}</td>
<td>{{ email.date_modified | date:'Y-m-d H:i'}}</td>
<td class="text-right">
<button class="btn btn-secondary dropdown-toggle sodar-list-dropdown"
type="button" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
<i class="iconify" data-icon="mdi:gear"></i>
</button>
<div class="dropdown-menu dropdown-menu-right sodar-user-email-dropdown">
<a class="dropdown-item sodar-user-email-resend {% if email.verified %}disabled{% endif %}"
href="#">
<i class="iconify" data-icon="mdi:send"></i> Resend Verification Mail
</a>
<a class="dropdown-item sodar-user-email-delete text-danger"
href="#">
<i class="iconify" data-icon="mdi:close-thick"></i> Delete Address
</a>
</div>
</td>
</tr>
{% endfor %}
{% else %}
<tr id="sodar-user-email-table-not-found">
<td class="bg-faded font-italic text-center" colspan="5">
No additional email addresses set.
</td>
</tr>
{% endif %}
</tbody>
</table>
</div>
</div>
</div>

{% endblock projectroles %}
Expand Down Expand Up @@ -143,5 +217,23 @@ <h4>
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
});
</script>
{% endblock javascript %}
41 changes: 38 additions & 3 deletions userprofile/tests/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -17,20 +18,54 @@


@override_settings(AUTH_LDAP_USERNAME_DOMAIN='EXAMPLE')
class TestUserDetails(UITestBase):
class TestUserDetails(SODARUserAdditionalEmailMixin, UITestBase):
"""Tests for user details page"""

def setUp(self):
super().setUp()
# 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, '[email protected]')
self.make_email(self.local_user, '[email protected]', verified=False)
# Another user, should not be visible
self.make_email(self.ldap_user, '[email protected]')
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):
Expand Down
19 changes: 17 additions & 2 deletions userprofile/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -36,7 +40,7 @@ def setUp(self):
# View tests -------------------------------------------------------------------


class TestUserDetailView(UserViewTestBase):
class TestUserDetailView(SODARUserAdditionalEmailMixin, UserViewTestBase):
"""Tests for UserDetailView"""

def test_get(self):
Expand All @@ -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, '[email protected]')
self.make_email(self.user, '[email protected]', 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):
Expand Down
5 changes: 4 additions & 1 deletion userprofile/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit d89b3a2

Please sign in to comment.