incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [23/36] git commit: [#6888] Invert user message pref to clean up default case
Date Mon, 16 Dec 2013 17:10:02 GMT
[#6888] Invert user message pref to clean up default case

Signed-off-by: Cory Johns <admin1@users.sf.net>


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

Branch: refs/heads/cj/6821
Commit: 1eea58c63d7af0ef278bdc6cfa0c356cafc4fc68
Parents: 3480d9b
Author: Cory Johns <admin1@users.sf.net>
Authored: Thu Dec 12 17:28:22 2013 +0000
Committer: Cory Johns <admin1@users.sf.net>
Committed: Thu Dec 12 17:28:22 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/auth.py                        | 4 ++--
 Allura/allura/ext/user_profile/templates/user_index.html | 2 +-
 Allura/allura/ext/user_profile/user_main.py              | 2 +-
 Allura/allura/lib/plugin.py                              | 3 ---
 Allura/allura/model/auth.py                              | 2 +-
 Allura/allura/templates/user_prefs.html                  | 2 +-
 Allura/allura/tests/functional/test_auth.py              | 6 +++---
 Allura/allura/tests/functional/test_user_profile.py      | 4 ++--
 8 files changed, 11 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1eea58c6/Allura/allura/controllers/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index 6116570..bb6e98f 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -509,8 +509,8 @@ class PreferencesController(BaseController):
 
     @expose()
     @require_post()
-    def user_message(self, allow_user_messages=None):
-        c.user.set_pref('allow_user_messages', allow_user_messages is not None)
+    def user_message(self, allow_user_messages=False):
+        c.user.set_pref('disable_user_messages', not allow_user_messages)
         redirect(request.referer)
 
 class UserInfoController(BaseController):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1eea58c6/Allura/allura/ext/user_profile/templates/user_index.html
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/user_profile/templates/user_index.html b/Allura/allura/ext/user_profile/templates/user_index.html
index 6052f75..41f7f67 100644
--- a/Allura/allura/ext/user_profile/templates/user_index.html
+++ b/Allura/allura/ext/user_profile/templates/user_index.html
@@ -229,7 +229,7 @@
       </div>
     {% endif %}
 
-    {% if user.get_pref('email_address') and c.user.get_pref('email_address') and user.get_pref('allow_user_messages')
%}
+    {% if user.get_pref('email_address') and c.user.get_pref('email_address') and not user.get_pref('disable_user_messages')
%}
     <div class="grid-24">
       <b><a href="send_message">Send me a message</a></b>
     </div>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1eea58c6/Allura/allura/ext/user_profile/user_main.py
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/user_profile/user_main.py b/Allura/allura/ext/user_profile/user_main.py
index b6342f8..793dbf5 100644
--- a/Allura/allura/ext/user_profile/user_main.py
+++ b/Allura/allura/ext/user_profile/user_main.py
@@ -107,7 +107,7 @@ class UserProfileController(BaseController, FeedController):
                     'an email address associated with their account.', 'info')
             redirect(request.referer)
 
-        if not to_user.get_pref('allow_user_messages'):
+        if to_user.get_pref('disable_user_messages'):
             flash('This user has disabled direct email messages', 'info')
             redirect(request.referer)
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1eea58c6/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 955b741..0c6c3b1 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -949,9 +949,6 @@ class LocalUserPreferencesProvider(UserPreferencesProvider):
 
     def get_pref(self, user, pref_name):
         if pref_name in user.preferences:
-            if pref_name == 'allow_user_messages' and user.preferences[pref_name] is None:
-                # allow_user_messages should be True by default
-                user.preferences[pref_name] = True
             return user.preferences[pref_name]
         else:
             return getattr(user, pref_name)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1eea58c6/Allura/allura/model/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index 6d5972e..fb8eaf7 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -320,7 +320,7 @@ class User(MappedClass, ActivityNode, ActivityObject):
             results_per_page=int,
             email_address=str,
             email_format=str,
-            allow_user_messages=bool))
+            disable_user_messages=bool))
 
     #Personal data
     sex=FieldProperty(

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1eea58c6/Allura/allura/templates/user_prefs.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/user_prefs.html b/Allura/allura/templates/user_prefs.html
index 4d75a6f..66b6c99 100644
--- a/Allura/allura/templates/user_prefs.html
+++ b/Allura/allura/templates/user_prefs.html
@@ -162,7 +162,7 @@
     <h2>User Messages</h2>
     <form method="POST" action="user_message">
     <div class="grid-19">
-        <input type="checkbox" id="allow_user_messages" name="allow_user_messages" {%
if c.user.get_pref('allow_user_messages') %} checked {% endif %}>
+        <input type="checkbox" id="allow_user_messages" name="allow_user_messages" {%
if not c.user.get_pref('disable_user_messages') %} checked {% endif %}>
         <label for="allow_user_messages">Allow another user to send me direct email
messages</label>
     </div>
     <label class="grid-4">&nbsp;</label>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1eea58c6/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 242d31b..3159784 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -714,11 +714,11 @@ class TestPreferences(TestController):
 
     @td.with_user_project('test-admin')
     def test_user_message(self):
-        assert M.User.query.get(username='test-admin').get_pref('allow_user_messages')
+        assert not M.User.query.get(username='test-admin').get_pref('disable_user_messages')
         self.app.post('/auth/preferences/user_message')
-        assert not M.User.query.get(username='test-admin').get_pref('allow_user_messages')
+        assert M.User.query.get(username='test-admin').get_pref('disable_user_messages')
         self.app.post('/auth/preferences/user_message', params={'allow_user_messages': 'on'})
-        assert M.User.query.get(username='test-admin').get_pref('allow_user_messages')
+        assert not M.User.query.get(username='test-admin').get_pref('disable_user_messages')
 
 
 class TestPasswordReset(TestController):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1eea58c6/Allura/allura/tests/functional/test_user_profile.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_user_profile.py b/Allura/allura/tests/functional/test_user_profile.py
index cc90e2b..25d6430 100644
--- a/Allura/allura/tests/functional/test_user_profile.py
+++ b/Allura/allura/tests/functional/test_user_profile.py
@@ -134,11 +134,11 @@ class TestUserProfile(TestController):
         assert '<a href="send_message">Send me a message</a>' not in r
 
     @td.with_user_project('test-user')
-    def test_allow_user_messages(self):
+    def test_disable_user_messages(self):
         User.by_username('test-admin').set_pref('email_address', 'admin@example.com')
         test_user = User.by_username('test-user')
         test_user.set_pref('email_address', 'user@example.com')
-        test_user.set_pref('allow_user_messages', False)
+        test_user.set_pref('disable_user_messages', True)
         r = self.app.get('/u/test-user/profile')
         assert '<a href="send_message">Send me a message</a>' not in r
         r = self.app.get('/u/test-user/profile/send_message', status=302)


Mime
View raw message