mirror of
https://github.com/pretix/pretix.git
synced 2026-05-03 14:54:04 +00:00
Fix concurrent login and duplicate UserKnownLoginSources (#4880)
This commit is contained in:
committed by
GitHub
parent
ac8cb3bfd1
commit
7da03ac17c
@@ -0,0 +1,41 @@
|
||||
# Generated by Django 4.2.16 on 2025-02-28 13:25
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def remove_duplicates(apps, schema_editor):
|
||||
UserKnownLoginSource = apps.get_model("pretixbase", "UserKnownLoginSource")
|
||||
unique_fields = ["user", "agent_type", "device_type", "os_type", "country"]
|
||||
|
||||
duplicates = (
|
||||
UserKnownLoginSource.objects
|
||||
.values(*unique_fields)
|
||||
.order_by()
|
||||
.annotate(latest_id=models.Max('id'), count=models.Count('id'))
|
||||
.filter(count__gt=1)
|
||||
)
|
||||
|
||||
for duplicate in duplicates:
|
||||
(
|
||||
UserKnownLoginSource.objects
|
||||
.filter(**{x: duplicate[x] for x in unique_fields})
|
||||
.exclude(id=duplicate["latest_id"])
|
||||
.delete()
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("pretixbase", "0277_customerssoclient_require_pkce_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(remove_duplicates, migrations.RunPython.noop),
|
||||
migrations.AlterUniqueTogether(
|
||||
name="userknownloginsource",
|
||||
unique_together={
|
||||
("user", "agent_type", "device_type", "os_type", "country")
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -602,6 +602,9 @@ class UserKnownLoginSource(models.Model):
|
||||
country = FastCountryField(null=True, blank=True)
|
||||
last_seen = models.DateTimeField()
|
||||
|
||||
class Meta:
|
||||
unique_together = ('user', 'agent_type', 'device_type', 'os_type', 'country')
|
||||
|
||||
|
||||
class StaffSession(models.Model):
|
||||
user = models.ForeignKey('User', on_delete=models.PROTECT)
|
||||
|
||||
Reference in New Issue
Block a user