You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2020/06/02 17:04:00 UTC
[allura] 01/03: email_change_notif email added/removed mail
notifications
This is an automated email from the ASF dual-hosted git repository.
brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git
commit 5df2588e768c41560c54504f8af88cf7e53e15a3
Author: Dillon Walls <di...@slashdotmedia.com>
AuthorDate: Wed May 20 22:42:29 2020 +0000
email_change_notif email added/removed mail notifications
---
Allura/allura/controllers/auth.py | 11 +++++++++++
Allura/allura/templates/mail/email_added.md | 26 ++++++++++++++++++++++++++
Allura/allura/templates/mail/email_removed.md | 26 ++++++++++++++++++++++++++
Allura/allura/tests/functional/test_auth.py | 15 ++++++++++++++-
4 files changed, 77 insertions(+), 1 deletion(-)
diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index f8dff10..a803533 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -554,6 +554,7 @@ class PreferencesController(BaseController):
addr = kw.pop('addr', None)
new_addr = kw.pop('new_addr', None)
primary_addr = kw.pop('primary_addr', None)
+ notify_addr = primary_addr
provider = plugin.AuthenticationProvider.get(request)
for i, (old_a, data) in enumerate(zip(user.email_addresses, addr or [])):
obj = user.address_object(old_a)
@@ -572,6 +573,11 @@ class PreferencesController(BaseController):
primary_addr = None
user.set_tool_data('AuthPasswordReset', hash='', hash_expiry='')
h.auditlog_user('Email address deleted: %s', user.email_addresses[i], user=user)
+ email_body = g.jinja2_env.get_template('allura:templates/mail/email_removed.md').render(dict(
+ user=user,
+ config=config,
+ ))
+ send_system_mail_to_user(notify_addr, 'Email Address Removed', email_body)
del user.email_addresses[i]
if obj:
obj.delete()
@@ -610,6 +616,11 @@ class PreferencesController(BaseController):
flash('A verification email has been sent. Please check your email and click to confirm.')
h.auditlog_user('New email address: %s', new_addr['addr'], user=user)
+ email_body = g.jinja2_env.get_template('allura:templates/mail/email_added.md').render(dict(
+ user=user,
+ config=config,
+ ))
+ send_system_mail_to_user(notify_addr, 'New Email Address Added', email_body)
else:
flash('Email address %s is invalid' % new_addr['addr'], 'error')
else:
diff --git a/Allura/allura/templates/mail/email_added.md b/Allura/allura/templates/mail/email_added.md
new file mode 100644
index 0000000..b0ecc58
--- /dev/null
+++ b/Allura/allura/templates/mail/email_added.md
@@ -0,0 +1,26 @@
+{#
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-#}
+
+Hello {{ user.display_name }},
+
+A new email address has been added to your {{ config['site_name'] }} account "{{ user.username }}". This is a confirmation email, you are all set.
+
+{% block footer %}
+If you did not do this, please contact us immediately.
+{% endblock %}
diff --git a/Allura/allura/templates/mail/email_removed.md b/Allura/allura/templates/mail/email_removed.md
new file mode 100644
index 0000000..6eb6a9f
--- /dev/null
+++ b/Allura/allura/templates/mail/email_removed.md
@@ -0,0 +1,26 @@
+{#
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-#}
+
+Hello {{ user.display_name }},
+
+An email address has been removed from your {{ config['site_name'] }} account "{{ user.username }}". This is a confirmation email, you are all set.
+
+{% block footer %}
+If you did not do this, please contact us immediately.
+{% endblock %}
diff --git a/Allura/allura/tests/functional/test_auth.py b/Allura/allura/tests/functional/test_auth.py
index 3d922b6..9d92260 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -674,8 +674,10 @@ class TestAuth(TestController):
user = M.User.by_username('test-admin')
assert_not_equal(old_pass, user.get_pref('password'))
+ @patch('allura.tasks.mail_tasks.sendsimplemail')
+ @patch('allura.lib.helpers.gen_message_id')
@td.with_user_project('test-admin')
- def test_prefs(self):
+ def test_prefs(self, gen_message_id, sendsimplemail):
r = self.app.get('/auth/preferences/',
extra_environ=dict(username=str('test-admin')))
# check preconditions of test data
@@ -701,6 +703,11 @@ class TestAuth(TestController):
user = M.User.query.get(username='test-admin')
assert_equal(user.get_pref('email_address'), 'test-admin@users.localhost')
+ # assert 'email added' notification email sent
+ args, kwargs = sendsimplemail.post.call_args
+ assert_equal(kwargs['toaddr'], 'test-admin@users.localhost')
+ assert_equal(kwargs['subject'], 'New Email Address Added')
+
# remove test-admin@users.localhost
with td.audits('Email address deleted: test-admin@users.localhost', user=True):
r = self.app.post('/auth/preferences/update_emails',
@@ -715,6 +722,12 @@ class TestAuth(TestController):
'preferences.email_format': 'plain',
'_session_id': self.app.cookies['_session_id'],
})
+
+ # assert 'remail removed' notification email sent
+ args, kwargs = sendsimplemail.post.call_args
+ assert_equal(kwargs['toaddr'], 'test-admin@users.localhost')
+ assert_equal(kwargs['subject'], 'Email Address Removed')
+
r = self.app.get('/auth/preferences/')
assert 'test-admin@users.localhost' not in r
# preferred address has not changed if email is not verified