Skip to content

Commit 5058a28

Browse files
authored
Ensure default favorites list gets created for new scim users (#2364)
* calling plugin method for new users * Revert "calling plugin method for new users" This reverts commit d8c678d. * adding auth plugin call for scim users * making sure scim adapter calls plugin method for user creation * removing duplicate favorites plugin from defaults * switching to using authentication method
1 parent f0104a0 commit 5058a28

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

main/settings_pluggy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
MITOL_AUTHENTICATION_PLUGINS = get_string(
44
"MITOL_AUTHENTICATION_PLUGINS",
5-
"learning_resources.plugins.FavoritesListPlugin,profiles.plugins.CreateProfilePlugin,learning_resources.plugins.FavoritesListPlugin",
5+
"learning_resources.plugins.FavoritesListPlugin,profiles.plugins.CreateProfilePlugin",
66
)
77
MITOL_LEARNING_RESOURCES_PLUGINS = get_string(
88
"MITOL_LEARNING_RESOURCES_PLUGINS",

users/adapters.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from mitol.scim.adapters import UserAdapter
22

3+
from authentication.api import user_created_actions
34
from profiles.models import Profile
45

56

@@ -45,6 +46,7 @@ def _save_related(self):
4546
"""
4647
self.obj.profile.user = self.obj
4748
self.obj.profile.save()
49+
user_created_actions(user=self.obj, details=self.to_dict(), is_new=True)
4850

4951
def _handle_replace_nested_path(self, nested_path, nested_value):
5052
"""Per-path replacement handling"""

users/adapters_test.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pytest
2+
from django.test import RequestFactory
3+
4+
from main.factories import UserFactory
5+
from users.adapters import LearnUserAdapter
6+
7+
8+
@pytest.mark.django_db
9+
def test_save_related_creates_profile_and_favorites_if_missing(mocker, settings):
10+
"""
11+
Test that saving a LearnUserAdapter creates a profile and default favorites list
12+
"""
13+
settings.MITOL_AUTHENTICATION_PLUGINS = "learning_resources.plugins.FavoritesListPlugin,profiles.plugins.CreateProfilePlugin"
14+
user = UserFactory()
15+
16+
scimUser = LearnUserAdapter(user)
17+
scimUser.request = RequestFactory()
18+
scimUser.obj.request = RequestFactory()
19+
scimUser.from_dict(
20+
{
21+
"userName": "test",
22+
"fullName": {"name": "test"},
23+
"externalId": 123,
24+
"profile": {},
25+
}
26+
)
27+
scimUser.save()
28+
user.refresh_from_db()
29+
assert user.user_lists.count() == 1
30+
# Profile should be linked to user and saved
31+
assert user.profile.user == user

0 commit comments

Comments
 (0)