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 776a1c79c03e61bc32f013e914d5caea74c69b0e Author: Guillermo Cruz <[email protected]> AuthorDate: Mon Nov 8 15:53:15 2021 -0700 message replies to email address is persisted in user preferences, fixed wrong sender email address and reverted 'From' value changes --- Allura/allura/ext/user_profile/user_main.py | 7 ++++++- Allura/allura/lib/widgets/user_profile.py | 2 +- Allura/allura/model/auth.py | 10 +++++++--- Allura/allura/tests/functional/test_user_profile.py | 9 +++++---- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Allura/allura/ext/user_profile/user_main.py b/Allura/allura/ext/user_profile/user_main.py index 2240e0f..b7ca32b 100644 --- a/Allura/allura/ext/user_profile/user_main.py +++ b/Allura/allura/ext/user_profile/user_main.py @@ -189,6 +189,8 @@ class UserProfileController(BaseController, FeedController): delay = c.user.time_to_next_user_message() expire_time = str(delay) if delay else None c.form = F.send_message + if c.user.get_pref('message_reply_real_address'): + c.form.fields.reply_to_real_address.attrs = {'checked': 'checked'} return dict(user=c.project.user_project_of, expire_time=expire_time) @require_post() @@ -203,9 +205,12 @@ class UserProfileController(BaseController, FeedController): if cc: cc = c.user.get_pref('email_address') + if c.user.can_send_user_message(): + if reply_to_real_address: + c.user.set_pref('message_reply_real_address', True) c.user.send_user_message( - c.project.user_project_of, subject, message, cc, reply_to_real_address) + c.project.user_project_of, subject, message, cc, reply_to_real_address, c.user.preferences.email_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 0c81356..ee0d652 100644 --- a/Allura/allura/lib/widgets/user_profile.py +++ b/Allura/allura/lib/widgets/user_profile.py @@ -63,7 +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') + reply_to_real_address = ew.Checkbox(label='Include my 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 7ef5b45..5382996 100644 --- a/Allura/allura/model/auth.py +++ b/Allura/allura/model/auth.py @@ -275,6 +275,7 @@ class User(MappedClass, ActivityNode, ActivityObject, SearchIndexable): disable_user_messages=bool, mention_notifications=bool, multifactor=bool, + message_reply_real_address=bool, )) # Additional top-level fields can/should be accessed with get/set_pref also # Not sure why we didn't put them within the 'preferences' dictionary :( @@ -455,7 +456,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, reply_to_real_address): + def send_user_message(self, user, subject, message, cc, reply_to_real_address, sender_email_address): """Send a user message (email) to ``user``. """ @@ -468,7 +469,9 @@ class User(MappedClass, ActivityNode, ActivityObject, SearchIndexable): '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') + reply_to = self.get_pref('email_address') + if reply_to_real_address: + reply_to = sender_email_address allura.tasks.mail_tasks.sendsimplemail.post( toaddr=user.get_pref('email_address'), fromaddr=self.get_pref('email_address'), @@ -812,8 +815,9 @@ 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 ac538dd..7296de8 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') + response.mustcontain('<b>From:</b> "Test Admin" <[email protected]>') self.app.post('/u/test-user/profile/send_user_message', params={'subject': 'test subject', @@ -158,23 +158,24 @@ class TestUserProfile(TestController): check.return_value = True gen_message_id.return_value = 'id' test_user = User.by_username('test-user') + test_admin = User.by_username('test-admin') test_user.set_pref('email_address', '[email protected]') 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') + response.mustcontain('<b>From:</b> "Test Admin" <[email protected]>') 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 + sender_address = test_admin.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, + reply_to=sender_address, message_id='id', subject='test subject')
