mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-13 14:30:17 +02:00
Revoke CharacterOwnership on token deletion.
I'm pretty sure this is what I meant to do initially. I created the OwnershipRecord system under the assumption that CharacterOwnership models were being deleted when they could no longer be validated. That turned out not to be the case - only main characters were rest. This ensures they are deleted when they can no longer be validated.
This commit is contained in:
parent
bee69cc250
commit
b65ccac58f
@ -112,20 +112,10 @@ def validate_main_character(sender, instance, *args, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
@receiver(post_delete, sender=Token)
|
@receiver(post_delete, sender=Token)
|
||||||
def validate_main_character_token(sender, instance, *args, **kwargs):
|
def validate_ownership(sender, instance, *args, **kwargs):
|
||||||
if UserProfile.objects.filter(main_character__character_id=instance.character_id).exists():
|
if not Token.objects.filter(character_owner_hash=instance.character_owner_hash).filter(refresh_token__isnull=False).exists():
|
||||||
logger.debug(
|
logger.info("No remaining tokens to validate ownership of character {0}. Revoking ownership.".format(instance.character_name))
|
||||||
"Token for a main character {0} is being deleted. Ensuring there are valid tokens to refresh.".format(
|
CharacterOwnership.objects.filter(owner_hash=instance.character_owner_hash).delete()
|
||||||
instance.character_name))
|
|
||||||
profile = UserProfile.objects.get(main_character__character_id=instance.character_id)
|
|
||||||
if not Token.objects.filter(character_id=instance.character_id).filter(
|
|
||||||
user=profile.user).filter(refresh_token__isnull=False).exists():
|
|
||||||
logger.info(
|
|
||||||
"No remaining tokens to validate {0} ownership of main character {1}. Resetting main character.".format(
|
|
||||||
profile.user, profile.main_character))
|
|
||||||
# clear main character as we can no longer verify ownership
|
|
||||||
profile.main_character = None
|
|
||||||
profile.save()
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(pre_save, sender=User)
|
@receiver(pre_save, sender=User)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user