mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-09 04:20:17 +02:00
* Port to Django 1.10 Initial migrations for current states of all models. Requires faking to retain data. Removed all references to render_to_response, replacing with render shortcut. Same for HttpResponseRedirect to render shortcut. Corrected notification signal import to wait for app registry to finish loading. * Correct typos from render conversion * Modify models to suppress Django field warnings * Script for automatic database conversion - fakes initial migrations to preserve data Include LOGIN_URL setting * Correct context processor import typo * Removed pathfinder support. Current pathfinder versions require SSO, not APIs added to database. Conditionally load additional database definitions only if services are enabled. Prevents errors when running auth without creating all possible databases. * Condense context processors * Include Django 1.10 installation in migrate script Remove syncdb/evolve, replace with migrate for update script * Replaced member/blue perms with user state system Removed sigtracker Initial migrations for default perms and groups Removed perm bootstrapping on first run * Clean up services list * Remove fleet fittings page * Provide action feedback via django messaging Display unread notification count Correct left navbar alignment * Stop storing service passwords. Provide them one time upon activation or reset. Closes #177 * Add group sync buttons to admin site Allow searcing of AuthServicesInfo models Display user main character * Correct button CSS to remove underlines on hover * Added bulk actions to notifications Altered notification default ordering * Centralize API key validation. Remove unused error count on API key model. Restructure API key refresh task to queue all keys per user and await completion. Closes #350 * Example configuration files for supervisor. Copy to /etc/supervisor/conf.d and restart to take effect. Closes #521 Closes #266 * Pre-save receiver for member/blue state switching Removed is_blue field Added link to admin site * Remove all hardcoded URLs from views and templates Correct missing render arguments Closes #540 * Correct celeryd process directory * Migration to automatically set user states. Runs instead of waiting for next API refresh cycle. Should make the transition much easier. * Verify service accounts accessible to member state * Restructure project to remove unnecessary apps. (celerytask, util, portal, registraion apps) Added workarounds for python 3 compatibility. * Correct python2 compatibility * Check services against state being changed to * Python3 compatibility fixes * Relocate x2bool py3 fix * SSO integration for logging in to existing accounts. * Add missing url names for fleetup reverse * Sanitize groupnames before syncing. * Correct trailing slash preventing url resolution * Alter group name sanitization to allow periods and hyphens * Correct state check on pre_save model for corp/alliance group assignment * Remove sigtracker table from old dbs to allow user deletion * Include missing celery configuration * Teamspeak error handling * Prevent celery worker deadlock on async group result wait * Correct active navbar links for translated urls. Correct corp status url resolution for some links. Remove DiscordAuthToken model.
169 lines
7.5 KiB
Python
169 lines
7.5 KiB
Python
from __future__ import unicode_literals
|
|
from services.tasks import validate_services
|
|
from django.contrib.auth.models import Group
|
|
from authentication.models import AuthServicesInfo
|
|
from authentication.states import MEMBER_STATE, BLUE_STATE, NONE_STATE
|
|
from eveonline.models import EveCharacter, EveCorporationInfo
|
|
from notifications import notify
|
|
from django.conf import settings
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def generate_corp_group_name(corpname):
|
|
return 'Corp_' + corpname.replace(' ', '_')
|
|
|
|
|
|
def generate_alliance_group_name(alliancename):
|
|
return 'Alliance_' + alliancename.replace(' ', '_')
|
|
|
|
|
|
def disable_member(user):
|
|
logger.debug("Disabling member %s" % user)
|
|
if user.user_permissions.all().exists():
|
|
logger.info("Clearning user %s permission to deactivate user." % user)
|
|
user.user_permissions.clear()
|
|
if user.groups.all().exists():
|
|
logger.info("Clearing user %s groups to deactivate user." % user)
|
|
user.groups.clear()
|
|
validate_services(user, None)
|
|
|
|
|
|
def make_member(auth):
|
|
logger.debug("Ensuring user %s has member permissions and groups." % auth.user)
|
|
# ensure member is not blue right now
|
|
blue_group, c = Group.objects.get_or_create(name=settings.DEFAULT_BLUE_GROUP)
|
|
if blue_group in auth.user.groups.all():
|
|
logger.info("Removing user %s blue group" % auth.user)
|
|
auth.user.groups.remove(blue_group)
|
|
# make member
|
|
member_group, c = Group.objects.get_or_create(name=settings.DEFAULT_AUTH_GROUP)
|
|
if member_group not in auth.user.groups.all():
|
|
logger.info("Adding user %s to member group" % auth.user)
|
|
auth.user.groups.add(member_group)
|
|
assign_corp_group(auth)
|
|
assign_alliance_group(auth)
|
|
|
|
|
|
def make_blue(auth):
|
|
logger.debug("Ensuring user %s has blue permissions and groups." % auth.user)
|
|
# ensure user is not a member
|
|
member_group, c = Group.objects.get_or_create(name=settings.DEFAULT_AUTH_GROUP)
|
|
if member_group in auth.user.groups.all():
|
|
logger.info("Removing user %s member group" % auth.user)
|
|
auth.user.groups.remove(member_group)
|
|
# make blue
|
|
blue_group, c = Group.objects.get_or_create(name=settings.DEFAULT_BLUE_GROUP)
|
|
if blue_group not in auth.user.groups.all():
|
|
logger.info("Adding user %s to blue group" % auth.user)
|
|
auth.user.groups.add(blue_group)
|
|
assign_corp_group(auth)
|
|
assign_alliance_group(auth)
|
|
|
|
|
|
def determine_membership_by_character(char):
|
|
if settings.IS_CORP:
|
|
if int(char.corporation_id) == int(settings.CORP_ID):
|
|
logger.debug("Character %s in owning corp id %s" % (char, char.corporation_id))
|
|
return MEMBER_STATE
|
|
else:
|
|
if int(char.alliance_id) == int(settings.ALLIANCE_ID):
|
|
logger.debug("Character %s in owning alliance id %s" % (char, char.alliance_id))
|
|
return MEMBER_STATE
|
|
if EveCorporationInfo.objects.filter(corporation_id=char.corporation_id).exists() is False:
|
|
logger.debug("No corp model for character %s corp id %s. Unable to check standings. Non-member." % (
|
|
char, char.corporation_id))
|
|
return NONE_STATE
|
|
else:
|
|
corp = EveCorporationInfo.objects.get(corporation_id=char.corporation_id)
|
|
if corp.is_blue:
|
|
logger.debug("Character %s member of blue corp %s" % (char, corp))
|
|
return BLUE_STATE
|
|
else:
|
|
logger.debug("Character %s member of non-blue corp %s. Non-member." % (char, corp))
|
|
return NONE_STATE
|
|
|
|
|
|
def determine_membership_by_user(user):
|
|
logger.debug("Determining membership of user %s" % user)
|
|
auth, c = AuthServicesInfo.objects.get_or_create(user=user)
|
|
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)
|
|
return determine_membership_by_character(char)
|
|
else:
|
|
logger.debug("Character model matching user %s main character id %s does not exist. Non-member." % (
|
|
user, auth.main_char_id))
|
|
return NONE_STATE
|
|
else:
|
|
logger.debug("User %s has no main character set. Non-member." % user)
|
|
return NONE_STATE
|
|
|
|
|
|
def set_state(user):
|
|
if user.is_active:
|
|
state = determine_membership_by_user(user)
|
|
else:
|
|
state = NONE_STATE
|
|
logger.debug("Assigning user %s to state %s" % (user, state))
|
|
auth = AuthServicesInfo.objects.get_or_create(user=user)[0]
|
|
if auth.state != state:
|
|
auth.state = state
|
|
auth.save()
|
|
notify(user, "Membership State Change", message="You membership state has been changed to %s" % state)
|
|
|
|
|
|
def assign_corp_group(auth):
|
|
corp_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)
|
|
corpname = generate_corp_group_name(char.corporation_name)
|
|
if auth.state == BLUE_STATE and settings.BLUE_CORP_GROUPS:
|
|
logger.debug("Validating blue user %s has corp group assigned." % auth.user)
|
|
corp_group, c = Group.objects.get_or_create(name=corpname)
|
|
elif auth.state == MEMBER_STATE and settings.MEMBER_CORP_GROUPS:
|
|
logger.debug("Validating member %s has corp group assigned." % auth.user)
|
|
corp_group, c = Group.objects.get_or_create(name=corpname)
|
|
else:
|
|
logger.debug("Ensuring %s has no corp groups assigned." % auth.user)
|
|
if corp_group:
|
|
if corp_group not in auth.user.groups.all():
|
|
logger.info("Adding user %s to corp group %s" % (auth.user, corp_group))
|
|
auth.user.groups.add(corp_group)
|
|
for g in auth.user.groups.all():
|
|
if str.startswith(str(g.name), "Corp_"):
|
|
if g != corp_group:
|
|
logger.info("Removing user %s from old corpgroup %s" % (auth.user, 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)
|
|
if auth.state == BLUE_STATE 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 auth.state == MEMBER_STATE 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 %s has no alliance groups assigned." % auth.user)
|
|
else:
|
|
logger.debug("User %s main character %s not in an alliance. Ensuring no alliance group assigned." % (
|
|
auth.user, char))
|
|
if alliance_group:
|
|
if alliance_group not 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 alliance group %s" % (auth.user, g))
|
|
auth.user.groups.remove(g)
|