mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 14:52:15 +00:00
Move signals to tasks, as they are triggered tasks now
This commit is contained in:
@@ -8,7 +8,6 @@ from django.db.models import signals
|
|||||||
from django.contrib.auth.models import User, UserManager, Group
|
from django.contrib.auth.models import User, UserManager, Group
|
||||||
from django.utils import simplejson as json
|
from django.utils import simplejson as json
|
||||||
|
|
||||||
from sso.tasks import update_user_access
|
|
||||||
from jsonfield.fields import JSONField
|
from jsonfield.fields import JSONField
|
||||||
from eve_api.models import EVEAccount, EVEPlayerCorporation, EVEPlayerAlliance, EVEPlayerCharacter
|
from eve_api.models import EVEAccount, EVEPlayerCorporation, EVEPlayerAlliance, EVEPlayerCharacter
|
||||||
from reddit.models import RedditAccount
|
from reddit.models import RedditAccount
|
||||||
@@ -43,13 +42,7 @@ class SSOUser(models.Model):
|
|||||||
if created:
|
if created:
|
||||||
profile, created = SSOUser.objects.get_or_create(user=instance)
|
profile, created = SSOUser.objects.get_or_create(user=instance)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def eveapi_deleted(sender, instance, **kwargs):
|
|
||||||
if instance.user:
|
|
||||||
update_user_access.delay(user=instance.user)
|
|
||||||
|
|
||||||
signals.post_save.connect(SSOUser.create_user_profile, sender=User)
|
signals.post_save.connect(SSOUser.create_user_profile, sender=User)
|
||||||
signals.post_delete.connect(SSOUser.eveapi_deleted, sender=EVEAccount)
|
|
||||||
|
|
||||||
class SSOUserNote(models.Model):
|
class SSOUserNote(models.Model):
|
||||||
""" Notes bound to a user's account. Used to store information regarding the user """
|
""" Notes bound to a user's account. Used to store information regarding the user """
|
||||||
|
|||||||
17
sso/tasks.py
17
sso/tasks.py
@@ -1,5 +1,16 @@
|
|||||||
from celery.decorators import task
|
from celery.decorators import task
|
||||||
from eve_api.models import *
|
from eve_api.models import EVEAccount, EVEPlayerCorporation, EVEPlayerAlliance
|
||||||
|
from sso.models import ServiceAccount
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
from django.db.models import signals
|
||||||
|
|
||||||
|
# Signals that the tasks need to listen for
|
||||||
|
def eveapi_deleted(sender, instance, **kwargs):
|
||||||
|
if instance.user:
|
||||||
|
update_user_access.delay(user=instance.user)
|
||||||
|
|
||||||
|
signals.post_delete.connect(eveapi_deleted, sender=EVEAccount)
|
||||||
|
|
||||||
|
|
||||||
@task()
|
@task()
|
||||||
def update_user_access(user):
|
def update_user_access(user):
|
||||||
@@ -34,8 +45,6 @@ def update_user_access(user):
|
|||||||
for g in addgroups:
|
for g in addgroups:
|
||||||
user.groups.add(g)
|
user.groups.add(g)
|
||||||
|
|
||||||
from sso.models import ServiceAccount
|
|
||||||
|
|
||||||
# For users set to not active, delete all accounts
|
# For users set to not active, delete all accounts
|
||||||
if not user.is_active:
|
if not user.is_active:
|
||||||
for servacc in ServiceAccount.objects.filter(user=user):
|
for servacc in ServiceAccount.objects.filter(user=user):
|
||||||
@@ -60,8 +69,6 @@ def update_user_access(user):
|
|||||||
|
|
||||||
@task(ignore_result=True)
|
@task(ignore_result=True)
|
||||||
def update_service_groups(user_id):
|
def update_service_groups(user_id):
|
||||||
from sso.models import ServiceAccount
|
|
||||||
|
|
||||||
for service in ServiceAccount.objects.filter(user=user_id, active=True).select_related('service__api'):
|
for service in ServiceAccount.objects.filter(user=user_id, active=True).select_related('service__api'):
|
||||||
api = service.service.api_class
|
api = service.service.api_class
|
||||||
api.update_groups(service.service_uid, service.user.groups.all())
|
api.update_groups(service.service_uid, service.user.groups.all())
|
||||||
|
|||||||
Reference in New Issue
Block a user