portal: change the way the new 'public apps' page in the portal is configured: add a simple bool toggle instead of having the 'public apps page' as a default app option, which allows to still configure a default app while the portal has the public apps page

This commit is contained in:
Alexandre Aubin 2024-08-19 01:02:28 +02:00
parent 8f636561d9
commit 748a20d864
5 changed files with 10 additions and 14 deletions

View file

@ -8,6 +8,10 @@ name = "Features"
# Only available for "topest" domains
name = "Portal"
[feature.portal.enable_public_apps_page]
type = "boolean"
default = false
[feature.portal.show_other_domains_apps]
type = "boolean"
default = false
@ -52,7 +56,6 @@ name = "Features"
type = "app"
filter = "is_webapp"
default = "_none"
add_yunohost_portal_to_choices = true
[feature.mail]
name = "Email"

View file

@ -1657,9 +1657,7 @@ def app_ssowatconf():
for domain in domains:
default_app = _get_raw_domain_settings(domain).get("default_app")
if default_app == "_yunohost_portal_with_public_apps":
redirected_urls[domain + "/"] = domain_portal_dict[domain]
elif default_app not in ["_none", None] and _is_installed(default_app):
if default_app not in ["_none", None] and _is_installed(default_app):
app_settings = _get_app_settings(default_app)
app_domain = app_settings["domain"]
app_path = app_settings["path"]
@ -1667,6 +1665,8 @@ def app_ssowatconf():
# Prevent infinite redirect loop...
if domain + "/" != app_domain + app_path:
redirected_urls[domain + "/"] = app_domain + app_path
elif bool(_get_raw_domain_settings(domain).get("enable_public_apps_page", False)):
redirected_urls[domain + "/"] = domain_portal_dict[domain]
# Will organize apps by portal domain
portal_domains_apps = {domain: {} for domain in portal_domains}

View file

@ -778,7 +778,7 @@ def _get_DomainConfigPanel():
form.custom_css = ""
portal_options = [
"default_app",
"enable_public_apps_page",
"show_other_domains_apps",
"portal_title",
"portal_logo",
@ -832,7 +832,7 @@ def _get_DomainConfigPanel():
super()._apply(form, previous_settings, exclude={"recovery_password"})
# Reload ssowat if default app changed
if "default_app" in next_settings:
if "default_app" in next_settings or "enable_public_apps_page" in next_settings:
from yunohost.app import app_ssowatconf
app_ssowatconf()

View file

@ -81,9 +81,7 @@ def _get_portal_settings(
if portal_settings_path.exists():
settings.update(read_json(str(portal_settings_path)))
# Portal may be public (no login required)
settings["public"] = (
settings.pop("default_app", None) == "_yunohost_portal_with_public_apps"
)
settings["public"] = bool(settings.pop("enable_public_apps_page", False))
# First clear apps since it may contains private apps
apps: dict[str, Any] = settings.pop("apps", {})

View file

@ -1672,7 +1672,6 @@ class AppOption(BaseChoicesOption):
type: Literal[OptionType.app] = OptionType.app
filter: Union[JSExpression, None] = None
add_yunohost_portal_to_choices: bool = False
choices: Union[dict[str, str], None]
@validator("choices", pre=True, always=True)
@ -1692,10 +1691,6 @@ class AppOption(BaseChoicesOption):
]
value = {"_none": "---"}
if values.get("add_yunohost_portal_to_choices", False):
value["_yunohost_portal_with_public_apps"] = "YunoHost's portal with public apps"
value.update(
{
app["id"]: f"{app['label']} ({app.get('domain_path', app['id'])})"