From f37e1ca642ccd7ab5987c4f0fcd317509ad8e1e3 Mon Sep 17 00:00:00 2001 From: "Jens L." Date: Wed, 19 Mar 2025 22:52:38 +0000 Subject: [PATCH] brands: migrate custom CSS to brands (#13172) * brands: migrate custom CSS to brands Signed-off-by: Jens Langhammer * fix missing default Signed-off-by: Jens Langhammer * fix tests Signed-off-by: Jens Langhammer * simpler migration Signed-off-by: Jens Langhammer * add css to brand form Signed-off-by: Jens Langhammer * fix Signed-off-by: Jens Langhammer --------- Signed-off-by: Jens Langhammer --- authentik/brands/api.py | 2 + .../0008_brand_branding_custom_css.py | 35 +++++++++++++++++ authentik/brands/models.py | 1 + authentik/brands/tests.py | 3 ++ authentik/core/templates/base/skeleton.html | 2 +- blueprints/schema.json | 4 ++ internal/outpost/proxyv2/templates/error.html | 1 - schema.yml | 9 +++++ web/package-lock.json | 8 ++-- web/package.json | 2 +- web/scripts/build-web.mjs | 1 - web/src/admin/brands/BrandForm.ts | 39 +++++++++++-------- web/src/custom.css | 1 - web/src/elements/Base.ts | 35 +++-------------- web/src/elements/CodeMirror.ts | 4 ++ web/src/elements/sidebar/SidebarBrand.ts | 1 + 16 files changed, 94 insertions(+), 54 deletions(-) create mode 100644 authentik/brands/migrations/0008_brand_branding_custom_css.py delete mode 100644 web/src/custom.css diff --git a/authentik/brands/api.py b/authentik/brands/api.py index e8e1fc1171..3089f86eab 100644 --- a/authentik/brands/api.py +++ b/authentik/brands/api.py @@ -49,6 +49,7 @@ class BrandSerializer(ModelSerializer): "branding_title", "branding_logo", "branding_favicon", + "branding_custom_css", "flow_authentication", "flow_invalidation", "flow_recovery", @@ -86,6 +87,7 @@ class CurrentBrandSerializer(PassiveSerializer): branding_title = CharField() branding_logo = CharField(source="branding_logo_url") branding_favicon = CharField(source="branding_favicon_url") + branding_custom_css = CharField() ui_footer_links = ListField( child=FooterLinkSerializer(), read_only=True, diff --git a/authentik/brands/migrations/0008_brand_branding_custom_css.py b/authentik/brands/migrations/0008_brand_branding_custom_css.py new file mode 100644 index 0000000000..838694e32f --- /dev/null +++ b/authentik/brands/migrations/0008_brand_branding_custom_css.py @@ -0,0 +1,35 @@ +# Generated by Django 5.0.12 on 2025-02-22 01:51 + +from pathlib import Path +from django.db import migrations, models +from django.apps.registry import Apps + +from django.db.backends.base.schema import BaseDatabaseSchemaEditor + + +def migrate_custom_css(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): + Brand = apps.get_model("authentik_brands", "brand") + + db_alias = schema_editor.connection.alias + + path = Path("/web/dist/custom.css") + if not path.exists(): + return + with path.read_text() as css: + Brand.objects.using(db_alias).update(branding_custom_css=css) + + +class Migration(migrations.Migration): + + dependencies = [ + ("authentik_brands", "0007_brand_default_application"), + ] + + operations = [ + migrations.AddField( + model_name="brand", + name="branding_custom_css", + field=models.TextField(blank=True, default=""), + ), + migrations.RunPython(migrate_custom_css), + ] diff --git a/authentik/brands/models.py b/authentik/brands/models.py index 12e975b1de..ee4e73d52b 100644 --- a/authentik/brands/models.py +++ b/authentik/brands/models.py @@ -33,6 +33,7 @@ class Brand(SerializerModel): branding_logo = models.TextField(default="/static/dist/assets/icons/icon_left_brand.svg") branding_favicon = models.TextField(default="/static/dist/assets/icons/icon.png") + branding_custom_css = models.TextField(default="", blank=True) flow_authentication = models.ForeignKey( Flow, null=True, on_delete=models.SET_NULL, related_name="brand_authentication" diff --git a/authentik/brands/tests.py b/authentik/brands/tests.py index 69b8d10d71..f03dea322e 100644 --- a/authentik/brands/tests.py +++ b/authentik/brands/tests.py @@ -24,6 +24,7 @@ class TestBrands(APITestCase): "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg", "branding_favicon": "/static/dist/assets/icons/icon.png", "branding_title": "authentik", + "branding_custom_css": "", "matched_domain": brand.domain, "ui_footer_links": [], "ui_theme": Themes.AUTOMATIC, @@ -43,6 +44,7 @@ class TestBrands(APITestCase): "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg", "branding_favicon": "/static/dist/assets/icons/icon.png", "branding_title": "custom", + "branding_custom_css": "", "matched_domain": "bar.baz", "ui_footer_links": [], "ui_theme": Themes.AUTOMATIC, @@ -59,6 +61,7 @@ class TestBrands(APITestCase): "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg", "branding_favicon": "/static/dist/assets/icons/icon.png", "branding_title": "authentik", + "branding_custom_css": "", "matched_domain": "fallback", "ui_footer_links": [], "ui_theme": Themes.AUTOMATIC, diff --git a/authentik/core/templates/base/skeleton.html b/authentik/core/templates/base/skeleton.html index 2e28dfbcbd..0c3a79122b 100644 --- a/authentik/core/templates/base/skeleton.html +++ b/authentik/core/templates/base/skeleton.html @@ -16,7 +16,7 @@ {% block head_before %} {% endblock %} - + {% block head %} diff --git a/blueprints/schema.json b/blueprints/schema.json index 8fcf08074d..7414cd07fc 100644 --- a/blueprints/schema.json +++ b/blueprints/schema.json @@ -13016,6 +13016,10 @@ "minLength": 1, "title": "Branding favicon" }, + "branding_custom_css": { + "type": "string", + "title": "Branding custom css" + }, "flow_authentication": { "type": "string", "format": "uuid", diff --git a/internal/outpost/proxyv2/templates/error.html b/internal/outpost/proxyv2/templates/error.html index b0e00b4292..6ef3917b56 100644 --- a/internal/outpost/proxyv2/templates/error.html +++ b/internal/outpost/proxyv2/templates/error.html @@ -8,7 +8,6 @@ -