mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Moved service enable/disable functions to the update_access() function on the user profile
This will remove the need for the cronjob, but not totally, best still to run the cronjob to catch situations where the permission changes can be missed.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import re
|
||||
import unicodedata
|
||||
import logging
|
||||
|
||||
from django.db import models
|
||||
from django.db.models import signals
|
||||
@@ -36,10 +37,17 @@ class SSOUser(models.Model):
|
||||
icq = models.CharField("ICQ", max_length=15, blank=True)
|
||||
xmpp = models.CharField("XMPP", max_length=200, blank=True)
|
||||
|
||||
@property
|
||||
def _log(self):
|
||||
if not hasattr(self, '__log'):
|
||||
self.__log = logging.getLogger(self.__class__.__name__)
|
||||
return self.__log
|
||||
|
||||
def update_access(self):
|
||||
""" Steps through each Eve API registered to the user and updates their group
|
||||
access accordingly """
|
||||
|
||||
self._log.debug("Update - User %s" % self.user)
|
||||
# Create a list of all Corp groups
|
||||
corpgroups = []
|
||||
for corp in EVEPlayerCorporation.objects.all():
|
||||
@@ -64,7 +72,30 @@ class SSOUser(models.Model):
|
||||
for g in addgroups:
|
||||
self.user.groups.add(g)
|
||||
|
||||
print "%s, Add: %s, Del: %s, Current: %s" % (self.user, addgroups, delgroups, self.user.groups.all())
|
||||
# For users set to not active, delete all accounts
|
||||
if not self.user.is_active:
|
||||
self._log.debug("Inactive - User %s" % (self.user))
|
||||
for servacc in ServiceAccount.objects.filter(user=self.user):
|
||||
servacc.active = 0
|
||||
servacc.save()
|
||||
pass
|
||||
|
||||
# For each of the user's services, check they're in a valid group for it and enable/disable as needed.
|
||||
for servacc in ServiceAccount.objects.filter(user=self.user):
|
||||
if not (set(self.user.groups.all()) & set(servacc.service.groups.all())):
|
||||
if servacc.active:
|
||||
servacc.active = 0
|
||||
servacc.save()
|
||||
self._log.debug("Disabled - User %s, Acc %s" % (self.user, servacc.service))
|
||||
servacc.user.message_set.create(message="Your %s account has been disabled due to lack of permissions. If this is incorrect, check your API keys to see if they are valid" % (servacc.service))
|
||||
pass
|
||||
else:
|
||||
if not servacc.active:
|
||||
servacc.active = 1
|
||||
servacc.save()
|
||||
self._log.debug("Enabled - User %s, Acc %s" % (self.user, servacc.service))
|
||||
servacc.user.message_set.create(message="Your %s account has been re-enabled, you may need to reset your password to access this service again" % (servacc.service))
|
||||
pass
|
||||
|
||||
def __str__(self):
|
||||
return self.user.__str__()
|
||||
|
||||
Reference in New Issue
Block a user