mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2026-02-10 09:06:21 +01:00
Update to rule all updates. group support and clean up
This commit is contained in:
0
celerytask/__init__.py
Normal file
0
celerytask/__init__.py
Normal file
3
celerytask/admin.py
Normal file
3
celerytask/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
10
celerytask/models.py
Normal file
10
celerytask/models.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from django.db import models
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
class SyncGroupCache(models.Model):
|
||||
groupname = models.CharField(max_length=254)
|
||||
user = models.ForeignKey(User)
|
||||
|
||||
admin.site.register(SyncGroupCache)
|
||||
95
celerytask/tasks.py
Normal file
95
celerytask/tasks.py
Normal file
@@ -0,0 +1,95 @@
|
||||
from models import SyncGroupCache
|
||||
from celery import task
|
||||
from celery.task import periodic_task
|
||||
from celery.task.schedules import crontab
|
||||
from django.contrib.auth.models import User
|
||||
from services.managers.jabber_manager import JabberManager
|
||||
from services.managers.mumble_manager import MumbleManager
|
||||
from services.managers.forum_manager import ForumManager
|
||||
from authentication.models import AuthServicesInfo
|
||||
from django.utils.timezone import timedelta
|
||||
|
||||
|
||||
def update_jabber_groups(user):
|
||||
syncgroups = SyncGroupCache.objects.filter(user=user)
|
||||
authserviceinfo = AuthServicesInfo.objects.get(user=user)
|
||||
groups = []
|
||||
for syncgroup in syncgroups:
|
||||
groups.append(str(syncgroup.groupname))
|
||||
|
||||
if len(groups) == 0:
|
||||
groups.append('empty')
|
||||
|
||||
JabberManager.update_user_groups(authserviceinfo.jabber_username, authserviceinfo.jabber_password, groups)
|
||||
|
||||
|
||||
def update_mumble_groups(user):
|
||||
syncgroups = SyncGroupCache.objects.filter(user=user)
|
||||
authserviceinfo = AuthServicesInfo.objects.get(user=user)
|
||||
groups = []
|
||||
for syncgroup in syncgroups:
|
||||
groups.append(str(syncgroup.groupname))
|
||||
|
||||
if len(groups) == 0:
|
||||
groups.append('empty')
|
||||
|
||||
MumbleManager.update_groups(authserviceinfo.mumble_username, groups)
|
||||
|
||||
|
||||
def update_forum_groups(user):
|
||||
syncgroups = SyncGroupCache.objects.filter(user=user)
|
||||
authserviceinfo = AuthServicesInfo.objects.get(user=user)
|
||||
groups = []
|
||||
for syncgroup in syncgroups:
|
||||
groups.append(str(syncgroup.groupname))
|
||||
|
||||
if len(groups) == 0:
|
||||
groups.append('empty')
|
||||
|
||||
ForumManager.update_groups(authserviceinfo.forum_username, groups)
|
||||
|
||||
|
||||
def add_to_databases(user, groups, syncgroups):
|
||||
update = False
|
||||
for group in groups:
|
||||
syncgroup = syncgroups.filter(groupname=group.name)
|
||||
if not syncgroup:
|
||||
# gotta create group
|
||||
# create syncgroup
|
||||
# create service groups
|
||||
synccache = SyncGroupCache()
|
||||
synccache.groupname = group.name
|
||||
synccache.user = user
|
||||
synccache.save()
|
||||
update = True
|
||||
|
||||
if update:
|
||||
update_jabber_groups(user)
|
||||
update_mumble_groups(user)
|
||||
update_forum_groups(user)
|
||||
|
||||
|
||||
def remove_from_databases(user, groups, syncgroups):
|
||||
update = False
|
||||
for syncgroup in syncgroups:
|
||||
group = groups.filter(name=syncgroup.groupname)
|
||||
|
||||
if not group:
|
||||
syncgroup.delete()
|
||||
update = True
|
||||
|
||||
if update:
|
||||
update_jabber_groups(user)
|
||||
update_mumble_groups(user)
|
||||
update_forum_groups(user)
|
||||
|
||||
|
||||
@periodic_task(run_every=timedelta(seconds=10))
|
||||
#@periodic_task(run_every=crontab(minute="*/1"))
|
||||
def run_databaseUpdate():
|
||||
users = User.objects.all()
|
||||
for user in users:
|
||||
groups = user.groups.all()
|
||||
syncgroups = SyncGroupCache.objects.filter(user=user)
|
||||
add_to_databases(user, groups, syncgroups)
|
||||
remove_from_databases(user, groups, syncgroups)
|
||||
3
celerytask/tests.py
Normal file
3
celerytask/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
3
celerytask/views.py
Normal file
3
celerytask/views.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
Reference in New Issue
Block a user