From 4dcd481010d9f5242f44f616b673dc15d543e65e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simonyi=20Gerg=C5=91?= <28359278+gergosimonyi@users.noreply.github.com> Date: Wed, 14 May 2025 15:02:29 +0200 Subject: [PATCH] core: remove `OldAuthenticatedSession` content type (#14507) * core: remove `OldAuthenticatedSession` content type This was left out from https://github.com/goauthentik/authentik/pull/9736 * remove stale content types in `repair_permissions` Co-authored-by: Jens Langhammer * run `remove_stale_contenttypes` for each tenant --------- Co-authored-by: Jens Langhammer --- .../management/commands/repair_permissions.py | 5 ++++ ...te_oldauthenticatedsession_content_type.py | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 authentik/core/migrations/0048_delete_oldauthenticatedsession_content_type.py diff --git a/authentik/core/management/commands/repair_permissions.py b/authentik/core/management/commands/repair_permissions.py index 3dfa9b8d7d..dada3e6772 100644 --- a/authentik/core/management/commands/repair_permissions.py +++ b/authentik/core/management/commands/repair_permissions.py @@ -2,6 +2,7 @@ from django.apps import apps from django.contrib.auth.management import create_permissions +from django.core.management import call_command from django.core.management.base import BaseCommand, no_translations from guardian.management import create_anonymous_user @@ -16,6 +17,10 @@ class Command(BaseCommand): """Check permissions for all apps""" for tenant in Tenant.objects.filter(ready=True): with tenant: + # See https://code.djangoproject.com/ticket/28417 + # Remove potential lingering old permissions + call_command("remove_stale_contenttypes", "--no-input") + for app in apps.get_app_configs(): self.stdout.write(f"Checking app {app.name} ({app.label})\n") create_permissions(app, verbosity=0) diff --git a/authentik/core/migrations/0048_delete_oldauthenticatedsession_content_type.py b/authentik/core/migrations/0048_delete_oldauthenticatedsession_content_type.py new file mode 100644 index 0000000000..d79f14a74a --- /dev/null +++ b/authentik/core/migrations/0048_delete_oldauthenticatedsession_content_type.py @@ -0,0 +1,27 @@ +# Generated by Django 5.1.9 on 2025-05-14 11:15 + +from django.apps.registry import Apps +from django.db import migrations +from django.db.backends.base.schema import BaseDatabaseSchemaEditor + + +def remove_old_authenticated_session_content_type( + apps: Apps, schema_editor: BaseDatabaseSchemaEditor +): + db_alias = schema_editor.connection.alias + ContentType = apps.get_model("contenttypes", "ContentType") + + ContentType.objects.using(db_alias).filter(model="oldauthenticatedsession").delete() + + +class Migration(migrations.Migration): + + dependencies = [ + ("authentik_core", "0047_delete_oldauthenticatedsession"), + ] + + operations = [ + migrations.RunPython( + code=remove_old_authenticated_session_content_type, + ), + ]