diff --git a/lemarche/users/admin.py b/lemarche/users/admin.py index 68d221e6f..9f9f71343 100644 --- a/lemarche/users/admin.py +++ b/lemarche/users/admin.py @@ -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")}, diff --git a/lemarche/users/migrations/0040_user_old_api_keys.py b/lemarche/users/migrations/0040_user_old_api_keys.py deleted file mode 100644 index ae4e39e3f..000000000 --- a/lemarche/users/migrations/0040_user_old_api_keys.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 4.2.15 on 2024-11-20 14:18 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("users", "0039_remove_user_user_email_ci_uniqueness_and_more"), - ] - - operations = [ - migrations.AddField( - model_name="user", - name="old_api_keys", - field=models.JSONField(blank=True, default=list, verbose_name="Anciennes clés API"), - ), - ] diff --git a/lemarche/users/models.py b/lemarche/users/models.py index 61558166d..0213b8658 100644 --- a/lemarche/users/models.py +++ b/lemarche/users/models.py @@ -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 ) @@ -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)