Fixes the cron jobs and account validation, enables account deletion

This commit is contained in:
2010-03-14 02:27:16 +00:00
parent 301aa58bf3
commit b6c402f4fa
5 changed files with 28 additions and 19 deletions

View File

@@ -28,6 +28,17 @@ def import_eve_account(api_key, user_id):
#print account_doc.body
dom = minidom.parseString(account_doc.body)
if dom.getElementsByTagName('error'):
try:
account = EVEAccount.objects.get(id=user_id)
except EVEAccount.DoesNotExist:
return
account.api_status = API_STATUS_OTHER_ERROR
account.save()
return
characters_node_children = dom.getElementsByTagName('rowset')[0].childNodes
# Create or retrieve the account last to make sure everything

View File

@@ -3,6 +3,7 @@ import logging
from django_cron import cronScheduler, Job
from eve_api.models.api_player import EVEAccount, EVEPlayerCorporation
import eve_api.api_puller.accounts
from eve_api.api_exceptions import APIAuthException, APINoUserIDException
class UpdateAPIs(Job):
"""

View File

@@ -26,23 +26,16 @@ class RemoveInvalidUsers(Job):
# Check each service account and delete access if they're not allowed
for servacc in ServiceAccount.objects.filter(user=user):
print servacc.service.groups.all()
print user.groups.all()
allowedgroups = servacc.service.groups.all()
print set(servacc.service.groups.all()) & set(servacc.service.groups.all())
if not (set(servacc.service.groups.all()) & set(servacc.service.groups.all())):
if not (set(user.groups.all()) & set(servacc.service.groups.all())):
print "User %s is not in allowed group for %s, deleting account" % (user.username, servacc.service)
#servacc.delete()
servacc.delete()
pass
# For users set to not active, delete all accounts
if not user.is_active:
print "User %s is inactive, deleting related service accounts" % user.username
for servacc in ServiceAccount.objects.filter(user=user):
#servacc.delete()
servacc.delete()
pass

View File

@@ -42,22 +42,23 @@ class SSOUser(models.Model):
# Create a list of Char groups
chargroups = []
for eacc in EVEAccount.objects.filter(user=self.user):
for char in eacc.characters.all():
if char.corporation.group:
chargroups.append(char.corporation.group)
if eacc.api_status == 1:
for char in eacc.characters.all():
if char.corporation.group:
chargroups.append(char.corporation.group)
# Generate the list of groups to add/remove
delgroups = set(set(self.user.groups.all()) & set(corpgroups)) - set(chargroups)
addgroups = set(chargroups) - set(set(self.user.groups.all()) & set(corpgroups))
print "Del:", delgroups
for g in delgroups:
self.user.groups.remove(g)
print "Add:", addgroups
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())
def __str__(self):
return self.user.__str__()

11
test.py
View File

@@ -1,9 +1,12 @@
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from sso.models import Service
from sso.services.jabber import JabberService
from eve_api.cron import UpdateAPIs
b = JabberService()
b = UpdateAPIs()
b.job()
print b.check_user('matalok')
from sso.cron import RemoveInvalidUsers
b = RemoveInvalidUsers()
b.job()