mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-13 22:40:16 +02:00
Merge branch 'master' of https://github.com/R4stl1n/allianceauth into notification
Conflicts: celerytask/tasks.py
This commit is contained in:
commit
58584903bc
@ -221,7 +221,9 @@ FORUM_URL = os.environ.get('AA_FORUM_URL', '')
|
|||||||
DEFAULT_AUTH_GROUP = os.environ.get('AA_DEFAULT_ALLIANCE_GROUP', 'Member')
|
DEFAULT_AUTH_GROUP = os.environ.get('AA_DEFAULT_ALLIANCE_GROUP', 'Member')
|
||||||
DEFAULT_BLUE_GROUP = os.environ.get('AA_DEFAULT_BLUE_GROUP', 'Blue')
|
DEFAULT_BLUE_GROUP = os.environ.get('AA_DEFAULT_BLUE_GROUP', 'Blue')
|
||||||
MEMBER_CORP_GROUPS = 'True' == os.environ.get('AA_MEMBER_CORP_GROUPS', 'True')
|
MEMBER_CORP_GROUPS = 'True' == os.environ.get('AA_MEMBER_CORP_GROUPS', 'True')
|
||||||
|
MEMBER_ALLIANCE_GROUPS = 'True' == os.environ.get('AA_MEMBER_ALLIANCE_GROUPS', 'False')
|
||||||
BLUE_CORP_GROUPS = 'True' == os.environ.get('AA_BLUE_CORP_GROUPS', 'False')
|
BLUE_CORP_GROUPS = 'True' == os.environ.get('AA_BLUE_CORP_GROUPS', 'False')
|
||||||
|
BLUE_ALLIANCE_GROUPS = 'True' == os.environ.get('AA_BLUE_ALLIANCE_GROUPS', 'False')
|
||||||
|
|
||||||
#########################
|
#########################
|
||||||
# Alliance Service Setup
|
# Alliance Service Setup
|
||||||
|
@ -2,7 +2,11 @@ from django.conf import settings
|
|||||||
from celery.task import periodic_task
|
from celery.task import periodic_task
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.auth.models import Group
|
from django.contrib.auth.models import Group
|
||||||
|
<<<<<<< HEAD
|
||||||
from notifications import notify
|
from notifications import notify
|
||||||
|
=======
|
||||||
|
from celery import task
|
||||||
|
>>>>>>> 450f577860abad4644e02eb5a14a58bf047f17b2
|
||||||
from models import SyncGroupCache
|
from models import SyncGroupCache
|
||||||
from celery.task.schedules import crontab
|
from celery.task.schedules import crontab
|
||||||
from services.managers.openfire_manager import OpenfireManager
|
from services.managers.openfire_manager import OpenfireManager
|
||||||
@ -23,6 +27,7 @@ from util import check_if_user_has_permission
|
|||||||
from util.common_task import add_user_to_group
|
from util.common_task import add_user_to_group
|
||||||
from util.common_task import remove_user_from_group
|
from util.common_task import remove_user_from_group
|
||||||
from util.common_task import generate_corp_group_name
|
from util.common_task import generate_corp_group_name
|
||||||
|
from util.common_task import generate_alliance_group_name
|
||||||
from eveonline.models import EveCharacter
|
from eveonline.models import EveCharacter
|
||||||
from eveonline.models import EveCorporationInfo
|
from eveonline.models import EveCorporationInfo
|
||||||
from eveonline.models import EveAllianceInfo
|
from eveonline.models import EveAllianceInfo
|
||||||
@ -275,6 +280,34 @@ def assign_corp_group(auth):
|
|||||||
logger.info("Removing user %s from old corpgroup %s" % (auth.user, g))
|
logger.info("Removing user %s from old corpgroup %s" % (auth.user, g))
|
||||||
auth.user.groups.remove(g)
|
auth.user.groups.remove(g)
|
||||||
|
|
||||||
|
def assign_alliance_group(auth):
|
||||||
|
alliance_group = None
|
||||||
|
if auth.main_char_id:
|
||||||
|
if EveCharacter.objects.filter(character_id=auth.main_char_id).exists():
|
||||||
|
char = EveCharacter.objects.get(character_id=auth.main_char_id)
|
||||||
|
if char.alliance_name:
|
||||||
|
alliancename = generate_alliance_group_name(char.alliance_name)
|
||||||
|
state = determine_membership_by_character(char)
|
||||||
|
if state == "BLUE" and settings.BLUE_ALLIANCE_GROUPS:
|
||||||
|
logger.debug("Validating blue user %s has alliance group assigned." % auth.user)
|
||||||
|
alliance_group, c = Group.objects.get_or_create(name=alliancename)
|
||||||
|
elif state == "MEMBER" and settings.MEMBER_ALLIANCE_GROUPS:
|
||||||
|
logger.debug("Validating member %s has alliance group assigned." % auth.user)
|
||||||
|
alliance_group, c = Group.objects.get_or_create(name=alliancename)
|
||||||
|
else:
|
||||||
|
logger.debug("Ensuring non-member %s has no alliance groups assigned." % auth.user)
|
||||||
|
else:
|
||||||
|
logger.debug("User %s main character %s not in an alliance. Ensuring no allinace group assigned." % (auth.user, char))
|
||||||
|
if alliance_group:
|
||||||
|
if not alliance_group in auth.user.groups.all():
|
||||||
|
logger.info("Adding user %s to alliance group %s" % (auth.user, alliance_group))
|
||||||
|
auth.user.groups.add(alliance_group)
|
||||||
|
for g in auth.user.groups.all():
|
||||||
|
if str.startswith(str(g.name), "Alliance_"):
|
||||||
|
if g != alliance_group:
|
||||||
|
logger.info("Removing user %s from old alliancegroup %s" % (auth.user, g))
|
||||||
|
auth.user.groups.remove(g)
|
||||||
|
|
||||||
def make_member(user):
|
def make_member(user):
|
||||||
change = False
|
change = False
|
||||||
logger.debug("Ensuring user %s has member permissions and groups." % user)
|
logger.debug("Ensuring user %s has member permissions and groups." % user)
|
||||||
@ -305,6 +338,7 @@ def make_member(user):
|
|||||||
auth.save()
|
auth.save()
|
||||||
change = True
|
change = True
|
||||||
assign_corp_group(auth)
|
assign_corp_group(auth)
|
||||||
|
assign_alliance_group(auth)
|
||||||
return change
|
return change
|
||||||
|
|
||||||
def make_blue(user):
|
def make_blue(user):
|
||||||
@ -337,6 +371,7 @@ def make_blue(user):
|
|||||||
auth.save()
|
auth.save()
|
||||||
change = True
|
change = True
|
||||||
assign_corp_group(auth)
|
assign_corp_group(auth)
|
||||||
|
assign_alliance_group(auth)
|
||||||
return change
|
return change
|
||||||
|
|
||||||
def determine_membership_by_character(char):
|
def determine_membership_by_character(char):
|
||||||
@ -551,6 +586,39 @@ def populate_alliance(id, blue=False):
|
|||||||
EveManager.create_corporation_info(corpinfo['id'], corpinfo['name'], corpinfo['ticker'],
|
EveManager.create_corporation_info(corpinfo['id'], corpinfo['name'], corpinfo['ticker'],
|
||||||
corpinfo['members']['current'], blue, alliance)
|
corpinfo['members']['current'], blue, alliance)
|
||||||
|
|
||||||
|
@task
|
||||||
|
def update_alliance(id):
|
||||||
|
alliance = EveAllianceInfo.objects.get(alliance_id=id)
|
||||||
|
corps = EveCorporationInfo.objects.filter(alliance=alliance)
|
||||||
|
logger.debug("Updating alliance %s with %s member corps" % (alliance, len(corps)))
|
||||||
|
allianceinfo = EveApiManager.get_alliance_information(alliance.alliance_id)
|
||||||
|
if allianceinfo:
|
||||||
|
EveManager.update_alliance_info(allianceinfo['id'], allianceinfo['executor_id'],
|
||||||
|
allianceinfo['member_count'], alliance.is_blue)
|
||||||
|
for corp in corps:
|
||||||
|
if corp.corporation_id in allianceinfo['member_corps'] is False:
|
||||||
|
logger.info("Corp %s no longer in alliance %s" % (corp, alliance))
|
||||||
|
corp.alliance = None
|
||||||
|
corp.save()
|
||||||
|
populate_alliance(alliance.alliance_id, blue=alliance.is_blue)
|
||||||
|
elif EveApiManager.check_if_alliance_exists(alliance.alliance_id) is False:
|
||||||
|
logger.info("Alliance %s has closed. Deleting model" % alliance)
|
||||||
|
alliance.delete()
|
||||||
|
|
||||||
|
@task
|
||||||
|
def update_corp(id):
|
||||||
|
corp = EveCorporationInfo.objects.get(corporation_id=id)
|
||||||
|
logger.debug("Updating corp %s" % corp)
|
||||||
|
corpinfo = EveApiManager.get_corporation_information(corp.corporation_id)
|
||||||
|
if corpinfo:
|
||||||
|
alliance = None
|
||||||
|
if EveAllianceInfo.objects.filter(alliance_id=corpinfo['alliance']['id']).exists():
|
||||||
|
alliance = EveAllianceInfo.objects.get(alliance_id=corpinfo['alliance']['id'])
|
||||||
|
EveManager.update_corporation_info(corpinfo['id'], corpinfo['members']['current'], alliance, corp.is_blue)
|
||||||
|
elif EveApiManager.check_if_corp_exists(corp.corporation_id) is False:
|
||||||
|
logger.info("Corp %s has closed. Deleting model" % corp)
|
||||||
|
corp.delete()
|
||||||
|
|
||||||
# Run Every 2 hours
|
# Run Every 2 hours
|
||||||
@periodic_task(run_every=crontab(minute=0, hour="*/2"))
|
@periodic_task(run_every=crontab(minute=0, hour="*/2"))
|
||||||
def run_corp_update():
|
def run_corp_update():
|
||||||
@ -624,33 +692,11 @@ def run_corp_update():
|
|||||||
|
|
||||||
# update existing corp models
|
# update existing corp models
|
||||||
for corp in EveCorporationInfo.objects.all():
|
for corp in EveCorporationInfo.objects.all():
|
||||||
logger.debug("Updating corp %s" % corp)
|
update_corp.delay(corp.corporation_id)
|
||||||
corpinfo = EveApiManager.get_corporation_information(corp.corporation_id)
|
|
||||||
if corpinfo:
|
|
||||||
alliance = None
|
|
||||||
if EveAllianceInfo.objects.filter(alliance_id=corpinfo['alliance']['id']).exists():
|
|
||||||
alliance = EveAllianceInfo.objects.get(alliance_id=corpinfo['alliance']['id'])
|
|
||||||
EveManager.update_corporation_info(corpinfo['id'], corpinfo['members']['current'], alliance, corp.is_blue)
|
|
||||||
elif EveApiManager.check_if_corp_exists(corp.corporation_id) is False:
|
|
||||||
logger.info("Corp %s has closed. Deleting model" % corp)
|
|
||||||
corp.delete()
|
|
||||||
|
|
||||||
# update existing alliance models
|
# update existing alliance models
|
||||||
for alliance in EveAllianceInfo.objects.all():
|
for alliance in EveAllianceInfo.objects.all():
|
||||||
logger.debug("Updating alliance %s" % alliance)
|
update_alliance.delay(alliance.alliance_id)
|
||||||
allianceinfo = EveApiManager.get_alliance_information(alliance.alliance_id)
|
|
||||||
if allianceinfo:
|
|
||||||
EveManager.update_alliance_info(allianceinfo['id'], allianceinfo['executor_id'],
|
|
||||||
allianceinfo['member_count'], alliance.is_blue)
|
|
||||||
for corp in EveCorporationInfo.objects.filter(alliance=alliance):
|
|
||||||
if corp.corporation_id in allianceinfo['member_corps'] is False:
|
|
||||||
logger.info("Corp %s no longer in alliance %s" % (corp, alliance))
|
|
||||||
corp.alliance = None
|
|
||||||
corp.save()
|
|
||||||
populate_alliance(alliance.alliance_id, blue=alliance.is_blue)
|
|
||||||
elif EveApiManager.check_if_alliance_exists(alliance.alliance_id) is False:
|
|
||||||
logger.info("Alliance %s has closed. Deleting model" % alliance)
|
|
||||||
alliance.delete()
|
|
||||||
|
|
||||||
# create standings
|
# create standings
|
||||||
standings = EveApiManager.get_corp_standings()
|
standings = EveApiManager.get_corp_standings()
|
||||||
|
@ -170,7 +170,7 @@ class EveApiManager():
|
|||||||
logger.debug("Confirmed id %s is a corp." % corp_id)
|
logger.debug("Confirmed id %s is a corp." % corp_id)
|
||||||
return True
|
return True
|
||||||
except evelink.api.APIError as error:
|
except evelink.api.APIError as error:
|
||||||
logger.exception("APIError occured while checking if id %s is corp. Possibly not corp?" % corp_id)
|
logger.debug("APIError occured while checking if id %s is corp. Possibly not corp?" % corp_id)
|
||||||
|
|
||||||
logger.debug("Unable to verify id %s is corp." % corp_id)
|
logger.debug("Unable to verify id %s is corp." % corp_id)
|
||||||
return False
|
return False
|
||||||
|
114
services/tasks.py
Normal file
114
services/tasks.py
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
from authentication.models import AuthServicesInfo
|
||||||
|
from celerytask.models import SyncGroupCache
|
||||||
|
from django.conf import settings
|
||||||
|
import logging
|
||||||
|
from services.models import UserTSgroup
|
||||||
|
from services.models import AuthTS
|
||||||
|
from services.models import TSgroup
|
||||||
|
from services.models import DiscordAuthToken
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
def disable_teamspeak():
|
||||||
|
if settings.ENABLE_AUTH_TEAMSPEAK3:
|
||||||
|
logger.warn("ENABLE_AUTH_TEAMSPEAK3 still True, after disabling users will still be able to create teamspeak accounts")
|
||||||
|
if settings.ENABLE_BLUE_TEAMSPEAK3:
|
||||||
|
logger.warn("ENABLE_BLUE_TEAMSPEAK3 still True, after disabling blues will still be able to create teamspeak accounts")
|
||||||
|
for auth in AuthServicesInfo.objects.all():
|
||||||
|
if auth.teamspeak3_uid:
|
||||||
|
logger.info("Clearing %s Teamspeak3 UID" % auth.user)
|
||||||
|
auth.teamspeak3_uid = ''
|
||||||
|
auth.save()
|
||||||
|
if auth.teamspeak3_perm_key:
|
||||||
|
logger.info("Clearing %s Teamspeak3 permission key" % auth.user)
|
||||||
|
auth.teamspeak3_perm_key = ''
|
||||||
|
auth.save()
|
||||||
|
logger.info("Deleting all UserTSgroup models")
|
||||||
|
UserTSgroup.objects.all().delete()
|
||||||
|
logger.info("Deleting all AuthTS models")
|
||||||
|
AuthTS.objects.all().delete()
|
||||||
|
logger.info("Deleting all TSgroup models")
|
||||||
|
TSgroup.objects.all().delete()
|
||||||
|
logger.info("Teamspeak3 disabled")
|
||||||
|
|
||||||
|
def disable_forum():
|
||||||
|
if settings.ENABLE_AUTH_FORUM:
|
||||||
|
logger.warn("ENABLE_AUTH_FORUM still True, after disabling users will still be able to create forum accounts")
|
||||||
|
if settings.ENABLE_BLUE_FORUM:
|
||||||
|
logger.warn("ENABLE_BLUE_FORUM still True, after disabling blues will still be able to create forum accounts")
|
||||||
|
for auth in AuthServicesInfo.objects.all():
|
||||||
|
if auth.forum_username:
|
||||||
|
logger.info("Clearing %s forum username" % auth.user)
|
||||||
|
auth.forum_username = ''
|
||||||
|
auth.save()
|
||||||
|
if auth.forum_password:
|
||||||
|
logger.info("Clearing %s forum password" % auth.user)
|
||||||
|
auth.forum_password = ''
|
||||||
|
auth.save()
|
||||||
|
logger.info("Deleting all SyncGroupCache models for forum")
|
||||||
|
SyncGroupCache.objects.filter(servicename="forum").delete()
|
||||||
|
|
||||||
|
def disable_jabber():
|
||||||
|
if settings.ENABLE_AUTH_JABBER:
|
||||||
|
logger.warn("ENABLE_AUTH_JABBER still True, after disabling users will still be able to create jabber accounts")
|
||||||
|
if settings.ENABLE_BLUE_JABBER:
|
||||||
|
logger.warn("ENABLE_BLUE_JABBER still True, after disabling blues will still be able to create jabber accounts")
|
||||||
|
for auth in AuthServicesInfo.objects.all():
|
||||||
|
if auth.jabber_username:
|
||||||
|
logger.info("Clearing %s jabber username" % auth.user)
|
||||||
|
auth.jabber_username = ''
|
||||||
|
auth.save()
|
||||||
|
if auth.jabber_password:
|
||||||
|
logger.info("Clearing %s jabber password" % auth.user)
|
||||||
|
auth.jabber_password = ''
|
||||||
|
auth.save()
|
||||||
|
logger.info("Deleting all SyncGroupCache models for jabber")
|
||||||
|
SyncGroupCache.objects.filter(servicename="jabber").delete()
|
||||||
|
|
||||||
|
def disable_mumble():
|
||||||
|
if settings.ENABLE_AUTH_MUMBLE:
|
||||||
|
logger.warn("ENABLE_AUTH_MUMBLE still True, after disabling users will still be able to create mumble accounts")
|
||||||
|
if settings.ENABLE_BLUE_MUMBLE:
|
||||||
|
logger.warn("ENABLE_BLUE_MUMBLE still True, after disabling blues will still be able to create mumble accounts")
|
||||||
|
for auth in AuthServicesInfo.objects.all():
|
||||||
|
if auth.mumble_username:
|
||||||
|
logger.info("Clearing %s mumble username" % auth.user)
|
||||||
|
auth.mumble_username = ''
|
||||||
|
auth.save()
|
||||||
|
if auth.mumble_password:
|
||||||
|
logger.info("Clearing %s mumble password" % auth.user)
|
||||||
|
auth.mumble_password = ''
|
||||||
|
auth.save()
|
||||||
|
logger.info("Deleting all SyncGroupCache models for mumble")
|
||||||
|
SyncGroupCache.objects.filter(servicename="mumble").delete()
|
||||||
|
|
||||||
|
def disable_ipboard():
|
||||||
|
if settings.ENABLE_AUTH_IPBOARD:
|
||||||
|
logger.warn("ENABLE_AUTH_IPBOARD still True, after disabling users will still be able to create IPBoard accounts")
|
||||||
|
if settings.ENABLE_BLUE_IPBOARD:
|
||||||
|
logger.warn("ENABLE_BLUE_IPBOARD still True, after disabling blues will still be able to create IPBoard accounts")
|
||||||
|
for auth in AuthServicesInfo.objects.all():
|
||||||
|
if auth.ipboard_username:
|
||||||
|
logger.info("Clearing %s ipboard username" % auth.user)
|
||||||
|
auth.ipboard_username = ''
|
||||||
|
auth.save()
|
||||||
|
if auth.ipboard_password:
|
||||||
|
logger.info("Clearing %s ipboard password" % auth.user)
|
||||||
|
auth.ipboard_password = ''
|
||||||
|
auth.save()
|
||||||
|
logger.info("Deleting all SyncGroupCache models for ipboard")
|
||||||
|
SyncGroupCache.objects.filter(servicename="ipboard").delete()
|
||||||
|
|
||||||
|
|
||||||
|
def disable_discord():
|
||||||
|
if settings.ENABLE_AUTH_DISCORD:
|
||||||
|
logger.warn("ENABLE_AUTH_DISCORD still True, after disabling users will still be able to link Discord accounts")
|
||||||
|
if settings.ENABLE_BLUE_DISCORD:
|
||||||
|
logger.warn("ENABLE_BLUE_DISCORD still True, after disabling blues will still be able to link Discord accounts")
|
||||||
|
for auth in AuthServicesInfo.objects.all():
|
||||||
|
if auth.discord_uid:
|
||||||
|
logger.info("Clearing %s Discord UID" % auth.user)
|
||||||
|
auth.discord_uid = ''
|
||||||
|
auth.save()
|
||||||
|
logger.info("Deleting all DiscordAuthToken models")
|
||||||
|
DiscordAuthToken.objects.all().delete()
|
@ -78,3 +78,5 @@ def deactivate_services(user):
|
|||||||
def generate_corp_group_name(corpname):
|
def generate_corp_group_name(corpname):
|
||||||
return 'Corp_' + corpname.replace(' ', '_')
|
return 'Corp_' + corpname.replace(' ', '_')
|
||||||
|
|
||||||
|
def generate_alliance_group_name(alliancename):
|
||||||
|
return 'Alliance_' + alliancename.replace(' ', '_')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user