-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update logic, remove app setting, update tests (#874)
- Loading branch information
Showing
12 changed files
with
164 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
|
||
# Projectroles dependency | ||
from projectroles.app_settings import AppSettingAPI | ||
from projectroles.tests.test_models import SODARUserAdditionalEmailMixin | ||
|
||
from adminalerts.models import AdminAlert | ||
from adminalerts.tests.test_models import AdminAlertMixin | ||
|
@@ -26,9 +27,13 @@ | |
ALERT_DESC_UPDATED = 'Updated description' | ||
ALERT_DESC_MARKDOWN = '## Description' | ||
EMAIL_DESC_LEGEND = 'Additional details' | ||
ADD_EMAIL = '[email protected]' | ||
ADD_EMAIL2 = '[email protected]' | ||
|
||
|
||
class AdminalertsViewTestBase(AdminAlertMixin, TestCase): | ||
class AdminalertsViewTestBase( | ||
AdminAlertMixin, SODARUserAdditionalEmailMixin, TestCase | ||
): | ||
"""Base class for adminalerts view testing""" | ||
|
||
def _make_alert(self): | ||
|
@@ -199,16 +204,10 @@ def test_post_multiple_users(self): | |
self.assertIn(EMAIL_DESC_LEGEND, mail.outbox[0].body) | ||
self.assertIn(ALERT_DESC, mail.outbox[0].body) | ||
|
||
def test_post_alt_email_regular_user(self): | ||
"""Test POST with alt emails on regular user""" | ||
alt_email = '[email protected]' | ||
alt_email2 = '[email protected]' | ||
app_settings.set( | ||
'projectroles', | ||
'user_email_additional', | ||
';'.join([alt_email, alt_email2]), | ||
user=self.user_regular, | ||
) | ||
def test_post_add_email_regular_user(self): | ||
"""Test POST with additional emails on regular user""" | ||
self.make_email(self.user_regular, ADD_EMAIL) | ||
self.make_email(self.user_regular, ADD_EMAIL2) | ||
self.assertEqual(len(mail.outbox), 0) | ||
data = self._get_post_data() | ||
with self.login(self.superuser): | ||
|
@@ -220,28 +219,41 @@ def test_post_alt_email_regular_user(self): | |
[ | ||
settings.EMAIL_SENDER, | ||
self.user_regular.email, | ||
alt_email, | ||
alt_email2, | ||
ADD_EMAIL, | ||
ADD_EMAIL2, | ||
], | ||
) | ||
|
||
def test_post_alt_email_superuser(self): | ||
"""Test POST with alt emails on superuser""" | ||
alt_email = '[email protected]' | ||
alt_email2 = '[email protected]' | ||
app_settings.set( | ||
'projectroles', | ||
'user_email_additional', | ||
';'.join([alt_email, alt_email2]), | ||
user=self.superuser, | ||
def test_post_add_email_regular_user_unverified(self): | ||
"""Test POST with additional and unverified emails on regular user""" | ||
self.make_email(self.user_regular, ADD_EMAIL) | ||
self.make_email(self.user_regular, ADD_EMAIL2, verified=False) | ||
self.assertEqual(len(mail.outbox), 0) | ||
data = self._get_post_data() | ||
with self.login(self.superuser): | ||
response = self.client.post(self.url, data) | ||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(len(mail.outbox), 1) | ||
self.assertEqual( | ||
mail.outbox[0].recipients(), | ||
[ | ||
settings.EMAIL_SENDER, | ||
self.user_regular.email, | ||
ADD_EMAIL, | ||
], | ||
) | ||
|
||
def test_post_add_email_superuser(self): | ||
"""Test POST with additional emails on superuser""" | ||
self.make_email(self.superuser, ADD_EMAIL) | ||
self.make_email(self.superuser, ADD_EMAIL2) | ||
self.assertEqual(len(mail.outbox), 0) | ||
data = self._get_post_data() | ||
with self.login(self.superuser): | ||
response = self.client.post(self.url, data) | ||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(len(mail.outbox), 1) | ||
# Superuser alt emails should not be included | ||
# Superuser additional emails should not be included | ||
self.assertEqual( | ||
mail.outbox[0].recipients(), | ||
[settings.EMAIL_SENDER, self.user_regular.email], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,18 +98,6 @@ | |
'user_modifiable': True, | ||
'global': True, | ||
}, | ||
'user_email_additional': { | ||
'scope': APP_SETTING_SCOPE_USER, | ||
'type': 'STRING', | ||
'default': '', | ||
'placeholder': '[email protected];[email protected]', | ||
'label': 'Additional email', | ||
'description': 'Also send user emails to these addresses. Separate ' | ||
'multiple emails with semicolon.', | ||
'user_modifiable': True, | ||
'global': True, | ||
'project_types': [PROJECT_TYPE_PROJECT], | ||
}, | ||
'project_star': { | ||
'scope': APP_SETTING_SCOPE_PROJECT_USER, | ||
'type': 'BOOLEAN', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
projectroles/migrations/0030_populate_sodaruseradditionalemail.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Generated by Django 4.2.11 on 2024-04-25 13:14 | ||
|
||
import random | ||
import string | ||
|
||
from django.db import migrations | ||
|
||
|
||
def populate_model(apps, schema_editor): | ||
""" | ||
Move existing additional email app settings into the | ||
SODARUserAdditionalEmail model as verified emais. Delete the settings | ||
objects. | ||
""" | ||
AppSetting = apps.get_model('projectroles', 'AppSetting') | ||
SODARUserAdditionalEmail = apps.get_model( | ||
'projectroles', 'SODARUserAdditionalEmail' | ||
) | ||
for a in AppSetting.objects.filter( | ||
app_plugin=None, name='user_email_additional' | ||
): | ||
for v in a.value.split(';'): | ||
secret = ''.join( | ||
random.SystemRandom().choice( | ||
string.ascii_lowercase + string.digits | ||
) | ||
for _ in range(32) | ||
) | ||
try: | ||
SODARUserAdditionalEmail.objects.create( | ||
user=a.user, email=v, verified=True, secret=secret | ||
) | ||
except Exception: | ||
pass | ||
a.delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("projectroles", "0029_sodaruseradditionalemail"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
populate_model, reverse_code=migrations.RunPython.noop | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -518,20 +518,20 @@ def test_set_target_global_remote(self): | |
|
||
def test_set_user_global(self): | ||
"""Test setting global user setting on source site""" | ||
n = 'user_email_additional' | ||
v = '[email protected]' | ||
n = 'notify_email_project' | ||
v = '0' | ||
self.assertEqual(AppSetting.objects.filter(name=n, value=v).count(), 0) | ||
app_settings.set('projectroles', n, v, user=self.user) | ||
app_settings.set('projectroles', n, False, user=self.user) | ||
self.assertEqual(AppSetting.objects.filter(name=n, value=v).count(), 1) | ||
|
||
@override_settings(PROJECTROLES_SITE_MODE=SITE_MODE_TARGET) | ||
def test_set_user_global_target(self): | ||
"""Test setting global user setting on target site""" | ||
n = 'user_email_additional' | ||
v = '[email protected]' | ||
n = 'notify_email_project' | ||
v = '0' | ||
self.assertEqual(AppSetting.objects.filter(name=n, value=v).count(), 0) | ||
with self.assertRaises(ValueError): | ||
app_settings.set('projectroles', n, v, user=self.user) | ||
app_settings.set('projectroles', n, False, user=self.user) | ||
self.assertEqual(AppSetting.objects.filter(name=n, value=v).count(), 0) | ||
|
||
def test_validate_boolean(self): | ||
|
Oops, something went wrong.