Skip to content

Commit

Permalink
add settings getter + /public route to get settings and public apps
Browse files Browse the repository at this point in the history
  • Loading branch information
Axolotle committed Sep 4, 2023
1 parent 2136db3 commit bfedf14
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion src/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
along with this program; if not, see http://www.gnu.org/licenses
"""
from pathlib import Path
from typing import Any, Union

import ldap
from moulinette.utils.filesystem import read_json
from moulinette.utils.filesystem import read_json, read_yaml
from moulinette.utils.log import getActionLogger
from yunohost.authenticators.ldap_ynhuser import URI, USERDN, Authenticator as Auth
from yunohost.user import _hash_user_password
Expand Down Expand Up @@ -50,6 +51,56 @@ def _get_user_infos(
return username, auth["host"], result[0], ldap_interface


def _get_portal_settings(domain: Union[str, None] = None):
from yunohost.domain import DOMAIN_SETTINGS_DIR

if not domain:
from bottle import request

domain = request.get_header("host")

if Path(f"{DOMAIN_SETTINGS_DIR}/{domain}.portal.yml").exists():
settings = read_yaml(f"{DOMAIN_SETTINGS_DIR}/{domain}.portal.yml")
else:
settings = {
"public": False,
"portal_logo": "",
"portal_theme": "system",
"portal_title": "YunoHost",
"show_other_domains_apps": 1,
}

settings["domain"] = domain

return settings


def portal_public():
settings = _get_portal_settings()
settings["apps"] = {}
settings["public"] = settings.pop("default_app") == "portal_public_apps"

if settings["public"]:
ssowat_conf = read_json("/etc/ssowat/conf.json")
settings["apps"] = {
perm.replace(".main", ""): {
"label": infos["label"],
"url": infos["uris"][0],
}
for perm, infos in ssowat_conf["permissions"].items()
if infos["show_tile"] and infos["public"]
}

if not settings["show_other_domains_apps"]:
settings["apps"] = {
name: data
for name, data in settings["apps"].items()
if settings["domain"] in data["url"]
}

return settings


def portal_me():
"""
Get user informations
Expand All @@ -76,6 +127,10 @@ def portal_me():
if perm in permissions and infos["show_tile"] and username in infos["users"]
}

settings = _get_portal_settings(domain=domain)
if not settings["show_other_domains_apps"]:
apps = {name: data for name, data in apps.items() if domain in data["url"]}

result_dict = {
"username": username,
"fullname": user["cn"][0],
Expand Down

0 comments on commit bfedf14

Please sign in to comment.