From 8f636561d9781c749bccfa518d6aeaa37eed2d39 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 19 Aug 2024 00:32:09 +0200 Subject: [PATCH] portal: allow to configure custom CSS from the domain config panel --- conf/nginx/yunohost_sso.conf.inc | 7 +++++++ share/config_domain.toml | 4 ++++ src/domain.py | 16 ++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/conf/nginx/yunohost_sso.conf.inc b/conf/nginx/yunohost_sso.conf.inc index 7e9207305..839b50c40 100644 --- a/conf/nginx/yunohost_sso.conf.inc +++ b/conf/nginx/yunohost_sso.conf.inc @@ -17,5 +17,12 @@ location /yunohost/sso/ { alias /usr/share/yunohost/applogos/; } + location = /yunohost/sso/customassets/custom.css { + alias /usr/share/yunohost/portal/customassets/$host.custom.css; + etag off; + expires off; + more_set_headers "Cache-Control: no-store, no-cache, must-revalidate"; + } + more_set_headers "Content-Security-Policy: upgrade-insecure-requests; default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline'; object-src 'none'; img-src 'self' data:;"; } diff --git a/share/config_domain.toml b/share/config_domain.toml index 68afe61bc..ebab2d066 100644 --- a/share/config_domain.toml +++ b/share/config_domain.toml @@ -43,6 +43,10 @@ name = "Features" # FIXME link to GCU + [feature.portal.custom_css] + # NB: this is wrote into "/usr/share/yunohost/portal/customassets/{domain}.custom.css" + type = "text" + [feature.app] [feature.app.default_app] type = "app" diff --git a/src/domain.py b/src/domain.py index b6e78ba67..0d9342487 100644 --- a/src/domain.py +++ b/src/domain.py @@ -29,6 +29,7 @@ from moulinette.utils.filesystem import ( read_json, read_yaml, rm, + read_file, write_to_file, write_to_json, write_to_yaml, @@ -735,6 +736,15 @@ def _get_DomainConfigPanel(): return raw_config + def _get_raw_settings(self) -> "RawSettings": + raw_settings = super()._get_raw_settings() + + custom_css = Path(f"/usr/share/yunohost/portal/customassets/{self.entity}.custom.css") + if custom_css.exists(): + raw_settings["custom_css"] = read_file(str(custom_css)) + + return raw_settings + def _apply( self, form: "FormModel", @@ -761,6 +771,12 @@ def _get_DomainConfigPanel(): self.entity, next_settings["recovery_password"] ) + custom_css = next_settings.pop("custom_css", "").strip() + if custom_css: + write_to_file(f"/usr/share/yunohost/portal/customassets/{self.entity}.custom.css", custom_css) + # Make sure the value doesnt get written in the yml + form.custom_css = "" + portal_options = [ "default_app", "show_other_domains_apps",