Return-Path: X-Original-To: apmail-allura-commits-archive@www.apache.org Delivered-To: apmail-allura-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F169D1135E for ; Fri, 13 Jun 2014 18:34:43 +0000 (UTC) Received: (qmail 10481 invoked by uid 500); 13 Jun 2014 18:34:43 -0000 Delivered-To: apmail-allura-commits-archive@allura.apache.org Received: (qmail 10428 invoked by uid 500); 13 Jun 2014 18:34:43 -0000 Mailing-List: contact commits-help@allura.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@allura.apache.org Delivered-To: mailing list commits@allura.apache.org Received: (qmail 10350 invoked by uid 99); 13 Jun 2014 18:34:43 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Jun 2014 18:34:43 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 6778F933C39; Fri, 13 Jun 2014 18:34:43 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: brondsem@apache.org To: commits@allura.apache.org Date: Fri, 13 Jun 2014 18:34:53 -0000 Message-Id: <8c42393d8a3844c588a6613e13483202@git.apache.org> In-Reply-To: <2f24545dbd5348b79b2927140394b8d8@git.apache.org> References: <2f24545dbd5348b79b2927140394b8d8@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [11/17] 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/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 Authored: Wed Jun 11 21:27:01 2014 +0000 Committer: Dave Brondsema 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',