mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-09 12:30:15 +02:00
* Hooks registration, discovery and retrieval module Will discover @hooks.register decorated functions inside the auth_hooks module in any installed django app. * Class to register modular service apps * Register service modules URLs * Example service module * Refactor services into modules Each service type has been split out into its own django app/module. A hook mechanism is provided to register a subclass of the ServiceHook class. The modules then overload functions defined in ServiceHook as required to provide interoperability with alliance auth. Service modules provide their own urls and views for user registration and account management and a partial template to display on the services page. Where possible, new modules should provide their own models for local data storage. * Added menu items hooks and template tags * Added menu item hook for broadcasts * Added str method to ServicesHook * Added exception handling to hook iterators * Refactor mumble migration and table name Upgrading will require `migrate mumble --fake-initial` to be run first and then `migrate mumble` to rename the table. * Refactor teamspeak3 migration and rename table Upgrading will require `migrate teamspeak3 --fake-initial` * Added module models and migrations for refactoring AuthServicesInfo * Migrate AuthServiceInfo fields to service modules models * Added helper for getting a users main character * Added new style celery instance * Changed Discord from AuthServicesInfo to DiscordUser model * Switch celery tasks to staticmethods * Changed Discourse from AuthServicesInfo to DiscourseUser model * Changed IPBoard from AuthServicesInfo to IpboardUser model * Changed Ips4 from AuthServicesInfo to Ips4User model Also added disable service task. This service still needs some love though. Was always missing a deactivate services hook (before refactoring) for reasons I'm unsure of so I'm reluctant to add it without knowing why. * Changed Market from AuthServicesInfo to MarketUser model * Changed Mumble from AuthServicesInfo to MumbleUser model Switched user foreign key to one to one relationship. Removed implicit password change on user exists. Combined regular and blue user creation. * Changed Openfire from AuthServicesInfo to OpenfireUser model * Changed SMF from AuthServicesInfo to SmfUser model Added disable task * Changed Phpbb3 from AuthServicesInfo to Phpbb3User model * Changed XenForo from AuthServicesInfo to XenforoUser model * Changed Teamspeak3 from AuthServicesInfo to Teamspeak3User model * Remove obsolete manager functions * Standardise URL format This will break some callback URLs Discord changes from /discord_callback/ to /discord/callback/ * Removed unnecessary imports * Mirror upstream decorator change * Setup for unit testing * Unit tests for discord service * Added add main character helper * Added Discourse unit tests * Added Ipboard unit tests * Added Ips4 unit tests * Fix naming of market manager, switch to use class methods * Remove unused hook functions * Added market service unit tests * Added corp ticker to add main character helper * Added mumble unit tests * Fix url name and remove namespace * Fix missing return and add missing URL * Added openfire unit tests * Added missing return * Added phpbb3 unit tests * Fix SmfManager naming inconsistency and switch to classmethods * Added smf unit tests * Remove unused functions, Added missing return * Added xenforo unit tests * Added missing return * Fixed reference to old model * Fixed error preventing groups from syncing on reset request * Added teamspeak3 unit tests * Added nose as test runner and some test settings * Added package requirements for running tests * Added unit tests for services signals and tasks * Remove unused tests file * Fix teamspeak3 service signals * Added unit tests for teamspeak3 signals Changed other unit tests setUp to inert signals * Fix password gen and hashing python3 compatibility Fixes #630 Adds unit tests to check the password functions run on both platforms. * Fix unit test to not rely on checking url params * Add Travis CI settings file * Remove default blank values from services models * Added dynamic user model admin actions for syncing service groups * Remove unused search fields * Add hook function for syncing nicknames * Added discord hook for sync nickname * Added user admin model menu actions for sync nickname hook * Remove obsolete code * Rename celery config app to avoid package name clash * Added new style celerybeat schedule configuration periodic_task decorator is depreciated * Added string representations * Added admin pages for services user models * Removed legacy code * Move link discord button to correct template * Remove blank default fields from example model * Disallow empty django setting * Fix typos * Added coverage configuration file * Add coverage and coveralls to travis config Should probably use nose's built in coverage, but this works for now. * Replace AuthServicesInfo get_or_create instances with get Reflects upstream changes to AuthServicesInfo behaviour. * Update mumble user table name * Split out mumble authenticator requirements zeroc-ice seems to cause long build times on travis-ci and isn't required for the core projects functionality or testing.
276 lines
11 KiB
Python
276 lines
11 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Generated by Django 1.10.2 on 2016-12-11 23:14
|
|
from __future__ import unicode_literals
|
|
|
|
from django.db import migrations
|
|
from django.conf import settings
|
|
from django.core.exceptions import ObjectDoesNotExist
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def optional_dependencies():
|
|
"""
|
|
Only require these migrations if the given app
|
|
is installed. If the app isn't installed then
|
|
the relevant AuthServicesInfo field will be LOST
|
|
when the data migration is run.
|
|
"""
|
|
installed_apps = settings.INSTALLED_APPS
|
|
|
|
dependencies = []
|
|
|
|
if 'services.modules.xenforo' in installed_apps:
|
|
dependencies.append(('xenforo', '0001_initial'))
|
|
if 'services.modules.discord' in installed_apps:
|
|
dependencies.append(('discord', '0001_initial'))
|
|
if 'services.modules.discourse' in installed_apps:
|
|
dependencies.append(('discourse', '0001_initial'))
|
|
if 'services.modules.ipboard' in installed_apps:
|
|
dependencies.append(('ipboard', '0001_initial'))
|
|
if 'services.modules.ips4' in installed_apps:
|
|
dependencies.append(('ips4', '0001_initial'))
|
|
if 'services.modules.market' in installed_apps:
|
|
dependencies.append(('market', '0001_initial'))
|
|
if 'services.modules.openfire' in installed_apps:
|
|
dependencies.append(('openfire', '0001_initial'))
|
|
if 'services.modules.smf' in installed_apps:
|
|
dependencies.append(('smf', '0001_initial'))
|
|
if 'services.modules.teamspeak3' in installed_apps:
|
|
dependencies.append(('teamspeak3', '0003_teamspeak3user'))
|
|
if 'services.modules.mumble' in installed_apps:
|
|
dependencies.append(('mumble', '0003_mumbleuser_user'))
|
|
if 'services.modules.phpbb3' in installed_apps:
|
|
dependencies.append(('phpbb3', '0001_initial'))
|
|
|
|
return dependencies
|
|
|
|
|
|
def forward(apps, schema_editor):
|
|
installed_apps = settings.INSTALLED_APPS
|
|
AuthServicesInfo = apps.get_model("authentication", "AuthServicesInfo")
|
|
|
|
XenforoUser = apps.get_model('xenforo', 'XenforoUser') if 'services.modules.xenforo' in installed_apps else None
|
|
DiscordUser = apps.get_model('discord', 'DiscordUser') if 'services.modules.discord' in installed_apps else None
|
|
DiscourseUser = apps.get_model('discourse', 'DiscourseUser') if 'services.modules.discourse' in installed_apps else None
|
|
IpboardUser = apps.get_model('ipboard', 'IpboardUser') if 'services.modules.ipboard' in installed_apps else None
|
|
Ips4User = apps.get_model('ips4', 'Ips4User') if 'services.modules.ips4' in installed_apps else None
|
|
MarketUser = apps.get_model('market', 'MarketUser') if 'services.modules.market' in installed_apps else None
|
|
OpenfireUser = apps.get_model('openfire', 'OpenfireUser') if 'services.modules.openfire' in installed_apps else None
|
|
SmfUser = apps.get_model('smf', 'SmfUser') if 'services.modules.smf' in installed_apps else None
|
|
Teamspeak3User = apps.get_model('teamspeak3', 'Teamspeak3User') if 'services.modules.teamspeak3' in installed_apps else None
|
|
MumbleUser = apps.get_model('mumble', 'MumbleUser') if 'services.modules.mumble' in installed_apps else None
|
|
Phpbb3User = apps.get_model('phpbb3', 'Phpbb3User') if 'services.modules.phpbb3' in installed_apps else None
|
|
|
|
for authinfo in AuthServicesInfo.objects.all():
|
|
user = authinfo.user
|
|
|
|
if XenforoUser is not None and authinfo.xenforo_username:
|
|
logging.debug('Updating Xenforo info for %s' % user.username)
|
|
xfu = XenforoUser()
|
|
xfu.user = user
|
|
xfu.username = authinfo.xenforo_username
|
|
xfu.save()
|
|
|
|
if DiscordUser is not None and authinfo.discord_uid:
|
|
logging.debug('Updating Discord info for %s' % user.username)
|
|
du = DiscordUser()
|
|
du.user = user
|
|
du.uid = authinfo.discord_uid
|
|
du.save()
|
|
|
|
if DiscourseUser is not None and authinfo.discourse_enabled:
|
|
logging.debug('Updating Discourse info for %s' % user.username)
|
|
du = DiscourseUser()
|
|
du.user = user
|
|
du.enabled = authinfo.discourse_enabled
|
|
du.save()
|
|
|
|
if IpboardUser is not None and authinfo.ipboard_username:
|
|
logging.debug('Updating IPBoard info for %s' % user.username)
|
|
ipb = IpboardUser()
|
|
ipb.user = user
|
|
ipb.username = authinfo.ipboard_username
|
|
ipb.save()
|
|
|
|
if Ips4User is not None and authinfo.ips4_id:
|
|
logging.debug('Updating Ips4 info for %s' % user.username)
|
|
ips = Ips4User()
|
|
ips.user = user
|
|
ips.id = authinfo.ips4_id
|
|
ips.username = authinfo.ips4_username
|
|
ips.save()
|
|
|
|
if MarketUser is not None and authinfo.market_username:
|
|
logging.debug('Updating Market info for %s' % user.username)
|
|
mkt = MarketUser()
|
|
mkt.user = user
|
|
mkt.username = authinfo.market_username
|
|
mkt.save()
|
|
|
|
if OpenfireUser is not None and authinfo.jabber_username:
|
|
logging.debug('Updating Openfire (jabber) info for %s' % user.username)
|
|
ofu = OpenfireUser()
|
|
ofu.user = user
|
|
ofu.username = authinfo.jabber_username
|
|
ofu.save()
|
|
|
|
if SmfUser is not None and authinfo.smf_username:
|
|
logging.debug('Updating SMF info for %s' % user.username)
|
|
smf = SmfUser()
|
|
smf.user = user
|
|
smf.username = authinfo.smf_username
|
|
smf.save()
|
|
|
|
if Teamspeak3User is not None and authinfo.teamspeak3_uid:
|
|
logging.debug('Updating Teamspeak3 info for %s' % user.username)
|
|
ts3 = Teamspeak3User()
|
|
ts3.user = user
|
|
ts3.uid = authinfo.teamspeak3_uid
|
|
ts3.perm_key = authinfo.teamspeak3_perm_key
|
|
ts3.save()
|
|
|
|
if MumbleUser is not None and authinfo.mumble_username:
|
|
logging.debug('Updating mumble info for %s' % user.username)
|
|
try:
|
|
mbl = MumbleUser.objects.get(username=authinfo.mumble_username)
|
|
mbl.user = user
|
|
mbl.save()
|
|
except ObjectDoesNotExist:
|
|
logger.warn('AuthServiceInfo mumble_username for {} but no '
|
|
'corresponding record in MumbleUser, dropping'.format(user.username))
|
|
|
|
if Phpbb3User is not None and authinfo.forum_username:
|
|
logging.debug('Updating phpbb3 info for %s' % user.username)
|
|
phb = Phpbb3User()
|
|
phb.user = user
|
|
phb.username = authinfo.forum_username
|
|
phb.save()
|
|
|
|
|
|
def reverse(apps, schema_editor):
|
|
User = apps.get_model('auth', 'User')
|
|
AuthServicesInfo = apps.get_model("authentication", "AuthServicesInfo")
|
|
|
|
for user in User.objects.all():
|
|
authinfo, c = AuthServicesInfo.objects.get_or_create(user=user)
|
|
|
|
if hasattr(user, 'xenforo'):
|
|
logging.debug('Reversing xenforo for %s' % user.username)
|
|
authinfo.xenforo_username = user.xenforo.username
|
|
|
|
if hasattr(user, 'discord'):
|
|
logging.debug('Reversing discord for %s' % user.username)
|
|
authinfo.discord_uid = user.discord.uid
|
|
|
|
if hasattr(user, 'discourse'):
|
|
logging.debug('Reversing discourse for %s' % user.username)
|
|
authinfo.discourse_enabled = user.discourse.enabled
|
|
|
|
if hasattr(user, 'ipboard'):
|
|
logging.debug('Reversing ipboard for %s' % user.username)
|
|
authinfo.ipboard_username = user.ipboard.username
|
|
|
|
if hasattr(user, 'ips4'):
|
|
logging.debug('Reversing ips4 for %s' % user.username)
|
|
authinfo.ips4_id = user.ips4.id
|
|
authinfo.ips4_username = user.ips4.username
|
|
|
|
if hasattr(user, 'market'):
|
|
logging.debug('Reversing market for %s' % user.username)
|
|
authinfo.market_username = user.market.username
|
|
|
|
if hasattr(user, 'openfire'):
|
|
logging.debug('Reversing openfire (jabber) for %s' % user.username)
|
|
authinfo.jabber_username = user.openfire.username
|
|
|
|
if hasattr(user, 'smf'):
|
|
logging.debug('Reversing smf for %s' % user.username)
|
|
authinfo.smf_username = user.smf.username
|
|
|
|
if hasattr(user, 'teamspeak3'):
|
|
logging.debug('Reversing teamspeak3 for %s' % user.username)
|
|
authinfo.teamspeak3_uid = user.teamspeak3.uid
|
|
authinfo.teamspeak3_perm_key = user.teamspeak3.perm_key
|
|
|
|
if hasattr(user, 'mumble'):
|
|
logging.debug('Reversing mumble for %s' % user.username)
|
|
try:
|
|
authinfo.mumble_username = user.mumble.all()[:1].get().username
|
|
except ObjectDoesNotExist:
|
|
logging.debug('Failed to reverse mumble for %s' % user.username)
|
|
|
|
if hasattr(user, 'phpbb3'):
|
|
logging.debug('Reversing phpbb3 for %s' % user.username)
|
|
authinfo.forum_username = user.phpbb3.username
|
|
|
|
logging.debug('Saving AuthServicesInfo for %s ' % user.username)
|
|
authinfo.save()
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = optional_dependencies() + [
|
|
('authentication', '0012_remove_add_delete_authservicesinfo_permissions'),
|
|
]
|
|
|
|
operations = [
|
|
# Migrate data
|
|
migrations.RunPython(forward, reverse),
|
|
# Remove fields
|
|
migrations.RemoveField(
|
|
model_name='authservicesinfo',
|
|
name='discord_uid',
|
|
),
|
|
migrations.RemoveField(
|
|
model_name='authservicesinfo',
|
|
name='discourse_enabled',
|
|
),
|
|
migrations.RemoveField(
|
|
model_name='authservicesinfo',
|
|
name='forum_username',
|
|
),
|
|
migrations.RemoveField(
|
|
model_name='authservicesinfo',
|
|
name='ipboard_username',
|
|
),
|
|
migrations.RemoveField(
|
|
model_name='authservicesinfo',
|
|
name='ips4_id',
|
|
),
|
|
migrations.RemoveField(
|
|
model_name='authservicesinfo',
|
|
name='ips4_username',
|
|
),
|
|
migrations.RemoveField(
|
|
model_name='authservicesinfo',
|
|
name='jabber_username',
|
|
),
|
|
migrations.RemoveField(
|
|
model_name='authservicesinfo',
|
|
name='market_username',
|
|
),
|
|
migrations.RemoveField(
|
|
model_name='authservicesinfo',
|
|
name='mumble_username',
|
|
),
|
|
migrations.RemoveField(
|
|
model_name='authservicesinfo',
|
|
name='smf_username',
|
|
),
|
|
migrations.RemoveField(
|
|
model_name='authservicesinfo',
|
|
name='teamspeak3_perm_key',
|
|
),
|
|
migrations.RemoveField(
|
|
model_name='authservicesinfo',
|
|
name='teamspeak3_uid',
|
|
),
|
|
migrations.RemoveField(
|
|
model_name='authservicesinfo',
|
|
name='xenforo_username',
|
|
),
|
|
]
|