Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions authentication/backends/ol_open_id_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,17 @@ class OlOpenIdConnectAuth(OpenIdConnectAuth):
"""

name = "ol-oidc"

def get_user_details(self, response):
"""Get the user details from the API response"""
details = super().get_user_details(response)

return {
**details,
"profile": {
"name": response.get("name", ""),
"email_optin": bool(int(response["email_optin"]))
if "email_optin" in response
else None,
},
}
2 changes: 1 addition & 1 deletion authentication/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AuthenticationHooks:
"""Pluggy hooks specs for authentication"""

@hookspec
def user_created(self, user):
def user_created(self, user, user_data):
"""Trigger actions after a user is created"""


Expand Down
7 changes: 5 additions & 2 deletions authentication/pipeline/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from social_core.exceptions import AuthException

from authentication.hooks import get_plugin_manager
from profiles import api as profile_api


def forbid_hijack(
Expand All @@ -23,14 +24,16 @@ def forbid_hijack(
return {}


def user_created_actions(**kwargs):
def user_created_actions(*, user, details, **kwargs):
"""
Trigger plugins when a user is created
"""
if kwargs.get("is_new"):
pm = get_plugin_manager()
hook = pm.hook
hook.user_created(user=kwargs["user"])
hook.user_created(user=user, user_data=details)
else:
profile_api.ensure_profile(user=user, profile_data=details.get("profile", {}))


def user_onboarding(*, backend, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions authentication/pipeline/user_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def test_user_created_actions(mocker, is_new):
kwargs = {
"user": user,
"is_new": is_new,
"details": {},
}

user_actions.user_created_actions(**kwargs)
Expand Down
3 changes: 2 additions & 1 deletion learning_resources/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ class FavoritesListPlugin:
hookimpl = apps.get_app_config("authentication").hookimpl

@hookimpl
def user_created(self, user):
def user_created(self, user, user_data): # noqa: ARG002
"""
Perform functions on a newly created user

Args:
user(User): The user to create the list for
user_data(dict): the user data
"""
UserList.objects.get_or_create(
author=user, title=FAVORITES_TITLE, defaults={"description": "My Favorites"}
Expand Down
2 changes: 1 addition & 1 deletion learning_resources/plugins_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ def test_favorites_plugin_user_created(existing_list):
UserListFactory.create(
author=user, title=FAVORITES_TITLE, description="My Favorites"
)
FavoritesListPlugin().user_created(user)
FavoritesListPlugin().user_created(user, user_data={})
user.refresh_from_db()
assert user.user_lists.count() == 1
8 changes: 6 additions & 2 deletions main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@
"documentationUri": "",
},
],
"USER_ADAPTER": "profiles.adapters.SCIMProfile",
"USER_MODEL_GETTER": "profiles.adapters.get_user_model_for_scim",
"USER_ADAPTER": "profiles.scim.adapters.LearnSCIMUser",
"USER_MODEL_GETTER": "profiles.scim.adapters.get_user_model_for_scim",
"USER_FILTER_PARSER": "profiles.scim.filters.LearnUserFilterQuery",
}


Expand Down Expand Up @@ -297,6 +298,9 @@
),
urlparse(APP_BASE_URL).netloc,
]
SOCIAL_AUTH_PROTECTED_USER_FIELDS = [
"profile", # this avoids an error because profile is a related model
]

SOCIAL_AUTH_PIPELINE = (
# Checks if an admin user attempts to login/register while hijacking another user.
Expand Down
218 changes: 0 additions & 218 deletions profiles/adapters.py

This file was deleted.

10 changes: 6 additions & 4 deletions profiles/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

from django.apps import apps

from profiles.models import Profile
from profiles.api import ensure_profile


class CreateProfilePlugin:
hookimpl = apps.get_app_config("authentication").hookimpl

@hookimpl
def user_created(self, user):
def user_created(self, user, user_data):
"""
Perform functions on a newly created user

Args:
user(User): The user to create the list for
user(User): the user that was created
user_data(dict): the user data
"""
Profile.objects.get_or_create(user=user)
profile_data = user_data.get("profile", {})
ensure_profile(user, profile_data)
Empty file added profiles/scim/__init__.py
Empty file.
Loading
Loading