mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2026-02-04 22:26:19 +01:00
The Great Services Refactor (#594)
* 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.
This commit is contained in:
@@ -1,22 +1,19 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.text import slugify
|
||||
|
||||
from authentication.models import AuthServicesInfo
|
||||
from eveonline.models import EveCharacter
|
||||
from services.tasks import update_jabber_groups
|
||||
from services.tasks import update_mumble_groups
|
||||
from services.tasks import update_forum_groups
|
||||
from services.tasks import update_ipboard_groups
|
||||
from services.tasks import update_smf_groups
|
||||
from services.tasks import update_teamspeak3_groups
|
||||
from services.tasks import update_discord_groups
|
||||
from services.tasks import update_discord_nickname
|
||||
from services.tasks import update_discourse_groups
|
||||
from alliance_auth.hooks import get_hooks
|
||||
from services.hooks import ServicesHook
|
||||
|
||||
|
||||
@admin.register(AuthServicesInfo)
|
||||
class AuthServicesInfoManager(admin.ModelAdmin):
|
||||
|
||||
@staticmethod
|
||||
def main_character(obj):
|
||||
if obj.main_char_id:
|
||||
@@ -34,120 +31,69 @@ class AuthServicesInfoManager(admin.ModelAdmin):
|
||||
def has_add_permission(request, obj=None):
|
||||
return False
|
||||
|
||||
def sync_jabber(self, request, queryset):
|
||||
count = 0
|
||||
for a in queryset: # queryset filtering doesn't work here?
|
||||
if a.jabber_username != "":
|
||||
update_jabber_groups.delay(a.user.pk)
|
||||
count += 1
|
||||
self.message_user(request, "%s jabber accounts queued for group sync." % count)
|
||||
|
||||
sync_jabber.short_description = "Sync groups for selected jabber accounts"
|
||||
|
||||
def sync_mumble(self, request, queryset):
|
||||
count = 0
|
||||
for a in queryset:
|
||||
if a.mumble_username != "":
|
||||
update_mumble_groups.delay(a.user.pk)
|
||||
count += 1
|
||||
self.message_user(request, "%s mumble accounts queued for group sync." % count)
|
||||
|
||||
sync_mumble.short_description = "Sync groups for selected mumble accounts"
|
||||
|
||||
def sync_forum(self, request, queryset):
|
||||
count = 0
|
||||
for a in queryset:
|
||||
if a.forum_username != "":
|
||||
update_forum_groups.delay(a.user.pk)
|
||||
count += 1
|
||||
self.message_user(request, "%s forum accounts queued for group sync." % count)
|
||||
|
||||
sync_forum.short_description = "Sync groups for selected forum accounts"
|
||||
|
||||
def sync_ipboard(self, request, queryset):
|
||||
count = 0
|
||||
for a in queryset:
|
||||
if a.ipboard_username != "":
|
||||
update_ipboard_groups.delay(a.user.pk)
|
||||
count += 1
|
||||
self.message_user(request, "%s ipboard accounts queued for group sync." % count)
|
||||
|
||||
sync_ipboard.short_description = "Sync groups for selected ipboard accounts"
|
||||
|
||||
def sync_smf(self, request, queryset):
|
||||
count = 0
|
||||
for a in queryset:
|
||||
if a.smf_username != "":
|
||||
update_smf_groups.delay(a.user.pk)
|
||||
count += 1
|
||||
self.message_user(request, "%s smf accounts queued for group sync." % count)
|
||||
|
||||
sync_smf.short_description = "Sync groups for selected smf accounts"
|
||||
|
||||
def sync_teamspeak(self, request, queryset):
|
||||
count = 0
|
||||
for a in queryset:
|
||||
if a.teamspeak3_uid != "":
|
||||
update_teamspeak3_groups.delay(a.user.pk)
|
||||
count += 1
|
||||
self.message_user(request, "%s teamspeak accounts queued for group sync." % count)
|
||||
|
||||
sync_teamspeak.short_description = "Sync groups for selected teamspeak accounts"
|
||||
|
||||
def sync_discord(self, request, queryset):
|
||||
count = 0
|
||||
for a in queryset:
|
||||
if a.discord_uid != "":
|
||||
update_discord_groups.delay(a.user.pk)
|
||||
count += 1
|
||||
self.message_user(request, "%s discord accounts queued for group sync." % count)
|
||||
|
||||
sync_discord.short_description = "Sync groups for selected discord accounts"
|
||||
|
||||
def sync_discourse(self, request, queryset):
|
||||
count = 0
|
||||
for a in queryset:
|
||||
if a.discourse_enabled:
|
||||
update_discourse_groups.delay(a.user.pk)
|
||||
count += 1
|
||||
self.message_user(request, "%s discourse accounts queued for group sync." % count)
|
||||
|
||||
sync_discourse.short_description = "Sync groups for selected discourse accounts"
|
||||
|
||||
def sync_nicknames(self, request, queryset):
|
||||
count = 0
|
||||
for a in queryset:
|
||||
if a.discord_uid != "":
|
||||
update_discord_nickname(a.user.pk)
|
||||
count += 1
|
||||
self.message_user(request, "%s discord accounts queued for nickname sync." % count)
|
||||
|
||||
sync_nicknames.short_description = "Sync nicknames for selected discord accounts"
|
||||
|
||||
actions = [
|
||||
'sync_jabber',
|
||||
'sync_mumble',
|
||||
'sync_forum',
|
||||
'sync_ipboard',
|
||||
'sync_smf',
|
||||
'sync_teamspeak',
|
||||
'sync_discord',
|
||||
'sync_discourse',
|
||||
'sync_nicknames',
|
||||
]
|
||||
|
||||
search_fields = [
|
||||
'user__username',
|
||||
'ipboard_username',
|
||||
'xenforo_username',
|
||||
'forum_username',
|
||||
'jabber_username',
|
||||
'mumble_username',
|
||||
'teamspeak3_uid',
|
||||
'discord_uid',
|
||||
'ips4_username',
|
||||
'smf_username',
|
||||
'market_username',
|
||||
'main_char_id',
|
||||
]
|
||||
list_display = ('user', 'main_character')
|
||||
|
||||
|
||||
def make_service_hooks_update_groups_action(service):
|
||||
"""
|
||||
Make a admin action for the given service
|
||||
:param service: services.hooks.ServicesHook
|
||||
:return: fn to update services groups for the selected users
|
||||
"""
|
||||
def update_service_groups(modeladmin, request, queryset):
|
||||
for user in queryset: # queryset filtering doesn't work here?
|
||||
service.update_groups(user)
|
||||
|
||||
update_service_groups.__name__ = str('update_{}_groups'.format(slugify(service.name)))
|
||||
update_service_groups.short_description = "Sync groups for selected {} accounts".format(service.title)
|
||||
return update_service_groups
|
||||
|
||||
|
||||
def make_service_hooks_sync_nickname_action(service):
|
||||
"""
|
||||
Make a sync_nickname admin action for the given service
|
||||
:param service: services.hooks.ServicesHook
|
||||
:return: fn to sync nickname for the selected users
|
||||
"""
|
||||
def sync_nickname(modeladmin, request, queryset):
|
||||
for user in queryset: # queryset filtering doesn't work here?
|
||||
service.sync_nickname(user)
|
||||
|
||||
sync_nickname.__name__ = str('sync_{}_nickname'.format(slugify(service.name)))
|
||||
sync_nickname.short_description = "Sync nicknames for selected {} accounts".format(service.title)
|
||||
return sync_nickname
|
||||
|
||||
|
||||
class UserAdmin(BaseUserAdmin):
|
||||
"""
|
||||
Extending Django's UserAdmin model
|
||||
"""
|
||||
def get_actions(self, request):
|
||||
actions = super(BaseUserAdmin, self).get_actions(request)
|
||||
|
||||
for hook in get_hooks('services_hook'):
|
||||
svc = hook()
|
||||
# Check update_groups is redefined/overloaded
|
||||
if svc.update_groups.__module__ != ServicesHook.update_groups.__module__:
|
||||
action = make_service_hooks_update_groups_action(svc)
|
||||
actions[action.__name__] = (action,
|
||||
action.__name__,
|
||||
action.short_description)
|
||||
# Create sync nickname action if service implements it
|
||||
if svc.sync_nickname.__module__ != ServicesHook.sync_nickname.__module__:
|
||||
action = make_service_hooks_sync_nickname_action(svc)
|
||||
actions[action.__name__] = (action,
|
||||
action.__name__,
|
||||
action.short_description)
|
||||
|
||||
return actions
|
||||
|
||||
# Re-register UserAdmin
|
||||
try:
|
||||
admin.site.unregister(User)
|
||||
finally:
|
||||
admin.site.register(User, UserAdmin)
|
||||
|
||||
@@ -24,73 +24,6 @@ class AuthServicesInfoManager:
|
||||
else:
|
||||
logger.error("Failed to update user %s main character id to %s: user does not exist." % (user, char_id))
|
||||
|
||||
@staticmethod
|
||||
def update_user_forum_info(username, user):
|
||||
if User.objects.filter(username=user.username).exists():
|
||||
logger.debug("Updating user %s forum info: username %s" % (user, username))
|
||||
authserviceinfo = AuthServicesInfo.objects.get(user=user)
|
||||
authserviceinfo.forum_username = username
|
||||
authserviceinfo.save(update_fields=['forum_username'])
|
||||
logger.info("Updated user %s forum info in authservicesinfo model." % user)
|
||||
else:
|
||||
logger.error("Failed to update user %s forum info: user does not exist." % user)
|
||||
|
||||
@staticmethod
|
||||
def update_user_jabber_info(username, user):
|
||||
if User.objects.filter(username=user.username).exists():
|
||||
logger.debug("Updating user %s jabber info: username %s" % (user, username))
|
||||
authserviceinfo = AuthServicesInfo.objects.get(user=user)
|
||||
authserviceinfo.jabber_username = username
|
||||
authserviceinfo.save(update_fields=['jabber_username'])
|
||||
logger.info("Updated user %s jabber info in authservicesinfo model." % user)
|
||||
else:
|
||||
logger.error("Failed to update user %s jabber info: user does not exist." % user)
|
||||
|
||||
@staticmethod
|
||||
def update_user_mumble_info(username, user):
|
||||
if User.objects.filter(username=user.username).exists():
|
||||
logger.debug("Updating user %s mumble info: username %s" % (user, username))
|
||||
authserviceinfo = AuthServicesInfo.objects.get(user=user)
|
||||
authserviceinfo.mumble_username = username
|
||||
authserviceinfo.save(update_fields=['mumble_username'])
|
||||
logger.info("Updated user %s mumble info in authservicesinfo model." % user)
|
||||
else:
|
||||
logger.error("Failed to update user %s mumble info: user does not exist." % user)
|
||||
|
||||
@staticmethod
|
||||
def update_user_ipboard_info(username, user):
|
||||
if User.objects.filter(username=user.username).exists():
|
||||
logger.debug("Updating user %s ipboard info: uername %s" % (user, username))
|
||||
authserviceinfo = AuthServicesInfo.objects.get(user=user)
|
||||
authserviceinfo.ipboard_username = username
|
||||
authserviceinfo.save(update_fields=['ipboard_username'])
|
||||
logger.info("Updated user %s ipboard info in authservicesinfo model." % user)
|
||||
else:
|
||||
logger.error("Failed to update user %s ipboard info: user does not exist." % user)
|
||||
|
||||
@staticmethod
|
||||
def update_user_xenforo_info(username, user):
|
||||
if User.objects.filter(username=user.username).exists():
|
||||
logger.debug("Updating user %s xenforo info: uername %s" % (user, username))
|
||||
authserviceinfo = AuthServicesInfo.objects.get(user=user)
|
||||
authserviceinfo.xenforo_username = username
|
||||
authserviceinfo.save(update_fields=['xenforo_username'])
|
||||
logger.info("Updated user %s xenforo info in authservicesinfo model." % user)
|
||||
else:
|
||||
logger.error("Failed to update user %s xenforo info: user does not exist." % user)
|
||||
|
||||
@staticmethod
|
||||
def update_user_teamspeak3_info(uid, perm_key, user):
|
||||
if User.objects.filter(username=user.username).exists():
|
||||
logger.debug("Updating user %s teamspeak3 info: uid %s" % (user, uid))
|
||||
authserviceinfo = AuthServicesInfo.objects.get(user=user)
|
||||
authserviceinfo.teamspeak3_uid = uid
|
||||
authserviceinfo.teamspeak3_perm_key = perm_key
|
||||
authserviceinfo.save(update_fields=['teamspeak3_uid', 'teamspeak3_perm_key'])
|
||||
logger.info("Updated user %s teamspeak3 info in authservicesinfo model." % user)
|
||||
else:
|
||||
logger.error("Failed to update user %s teamspeak3 info: user does not exist." % user)
|
||||
|
||||
@staticmethod
|
||||
def update_is_blue(is_blue, user):
|
||||
if User.objects.filter(username=user.username).exists():
|
||||
@@ -100,51 +33,6 @@ class AuthServicesInfoManager:
|
||||
authserviceinfo.save(update_fields=['is_blue'])
|
||||
logger.info("Updated user %s blue status to %s in authservicesinfo model." % (user, is_blue))
|
||||
|
||||
@staticmethod
|
||||
def update_user_discord_info(user_id, user):
|
||||
if User.objects.filter(username=user.username).exists():
|
||||
logger.debug("Updating user %s discord info: user_id %s" % (user, user_id))
|
||||
authserviceinfo = AuthServicesInfo.objects.get(user=user)
|
||||
authserviceinfo.discord_uid = user_id
|
||||
authserviceinfo.save(update_fields=['discord_uid'])
|
||||
logger.info("Updated user %s discord info in authservicesinfo model." % user)
|
||||
else:
|
||||
logger.error("Failed to update user %s discord info: user does not exist." % user)
|
||||
|
||||
@staticmethod
|
||||
def update_user_ips4_info(username, id, user):
|
||||
if User.objects.filter(username=user.username).exists():
|
||||
logger.debug("Updating user %s IPS4 info: username %s" % (user, username))
|
||||
authserviceinfo = AuthServicesInfo.objects.get(user=user)
|
||||
authserviceinfo.ips4_username = username
|
||||
authserviceinfo.ips4_id = id
|
||||
authserviceinfo.save(update_fields=['ips4_username', 'ips4_id'])
|
||||
logger.info("Updated user %s IPS4 info in authservicesinfo model." % user)
|
||||
else:
|
||||
logger.error("Failed to update user %s IPS4 info: user does not exist." % user)
|
||||
|
||||
@staticmethod
|
||||
def update_user_smf_info(username, user):
|
||||
if User.objects.filter(username=user.username).exists():
|
||||
logger.debug("Updating user %s forum info: username %s" % (user, username))
|
||||
authserviceinfo = AuthServicesInfo.objects.get(user=user)
|
||||
authserviceinfo.smf_username = username
|
||||
authserviceinfo.save(update_fields=['smf_username'])
|
||||
logger.info("Updated user %s smf info in authservicesinfo model." % user)
|
||||
else:
|
||||
logger.error("Failed to update user %s smf info: user does not exist." % user)
|
||||
|
||||
@staticmethod
|
||||
def update_user_market_info(username, user):
|
||||
if User.objects.filter(username=user.username).exists():
|
||||
logger.debug("Updating user %s market info: username %s" % (user, username))
|
||||
authserviceinfo = AuthServicesInfo.objects.get(user=user)
|
||||
authserviceinfo.market_username = username
|
||||
authserviceinfo.save(update_fields=['market_username'])
|
||||
logger.info("Updated user %s market info in authservicesinfo model." % user)
|
||||
else:
|
||||
logger.error("Failed to update user %s market info: user does not exist." % user)
|
||||
|
||||
|
||||
class UserState:
|
||||
def __init__(self):
|
||||
|
||||
275
authentication/migrations/0013_service_modules.py
Normal file
275
authentication/migrations/0013_service_modules.py
Normal file
@@ -0,0 +1,275 @@
|
||||
# -*- 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',
|
||||
),
|
||||
]
|
||||
@@ -16,19 +16,6 @@ class AuthServicesInfo(models.Model):
|
||||
(MEMBER_STATE, 'Member'),
|
||||
)
|
||||
|
||||
ipboard_username = models.CharField(max_length=254, blank=True, default="")
|
||||
xenforo_username = models.CharField(max_length=254, blank=True, default="")
|
||||
forum_username = models.CharField(max_length=254, blank=True, default="")
|
||||
jabber_username = models.CharField(max_length=254, blank=True, default="")
|
||||
mumble_username = models.CharField(max_length=254, blank=True, default="")
|
||||
teamspeak3_uid = models.CharField(max_length=254, blank=True, default="")
|
||||
teamspeak3_perm_key = models.CharField(max_length=254, blank=True, default="")
|
||||
discord_uid = models.CharField(max_length=254, blank=True, default="")
|
||||
discourse_enabled = models.BooleanField(default=False, blank=True)
|
||||
ips4_username = models.CharField(max_length=254, blank=True, default="")
|
||||
ips4_id = models.CharField(max_length=254, blank=True, default="")
|
||||
smf_username = models.CharField(max_length=254, blank=True, default="")
|
||||
market_username = models.CharField(max_length=254, blank=True, default="")
|
||||
main_char_id = models.CharField(max_length=64, blank=True, default="")
|
||||
user = models.OneToOneField(User)
|
||||
state = models.CharField(blank=True, null=True, choices=STATE_CHOICES, default=NONE_STATE, max_length=10)
|
||||
|
||||
Reference in New Issue
Block a user