diff --git a/scim_app/core/__init__.py b/scim_app/core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/scim_app/core/admin.py b/scim_app/core/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/scim_app/core/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/scim_app/core/apps.py b/scim_app/core/apps.py new file mode 100644 index 0000000..bc42f7e --- /dev/null +++ b/scim_app/core/apps.py @@ -0,0 +1,14 @@ +from django.apps import AppConfig +from django.db.models.signals import post_save + + +from . import signals + +class CoreConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'core' + + def ready(self) -> None: + from oauth2_provider.models import get_access_token_model + TokenModel = get_access_token_model() + post_save.connect(signals.set_user_on_application_token, sender=TokenModel) diff --git a/scim_app/core/migrations/__init__.py b/scim_app/core/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/scim_app/core/models.py b/scim_app/core/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/scim_app/core/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/scim_app/core/signals.py b/scim_app/core/signals.py new file mode 100644 index 0000000..ff4ce38 --- /dev/null +++ b/scim_app/core/signals.py @@ -0,0 +1,5 @@ +def set_user_on_application_token(sender, **kwargs): + instance = kwargs['instance'] + if kwargs['created'] and not instance.user: + instance.user = sender.user.get_queryset().first() + instance.save() diff --git a/scim_app/core/tests.py b/scim_app/core/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/scim_app/core/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/scim_app/core/views.py b/scim_app/core/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/scim_app/core/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/scim_app/scim_app/settings.py b/scim_app/scim_app/settings.py index 52c4367..8bcc78d 100644 --- a/scim_app/scim_app/settings.py +++ b/scim_app/scim_app/settings.py @@ -43,6 +43,8 @@ INSTALLED_APPS = [ 'django_scim', 'oauth2_provider', + + 'core', ] MIDDLEWARE = [