Skip to content

Commit

Permalink
remove historic tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
madjid-asa committed Nov 27, 2024
1 parent 8ffbde6 commit 3457a75
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lemarche/users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class UserAdmin(FieldsetsInlineMixin, UserAdmin):
)
},
),
("API", {"fields": ("api_key", "old_api_keys", "api_key_last_updated")}),
("API", {"fields": ("api_key", "api_key_last_updated")}),
(
"Permissions",
{"classes": ["collapse"], "fields": ("is_active", "is_staff", "is_superuser", "groups")},
Expand Down
17 changes: 0 additions & 17 deletions lemarche/users/migrations/0040_user_old_api_keys.py

This file was deleted.

9 changes: 3 additions & 6 deletions lemarche/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ class User(AbstractUser):
)

api_key = models.CharField(verbose_name="Clé API", max_length=128, unique=True, blank=True, null=True)
old_api_keys = models.JSONField(verbose_name="Anciennes clés API", blank=True, default=list)
api_key_last_updated = models.DateTimeField(
verbose_name="Date de dernière mise à jour de la clé API", blank=True, null=True
)
Expand Down Expand Up @@ -420,13 +419,11 @@ def update_old_api_keys(sender, instance, **kwargs):
if instance.pk: # Check if the user already exists (not a new creation)
try:
old_instance = sender.objects.get(pk=instance.pk)
if old_instance.api_key != instance.api_key and old_instance.api_key:
if old_instance.api_key != instance.api_key:
# Add the old key to the list of old keys
if instance.old_api_keys is None:
instance.old_api_keys = list()
instance.old_api_keys.append(old_instance.api_key)
instance.api_key_last_updated = timezone.now()
except sender.DoesNotExist:
pass # The user does not exist yet
instance.api_key_last_updated = timezone.now()


@receiver(post_save, sender=User)
Expand Down

0 comments on commit 3457a75

Please sign in to comment.