From 8360371ab7753b06a0214334608bf4a9e152ae0e Mon Sep 17 00:00:00 2001 From: Adarnof Date: Wed, 11 Jan 2017 21:48:20 -0500 Subject: [PATCH] Enforce unique AuthServicesInfo (#618) 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. --- authentication/admin.py | 8 ++ authentication/managers.py | 28 ++-- authentication/migrations/0008_set_state.py | 4 +- .../0010_only_one_authservicesinfo.py | 40 ++++++ ...011_authservicesinfo_user_onetoonefield.py | 22 +++ ...add_delete_authservicesinfo_permissions.py | 39 +++++ authentication/models.py | 5 +- authentication/signals.py | 11 +- authentication/tasks.py | 4 +- corputils/managers.py | 2 +- corputils/models.py | 2 +- docs/features/corpstats.md | 133 ++++++++++++++++++ docs/features/index.md | 1 + docs/installation/auth/settings.md | 108 ++++++++------ eveonline/admin.py | 2 +- eveonline/tasks.py | 2 +- eveonline/views.py | 10 +- groupmanagement/views.py | 6 +- hrapplications/views.py | 4 +- optimer/views.py | 4 +- services/managers/eve_api_manager.py | 2 +- services/signals.py | 2 +- services/tasks.py | 4 +- services/views.py | 80 +++++------ srp/views.py | 4 +- timerboard/views.py | 8 +- 26 files changed, 406 insertions(+), 129 deletions(-) create mode 100644 authentication/migrations/0010_only_one_authservicesinfo.py create mode 100644 authentication/migrations/0011_authservicesinfo_user_onetoonefield.py create mode 100644 authentication/migrations/0012_remove_add_delete_authservicesinfo_permissions.py create mode 100644 docs/features/corpstats.md diff --git a/authentication/admin.py b/authentication/admin.py index a700af4e..22860d17 100644 --- a/authentication/admin.py +++ b/authentication/admin.py @@ -26,6 +26,14 @@ class AuthServicesInfoManager(admin.ModelAdmin): pass return None + @staticmethod + def has_delete_permission(request, obj=None): + return False + + @staticmethod + 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? diff --git a/authentication/managers.py b/authentication/managers.py index a577a05a..f9b2ef7b 100755 --- a/authentication/managers.py +++ b/authentication/managers.py @@ -17,7 +17,7 @@ class AuthServicesInfoManager: def update_main_char_id(char_id, user): if User.objects.filter(username=user.username).exists(): logger.debug("Updating user %s main character to id %s" % (user, char_id)) - authserviceinfo = AuthServicesInfo.objects.get_or_create(user=user)[0] + authserviceinfo = AuthServicesInfo.objects.get(user=user) authserviceinfo.main_char_id = char_id authserviceinfo.save(update_fields=['main_char_id']) logger.info("Updated user %s main character to id %s" % (user, char_id)) @@ -28,7 +28,7 @@ class AuthServicesInfoManager: 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_or_create(user=user)[0] + 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) @@ -39,7 +39,7 @@ class AuthServicesInfoManager: 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_or_create(user=user)[0] + 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) @@ -50,7 +50,7 @@ class AuthServicesInfoManager: 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_or_create(user=user)[0] + 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) @@ -61,7 +61,7 @@ class AuthServicesInfoManager: 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_or_create(user=user)[0] + 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) @@ -72,7 +72,7 @@ class AuthServicesInfoManager: 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_or_create(user=user)[0] + 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) @@ -83,7 +83,7 @@ class AuthServicesInfoManager: 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_or_create(user=user)[0] + 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']) @@ -95,7 +95,7 @@ class AuthServicesInfoManager: def update_is_blue(is_blue, user): if User.objects.filter(username=user.username).exists(): logger.debug("Updating user %s blue status: %s" % (user, is_blue)) - authserviceinfo = AuthServicesInfo.objects.get_or_create(user=user)[0] + authserviceinfo = AuthServicesInfo.objects.get(user=user) authserviceinfo.is_blue = is_blue authserviceinfo.save(update_fields=['is_blue']) logger.info("Updated user %s blue status to %s in authservicesinfo model." % (user, is_blue)) @@ -104,7 +104,7 @@ class AuthServicesInfoManager: 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_or_create(user=user)[0] + 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) @@ -115,7 +115,7 @@ class AuthServicesInfoManager: 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_or_create(user=user)[0] + authserviceinfo = AuthServicesInfo.objects.get(user=user) authserviceinfo.ips4_username = username authserviceinfo.ips4_id = id authserviceinfo.save(update_fields=['ips4_username', 'ips4_id']) @@ -127,7 +127,7 @@ class AuthServicesInfoManager: 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_or_create(user=user)[0] + 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) @@ -138,7 +138,7 @@ class AuthServicesInfoManager: 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_or_create(user=user)[0] + 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) @@ -173,7 +173,7 @@ class UserState: @classmethod def get_membership_state(cls, request): if request.user.is_authenticated: - auth = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + auth = AuthServicesInfo.objects.get(user=request.user) return {'STATE': auth.state} return {'STATE': cls.NONE_STATE} @@ -182,6 +182,6 @@ class UserState: if user.is_superuser and settings.SUPERUSER_STATE_BYPASS: return True if user.is_authenticated: - auth = AuthServicesInfo.objects.get_or_create(user=user)[0] + auth = AuthServicesInfo.objects.get(user=user) return auth.state in states return False diff --git a/authentication/migrations/0008_set_state.py b/authentication/migrations/0008_set_state.py index 41d54420..7fffd92a 100644 --- a/authentication/migrations/0008_set_state.py +++ b/authentication/migrations/0008_set_state.py @@ -24,7 +24,7 @@ def determine_membership_by_character(char, apps): def determine_membership_by_user(user, apps): AuthServicesInfo = apps.get_model('authentication', 'AuthServicesInfo') - auth, c = AuthServicesInfo.objects.get_or_create(user=user) + 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(): @@ -41,7 +41,7 @@ def set_state(user, apps): else: state = NONE_STATE AuthServicesInfo = apps.get_model('authentication', 'AuthServicesInfo') - auth = AuthServicesInfo.objects.get_or_create(user=user)[0] + auth = AuthServicesInfo.objects.get(user=user) if auth.state != state: auth.state = state auth.save() diff --git a/authentication/migrations/0010_only_one_authservicesinfo.py b/authentication/migrations/0010_only_one_authservicesinfo.py new file mode 100644 index 00000000..c93c5387 --- /dev/null +++ b/authentication/migrations/0010_only_one_authservicesinfo.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.1 on 2017-01-07 06:47 +from __future__ import unicode_literals + +from django.db import migrations + +def count_completed_fields(model): + return len([True for key, value in model.__dict__.items() if bool(value)]) + +def forward(apps, schema_editor): + # this ensures only one model exists per user + AuthServicesInfo = apps.get_model('authentication', 'AuthServicesInfo') + users = set([a.user for a in AuthServicesInfo.objects.all()]) + for u in users: + auths = AuthServicesInfo.objects.filter(user=u) + if auths.count() > 1: + pk = auths[0].pk + largest = 0 + for auth in auths: + completed = count_completed_fields(auth) + if completed > largest: + largest = completed + pk = auth.pk + auths.exclude(pk=pk).delete() + + # ensure all users have a model + User = apps.get_model('auth', 'User') + for u in User.objects.exclude(pk__in=[user.pk for user in users]): + AuthServicesInfo.objects.create(user=u) + + +class Migration(migrations.Migration): + + dependencies = [ + ('authentication', '0009_auto_20161021_0228'), + ] + + operations = [ + migrations.RunPython(forward, migrations.RunPython.noop) + ] diff --git a/authentication/migrations/0011_authservicesinfo_user_onetoonefield.py b/authentication/migrations/0011_authservicesinfo_user_onetoonefield.py new file mode 100644 index 00000000..ef83dbec --- /dev/null +++ b/authentication/migrations/0011_authservicesinfo_user_onetoonefield.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.1 on 2017-01-07 07:11 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('authentication', '0010_only_one_authservicesinfo'), + ] + + operations = [ + migrations.AlterField( + model_name='authservicesinfo', + name='user', + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/authentication/migrations/0012_remove_add_delete_authservicesinfo_permissions.py b/authentication/migrations/0012_remove_add_delete_authservicesinfo_permissions.py new file mode 100644 index 00000000..0ba0fdf0 --- /dev/null +++ b/authentication/migrations/0012_remove_add_delete_authservicesinfo_permissions.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-01-12 00:59 +from __future__ import unicode_literals + +from django.db import migrations, models + +def remove_permissions(apps, schema_editor): + ContentType = apps.get_model('contenttypes', 'ContentType') + Permission = apps.get_model('auth', 'Permission') + AuthServicesInfo = apps.get_model('authentication', 'AuthServicesInfo') + + # delete the add and remove permissions for AuthServicesInfo + ct = ContentType.objects.get_for_model(AuthServicesInfo) + Permission.objects.filter(content_type=ct).filter(codename__in=['add_authservicesinfo', 'delete_authservicesinfo']).delete() + + +def add_permissions(apps, schema_editor): + ContentType = apps.get_model('contenttypes', 'ContentType') + Permission = apps.get_model('auth', 'Permission') + AuthServicesInfo = apps.get_model('authentication', 'AuthServicesInfo') + + # recreate the add and remove permissions for AuthServicesInfo + ct = ContentType.objects.get_for_model(AuthServicesInfo) + Permission.objects.create(content_type=ct, codename='add_authservicesinfo', name='Can add auth services info') + Permission.objects.create(content_type=ct, codename='delete_authservicesinfo', name='Can delete auth services info') + +class Migration(migrations.Migration): + + dependencies = [ + ('authentication', '0011_authservicesinfo_user_onetoonefield'), + ] + + operations = [ + migrations.AlterModelOptions( + name='authservicesinfo', + options={'default_permissions': ('change',)}, + ), + migrations.RunPython(remove_permissions, add_permissions), + ] diff --git a/authentication/models.py b/authentication/models.py index 6782e5e8..024c037c 100755 --- a/authentication/models.py +++ b/authentication/models.py @@ -7,6 +7,9 @@ from authentication.states import MEMBER_STATE, BLUE_STATE, NONE_STATE @python_2_unicode_compatible class AuthServicesInfo(models.Model): + class Meta: + default_permissions = ('change',) + STATE_CHOICES = ( (NONE_STATE, 'None'), (BLUE_STATE, 'Blue'), @@ -27,7 +30,7 @@ class AuthServicesInfo(models.Model): 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.ForeignKey(User) + user = models.OneToOneField(User) state = models.CharField(blank=True, null=True, choices=STATE_CHOICES, default=NONE_STATE, max_length=10) def __str__(self): diff --git a/authentication/signals.py b/authentication/signals.py index 929eea6f..452a6af9 100644 --- a/authentication/signals.py +++ b/authentication/signals.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals -from django.db.models.signals import pre_save +from django.db.models.signals import pre_save, post_save from django.dispatch import receiver +from django.contrib.auth.models import User from authentication.models import AuthServicesInfo from authentication.states import MEMBER_STATE, BLUE_STATE from authentication.tasks import make_member, make_blue, disable_member @@ -23,3 +24,11 @@ def pre_save_auth_state(sender, instance, *args, **kwargs): else: disable_member(instance.user) validate_services(instance.user, instance.state) + + +@receiver(post_save, sender=User) +def post_save_user(sender, instance, created, *args, **kwargs): + # ensure all users have a model + if created: + AuthServicesInfo.objects.get_or_create(user=instance) + diff --git a/authentication/tasks.py b/authentication/tasks.py index 7263ca7a..865fa9ba 100644 --- a/authentication/tasks.py +++ b/authentication/tasks.py @@ -85,7 +85,7 @@ def determine_membership_by_character(char): def determine_membership_by_user(user): logger.debug("Determining membership of user %s" % user) - auth, c = AuthServicesInfo.objects.get_or_create(user=user) + auth = AuthServicesInfo.objects.get(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) @@ -105,7 +105,7 @@ def set_state(user): else: state = NONE_STATE logger.debug("Assigning user %s to state %s" % (user, state)) - auth = AuthServicesInfo.objects.get_or_create(user=user)[0] + auth = AuthServicesInfo.objects.get(user=user) if auth.state != state: auth.state = state auth.save() diff --git a/corputils/managers.py b/corputils/managers.py index 8da08ac4..86e984d9 100644 --- a/corputils/managers.py +++ b/corputils/managers.py @@ -9,7 +9,7 @@ class CorpStatsQuerySet(models.QuerySet): if user.is_superuser: return self - auth = AuthServicesInfo.objects.get_or_create(user=user)[0] + auth = AuthServicesInfo.objects.get(user=user) try: char = EveCharacter.objects.get(character_id=auth.main_char_id) # build all accepted queries diff --git a/corputils/models.py b/corputils/models.py index 237bc6e3..8366a86c 100644 --- a/corputils/models.py +++ b/corputils/models.py @@ -89,7 +89,7 @@ class CorpStats(models.Model): return [name for id, name in self.members.items()] def show_apis(self, user): - auth = AuthServicesInfo.objects.get_or_create(user=user)[0] + auth = AuthServicesInfo.objects.get(user=user) if auth.main_char_id: try: char = EveCharacter.objects.get(character_id=auth.main_char_id) diff --git a/docs/features/corpstats.md b/docs/features/corpstats.md new file mode 100644 index 00000000..5325b7b6 --- /dev/null +++ b/docs/features/corpstats.md @@ -0,0 +1,133 @@ +# Corp Stats + +This module is used to check the registration status of corp members and to determine character relationships, being mains or alts. + +## Creating a Corp Stats + +Upon initial install, nothing will be visible. For every corp, a model will have to be created before data can be viewed. + +![nothing is visible](http://i.imgur.com/va3DyT6.png) + +If you are a superuser, the add button will be immediate visible to you. If not, your user account requires the `add_corpstats` permission. + +Corp Stats requires an EVE SSO token to access data from the EVE Swagger Interface. Upon pressing the Add button, you will be prompted to authenticated. Please select the character who is in the corp you want data for. + +![authorize from the EVE site](http://i.imgur.com/OnyoOAZ.png) + +You will return to auth where you are asked to select a token with the green arrow button. If you want to use a different character, press the `LOG IN with EVE Online` button. + +![select an SSO token to create with](http://i.imgur.com/KdA0XH0.png) + +If this works (and you have permission to view the Corp Stats you just created) you'll be returned to a view of the Corp Stats. +If it fails an error message will be displayed. + +## Corp Stats View + +### Navigation Bar + +![navigation bar](http://i.imgur.com/2l9gbml.png) + +This bar contains a dropdown menu of all available corps. If the user has the `add_corpstats` permission, a button to add a Corp Stats will be shown. + +On the right of this bar is a search field. Press enter to search. It checks all characters in all Corp Stats you have view permission to and returns search results. Generic searches (such as 'a') will be slow. + +### API Index + +![API Index](http://i.imgur.com/P1U2WJ2.png) + +This is a visual indication of the number of registered characters. + +### Last Update + +![last update and update button](http://i.imgur.com/yHbueGK.png) + +Corp Stats do not automatically update. They update once upon creation for initial data, and whenever someone presses the update button. + +Only superusers and the creator of the Corp Stat can update it. + +### Member List + +![member list](http://i.imgur.com/udEVoSh.png) + +The list contains all characters in the corp. Red backgrounds means they are not registered in auth. If registered, and the user has the required permission to view APIs, a link to JackKnife will be present. +A link to zKillboard is present for all characters. +If registered, the character will also have a main character, main corporation, and main alliance field. + +This view is paginated: use the navigation arrows to view more pages (sorted alphabetically by character name), or search for a specific character. + +![pagination buttons](http://i.imgur.com/otcPGsU.png) + +## Search View + +![search results](http://i.imgur.com/7wf0Q2C.png) + +This view is essentially the same as the Corp Stats page, but not specific to a single corp. +The search query is visible in the search box. +Characters from all Corp Stats to which the user has view access will be displayed. APIs respect permissions. + +This view is paginated: use the navigation arrows to view more pages (sorted alphabetically by character name). + +## Permissions + +To use this feature, users will require some of the following: + +```eval_rst ++---------------------------------------+------------------+----------------------------------------------------+ +| Permission | Admin Site | Auth Site | ++=======================================+==================+====================================================+ +| corpstats.corp_apis | None | Can view API keys of members of their corporation. | ++---------------------------------------+------------------+----------------------------------------------------+ +| corpstats.alliance_apis | None | Can view API keys of members of their alliance. | ++---------------------------------------+------------------+----------------------------------------------------+ +| corpstats.blue_apis | None | Can view API keys of members of blue corporations. | +----------------------------------------+------------------+----------------------------------------------------+ +| corpstats.view_corp_corpstats | None | Can view corp stats of their corporation. | ++---------------------------------------+------------------+----------------------------------------------------+ +| corpstats.view_alliance_corpstats | None | Can view corp stats of members of their alliance. | ++---------------------------------------+------------------+----------------------------------------------------+ +| corpstats.view_blue_corpstats | None | Can view corp stats of blue corporations. | ++---------------------------------------+------------------+----------------------------------------------------+ +| corpstats.add_corpstats | Can create model | Can add new corpstats using an SSO token. | ++---------------------------------------+------------------+----------------------------------------------------+ +| corpstats.change_corpstats | Can edit model | None. | ++---------------------------------------+------------------+----------------------------------------------------+ +| corpstats.remove_corpstats | Can delete model | None. | ++---------------------------------------+------------------+----------------------------------------------------+ + +``` + +Typical use-cases would see the bundling of `corp_apis` and `view_corp_corpstats`, same for alliances and blues. +Alliance permissions supersede corp permissions. Note that these evaluate against the user's main character. + +## Troubleshooting + +### Failure to create Corp Stats + +>Unrecognized corporation. Please ensure it is a member of the alliance or a blue. + +Corp Stats can only be created for corporations who have a model in the database. These only exist for tenant corps, +corps of tenant alliances, blue corps, and members of blue alliances. + +>Selected corp already has a statistics module. + +Only one Corp Stats may exist at a time for a given corporation. + +>Failed to gather corporation statistics with selected token. + +During initial population, the EVE Swagger Interface did not return any member data. This aborts the creation process. Please wait for the API to start working before attempting to create again. + +### Failure to update Corp Stats + +Any of the following errors will result in a notification to the owning user, and deletion of the Corp Stats model. + +>Your token has expired or is no longer valid. Please add a new one to create a new CorpStats. + +This occurs when the SSO token is invalid, which can occur when deleted by the user, the character is transferred between accounts, or the API is having a bad day. + +>CorpStats for corp_name cannot update with your ESI token as you have left corp. + +The SSO token's character is no longer in the corp which the Corp Stats is for, and therefore membership data cannot be retrieved. + +>HTTPForbidden + +The SSO token lacks the required scopes to update membership data. \ No newline at end of file diff --git a/docs/features/index.md b/docs/features/index.md index 02aac518..c11f0b2d 100644 --- a/docs/features/index.md +++ b/docs/features/index.md @@ -6,4 +6,5 @@ :caption: Contents hrapplications + corpstats ``` diff --git a/docs/installation/auth/settings.md b/docs/installation/auth/settings.md index 5f8d8224..32f44cc0 100644 --- a/docs/installation/auth/settings.md +++ b/docs/installation/auth/settings.md @@ -16,41 +16,35 @@ They're handled as strings because when settings are exported from shell command When changing these booleans, edit the setting within the brackets (eg `('AA_MEMBER_CORP_GROUPS', 'True')` vs `('AA_MEMBER_CORP_GROUPS', 'False')`) and not the `True` earlier in the statement. Otherwise these will have unexpected behaviours. -## Fields to Modify +# Fields to Modify -### Required +## Required - [SECRET_KEY](#secret_key) - Use [this tool](http://www.miniwebtool.com/django-secret-key-generator/) to generate a key on initial install - [DEBUG](#debug) - If issues are encountered, set this to `True` to view a more detailed error report, otherwise set `False` - [ALLOWED_HOSTS](#allowed_hosts) + - This restricts web addresses auth will answer to. Separate with commas. - Should include localhost `127.0.0.1` and `yourdomain.com` + - To allow from all, include `'*'` - [DATABASES](#databases) - Fill out the database name and user credentials to manage the auth database. - - [IS_CORP](#is_corp) - - Set to `True` to run in corp mode, or `False` to run in alliance mode - [DOMAIN](#domain) - Set to the domain name AllianceAuth will be accessible under - [EMAIL_HOST_USER](#email_host_user) - Username to send emails from. If gmail account, the full gmail address. - [EMAIL_HOST_PASSWORD](#email_host_password) - Password for the email user. - - [CORP_ID](#corp_id) - - If running in corp mode, set to the corp ID of the owning corp. - - [CORP_NAME](#corp_name) - - If running in corp mode, set to the name of the owning corp. - - [ALLIANCE_ID](#alliance_id) - - If running in alliance mode, set to the alliance ID of the owning alliance. - - [ALLIANCE_NAME](#alliance_name) - - If running in alliance mode, set to the name of the owning alliance. - - [MEMBER_API_MASK](#member_api_mask) - - Set the minimum access mask for member API keys. - - [MEMBER_API_ACCOUNT](#member_api_account) - - Set to `True` to require member API keys be account keys. - - [BLUE_API_MASK](#blue_api_mask) - - Set the minimum access mask for blue API keys. - - [BLUE_API_ACCOUNT](#blue_api_account) - - Set to `True` to require blue API keys be account keys. + - [CORP_IDS](#corp_ids) + - List of corp IDs who are members. Exclude if their alliance is in `ALLIANCE_IDS` + - [ALLIANCE_IDS](#alliance_ids) + - List of alliance IDs who are members. + - [ESI_SSO_CLIENT_ID](#esi_sso_client_id) + - EVE application ID from the developers site. See the [SSO Configuration Instruction](#ESI_SSO_CLIENT_ID) + - [ESI_SSO_CLIENT_SECRET](#esi_sso_client_secret) + - EVE application secret from the developers site. + - [ESI_SSO_CALLBACK_URL](#esi_sso_callback_url) + - OAuth callback URL. Should be `https://mydomain.com/sso/callback` ## Services ### Member Services @@ -130,6 +124,7 @@ If connecting to Discourse, set the following - [DISCOURSE_URL](#discourse_url) - [DISCOURSE_API_USERNAME](#discourse_api_username) - [DISCOURSE_API_KEY](#discourse_api_key) + - [DISCOURSE_SSO_SECRET](#discourse_sso_secret) ### IPSuite4 If using IPSuite4 (aka IPBoard4) the following are required: @@ -184,9 +179,6 @@ Absolute URL to serve static files from. Root folder to store static files in. ### SUPERUSER_STATE_BYPASS Overrides superuser account states to always return True on membership tests. If issues are encountered, or you want to test access to certain portions of the site, set to False to disable. -## ALLIANCE / CORP TOGGLE -### IS_CORP -Used to determine the criteria used for member and blue validation, either requiring membership in the corp or alliance specified later, and being a standing of the corp or alliance specified later. ## EMAIL SETTINGS ### DOMAIN The URL to which emails will link. @@ -195,11 +187,11 @@ The host address of the email server. ### EMAIL_PORT The host port of the email server. ### EMAIL_HOST_USER -The username to authenticate as on the email server. +The username to authenticate as on the email server. For GMail, this is the full address. ### EMAIL_HOST_PASSWORD The password of the user used to authenticate on the email server. ### EMAIL_USE_TLS -Enable TLS connections to the email server. +Enable TLS connections to the email server. Default is True. ## Front Page Links ### KILLBOARD_URL Link to a killboard. @@ -207,13 +199,15 @@ Link to a killboard. Link to another media site, eg YouTube channel. ### FORUM_URL Link to forums. Also used as the phpbb3 URL if enabled. +### SITE_NAME +Name to show in the top-left corner of auth. ## SSO Settings -If defined below, a `LOG IN WITH EVE ONLINE` button will be present on the login page. This allows registered users to log in as their characters instead of username/password. -### EVE_SSO_CLIENT_ID +An application will need to be created on the developers site. Please select `Authenticated API Access`, and choose all scopes starting with `esi`. +### ESI_SSO_CLIENT_ID The application cliend ID generated from the [developers site.](https://developers.eveonline.com) -### EVE_SSO_CLIENT_SECRET +### ESI_SSO_CLIENT_SECRET The application secret key generated from the [developers site.](https://developers.eveonline.com) -### EVE_SSO_CALLBACK_URL +### ESI_SSO_CALLBACK_URL The callback URL for authentication handshake. Should be `https://mydomain.com/sso/callback`. ## Default Group Settings ### DEFAULT_AUTH_GROUP @@ -276,20 +270,22 @@ Allow blues of the owning corp or alliance to generate accounts on a SMF install Allow blues of the owning corp or alliance to generate accounts on an alliance market install. ### ENABLE_BLUE_XENFORO Allow blues of the owning corp or alliance to generate accounts on a XenForo install. -## Corp Configuration -### CORP_ID -EVE corp ID of the owning corp, if `IS_CORP` is set to `True` -## CORP_NAME -Name of the owning corp, if `IS_CORP` is set to `True` -## CORP_API_ID +## Tenant Configuration +Characters of any corp or alliance with their ID here will be treated as a member. +### CORP_IDS +EVE corp IDs of member corps. Separate with a comma. +### ALLIANCE_IDS +EVE alliance IDs of member alliances. Separate with a comma. +## Standings Configuration +To allow blues to access auth, standings must be pulled from a corp-level API. This API needs access mask 16 (ContactList). +### CORP_API_ID The ID of an API key for a corp from which to pull standings, if desired. Needed for blues to gain access. -## CORP_API_VCODE +### CORP_API_VCODE The verification code of an API key for a corp from which to pull standings, if desired. Needed for blues to gain access. -## Alliance Configuration -### ALLIANCE_ID -EVE alliance ID of the owning alliance, if `IS_CORP` is set to `False` -### ALLIANCE_NAME -Name of the owning alliance, if `IS_CORP` is set to `False` +### BLUE_STANDING +The minimum standing value to consider blue. Default is 5.0 +### STANDING_LEVEL +Standings from the API come at two levels: `corp` and `alliance`. Select which level to consider here. ## API Configuration ### MEMBER_API_MASK Required access mask for members' API keys to be considered valid. @@ -303,10 +299,28 @@ If `True`, require API keys from blues to be account-wide, not character-restric Require each submitted API be newer than the latest submitted API. Protects against recycled or stolen API keys. ### REJECT_OLD_APIS_MARGIN Allows newly submitted APIs to have their ID this value lower than the highest API ID on record and still be accepted. Default is 50, 0 is safest. +## EVE Provider Settings +Data about EVE objects (characters, corps, alliances) can come from two sources: the XML API or the EVE Swagger Interface. +These settings define the default source. + +For most situations, the EVE Swagger Interface is best. But if it goes down or experiences issues, these can be reverted to the XML API. + +Accepted values are `esi` and `xml`. +### EVEONLINE_CHARACTER_PROVIDER +The default data source to get character information. Default is `esi` +### EVEONLINE_CORP_PROVIDER +The default data source to get corporation information. Default is `esi` +### EVEONLINE_ALLIANCE_PROVIDER +The default data source to get alliance information. Default is `esi` +## Alliance Market +### MARKET_URL +The web address to access the Evernus Alliance Market application. +### MARKET_DB +The Evernus Alliance Market database connection information. ## HR Configuration ### JACK_KNIFE_URL Link to an install of [eve-jackknife](https://code.google.com/archive/p/eve-jackknife/) -## Forum Configuration +## IPBoard3 Configuration ### IPBOARD_ENDPOINT URL to the `index.php` file of a IPBoard install's API server. ### IPBOARD_APIKEY @@ -340,6 +354,8 @@ Name of the broadcast service running on an Openfire install. Usually `broadcast ## Mumble Configuration ### MUMBLE_URL Address to instruct members to connect their Mumble clients to. +### MUMBLE_SERVER_ID +Depreciated. We're too scared to delete it. ## Teamspeak3 Configuration ### TEAMSPEAK3_SERVER_IP IP of a Teamspeak3 server on which to manage users. Usually `127.0.0.1` @@ -375,11 +391,13 @@ The web address of the Discourse server to direct users to. Username of the account which generated the API key on Discourse. ### DISCOURSE_API_KEY API key defined on Discourse. +### DISCOURSE_SSO_SECRET +The SSO secret key defined on Discourse. ## IPS4 Configuration ### IPS4_URL URL of the IPSuite4 install to direct users to. ### IPS4_API_KEY -Depreciated. +Depreciated. We're too scared to delete it. ### IPS4_DB The database connection to manage users on. ## SMF Configuration @@ -398,3 +416,7 @@ API ID as [defined on Fleet-Up.](http://fleet-up.com/Api/MyKeys) The group ID from which to pull data. Can be [retrieved from Fleet-Up](http://fleet-up.com/Api/Endpoints#groups_mygroupmemberships) ## Logging Configuration This section is used to manage how logging messages are processed. + +To turn off logging notifications, change the `handlers` `notifications` `class` to `logging.NullHandler` + +## Everything below logging is magic. Do Not Touch \ No newline at end of file diff --git a/eveonline/admin.py b/eveonline/admin.py index 5ef4ffd3..df59046f 100644 --- a/eveonline/admin.py +++ b/eveonline/admin.py @@ -23,7 +23,7 @@ class EveCharacterAdmin(admin.ModelAdmin): @staticmethod def main_character(obj): if obj.user: - auth = AuthServicesInfo.objects.get_or_create(user=obj.user)[0] + auth = AuthServicesInfo.objects.get(user=obj.user) if auth and auth.main_char_id: try: return EveCharacter.objects.get(character_id=auth.main_char_id) diff --git a/eveonline/tasks.py b/eveonline/tasks.py index ed626f2b..109d1ffb 100644 --- a/eveonline/tasks.py +++ b/eveonline/tasks.py @@ -77,7 +77,7 @@ def refresh_user_apis(user): for x in apis: refresh_api(x) # Check our main character - auth = AuthServicesInfo.objects.get_or_create(user=user)[0] + auth = AuthServicesInfo.objects.get(user=user) if auth.main_char_id: if EveCharacter.objects.filter(character_id=auth.main_char_id).exists() is False: logger.info( diff --git a/eveonline/views.py b/eveonline/views.py index 5e7de5f9..3b6acffb 100755 --- a/eveonline/views.py +++ b/eveonline/views.py @@ -51,7 +51,7 @@ def add_api_key(request): logger.info("Successfully processed api add form for user %s" % request.user) if not settings.API_SSO_VALIDATION: messages.success(request, 'Added API key %s to your account.' % form.cleaned_data['api_id']) - auth = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + auth = AuthServicesInfo.objects.get(user=request.user) if not auth.main_char_id: return redirect('auth_characters') return redirect("auth_dashboard") @@ -88,7 +88,7 @@ def api_sso_validate(request, token, api_id): api.save() EveCharacter.objects.filter(character_id__in=characters).update(user=request.user, api_id=api_id) messages.success(request, 'Confirmed ownership of API %s' % api.api_id) - auth, c = AuthServicesInfo.objects.get_or_create(user=request.user) + auth = AuthServicesInfo.objects.get(user=request.user) if not auth.main_char_id: return redirect('auth_characters') return redirect('auth_dashboard') @@ -100,7 +100,7 @@ def api_sso_validate(request, token, api_id): @login_required def dashboard_view(request): logger.debug("dashboard_view called by user %s" % request.user) - auth_info = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + auth_info = AuthServicesInfo.objects.get(user=request.user) apikeypairs = EveManager.get_api_key_pairs(request.user.id) sso_validation = settings.API_SSO_VALIDATION or False api_chars = [] @@ -124,7 +124,7 @@ def dashboard_view(request): @login_required def api_key_removal(request, api_id): logger.debug("api_key_removal called by user %s for api id %s" % (request.user, api_id)) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) EveManager.delete_api_key_pair(api_id, request.user.id) EveManager.delete_characters_by_api_id(api_id, request.user.id) messages.success(request, 'Deleted API key %s' % api_id) @@ -140,7 +140,7 @@ def api_key_removal(request, api_id): def characters_view(request): logger.debug("characters_view called by user %s" % request.user) render_items = {'characters': EveManager.get_characters_by_owner_id(request.user.id), - 'authinfo': AuthServicesInfo.objects.get_or_create(user=request.user)[0]} + 'authinfo': AuthServicesInfo.objects.get(user=request.user)} return render(request, 'registered/characters.html', context=render_items) diff --git a/groupmanagement/views.py b/groupmanagement/views.py index d0a00b4d..ce2171cf 100755 --- a/groupmanagement/views.py +++ b/groupmanagement/views.py @@ -86,7 +86,7 @@ def group_membership_list(request, group_id): members = list() for member in group.user_set.all().order_by('username'): - authinfo = AuthServicesInfo.objects.get_or_create(user=member)[0] + authinfo = AuthServicesInfo.objects.get(user=member) members.append({ 'user': member, @@ -294,7 +294,7 @@ def group_request_add(request, group_id): logger.info("%s joining %s as is an open group" % (request.user, group)) request.user.groups.add(group) return redirect("auth_groups") - auth_info = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + auth_info = AuthServicesInfo.objects.get(user=request.user) grouprequest = GroupRequest() grouprequest.status = _('Pending') grouprequest.group = group @@ -325,7 +325,7 @@ def group_request_leave(request, group_id): logger.info("%s leaving %s as is an open group" % (request.user, group)) request.user.groups.remove(group) return redirect("auth_groups") - auth_info = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + auth_info = AuthServicesInfo.objects.get(user=request.user) grouprequest = GroupRequest() grouprequest.status = _('Pending') grouprequest.group = group diff --git a/hrapplications/views.py b/hrapplications/views.py index 68787bac..9a6fa5df 100755 --- a/hrapplications/views.py +++ b/hrapplications/views.py @@ -19,7 +19,7 @@ logger = logging.getLogger(__name__) def create_application_test(user): - auth, c = AuthServicesInfo.objects.get_or_create(user=user) + auth = AuthServicesInfo.objects.get(user=user) if auth.main_char_id: return True else: @@ -31,7 +31,7 @@ def hr_application_management_view(request): logger.debug("hr_application_management_view called by user %s" % request.user) corp_applications = [] finished_corp_applications = [] - auth_info, c = AuthServicesInfo.objects.get_or_create(user=request.user) + auth_info = AuthServicesInfo.objects.get(user=request.user) main_char = None if auth_info.main_char_id: try: diff --git a/optimer/views.py b/optimer/views.py index 558a9397..d201dbe1 100644 --- a/optimer/views.py +++ b/optimer/views.py @@ -37,7 +37,7 @@ def add_optimer_view(request): # Get Current Time post_time = timezone.now() # Get character - auth_info = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + auth_info = AuthServicesInfo.objects.get(user=request.user) character = EveManager.get_character_by_id(auth_info.main_char_id) # handle valid form op = optimer() @@ -88,7 +88,7 @@ def edit_optimer(request, optimer_id): form = opForm(request.POST) logger.debug("Received POST request containing update optimer form, is valid: %s" % form.is_valid()) if form.is_valid(): - auth_info = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + auth_info = AuthServicesInfo.objects.get(user=request.user) character = EveManager.get_character_by_id(auth_info.main_char_id) op.doctrine = form.cleaned_data['doctrine'] op.system = form.cleaned_data['system'] diff --git a/services/managers/eve_api_manager.py b/services/managers/eve_api_manager.py index 840442c9..829179d4 100644 --- a/services/managers/eve_api_manager.py +++ b/services/managers/eve_api_manager.py @@ -325,7 +325,7 @@ class EveApiManager: raise e except (requests.exceptions.RequestExeception, HTTPError, URLError) as e: raise EveApiManager.ApiServerUnreachableError(e) - auth, c = AuthServicesInfo.objects.get_or_create(user=user) + auth = AuthServicesInfo.objects.get(user=user) states = [auth.state] from authentication.tasks import determine_membership_by_character # circular import issue chars = info['characters'] diff --git a/services/signals.py b/services/signals.py index 6fc2a692..ebbaa874 100644 --- a/services/signals.py +++ b/services/signals.py @@ -30,7 +30,7 @@ def m2m_changed_user_groups(sender, instance, action, *args, **kwargs): def trigger_service_group_update(): logger.debug("Triggering service group update for %s" % instance) - auth, c = AuthServicesInfo.objects.get_or_create(user=instance) + auth = AuthServicesInfo.objects.get(user=instance) if auth.jabber_username: update_jabber_groups.delay(instance.pk) if auth.teamspeak3_uid: diff --git a/services/tasks.py b/services/tasks.py index 2432827e..5b36e6ab 100644 --- a/services/tasks.py +++ b/services/tasks.py @@ -169,7 +169,7 @@ def disable_market(): def deactivate_services(user): change = False logger.debug("Deactivating services for user %s" % user) - authinfo = AuthServicesInfo.objects.get_or_create(user=user)[0] + authinfo = AuthServicesInfo.objects.get(user=user) if authinfo.mumble_username and authinfo.mumble_username != "": logger.debug("User %s has mumble account %s. Deleting." % (user, authinfo.mumble_username)) MumbleManager.delete_user(authinfo.mumble_username) @@ -235,7 +235,7 @@ def validate_services(self, user, state): deactivate_services(user) return logger.debug('Ensuring user %s services are available to state %s' % (user, state)) - auth = AuthServicesInfo.objects.get_or_create(user=user)[0] + auth = AuthServicesInfo.objects.get(user=user) if auth.mumble_username and not getattr(settings, 'ENABLE_%s_MUMBLE' % setting_string, False): MumbleManager.delete_user(auth.mumble_username) AuthServicesInfoManager.update_user_mumble_info("", user) diff --git a/services/views.py b/services/views.py index 6bddfdb1..d25fd2b7 100755 --- a/services/views.py +++ b/services/views.py @@ -142,7 +142,7 @@ def jabber_broadcast_view(request): @members_and_blues() def services_view(request): logger.debug("services_view called by user %s" % request.user) - auth = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + auth = AuthServicesInfo.objects.get(user=request.user) char = None if auth.main_char_id: try: @@ -185,7 +185,7 @@ def superuser_test(user): @members_and_blues() def activate_forum(request): logger.debug("activate_forum called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) # Valid now we get the main characters character = EveManager.get_character_by_id(authinfo.main_char_id) logger.debug("Adding phpbb user for user %s with main character %s" % (request.user, character)) @@ -213,7 +213,7 @@ def activate_forum(request): @members_and_blues() def deactivate_forum(request): logger.debug("deactivate_forum called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = Phpbb3Manager.disable_user(authinfo.forum_username) # false we failed if result: @@ -230,7 +230,7 @@ def deactivate_forum(request): @members_and_blues() def reset_forum_password(request): logger.debug("reset_forum_password called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = Phpbb3Manager.update_user_password(authinfo.forum_username, authinfo.main_char_id) # false we failed if result != "": @@ -252,7 +252,7 @@ def reset_forum_password(request): @members_and_blues() def activate_xenforo_forum(request): logger.debug("activate_xenforo_forum called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) character = EveManager.get_character_by_id(authinfo.main_char_id) logger.debug("Adding XenForo user for user %s with main character %s" % (request.user, character)) result = XenForoManager.add_user(character.character_name, request.user.email) @@ -278,7 +278,7 @@ def activate_xenforo_forum(request): @members_and_blues() def deactivate_xenforo_forum(request): logger.debug("deactivate_xenforo_forum called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = XenForoManager.disable_user(authinfo.xenforo_username) if result.status_code == 200: AuthServicesInfoManager.update_user_xenforo_info("", request.user) @@ -293,7 +293,7 @@ def deactivate_xenforo_forum(request): @members_and_blues() def reset_xenforo_password(request): logger.debug("reset_xenforo_password called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = XenForoManager.reset_password(authinfo.xenforo_username) # Based on XenAPI's response codes if result['response']['status_code'] == 200: @@ -322,7 +322,7 @@ def set_xenforo_password(request): if form.is_valid(): password = form.cleaned_data['password'] logger.debug("Form contains password of length %s" % len(password)) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = XenForoManager.update_user_password(authinfo.xenforo_username, password) if result['response']['status_code'] == 200: logger.info("Successfully reset XenForo password for user %s" % request.user) @@ -344,7 +344,7 @@ def set_xenforo_password(request): @members_and_blues() def activate_ipboard_forum(request): logger.debug("activate_ipboard_forum called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) # Valid now we get the main characters character = EveManager.get_character_by_id(authinfo.main_char_id) logger.debug("Adding ipboard user for user %s with main character %s" % (request.user, character)) @@ -371,7 +371,7 @@ def activate_ipboard_forum(request): @members_and_blues() def deactivate_ipboard_forum(request): logger.debug("deactivate_ipboard_forum called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = IPBoardManager.disable_user(authinfo.ipboard_username) # false we failed if result: @@ -388,7 +388,7 @@ def deactivate_ipboard_forum(request): @members_and_blues() def reset_ipboard_password(request): logger.debug("reset_ipboard_password called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = IPBoardManager.update_user_password(authinfo.ipboard_username, request.user.email) if result != "": logger.info("Successfully reset ipboard password for user %s" % request.user) @@ -409,7 +409,7 @@ def reset_ipboard_password(request): @members_and_blues() def activate_jabber(request): logger.debug("activate_jabber called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) character = EveManager.get_character_by_id(authinfo.main_char_id) logger.debug("Adding jabber user for user %s with main character %s" % (request.user, character)) info = OpenfireManager.add_user(character.character_name) @@ -436,7 +436,7 @@ def activate_jabber(request): @members_and_blues() def deactivate_jabber(request): logger.debug("deactivate_jabber called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = OpenfireManager.delete_user(authinfo.jabber_username) # If our username is blank means we failed if result: @@ -453,7 +453,7 @@ def deactivate_jabber(request): @members_and_blues() def reset_jabber_password(request): logger.debug("reset_jabber_password called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = OpenfireManager.update_user_pass(authinfo.jabber_username) # If our username is blank means we failed if result != "": @@ -476,7 +476,7 @@ def reset_jabber_password(request): @members_and_blues() def activate_mumble(request): logger.debug("activate_mumble called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) character = EveManager.get_character_by_id(authinfo.main_char_id) ticker = character.corporation_ticker @@ -513,7 +513,7 @@ def activate_mumble(request): @members_and_blues() def deactivate_mumble(request): logger.debug("deactivate_mumble called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) # if we successfully remove the user or the user is already removed if MumbleManager.delete_user(authinfo.mumble_username) or not MumbleManager.user_exists(authinfo.mumble_username): AuthServicesInfoManager.update_user_mumble_info("", request.user) @@ -529,7 +529,7 @@ def deactivate_mumble(request): @members_and_blues() def reset_mumble_password(request): logger.debug("reset_mumble_password called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = MumbleManager.update_user_password(authinfo.mumble_username) # if blank we failed @@ -552,7 +552,7 @@ def reset_mumble_password(request): @members_and_blues() def activate_teamspeak3(request): logger.debug("activate_teamspeak3 called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) character = EveManager.get_character_by_id(authinfo.main_char_id) ticker = character.corporation_ticker @@ -583,7 +583,7 @@ def activate_teamspeak3(request): @members_and_blues() def verify_teamspeak3(request): logger.debug("verify_teamspeak3 called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) if not authinfo.teamspeak3_uid: logger.warn("Unable to validate user %s teamspeak: no teamspeak data" % request.user) return redirect("auth_services") @@ -606,7 +606,7 @@ def verify_teamspeak3(request): @members_and_blues() def deactivate_teamspeak3(request): logger.debug("deactivate_teamspeak3 called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = Teamspeak3Manager.delete_user(authinfo.teamspeak3_uid) # if false we failed @@ -624,7 +624,7 @@ def deactivate_teamspeak3(request): @members_and_blues() def reset_teamspeak3_perm(request): logger.debug("reset_teamspeak3_perm called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) character = EveManager.get_character_by_id(authinfo.main_char_id) logger.debug("Deleting TS3 user for user %s" % request.user) Teamspeak3Manager.delete_user(authinfo.teamspeak3_uid) @@ -656,7 +656,7 @@ def reset_teamspeak3_perm(request): @members_and_blues() def deactivate_discord(request): logger.debug("deactivate_discord called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = DiscordOAuthManager.delete_user(authinfo.discord_uid) if result: AuthServicesInfoManager.update_user_discord_info("", request.user) @@ -672,7 +672,7 @@ def deactivate_discord(request): @members_and_blues() def reset_discord(request): logger.debug("reset_discord called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = DiscordOAuthManager.delete_user(authinfo.discord_uid) if result: AuthServicesInfoManager.update_user_discord_info("", request.user) @@ -729,7 +729,7 @@ def set_forum_password(request): if form.is_valid(): password = form.cleaned_data['password'] logger.debug("Form contains password of length %s" % len(password)) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = Phpbb3Manager.update_user_password(authinfo.forum_username, authinfo.main_char_id, password=password) if result != "": @@ -759,7 +759,7 @@ def set_mumble_password(request): if form.is_valid(): password = form.cleaned_data['password'] logger.debug("Form contains password of length %s" % len(password)) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = MumbleManager.update_user_password(authinfo.mumble_username, password=password) if result != "": logger.info("Successfully reset forum password for user %s" % request.user) @@ -788,7 +788,7 @@ def set_jabber_password(request): if form.is_valid(): password = form.cleaned_data['password'] logger.debug("Form contains password of length %s" % len(password)) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = OpenfireManager.update_user_pass(authinfo.jabber_username, password=password) if result != "": logger.info("Successfully set jabber password for user %s" % request.user) @@ -818,7 +818,7 @@ def set_ipboard_password(request): if form.is_valid(): password = form.cleaned_data['password'] logger.debug("Form contains password of length %s" % len(password)) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = IPBoardManager.update_user_password(authinfo.ipboard_username, request.user.email, plain_password=password) if result != "": @@ -841,7 +841,7 @@ def set_ipboard_password(request): @members_and_blues() def activate_ips4(request): logger.debug("activate_ips4 called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) # Valid now we get the main characters character = EveManager.get_character_by_id(authinfo.main_char_id) logger.debug("Adding IPS4 user for user %s with main character %s" % (request.user, character)) @@ -869,7 +869,7 @@ def activate_ips4(request): @members_and_blues() def reset_ips4_password(request): logger.debug("reset_ips4_password called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = Ips4Manager.update_user_password(authinfo.ips4_username) # false we failed if result != "": @@ -898,7 +898,7 @@ def set_ips4_password(request): if form.is_valid(): password = form.cleaned_data['password'] logger.debug("Form contains password of length %s" % len(password)) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = Ips4Manager.update_custom_password(authinfo.ips4_username, plain_password=password) if result != "": logger.info("Successfully set IPS4 password for user %s" % request.user) @@ -920,7 +920,7 @@ def set_ips4_password(request): @members_and_blues() def deactivate_ips4(request): logger.debug("deactivate_ips4 called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = Ips4Manager.delete_user(authinfo.ips4_id) if result != "": AuthServicesInfoManager.update_user_ips4_info("", "", request.user) @@ -936,7 +936,7 @@ def deactivate_ips4(request): @members_and_blues() def activate_smf(request): logger.debug("activate_smf called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) # Valid now we get the main characters character = EveManager.get_character_by_id(authinfo.main_char_id) logger.debug("Adding smf user for user %s with main character %s" % (request.user, character)) @@ -964,7 +964,7 @@ def activate_smf(request): @members_and_blues() def deactivate_smf(request): logger.debug("deactivate_smf called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = smfManager.disable_user(authinfo.smf_username) # false we failed if result: @@ -981,7 +981,7 @@ def deactivate_smf(request): @members_and_blues() def reset_smf_password(request): logger.debug("reset_smf_password called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = smfManager.update_user_password(authinfo.smf_username, authinfo.main_char_id) # false we failed if result != "": @@ -1010,7 +1010,7 @@ def set_smf_password(request): if form.is_valid(): password = form.cleaned_data['password'] logger.debug("Form contains password of length %s" % len(password)) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = smfManager.update_user_password(authinfo.smf_username, authinfo.main_char_id, password=password) if result != "": logger.info("Successfully set smf password for user %s" % request.user) @@ -1032,7 +1032,7 @@ def set_smf_password(request): @members_and_blues() def activate_market(request): logger.debug("activate_market called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) # Valid now we get the main characters character = EveManager.get_character_by_id(authinfo.main_char_id) logger.debug("Adding market user for user %s with main character %s" % (request.user, character)) @@ -1060,7 +1060,7 @@ def activate_market(request): @members_and_blues() def deactivate_market(request): logger.debug("deactivate_market called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = marketManager.disable_user(authinfo.market_username) # false we failed if result: @@ -1077,7 +1077,7 @@ def deactivate_market(request): @members_and_blues() def reset_market_password(request): logger.debug("reset_market_password called by user %s" % request.user) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = marketManager.update_user_password(authinfo.market_username) # false we failed if result != "": @@ -1106,7 +1106,7 @@ def set_market_password(request): if form.is_valid(): password = form.cleaned_data['password'] logger.debug("Form contains password of length %s" % len(password)) - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) result = marketManager.update_custom_password(authinfo.market_username, password) if result != "": logger.info("Successfully reset market password for user %s" % request.user) @@ -1129,7 +1129,7 @@ def discourse_sso(request): ## Check if user has access - auth, c = AuthServicesInfo.objects.get_or_create(user=request.user) + auth = AuthServicesInfo.objects.get(user=request.user) if not request.user.is_superuser: if not settings.ENABLE_AUTH_DISCOURSE and auth.state == MEMBER_STATE: messages.error(request, 'Members are not authorized to access Discourse.') diff --git a/srp/views.py b/srp/views.py index ade0c6d6..04bfb699 100755 --- a/srp/views.py +++ b/srp/views.py @@ -104,7 +104,7 @@ def srp_fleet_add_view(request): form = SrpFleetMainForm(request.POST) logger.debug("Request type POST contains form valid: %s" % form.is_valid()) if form.is_valid(): - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) character = EveManager.get_character_by_id(authinfo.main_char_id) srp_fleet_main = SrpFleetMain() @@ -231,7 +231,7 @@ def srp_request_view(request, fleet_srp): logger.debug("Request type POST contains form valid: %s" % form.is_valid()) if form.is_valid(): - authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + authinfo = AuthServicesInfo.objects.get(user=request.user) character = EveManager.get_character_by_id(authinfo.main_char_id) srp_fleet_main = SrpFleetMain.objects.get(fleet_srp_code=fleet_srp) post_time = timezone.now() diff --git a/timerboard/views.py b/timerboard/views.py index b5b30a9c..29e8c408 100755 --- a/timerboard/views.py +++ b/timerboard/views.py @@ -20,7 +20,7 @@ logger = logging.getLogger(__name__) def timer_util_test(user): - return AuthServicesInfo.objects.get_or_create(user=user)[0].state in [BLUE_STATE, MEMBER_STATE] + return AuthServicesInfo.objects.get(user=user).state in [BLUE_STATE, MEMBER_STATE] @login_required @@ -28,7 +28,7 @@ def timer_util_test(user): @permission_required('auth.timer_view') def timer_view(request): logger.debug("timer_view called by user %s" % request.user) - auth_info = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + auth_info = AuthServicesInfo.objects.get(user=request.user) char = EveManager.get_character_by_id(auth_info.main_char_id) if char: corp = EveManager.get_corporation_info_by_id(char.corporation_id) @@ -64,7 +64,7 @@ def add_timer_view(request): logger.debug("Request type POST contains form valid: %s" % form.is_valid()) if form.is_valid(): # Get character - auth_info = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + auth_info = AuthServicesInfo.objects.get(user=request.user) character = EveManager.get_character_by_id(auth_info.main_char_id) corporation = EveManager.get_corporation_info_by_id(character.corporation_id) logger.debug( @@ -127,7 +127,7 @@ def edit_timer(request, timer_id): form = TimerForm(request.POST) logger.debug("Received POST request containing updated timer form, is valid: %s" % form.is_valid()) if form.is_valid(): - auth_info = AuthServicesInfo.objects.get_or_create(user=request.user)[0] + auth_info = AuthServicesInfo.objects.get(user=request.user) character = EveManager.get_character_by_id(auth_info.main_char_id) corporation = EveManager.get_corporation_info_by_id(character.corporation_id) logger.debug(