mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-09 12:30:15 +02:00
Alter user field to OneToOneField Migration to enforce uniqueness pre-change Migration to ensure all users have an AuthServicesInfo Receiver to automatically create one upon user creation Replace AuthServicesInfo.get_or_create with get Prevent deletion of AuthServicesInfo from admin site Remove add and delete permissions from model. Get character names in chunks on corpstats update to prevent HTTP400 when requesting >350(ish) names Include corpstats docs. Update settings docs.
65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Generated by Django 1.10.1 on 2016-09-12 13:04
|
|
from __future__ import unicode_literals
|
|
|
|
from django.db import migrations
|
|
|
|
from authentication.states import MEMBER_STATE, BLUE_STATE, NONE_STATE
|
|
from django.conf import settings
|
|
|
|
def determine_membership_by_character(char, apps):
|
|
if str(char.corporation_id) in settings.STR_CORP_IDS:
|
|
return MEMBER_STATE
|
|
elif str(char.alliance_id) in settings.STR_ALLIANCE_IDS:
|
|
return MEMBER_STATE
|
|
EveCorporationInfo = apps.get_model('eveonline', 'EveCorporationInfo')
|
|
if EveCorporationInfo.objects.filter(corporation_id=char.corporation_id).exists() is False:
|
|
return NONE_STATE
|
|
else:
|
|
corp = EveCorporationInfo.objects.get(corporation_id=char.corporation_id)
|
|
if corp.is_blue:
|
|
return BLUE_STATE
|
|
else:
|
|
return NONE_STATE
|
|
|
|
def determine_membership_by_user(user, apps):
|
|
AuthServicesInfo = apps.get_model('authentication', 'AuthServicesInfo')
|
|
auth = AuthServicesInfo.objects.get(user=user)
|
|
if auth.main_char_id:
|
|
EveCharacter = apps.get_model('eveonline', 'EveCharacter')
|
|
if EveCharacter.objects.filter(character_id=auth.main_char_id).exists():
|
|
char = EveCharacter.objects.get(character_id=auth.main_char_id)
|
|
return determine_membership_by_character(char, apps)
|
|
else:
|
|
return NONE_STATE
|
|
else:
|
|
return NONE_STATE
|
|
|
|
def set_state(user, apps):
|
|
if user.is_active:
|
|
state = determine_membership_by_user(user, apps)
|
|
else:
|
|
state = NONE_STATE
|
|
AuthServicesInfo = apps.get_model('authentication', 'AuthServicesInfo')
|
|
auth = AuthServicesInfo.objects.get(user=user)
|
|
if auth.state != state:
|
|
auth.state = state
|
|
auth.save()
|
|
|
|
def set_initial_state(apps, schema_editor):
|
|
User = apps.get_model('auth', 'User')
|
|
for u in User.objects.all():
|
|
set_state(u, apps)
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('authentication', '0007_remove_authservicesinfo_is_blue'),
|
|
('eveonline', '0001_initial'),
|
|
('auth', '0001_initial'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(set_initial_state, migrations.RunPython.noop)
|
|
]
|