From a87ec2764f5c263366bac5ab0a0129e226a93440 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mat=C3=ADas=20Aguirre?= Date: Mon, 17 Oct 2011 05:11:25 -0200 Subject: [PATCH] Issue warnings for deprecated settings. Refs gh-90 --- social_auth/backends/pipeline/__init__.py | 11 +++++++++++ social_auth/backends/pipeline/associate.py | 3 +++ social_auth/backends/pipeline/social.py | 3 +++ social_auth/backends/pipeline/user.py | 19 +++++++++++++------ 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/social_auth/backends/pipeline/__init__.py b/social_auth/backends/pipeline/__init__.py index 360545b..6af8113 100644 --- a/social_auth/backends/pipeline/__init__.py +++ b/social_auth/backends/pipeline/__init__.py @@ -5,8 +5,19 @@ to next pipeline item. Pipelines must take **kwargs parameters to avoid failure. At some point a pipeline entry must create a UserSocialAuth instance and load it to the output if the user logged in correctly. """ +import warnings + +from django.conf import settings + from social_auth.models import User USERNAME = 'username' USERNAME_MAX_LENGTH = User._meta.get_field(USERNAME).max_length + + +def warn_setting(name, func_name): + """Warn about deprecated settings.""" + if hasattr(settings, name): + msg = '%s is deprecated, disable or override "%s" pipeline instead' + warnings.warn(msg % (name, func_name)) diff --git a/social_auth/backends/pipeline/associate.py b/social_auth/backends/pipeline/associate.py index c605dda..1e260fd 100644 --- a/social_auth/backends/pipeline/associate.py +++ b/social_auth/backends/pipeline/associate.py @@ -2,12 +2,15 @@ from django.conf import settings from django.core.exceptions import MultipleObjectsReturned from social_auth.models import User +from social_auth.backends.pipeline import warn_setting def associate_by_email(details, *args, **kwargs): """Return user entry with same email address as one returned on details.""" email = details.get('email') + warn_setting('SOCIAL_AUTH_ASSOCIATE_BY_MAIL', 'associate_by_email') + if email and getattr(settings, 'SOCIAL_AUTH_ASSOCIATE_BY_MAIL', False): # try to associate accounts registered with the same email address, # only if it's a single object. ValueError is raised if multiple diff --git a/social_auth/backends/pipeline/social.py b/social_auth/backends/pipeline/social.py index d7bb6f1..b1ad80c 100644 --- a/social_auth/backends/pipeline/social.py +++ b/social_auth/backends/pipeline/social.py @@ -2,6 +2,7 @@ from django.conf import settings from django.db.utils import IntegrityError from social_auth.models import User, UserSocialAuth +from social_auth.backends.pipeline import warn_setting def social_auth_user(backend, uid, user=None, *args, **kwargs): @@ -45,6 +46,8 @@ def load_extra_data(backend, details, response, social_user, uid, user, """Load extra data from provider and store it on current UserSocialAuth extra_data field. """ + warn_setting('SOCIAL_AUTH_EXTRA_DATA', 'load_extra_data') + if getattr(settings, 'SOCIAL_AUTH_EXTRA_DATA', True): extra_data = backend.extra_data(user, uid, response, details) if extra_data and social_user.extra_data != extra_data: diff --git a/social_auth/backends/pipeline/user.py b/social_auth/backends/pipeline/user.py index a7c5298..c011ec2 100644 --- a/social_auth/backends/pipeline/user.py +++ b/social_auth/backends/pipeline/user.py @@ -3,7 +3,7 @@ from uuid import uuid4 from django.conf import settings from social_auth.models import User -from social_auth.backends.pipeline import USERNAME, USERNAME_MAX_LENGTH +from social_auth.backends.pipeline import USERNAME, USERNAME_MAX_LENGTH, warn_setting from social_auth.signals import socialauth_not_registered, \ socialauth_registered, \ pre_update @@ -16,10 +16,12 @@ def get_username(details, user=None, *args, **kwargs): if user: return {'username': user.username} - FORCE_RANDOM_USERNAME = getattr(settings, - 'SOCIAL_AUTH_FORCE_RANDOM_USERNAME', - False) - if FORCE_RANDOM_USERNAME: + warn_setting('SOCIAL_AUTH_FORCE_RANDOM_USERNAME', 'get_username') + warn_setting('SOCIAL_AUTH_DEFAULT_USERNAME', 'get_username') + warn_setting('SOCIAL_AUTH_UUID_LENGTH', 'get_username') + warn_setting('SOCIAL_AUTH_USERNAME_FIXER', 'get_username') + + if getattr(settings, 'SOCIAL_AUTH_FORCE_RANDOM_USERNAME', False): username = uuid4().get_hex() elif details.get(USERNAME): username = details[USERNAME] @@ -53,13 +55,16 @@ def get_username(details, user=None, *args, **kwargs): return {'username': final_username} -def create_user(backend, details, response, uid, username, user=None, *args, **kwargs): +def create_user(backend, details, response, uid, username, user=None, *args, + **kwargs): """Create user. Depends on get_username pipeline.""" if user: return {'user': user} if not username: return None + warn_setting('SOCIAL_AUTH_CREATE_USERS', 'create_user') + if not getattr(settings, 'SOCIAL_AUTH_CREATE_USERS', True): # Send signal for cases where tracking failed registering is useful. socialauth_not_registered.send(sender=backend.__class__, @@ -79,6 +84,8 @@ def update_user_details(backend, details, response, user, is_new=False, *args, * """Update user details using data from provider.""" changed = False # flag to track changes + warn_setting('SOCIAL_AUTH_CHANGE_SIGNAL_ONLY', 'update_user_details') + # check if values update should be left to signals handlers only if not getattr(settings, 'SOCIAL_AUTH_CHANGE_SIGNAL_ONLY', False): for name, value in details.iteritems(): -- 2.39.5