Skip to content

Commit

Permalink
Issue warnings for deprecated settings. Refs gh-90
Browse files Browse the repository at this point in the history
  • Loading branch information
omab committed Oct 17, 2011
1 parent 7f74911 commit a87ec27
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
11 changes: 11 additions & 0 deletions social_auth/backends/pipeline/__init__.py
Expand Up @@ -5,8 +5,19 @@
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))
3 changes: 3 additions & 0 deletions social_auth/backends/pipeline/associate.py
Expand Up @@ -2,12 +2,15 @@
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')

This comment has been minimized.

Copy link
@bendemboski

bendemboski Dec 9, 2011

This isn't quite right. since the getattr() call on line 14 defaults to False, this pipeline component doesn't function without the SOCIAL_AUTH_ASSOCIATE_BY_MAIL setting set. This means that applications cannot use this component's functionality without getting the deprecation warnings. Changing the default value in the getattr() call is probably not a good idea because it would change the behavior for existing applications, so maybe just remove the deprecation warning?

This comment has been minimized.

Copy link
@omab

omab Dec 9, 2011

Author Owner

The warning is there to highlight that the use of the setting is deprecated and will be removed in the near future.


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
Expand Down
3 changes: 3 additions & 0 deletions social_auth/backends/pipeline/social.py
Expand Up @@ -2,6 +2,7 @@
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):
Expand Down Expand Up @@ -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:
Expand Down
19 changes: 13 additions & 6 deletions social_auth/backends/pipeline/user.py
Expand Up @@ -3,7 +3,7 @@
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
Expand All @@ -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]
Expand Down Expand Up @@ -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__,
Expand All @@ -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():
Expand Down

0 comments on commit a87ec27

Please sign in to comment.