Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow per-backend user pipeline settings #677

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions social_core/pipeline/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ def get_username(strategy, details, backend, user=None, *args, **kwargs):
storage = strategy.storage

if not user:
email_as_username = strategy.setting("USERNAME_IS_FULL_EMAIL", False)
uuid_length = strategy.setting("UUID_LENGTH", 16)
email_as_username = backend.setting("USERNAME_IS_FULL_EMAIL", False)
uuid_length = backend.setting("UUID_LENGTH", 16)
max_length = storage.user.username_max_length()
do_slugify = strategy.setting("SLUGIFY_USERNAMES", False)
do_clean = strategy.setting("CLEAN_USERNAMES", True)
do_slugify = backend.setting("SLUGIFY_USERNAMES", False)
do_clean = backend.setting("CLEAN_USERNAMES", True)

def identity_func(val):
return val

if do_clean:
override_clean = strategy.setting("CLEAN_USERNAME_FUNCTION")
override_clean = backend.setting("CLEAN_USERNAME_FUNCTION")
if override_clean:
clean_func = module_member(override_clean)
else:
Expand All @@ -30,7 +30,7 @@ def identity_func(val):
clean_func = identity_func

if do_slugify:
override_slug = strategy.setting("SLUGIFY_FUNCTION")
override_slug = backend.setting("SLUGIFY_FUNCTION")
slug_func = module_member(override_slug) if override_slug else slugify
else:
slug_func = identity_func
Expand Down Expand Up @@ -82,7 +82,7 @@ def user_details(strategy, details, backend, user=None, *args, **kwargs):

# Default protected user fields (username, id, pk and email) can be ignored
# by setting the SOCIAL_AUTH_NO_DEFAULT_PROTECTED_USER_FIELDS to True
if strategy.setting("NO_DEFAULT_PROTECTED_USER_FIELDS") is True:
if strategy.setting("NO_DEFAULT_PROTECTED_USER_FIELDS", backend=backend) is True:
protected = ()
else:
protected = (
Expand All @@ -96,13 +96,15 @@ def user_details(strategy, details, backend, user=None, *args, **kwargs):
"is_superuser",
)

protected = protected + tuple(strategy.setting("PROTECTED_USER_FIELDS", []))
protected = protected + tuple(
strategy.setting("PROTECTED_USER_FIELDS", [], backend=backend)
)

# 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.
field_mapping = strategy.setting("USER_FIELD_MAPPING", {}, backend)
field_mapping = strategy.setting("USER_FIELD_MAPPING", {}, backend=backend)
for name, value in details.items():
# Convert to existing user field if mapping exists
name = field_mapping.get(name, name)
Expand All @@ -113,7 +115,9 @@ def user_details(strategy, details, backend, user=None, *args, **kwargs):
if current_value == value:
continue

immutable_fields = tuple(strategy.setting("IMMUTABLE_USER_FIELDS", []))
immutable_fields = tuple(
strategy.setting("IMMUTABLE_USER_FIELDS", [], backend=backend)
)
if name in immutable_fields and current_value:
continue

Expand Down
Loading