[Python-modules-commits] [python-social-auth] 54/322: Allow initial definition of protected attributes

Wolfgang Borgert debacle at moszumanska.debian.org
Sat Dec 24 15:12:48 UTC 2016


This is an automated email from the git hooks/post-receive script.

debacle pushed a commit to tag v0.2.10
in repository python-social-auth.

commit 0e411aa2a78136c99ffd36fde232ceef7eb252e3
Author: Matías Aguirre <matiasaguirre at gmail.com>
Date:   Sat Nov 22 21:52:36 2014 -0200

    Allow initial definition of protected attributes
---
 social/pipeline/user.py | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/social/pipeline/user.py b/social/pipeline/user.py
index 9f20cb0..1e9971c 100644
--- a/social/pipeline/user.py
+++ b/social/pipeline/user.py
@@ -73,19 +73,20 @@ def user_details(strategy, details, user=None, *args, **kwargs):
     """Update user details using data from provider."""
     if user:
         changed = False  # flag to track changes
-        protected = strategy.setting('PROTECTED_USER_FIELDS', [])
-        keep = ('username', 'id', 'pk') + tuple(protected)
+        protected = ('username', 'id', 'pk') + \
+                    tuple(strategy.setting('PROTECTED_USER_FIELDS', []))
 
+        # Update user model attributes with the new data sent by the current
+        # provider. Update on some attributes is disabled by default, for
+        # example username and id fields. It's also possible to disable update
+        # on fields defined in SOCIAL_AUTH_PROTECTED_FIELDS.
         for name, value in details.items():
-            # do not update username, it was already generated
-            # do not update configured fields if user already existed
-            if name not in keep and hasattr(user, name):
-                if value and value != getattr(user, name, None):
-                    try:
-                        setattr(user, name, value)
-                        changed = True
-                    except AttributeError:
-                        pass
+            if not hasattr(user, name):
+                continue
+            current_value = getattr(user, name, None)
+            if not current_value or name not in protected:
+                changed |= current_value != value
+                setattr(user, name, value)
 
         if changed:
             strategy.storage.user.changed(user)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-social-auth.git



More information about the Python-modules-commits mailing list