Repository: allura
Updated Branches:
  refs/heads/master 7d48d48e9 -> f597b2e67


[#8191] change html-ony email_format to multipart text + html


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/f597b2e6
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/f597b2e6
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/f597b2e6

Branch: refs/heads/master
Commit: f597b2e6731bf2cfd8610e9bcd6361c92e126134
Parents: 7d48d48
Author: Dave Brondsema <d...@brondsema.net>
Authored: Wed Feb 28 17:01:26 2018 -0500
Committer: Kenton Taylor <ktay...@slashdotmedia.com>
Committed: Wed Mar 7 12:53:48 2018 -0500

----------------------------------------------------------------------
 Allura/allura/lib/plugin.py                      | 12 +++++++++---
 Allura/allura/lib/widgets/subscriptions.py       |  3 +--
 Allura/allura/tasks/mail_tasks.py                | 12 +++---------
 Allura/allura/templates/user_subs.html           |  2 +-
 Allura/allura/tests/functional/test_auth.py      |  7 +------
 ForgeGit/forgegit/tests/model/test_repository.py |  6 ++++--
 6 files changed, 19 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/f597b2e6/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 34fe57a..f7b6fed 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -1499,14 +1499,20 @@ class 
LocalUserPreferencesProvider(UserPreferencesProvider):
 
     def get_pref(self, user, pref_name):
         if pref_name in user.preferences:
-            return user.preferences[pref_name]
+            pref_value = user.preferences[pref_name]
         elif pref_name == 'display_name':
             # get the value directly from ming's internals, bypassing
             # FieldPropertyDisplayName which always calls back to this get_pref
             # method (infinite recursion)
-            return user.__dict__['__ming__'].state.document.display_name
+            pref_value = user.__dict__['__ming__'].state.document.display_name
         else:
-            return getattr(user, pref_name)
+            pref_value = getattr(user, pref_name)
+
+        if pref_name == 'email_format' and pref_value == 'html':
+            # html-only is no longer supported
+            pref_value = 'both'
+
+        return pref_value
 
     def set_pref(self, user, pref_name, pref_value):
         if pref_name == 'display_name' and 
asbool(config.get('activitystream.recording.enabled', False)):

http://git-wip-us.apache.org/repos/asf/allura/blob/f597b2e6/Allura/allura/lib/widgets/subscriptions.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/subscriptions.py 
b/Allura/allura/lib/widgets/subscriptions.py
index 2409d68..142463d 100644
--- a/Allura/allura/lib/widgets/subscriptions.py
+++ b/Allura/allura/lib/widgets/subscriptions.py
@@ -66,8 +66,7 @@ class SubscriptionForm(CsrfForm):
                 show_label=False,
                 options=[
                     ew.Option(py_value='plain', label='Plain Text'),
-                    ew.Option(py_value='html', label='HTML'),
-                    ew.Option(py_value='both', label='Combined')]),
+                    ew.Option(py_value='both', label='HTML')]),
         ]
 
 

http://git-wip-us.apache.org/repos/asf/allura/blob/f597b2e6/Allura/allura/tasks/mail_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/mail_tasks.py 
b/Allura/allura/tasks/mail_tasks.py
index a5af0a6..938f358 100644
--- a/Allura/allura/tasks/mail_tasks.py
+++ b/Allura/allura/tasks/mail_tasks.py
@@ -134,7 +134,7 @@ def create_multipart_msg(text, metalink=None):
     html_msg = mail_util.encode_email_part(html_text, 'html')
 
     multi_msg = mail_util.make_multipart_message(plain_msg, html_msg)
-    return multi_msg, html_msg, plain_msg
+    return multi_msg, plain_msg
 
 
 @task
@@ -149,7 +149,6 @@ def sendmail(fromaddr, destinations, text, reply_to, 
subject,
     '''
     from allura import model as M
     addrs_plain = []
-    addrs_html = []
     addrs_multi = []
     if fromaddr is None:
         fromaddr = g.noreply
@@ -187,21 +186,16 @@ def sendmail(fromaddr, destinations, text, reply_to, 
subject,
                 continue
             if user.get_pref('email_format') == 'plain':
                 addrs_plain.append(addr)
-            elif user.get_pref('email_format') == 'html':
-                addrs_html.append(addr)
             else:
                 addrs_multi.append(addr)
 
-    multi_msg, html_msg, plain_msg = create_multipart_msg(text, metalink)
+    multi_msg, plain_msg = create_multipart_msg(text, metalink)
     smtp_client.sendmail(
         addrs_multi, fromaddr, reply_to, subject, message_id,
         in_reply_to, multi_msg, sender=sender, references=references)
     smtp_client.sendmail(
         addrs_plain, fromaddr, reply_to, subject, message_id,
         in_reply_to, plain_msg, sender=sender, references=references)
-    smtp_client.sendmail(
-        addrs_html, fromaddr, reply_to, subject, message_id,
-        in_reply_to, html_msg, sender=sender, references=references)
 
 
 @task
@@ -245,7 +239,7 @@ def sendsimplemail(
         else:
             toaddr = user.email_address_header()
 
-    multi_msg, html_msg, plain_msg = create_multipart_msg(text)
+    multi_msg, plain_msg = create_multipart_msg(text)
     smtp_client.sendmail(
         [toaddr], fromaddr, reply_to, subject, message_id,
         in_reply_to, multi_msg, sender=sender, references=references, cc=cc, 
to=toaddr)

http://git-wip-us.apache.org/repos/asf/allura/blob/f597b2e6/Allura/allura/templates/user_subs.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/user_subs.html 
b/Allura/allura/templates/user_subs.html
index 15f3a7c..b49e85c 100644
--- a/Allura/allura/templates/user_subs.html
+++ b/Allura/allura/templates/user_subs.html
@@ -29,7 +29,7 @@
   {% if subscriptions %}
     <p><em>Mark tools that you want to subscribe to. Unmark tools that you 
want to unsubscribe from. Press 'Save' button.</em></p>
         <div class="grid-24">
-        {{c.form.display(action='update_subscriptions', 
value=dict(subscriptions=subscriptions, 
email_format=c.user.preferences.email_format))}}
+        {{c.form.display(action='update_subscriptions', 
value=dict(subscriptions=subscriptions, 
email_format=c.user.get_pref('email_format')))}}
         </div>
   {% else%}
     <p>No subscriptions.</p>

http://git-wip-us.apache.org/repos/asf/allura/blob/f597b2e6/Allura/allura/tests/functional/test_auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_auth.py 
b/Allura/allura/tests/functional/test_auth.py
index 07db7da..fa7163e 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -736,11 +736,6 @@ class TestAuth(TestController):
     def test_format_email(self):
         self.app.get('/')  # establish session
         self.app.post('/auth/subscriptions/update_subscriptions',
-                      params={'email_format': 'html', 'subscriptions': '',
-                              '_session_id': self.app.cookies['_session_id']})
-        r = self.app.get('/auth/subscriptions/')
-        assert '<option selected value="html">HTML</option>' in r
-        self.app.post('/auth/subscriptions/update_subscriptions',
                       params={'email_format': 'plain', 'subscriptions': '',
                               '_session_id': self.app.cookies['_session_id']})
         r = self.app.get('/auth/subscriptions/')
@@ -749,7 +744,7 @@ class TestAuth(TestController):
                       params={'email_format': 'both', 'subscriptions': '',
                               '_session_id': self.app.cookies['_session_id']})
         r = self.app.get('/auth/subscriptions/')
-        assert '<option selected value="both">Combined</option>' in r
+        assert '<option selected value="both">HTML</option>' in r
 
     def test_create_account(self):
         r = self.app.get('/auth/create_account')

http://git-wip-us.apache.org/repos/asf/allura/blob/f597b2e6/ForgeGit/forgegit/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py 
b/ForgeGit/forgegit/tests/model/test_repository.py
index bc89736..9412cb4 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -23,6 +23,7 @@ import stat
 import unittest
 import pkg_resources
 import datetime
+import email.iterators
 
 import mock
 from pylons import tmpl_context as c, app_globals as g
@@ -451,10 +452,11 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
         with mock.patch('allura.tasks.mail_tasks.smtp_client.sendmail') as 
sendmail:
             while M.MonQTask.run_ready():  # have to run them all multiple 
times since one task creates another
                 pass
+        multipart_msg = sendmail.call_args_list[0][0][6]
         text_msg = sendmail.call_args_list[1][0][6]
-        html_msg = sendmail.call_args_list[2][0][6]
         text_body = text_msg.get_payload(decode=True)
-        html_body = html_msg.get_payload(decode=True)
+        html_body = email.iterators.typed_subpart_iterator(multipart_msg, 
'text', 'html').next()\
+            .get_payload(decode=True)
 
         # no extra HTML in commit messages
         assert_in('''-----

Reply via email to