allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [11/17] git commit: [#7406] force user.display_name usage to go through prefs manager
Date Fri, 13 Jun 2014 18:34:53 GMT
[#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/177929f5
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/177929f5
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/177929f5

Branch: refs/heads/db/7406
Commit: 177929f50b972b4b3e8e2573454b007c06978f43
Parents: 856d780
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Wed Jun 11 21:27:01 2014 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Jun 13 17:51:59 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/177929f5/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/177929f5/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',


Mime
View raw message