mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
portalapi: add groups and apps list in infos returned by GET /me
This commit is contained in:
parent
6c6dd318fb
commit
2c0f49cef3
1 changed files with 30 additions and 35 deletions
|
@ -19,14 +19,14 @@
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# from moulinette import Moulinette, m18n
|
|
||||||
from moulinette.utils.log import getActionLogger
|
from moulinette.utils.log import getActionLogger
|
||||||
|
from moulinette.utils.filesystem import read_json
|
||||||
|
|
||||||
from yunohost.authenticators.ldap_ynhuser import Authenticator as Auth
|
from yunohost.authenticators.ldap_ynhuser import Authenticator as Auth
|
||||||
from yunohost.utils.ldap import LDAPInterface
|
from yunohost.utils.ldap import LDAPInterface
|
||||||
from yunohost.utils.error import YunohostValidationError
|
from yunohost.utils.error import YunohostValidationError
|
||||||
|
|
||||||
logger = getActionLogger("yunohostportal.user")
|
logger = getActionLogger("portal")
|
||||||
|
|
||||||
|
|
||||||
def portal_me():
|
def portal_me():
|
||||||
|
@ -39,48 +39,43 @@ def portal_me():
|
||||||
|
|
||||||
ldap = LDAPInterface(username, auth["pwd"])
|
ldap = LDAPInterface(username, auth["pwd"])
|
||||||
|
|
||||||
user_attrs = ["cn", "mail", "uid", "maildrop", "givenName", "sn", "mailuserquota"]
|
user_attrs = ["cn", "mail", "maildrop", "mailuserquota", "memberOf", "permission"]
|
||||||
|
|
||||||
filter = "uid=" + username
|
result = ldap.search("ou=users", f"uid={username}", user_attrs)
|
||||||
result = ldap.search("ou=users", filter, user_attrs)
|
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
user = result[0]
|
user = result[0]
|
||||||
else:
|
else:
|
||||||
raise YunohostValidationError("user_unknown", user=username)
|
raise YunohostValidationError("user_unknown", user=username)
|
||||||
|
|
||||||
result_dict = {
|
groups = [g.replace("cn=", "").replace(",ou=groups,dc=yunohost,dc=org", "") for g in user["memberOf"]]
|
||||||
"username": user["uid"][0],
|
groups = [g for g in groups if g not in [username, "all_users"]]
|
||||||
"fullname": user["cn"][0],
|
|
||||||
"firstname": user["givenName"][0],
|
permissions = [p.replace("cn=", "").replace(",ou=permission,dc=yunohost,dc=org", "") for p in user["permission"]]
|
||||||
"lastname": user["sn"][0],
|
|
||||||
"mail": user["mail"][0],
|
ssowat_conf = read_json("/etc/ssowat/conf.json")
|
||||||
"mail-aliases": [],
|
apps = {
|
||||||
"mail-forward": [],
|
perm.replace(".main", ""): {"label": infos["label"], "url": infos["uris"][0]}
|
||||||
|
for perm, infos in ssowat_conf["permissions"].items()
|
||||||
|
if perm in permissions and infos["show_tile"] and username in infos["users"]
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(user["mail"]) > 1:
|
result_dict = {
|
||||||
result_dict["mail-aliases"] = user["mail"][1:]
|
"username": username,
|
||||||
|
"fullname": user["cn"][0],
|
||||||
|
"mail": user["mail"][0],
|
||||||
|
"mail-aliases": user["mail"][1:],
|
||||||
|
"mail-forward": user["maildrop"][1:],
|
||||||
|
"groups": groups,
|
||||||
|
"apps": apps
|
||||||
|
}
|
||||||
|
|
||||||
if len(user["maildrop"]) > 1:
|
# FIXME / TODO : add mail quota status ?
|
||||||
result_dict["mail-forward"] = user["maildrop"][1:]
|
# result_dict["mailbox-quota"] = {
|
||||||
|
# "limit": userquota if is_limited else m18n.n("unlimit"),
|
||||||
if "mailuserquota" in user:
|
# "use": storage_use,
|
||||||
pass
|
# }
|
||||||
# FIXME
|
# Could use : doveadm -c /dev/null -f flow quota recalc -u johndoe
|
||||||
# result_dict["mailbox-quota"] = {
|
# But this requires to be in the mail group ...
|
||||||
# "limit": userquota if is_limited else m18n.n("unlimit"),
|
|
||||||
# "use": storage_use,
|
|
||||||
# }
|
|
||||||
|
|
||||||
# FIXME : should also parse "permission" key in ldap maybe ?
|
|
||||||
# and list of groups / memberof ?
|
|
||||||
# (in particular to have e.g. the mail / xmpp / ssh / ... perms)
|
|
||||||
|
|
||||||
return result_dict
|
return result_dict
|
||||||
|
|
||||||
|
|
||||||
def apps(username):
|
|
||||||
return {"foo": "bar"}
|
|
||||||
# FIXME: should list available apps and corresponding infos ?
|
|
||||||
# from /etc/ssowat/conf.json ?
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue