1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mautrix_whatsapp_ynh.git synced 2024-09-03 19:46:01 +02:00

try improve permission mgmt

This commit is contained in:
gredin67 2023-01-19 11:50:14 +01:00
parent d0a7cf72e5
commit 2440fac35f
3 changed files with 32 additions and 21 deletions

View file

@ -13,25 +13,26 @@ services = ["__APP__"]
- * : All Matrix users
- domain.tld : All users on a given homeserver
- mxid (@user:matrix.org) : Specific Matrix user
Increasing Power: Relay<User<Admin
'''
type = "markdown"
[main.permissions.listrelay]
ask = "Users bridged thanks to Relay Mode"
type = "tags"
help = "Talk on WhatsApp through the RelayBot in a room where it's activated '!wa set-relay', no access otherwise."
visible = "enable_relaybot"
[main.permissions.listuser]
ask = "Bridge Users"
type = "tags"
help = "Access to use the bridge to chat with a WhatsApp account."
[main.permissions.listadmin]
ask = "Bride Administrators"
ask = "Bridge Administrators"
type = "tags"
help = "User level and some additional administration tools."
[main.permissions.listrelay]
ask = "Users bridged thanks to Relay Mode"
type = "tags"
help = "Talk on WhatsApp through the RelayBot in a room where it's activated '!wa set-relay', no access otherwise."
visible = "enable_relaybot"
[main.bridge]
name = "Puppetting Bridge Settings"
@ -81,7 +82,9 @@ services = ["__APP__"]
name = "Portal Rooms & Encryption Settings"
[privacy.portal_rooms.text]
ask = "!! Inviting the Bridge in an encrypted room **breaks End-to-End Encryption (e2ee)** !! Messages will be unencrypted on the Bridge Server!"
ask = '''
!! Inviting the Bridge in an encrypted room **breaks End-to-End Encryption (e2ee)** !! Messages will be unencrypted on the Bridge Server!
'''
type = "markdown"
[privacy.portal_rooms.encryption]

View file

@ -51,14 +51,22 @@ function get__listadmin {
EOF
}
function get__role {
cat <<EOF
choices: ["admin", "user", "relay"]
default: "user"
EOF
function set__listuser {
role="user"
set_permissions
}
function set__role {
function set__listrelay {
role="relay"
set_permissions
}
function set__listadmin {
role="admin"
set_permissions
}
set_permissions() {
set -o noglob # Disable globbing to avoid expansions when passing * as value.
declare values="list$role"
newValues="${!values}" # Here we expand the dynamic variable we created in the previous line. ! Does the trick
@ -67,7 +75,7 @@ function set__role {
if [ -n "$newValues" ]
then
ynh_systemd_action --service_name="$app" --action=stop
#ynh_systemd_action --service_name="$app" --action=stop
# Get all entries between "permissions:" and "relay:" keys, remove the role part, remove commented parts, format it with newlines and clean whitespaces and double quotes.
allDefinedEntries=$(awk '/permissions:/{flag=1; next} /relay:/{flag=0} flag' "$final_path/config.yaml" | sed "/: $role/d" | sed -r 's/: (admin|user|relay)//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr ',' '\n' )
# Delete everything from the corresponding role to insert the new defined values. This way we also handle deletion of users.

View file

@ -306,12 +306,12 @@ ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start"
# Re-apply permissions to avoid wrong syntax "domain.tld,domain2.tld: admin"
role="user"
yunohost app config set mautrix_whatsapp usermanagement.config.role
role="admin"
yunohost app config set mautrix_whatsapp usermanagement.config.role
role="relay"
yunohost app config set mautrix_whatsapp usermanagement.config.role
yunohost app config get mautrix_whatsapp main.permissions.listuser
yunohost app config set mautrix_whatsapp main.permissions.listuser
yunohost app config get mautrix_whatsapp main.permissions.listrelay
yunohost app config set mautrix_whatsapp main.permissions.listrelay
yunohost app config get mautrix_whatsapp main.permissions.listadmin
yunohost app config set mautrix_whatsapp main.permissions.listadmin
#=================================================
# END OF SCRIPT