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 2014/06/19 17:53:12 UTC

[4/9] git commit: [#7406] force user.display_name usage to go through prefs manager

[#7406] force user.display_name usage to go through prefs manager


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

Branch: refs/heads/master
Commit: ff755b027f097fc770317d8ac7bb05c9ad380555
Parents: d84231f
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Wed Jun 11 21:27:01 2014 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Thu Jun 19 15:52:50 2014 +0000

----------------------------------------------------------------------
 Allura/allura/lib/plugin.py |  5 +++++
 Allura/allura/model/auth.py | 18 +++++++++++++++---
 2 files changed, 20 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/ff755b02/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 2e6000d..697d980 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -1104,6 +1104,11 @@ class LocalUserPreferencesProvider(UserPreferencesProvider):
     def get_pref(self, user, pref_name):
         if pref_name in user.preferences:
             return 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
         else:
             return getattr(user, pref_name)
 

http://git-wip-us.apache.org/repos/asf/allura/blob/ff755b02/Allura/allura/model/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index 6a9d279..df0bc16 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -196,6 +196,16 @@ class AuthGlobals(MappedClass):
         return g.next_uid
 
 
+class FieldPropertyDisplayName(FieldProperty):
+    # display_name is mongo field but only for preference storage
+    # force all requests for this field to use the get_pref mechanism
+
+    def __get__(self, instance, cls=None):
+        if instance is None:
+            return self
+        return instance.get_pref('display_name')
+
+
 class User(MappedClass, ActivityNode, ActivityObject):
     SALT_LEN = 8
 
@@ -214,15 +224,17 @@ class User(MappedClass, ActivityNode, ActivityObject):
     # full mount point: prefs dict
     tool_preferences = FieldProperty({str: {str: None}})
     tool_data = FieldProperty({str: {str: None}})  # entry point: prefs dict
-    display_name = FieldProperty(str)
     disabled = FieldProperty(bool, if_missing=False)
-    # Don't use directly, use get/set_pref() instead
+
+    # Don't use these directly, use get/set_pref() instead
     preferences = FieldProperty(dict(
         results_per_page=int,
         email_address=str,
         email_format=str,
         disable_user_messages=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 :(
+    display_name = FieldPropertyDisplayName(str)
     # Personal data
     sex = FieldProperty(
         S.OneOf('Male', 'Female', 'Other', 'Unknown',