mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2026-02-12 10:06:21 +01:00
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.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user