From 7f0454fce00cb9111f6c468dd102b45ccef21168 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Sun, 22 Mar 2020 18:00:47 +0100 Subject: [PATCH] Use new settings of social-auth cf #754 --- umap/settings/base.py | 3 ++- umap/utils.py | 34 ---------------------------------- 2 files changed, 2 insertions(+), 35 deletions(-) diff --git a/umap/settings/base.py b/umap/settings/base.py index 35017990..d244cbbe 100644 --- a/umap/settings/base.py +++ b/umap/settings/base.py @@ -220,6 +220,7 @@ COMPRESS_OFFLINE = True SOCIAL_AUTH_DEFAULT_USERNAME = lambda u: slugify(u) SOCIAL_AUTH_ASSOCIATE_BY_EMAIL = True +SOCIAL_AUTH_NO_DEFAULT_PROTECTED_USER_FIELDS = True LOGIN_URL = "login" SOCIAL_AUTH_LOGIN_REDIRECT_URL = "/login/popup/end/" SOCIAL_AUTH_PIPELINE = ( @@ -232,5 +233,5 @@ SOCIAL_AUTH_PIPELINE = ( 'social_core.pipeline.user.create_user', 'social_core.pipeline.social_auth.associate_user', 'social_core.pipeline.social_auth.load_extra_data', - 'umap.utils.oauth_user_details' + 'social_core.pipeline.user.user_details' ) diff --git a/umap/utils.py b/umap/utils.py index 38fb210d..57d4ce30 100644 --- a/umap/utils.py +++ b/umap/utils.py @@ -109,37 +109,3 @@ def gzip_file(from_path, to_path): with open(from_path, 'rb') as f_in: with gzip.open(to_path, 'wb') as f_out: f_out.writelines(f_in) - -def oauth_user_details(strategy, details, user=None, *args, **kwargs): - """ - This method is a pipeline stage only to be used with social_auth - Note this is a workaround that can break if social_auth is updated - Update user details using data from provider. - """ - if not user: - return - - changed = False # flag to track changes - # uMap fix: remove 'username' from protected fields - protected = ('id', 'pk', 'email') + \ - 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_USER_FIELDS. - for name, value in details.items(): - if value is None or not hasattr(user, name) or name in protected: - continue - - # Check https://github.com/omab/python-social-auth/issues/671 - current_value = getattr(user, name, None) - # uMap fix: update field when value has changed - if current_value == value: - continue - - changed = True - setattr(user, name, value) - - if changed: - strategy.storage.user.changed(user)