Create a signal that associates a user with an application
This commit is contained in:
parent
7867d49593
commit
490eb6cbff
|
@ -0,0 +1,3 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
|
@ -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)
|
|
@ -0,0 +1,3 @@
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
|
@ -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()
|
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
|
@ -0,0 +1,3 @@
|
||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
# Create your views here.
|
|
@ -43,6 +43,8 @@ INSTALLED_APPS = [
|
||||||
|
|
||||||
'django_scim',
|
'django_scim',
|
||||||
'oauth2_provider',
|
'oauth2_provider',
|
||||||
|
|
||||||
|
'core',
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
|
Loading…
Reference in New Issue