You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by gc...@apache.org on 2021/11/12 20:16:09 UTC
[allura] 01/03: Added checkbox option that sends message replies to
users active email address
This is an automated email from the ASF dual-hosted git repository.
gcruz pushed a commit to branch messages-ui
in repository https://gitbox.apache.org/repos/asf/allura.git
commit f5608abededde3d30b02ab13a26cecd270862779
Author: Guillermo Cruz <gu...@slashdotmedia.com>
AuthorDate: Mon Nov 1 07:58:31 2021 -0600
Added checkbox option that sends message replies to users active email address
---
.../user_profile/templates/send_message_form.html | 3 +++
Allura/allura/ext/user_profile/user_main.py | 4 +--
Allura/allura/lib/widgets/user_profile.py | 1 +
Allura/allura/model/auth.py | 9 ++++---
.../allura/tests/functional/test_user_profile.py | 31 +++++++++++++++++++++-
5 files changed, 41 insertions(+), 7 deletions(-)
diff --git a/Allura/allura/ext/user_profile/templates/send_message_form.html b/Allura/allura/ext/user_profile/templates/send_message_form.html
index 279572f..df31796 100644
--- a/Allura/allura/ext/user_profile/templates/send_message_form.html
+++ b/Allura/allura/ext/user_profile/templates/send_message_form.html
@@ -47,6 +47,9 @@
<div class="grid-19">
{{widget.display_field(widget.fields.cc)}}
</div>
+ <div class="grid-19">
+ {{widget.display_field(widget.fields.reply_to_real_address)}}
+ </div>
<div class="grid-19"> </div>
<div class="grid-12">
{{buttons[0].display()}}
diff --git a/Allura/allura/ext/user_profile/user_main.py b/Allura/allura/ext/user_profile/user_main.py
index f63bffe..2240e0f 100644
--- a/Allura/allura/ext/user_profile/user_main.py
+++ b/Allura/allura/ext/user_profile/user_main.py
@@ -195,7 +195,7 @@ class UserProfileController(BaseController, FeedController):
@expose()
@validate(dict(subject=validators.NotEmpty,
message=validators.NotEmpty))
- def send_user_message(self, subject='', message='', cc=None):
+ def send_user_message(self, subject='', message='', cc=None, reply_to_real_address=None):
"""Handle POST for sending a message to another user.
"""
@@ -205,7 +205,7 @@ class UserProfileController(BaseController, FeedController):
cc = c.user.get_pref('email_address')
if c.user.can_send_user_message():
c.user.send_user_message(
- c.project.user_project_of, subject, message, cc)
+ c.project.user_project_of, subject, message, cc, reply_to_real_address)
flash("Message sent.")
else:
flash("You can't send more than %i messages per %i seconds" % (
diff --git a/Allura/allura/lib/widgets/user_profile.py b/Allura/allura/lib/widgets/user_profile.py
index e6162b0..0c81356 100644
--- a/Allura/allura/lib/widgets/user_profile.py
+++ b/Allura/allura/lib/widgets/user_profile.py
@@ -63,6 +63,7 @@ class SendMessageForm(ForgeForm):
label='Message')
cc = ew.Checkbox(label='Send me a copy')
+ reply_to_real_address = ew.Checkbox(label='Include my active email address in the reply field for this message')
class SectionsUtil(object):
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index dd47515..7ef5b45 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -455,7 +455,7 @@ class User(MappedClass, ActivityNode, ActivityObject, SearchIndexable):
timedelta(seconds=g.user_message_time_interval) -
datetime.utcnow())
- def send_user_message(self, user, subject, message, cc):
+ def send_user_message(self, user, subject, message, cc, reply_to_real_address):
"""Send a user message (email) to ``user``.
"""
@@ -467,10 +467,12 @@ class User(MappedClass, ActivityNode, ActivityObject, SearchIndexable):
'base_url': config['base_url'],
'user': c.user,
}
+ real_address = user.preferences.email_address
+ reply_to = real_address if reply_to_real_address and real_address else self.get_pref('email_address')
allura.tasks.mail_tasks.sendsimplemail.post(
toaddr=user.get_pref('email_address'),
fromaddr=self.get_pref('email_address'),
- reply_to=self.get_pref('email_address'),
+ reply_to=reply_to,
message_id=h.gen_message_id(),
subject=subject,
text=tmpl.render(tmpl_context),
@@ -810,9 +812,8 @@ class User(MappedClass, ActivityNode, ActivityObject, SearchIndexable):
def email_address_header(self):
h = header.Header()
- h.append('"%s"%s' % (self.get_pref('display_name'),
+ h.append('%s %s' % (self.get_pref('display_name'),
' ' if six.PY2 else '')) # py2 needs explicit space for unicode/text_type cast of Header
- h.append('<%s>' % self.get_pref('email_address'))
return h
def update_notifications(self):
diff --git a/Allura/allura/tests/functional/test_user_profile.py b/Allura/allura/tests/functional/test_user_profile.py
index 43e4770..ac538dd 100644
--- a/Allura/allura/tests/functional/test_user_profile.py
+++ b/Allura/allura/tests/functional/test_user_profile.py
@@ -115,7 +115,7 @@ class TestUserProfile(TestController):
response = self.app.get(
'/u/test-user/profile/send_message', status=200)
assert 'you currently have user messages disabled' not in response
- response.mustcontain('<b>From:</b> "Test Admin" <test-admin@users.localhost>')
+ response.mustcontain('<b>From:</b> Test Admin')
self.app.post('/u/test-user/profile/send_user_message',
params={'subject': 'test subject',
@@ -149,6 +149,35 @@ class TestUserProfile(TestController):
'/u/test-user/profile/send_message', status=200)
assert 'Sorry, messaging is rate-limited' in response
+ @td.with_user_project('test-admin')
+ @td.with_user_project('test-user')
+ @mock.patch('allura.tasks.mail_tasks.sendsimplemail')
+ @mock.patch('allura.lib.helpers.gen_message_id')
+ @mock.patch('allura.model.User.can_send_user_message')
+ def test_send_message_with_real_address_reply(self, check, gen_message_id, sendsimplemail):
+ check.return_value = True
+ gen_message_id.return_value = 'id'
+ test_user = User.by_username('test-user')
+ test_user.set_pref('email_address', 'test-user@example.com')
+ response = self.app.get(
+ '/u/test-user/profile/send_message', status=200)
+ assert 'you currently have user messages disabled' not in response
+ response.mustcontain('<b>From:</b> Test Admin')
+ self.app.post('/u/test-user/profile/send_user_message',
+ params={'subject': 'test subject',
+ 'message': 'test message',
+ 'cc': 'on',
+ 'reply_to_real_address': 'on'})
+ real_address = test_user.preferences.email_address
+ sendsimplemail.post.assert_called_once_with(
+ cc=User.by_username('test-admin').get_pref('email_address'),
+ text='test message\n\n---\n\nThis message was sent to you via the Allura web mail form. You may reply to this message directly, or send a message to Test Admin at http://localhost/u/test-admin/profile/send_message\n',
+ toaddr=User.by_username('test-user').get_pref('email_address'),
+ fromaddr=User.by_username('test-admin').get_pref('email_address'),
+ reply_to=real_address,
+ message_id='id',
+ subject='test subject')
+
@td.with_user_project('test-user')
def test_send_message_for_anonymous(self):
r = self.app.get('/u/test-user/profile/send_message',