Skip to content

Commit

Permalink
update userprofile ui (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Jan 15, 2025
1 parent b4d9a6f commit d5ff801
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 48 deletions.
72 changes: 40 additions & 32 deletions userprofile/templates/userprofile/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

{% block projectroles %}

{% get_app_setting 'projectroles' 'site_read_only' as site_read_only %}

<div class="row sodar-pr-content-title pt-2">
<h2 class="sodar-pr-content-title">{{ request.user.get_full_name }}</h2>
<div class="sodar-pr-content-title-secondary text-muted">
Expand All @@ -43,7 +45,7 @@ <h2 class="sodar-pr-content-title">{{ request.user.get_full_name }}</h2>
<div class="card-header">
<h4>
<i class="iconify" data-icon="mdi:account-details"></i> Details
{% if request.user.is_local %}
{% if request.user.is_local and not site_read_only %}
<span class="sodar-header-input-group pull-right">
<a role="button"
class="btn btn-primary"
Expand Down Expand Up @@ -83,14 +85,16 @@ <h4>
<div class="card-header">
<h4>
<i class="iconify" data-icon="mdi:tune"></i> Settings
<span class="sodar-header-input-group pull-right">
<a role="button"
class="btn btn-primary {% if not user_settings or user_settings|length == 0 %}disabled{% endif %}"
href="{% url 'userprofile:settings_update' %}"
id="sodar-user-btn-settings">
<i class="iconify" data-icon="mdi:lead-pencil"></i> Update Settings
</a>
</span>
{% if request.user.is_superuser or not site_read_only %}
<span class="sodar-header-input-group pull-right">
<a role="button"
class="btn btn-primary {% if not user_settings or user_settings|length == 0 %}disabled{% endif %}"
href="{% url 'userprofile:settings_update' %}"
id="sodar-user-btn-settings">
<i class="iconify" data-icon="mdi:lead-pencil"></i> Update Settings
</a>
</span>
{% endif %}
</h4>
</div>
<div class="card-body">
Expand Down Expand Up @@ -128,14 +132,16 @@ <h4>
<i class="iconify" data-icon="mdi:email-multiple"></i>
Additional Email Addresses
{% if site_mode == 'SOURCE' %}
<span class="sodar-header-input-group pull-right">
<a role="button"
class="btn btn-primary"
id="sodar-user-btn-email-add"
href="{% url 'userprofile:email_create' %}">
<i class="iconify" data-icon="mdi:plus-thick"></i> Add Email
</a>
</span>
{% if request.user.is_superuser or not site_read_only %}
<span class="sodar-header-input-group pull-right">
<a role="button"
class="btn btn-primary"
id="sodar-user-btn-email-add"
href="{% url 'userprofile:email_create' %}">
<i class="iconify" data-icon="mdi:plus-thick"></i> Add Email
</a>
</span>
{% endif %}
{% endif %}
</h4>
</div>
Expand Down Expand Up @@ -163,21 +169,23 @@ <h4>
<td class="text-nowrap">{{ email.date_modified | date:'Y-m-d H:i'}}</td>
<td class="text-right">
{% if site_mode == 'SOURCE' %}
<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="{% url 'userprofile:email_verify_resend' sodaruseradditionalemail=email.sodar_uuid %}">
<i class="iconify" data-icon="mdi:send"></i> Resend Verification Mail
</a>
<a class="dropdown-item sodar-user-email-delete text-danger"
href="{% url 'userprofile:email_delete' sodaruseradditionalemail=email.sodar_uuid %}">
<i class="iconify" data-icon="mdi:close-thick"></i> Delete Address
</a>
</div>
{% if request.user.is_superuser or not site_read_only %}
<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="{% url 'userprofile:email_verify_resend' sodaruseradditionalemail=email.sodar_uuid %}">
<i class="iconify" data-icon="mdi:send"></i> Resend Verification Mail
</a>
<a class="dropdown-item sodar-user-email-delete text-danger"
href="{% url 'userprofile:email_delete' sodaruseradditionalemail=email.sodar_uuid %}">
<i class="iconify" data-icon="mdi:close-thick"></i> Delete Address
</a>
</div>
{% endif %}
{% endif %}
</td>
</tr>
Expand Down
108 changes: 92 additions & 16 deletions userprofile/tests/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@
from selenium.webdriver.support.ui import WebDriverWait

# Projectroles dependency
from projectroles.app_settings import AppSettingAPI
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


app_settings = AppSettingAPI()


# SODAR constants
SITE_MODE_TARGET = SODAR_CONSTANTS['SITE_MODE_TARGET']


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

def setUp(self):
super().setUp()
Expand All @@ -33,14 +37,56 @@ def test_update_button(self):
expected = [(self.local_user, 1), (self.ldap_user, 0)]
self.assert_element_count(expected, self.url, 'sodar-user-btn-update')

def test_update_button_read_only(self):
"""Test existence of user update button with site read-only mode"""
app_settings.set('projectroles', 'site_read_only', True)
expected = [(self.local_user, 0), (self.ldap_user, 0)]
self.assert_element_count(expected, self.url, 'sodar-user-btn-update')

def test_settings_button(self):
"""Test existence of settings update button"""
expected = [
(self.superuser, 1),
(self.local_user, 1),
(self.ldap_user, 1),
]
self.assert_element_count(expected, self.url, 'sodar-user-btn-settings')

def test_settings_button_read_only(self):
"""Test existence of settings update button with site read-only mode"""
app_settings.set('projectroles', 'site_read_only', True)
expected = [
(self.superuser, 1),
(self.local_user, 0),
(self.ldap_user, 0),
]
self.assert_element_count(expected, self.url, 'sodar-user-btn-settings')

def test_add_email_button(self):
"""Test existence of add email button"""
expected = [
(self.superuser, 1),
(self.local_user, 1),
(self.ldap_user, 1),
]
self.assert_element_count(
expected, self.url, 'sodar-user-btn-email-add'
)

def test_add_email_button_read_only(self):
"""Test existence of add email button with site read-only mode"""
app_settings.set('projectroles', 'site_read_only', True)
expected = [
(self.superuser, 1),
(self.local_user, 0),
(self.ldap_user, 0),
]
self.assert_element_count(
expected, self.url, 'sodar-user-btn-email-add'
)

def test_additional_email_unset(self):
"""Test existence of additional email elements without email"""
self.assert_element_exists(
[self.local_user],
self.url,
'sodar-user-btn-email-add',
True,
)
self.assert_element_count(
[(self.local_user, 0)],
self.url,
Expand All @@ -66,12 +112,6 @@ def test_additional_email_set(self):
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_exists(
[self.local_user],
self.url,
'sodar-user-btn-email-add',
True,
)
self.assert_element_count(
[(self.local_user, 2)],
self.url,
Expand All @@ -91,6 +131,42 @@ def test_additional_email_set(self):
False,
)

def test_additional_email_set_read_only(self):
"""Test additional email with site read-only mode"""
app_settings.set('projectroles', 'site_read_only', True)
self.make_email(self.local_user, '[email protected]')
self.make_email(self.local_user, '[email protected]', verified=False)
self.assert_element_count(
[(self.local_user, 2)],
self.url,
'sodar-user-email-table-row',
'class',
)
self.assert_element_count(
[(self.local_user, 0)],
self.url,
'sodar-user-email-dropdown',
'class',
)

def test_additional_email_set_read_only_superuser(self):
"""Test additional email with site read-only mode as superuser"""
app_settings.set('projectroles', 'site_read_only', True)
self.make_email(self.superuser, '[email protected]')
self.make_email(self.superuser, '[email protected]', verified=False)
self.assert_element_count(
[(self.superuser, 2)],
self.url,
'sodar-user-email-table-row',
'class',
)
self.assert_element_count(
[(self.superuser, 2)],
self.url,
'sodar-user-email-dropdown',
'class',
)

@override_settings(PROJECTROLES_SEND_EMAIL=False)
def test_additional_email_disabled(self):
"""Test existence of email card with PROJECTROLES_SEND_EMAIL=False"""
Expand Down Expand Up @@ -132,8 +208,8 @@ def test_additional_email_target(self):
)


class TestUserSettings(UITestBase):
"""Tests for user settings page"""
class TestUserSettingsView(UITestBase):
"""Tests for UserSettingsView"""

def setUp(self):
super().setUp()
Expand Down

0 comments on commit d5ff801

Please sign in to comment.