portal: allow to configure custom CSS from the domain config panel

This commit is contained in:
Alexandre Aubin 2024-08-19 00:32:09 +02:00
parent a6b7ba8435
commit 8f636561d9
3 changed files with 27 additions and 0 deletions

View file

@ -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:;";
}

View file

@ -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"

View file

@ -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",