Commit a8df9f4c authored by Ilias Tsitsimpis's avatar Ilias Tsitsimpis Committed by Ilias Tsitsimpis
Browse files

astakos: Sent notifications to the specified lists

Use *_RECIPIENTS settings and sent email notifications to the
appropriate lists.
parent 2414759b
......@@ -32,7 +32,6 @@ MEM_ENROLL_NOTIF = {
}
SENDER = settings.SERVER_EMAIL
NOTIFY_RECIPIENTS = [e[1] for e in settings.MANAGERS + settings.HELPDESK]
def membership_change_notify(project, user, action):
......@@ -88,11 +87,11 @@ def membership_request_notify(project, requested_user, action):
APPLICATION_DATA = {
"submit_new": lambda a: (
NOTIFY_RECIPIENTS,
[e[1] for e in settings.PROJECT_CREATION_RECIPIENTS],
_(messages.PROJECT_CREATION_SUBJECT) % a.chain.realname,
"im/projects/project_creation_notification.txt"),
"submit_modification": lambda a: (
NOTIFY_RECIPIENTS,
[e[1] for e in settings.PROJECT_MODIFICATION_RECIPIENTS],
_(messages.PROJECT_MODIFICATION_SUBJECT) % a.chain.realname,
"im/projects/project_modification_notification.txt"),
"deny": lambda a: (
......
......@@ -21,6 +21,10 @@ from astakos.im.tests.common import *
ui_url = lambda url: '/' + astakos_settings.BASE_PATH + '/ui/%s' % url
MANAGERS = (('Manager', 'manager@synnefo.org'),)
HELPDESK = (('Helpdesk', 'helpdesk@synnefo.org'),)
ADMINS = (('Admin', 'admin@synnefo.org'),)
class ShibbolethTests(TestCase):
"""
......@@ -435,7 +439,9 @@ class ShibbolethTests(TestCase):
class TestLocal(TestCase):
def setUp(self):
settings.ADMINS = (('admin', 'support@cloud.synnefo.org'),)
settings.ADMINS = ADMINS
settings.ACCOUNT_PENDING_MODERATION_RECIPIENTS = ADMINS
settings.ACCOUNT_ACTIVATED_RECIPIENTS = ADMINS
settings.SERVER_EMAIL = 'no-reply@synnefo.org'
self._orig_moderation = astakos_settings.MODERATION_ENABLED
settings.ASTAKOS_MODERATION_ENABLED = True
......@@ -482,7 +488,7 @@ class TestLocal(TestCase):
self.assertFalse(user.is_active)
# user (but not admin) gets notified
self.assertEqual(len(get_mailbox('support@cloud.synnefo.org')), 0)
self.assertEqual(len(get_mailbox('admin@synnefo.org')), 0)
self.assertEqual(len(get_mailbox('kpap@synnefo.org')), 1)
astakos_settings.MODERATION_ENABLED = True
......@@ -520,7 +526,9 @@ class TestLocal(TestCase):
form = forms.LocalUserCreationForm(data)
self.assertFalse(form.is_valid())
@im_settings(HELPDESK=(('support', 'support@synnefo.org'),),
@im_settings(HELPDESK=HELPDESK,
ACCOUNT_PENDING_MODERATION_RECIPIENTS=HELPDESK,
ACCOUNT_ACTIVATED_RECIPIENTS=HELPDESK,
FORCE_PROFILE_UPDATE=False, MODERATION_ENABLED=True)
def test_local_provider(self):
self.helpdesk_email = astakos_settings.HELPDESK[0][1]
......@@ -662,7 +670,7 @@ class TestLocal(TestCase):
self.assertFalse(r.context['request'].user.is_authenticated())
self.assertFalse(self.client.cookies.get('_pithos2_a').value)
#https://docs.djangoproject.com/en/dev/topics/testing/#persistent-state
# https://docs.djangoproject.com/en/dev/topics/testing/#persistent-state
del self.client.cookies['_pithos2_a']
# user can login
......@@ -881,7 +889,9 @@ class TestAuthProviderViews(TestCase):
@shibboleth_settings(CREATION_GROUPS_POLICY=['academic-login'],
AUTOMODERATE_POLICY=True)
@im_settings(IM_MODULES=['shibboleth', 'local'], MODERATION_ENABLED=True,
HELPDESK=(('support', 'support@synnefo.org'),),
HELPDESK=HELPDESK,
ACCOUNT_PENDING_MODERATION_RECIPIENTS=HELPDESK,
ACCOUNT_ACTIVATED_RECIPIENTS=HELPDESK,
FORCE_PROFILE_UPDATE=False)
def test_user(self):
Profile = AuthProviderPolicyProfile
......@@ -1344,12 +1354,13 @@ class TestActivationBackend(TestCase):
self.assertEqual(user3.moderated, True)
self.assertEqual(user3.accepted_policy, 'auth_provider_shibboleth')
@im_settings(MODERATION_ENABLED=False,
MANAGERS=(('Manager',
'manager@synnefo.org'),),
HELPDESK=(('Helpdesk',
'helpdesk@synnefo.org'),),
ADMINS=(('Admin', 'admin@synnefo.org'), ))
@im_settings(
MODERATION_ENABLED=False,
MANAGERS=MANAGERS,
HELPDESK=HELPDESK,
ADMINS=ADMINS,
ACCOUNT_PENDING_MODERATION_RECIPIENTS=MANAGERS+HELPDESK+ADMINS,
ACCOUNT_ACTIVATED_RECIPIENTS=MANAGERS+HELPDESK+ADMINS)
def test_without_moderation(self):
backend = activation_backends.get_backend()
form = backend.get_signup_form('local')
......@@ -1397,12 +1408,13 @@ class TestActivationBackend(TestCase):
self.assertEqual(user.email_verified, True)
self.assertTrue(user.activation_sent)
@im_settings(MODERATION_ENABLED=True,
MANAGERS=(('Manager',
'manager@synnefo.org'),),
HELPDESK=(('Helpdesk',
'helpdesk@synnefo.org'),),
ADMINS=(('Admin', 'admin@synnefo.org'), ))
@im_settings(
MODERATION_ENABLED=True,
MANAGERS=MANAGERS,
HELPDESK=HELPDESK,
ADMINS=ADMINS,
ACCOUNT_PENDING_MODERATION_RECIPIENTS=HELPDESK+MANAGERS+ADMINS,
ACCOUNT_ACTIVATED_RECIPIENTS=HELPDESK+MANAGERS+ADMINS)
def test_with_moderation(self):
backend = activation_backends.get_backend()
......@@ -1534,7 +1546,7 @@ class TestWebloginRedirect(TestCase):
AstakosUser.objects.get().auth_token)
# does not contain uuid
# reverted for 0.14.2 to support old pithos desktop clients
#self.assertFalse('uuid' in params)
# self.assertFalse('uuid' in params)
# invalid cases
r = self.client.get(invalid_scheme, follow=True)
......
......@@ -101,62 +101,39 @@ def send_verification(user, template_name='im/activation_email.txt'):
logger.info("Sent user verification email: %s", user.log_display)
def _send_admin_notification(template_name,
context=None,
user=None,
msg="",
subject='alpha2 testing notification',):
"""
Send notification email to settings.HELPDESK + settings.MANAGERS +
settings.ADMINS.
"""
if context is None:
context = {}
if 'user' not in context:
context['user'] = user
message = render_to_string(template_name, context)
sender = settings.SERVER_EMAIL
recipient_list = [e[1] for e in settings.HELPDESK +
settings.MANAGERS + settings.ADMINS]
send_mail(subject, message, sender, recipient_list,
connection=get_connection())
if user:
msg = 'Sent admin notification (%s) for user %s' % (msg,
user.log_display)
else:
msg = 'Sent admin notification (%s)' % msg
logger.log(settings.LOGGING_LEVEL, msg)
def send_account_pending_moderation_notification(
user,
template_name='im/account_pending_moderation_notification.txt'):
"""
Notify admins that a new user has verified his email address and moderation
step is required to activate his account.
Notify 'ACCOUNT_PENDING_MODERATION_RECIPIENTS' that a new user has verified
his email address and moderation step is required to activate his account.
"""
subject = (_(astakos_messages.ACCOUNT_CREATION_SUBJECT) %
{'user': user.email})
return _send_admin_notification(template_name, {}, subject=subject,
user=user, msg="account creation")
message = render_to_string(template_name, {'user': user})
sender = settings.SERVER_EMAIL
recipient_list = [e[1] for e in
settings.ACCOUNT_PENDING_MODERATION_RECIPIENTS]
send_mail(subject, message, sender, recipient_list,
connection=get_connection())
msg = 'Sent admin notification (account creation) for user %s'
logger.log(settings.LOGGING_LEVEL, msg, user.log_display)
def send_account_activated_notification(
user,
template_name='im/account_activated_notification.txt'):
"""
Send email to settings.HELPDESK + settings.MANAGERES + settings.ADMINS
lists to notify that a new account has been accepted and activated.
Send email to ACCOUNT_ACTIVATED_RECIPIENTS list to notify that a new
account has been accepted and activated.
"""
message = render_to_string(
template_name,
{'user': user}
)
sender = settings.SERVER_EMAIL
recipient_list = [e[1] for e in settings.HELPDESK +
settings.MANAGERS + settings.ADMINS]
recipient_list = [e[1] for e in
settings.ACCOUNT_ACTIVATED_RECIPIENTS]
send_mail(_(astakos_messages.HELPDESK_NOTIFICATION_EMAIL_SUBJECT) %
{'user': user.email},
message, sender, recipient_list, connection=get_connection())
......@@ -210,9 +187,10 @@ def send_greeting(user, email_template_name='im/welcome_email.txt'):
def send_feedback(msg, data, user, email_template_name='im/feedback_mail.txt'):
"""Send feedback to FEEDBACK_RECIPIENTS list."""
subject = _(astakos_messages.FEEDBACK_EMAIL_SUBJECT)
from_email = settings.SERVER_EMAIL
recipient_list = [e[1] for e in settings.HELPDESK]
recipient_list = [e[1] for e in settings.FEEDBACK_NOTIFICATIONS_RECIPIENTS]
content = render_to_string(email_template_name, {
'message': msg,
'data': data,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment