snapshots: do not delete snapshots on user deletion (#88622)
gitea/combo/pipeline/head This commit looks good Details

This commit is contained in:
Lauréline Guérin 2024-03-26 13:18:45 +01:00
parent bfdefa73cc
commit d964be219e
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
3 changed files with 7 additions and 2 deletions

View File

@ -32,7 +32,7 @@ class Migration(migrations.Migration):
(
'user',
models.ForeignKey(
null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL
null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL
),
),
],

View File

@ -802,7 +802,7 @@ class Page(models.Model):
class PageSnapshot(models.Model):
page = models.ForeignKey(Page, on_delete=models.SET_NULL, null=True)
timestamp = models.DateTimeField(auto_now_add=True)
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True)
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True)
comment = models.TextField(blank=True, null=True)
serialization = JSONField(blank=True, default=dict)
label = models.CharField(_('Label'), max_length=150, blank=True)

View File

@ -1090,6 +1090,11 @@ def test_site_export_import_json(app, admin_user):
resp = resp.form.submit()
assert 'File is not in the expected TAR or JSON format.' in resp.text
assert PageSnapshot.objects.filter(user__isnull=False).count() == 8
admin_user.delete()
assert PageSnapshot.objects.all().count() == 8
assert PageSnapshot.objects.filter(user__isnull=True).count() == 8
def test_site_export_import_tar(app, admin_user):
Page.objects.all().delete()