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 - * : All Matrix users
- domain.tld : All users on a given homeserver - domain.tld : All users on a given homeserver
- mxid (@user:matrix.org) : Specific Matrix user - mxid (@user:matrix.org) : Specific Matrix user
Increasing Power: Relay<User<Admin
''' '''
type = "markdown" 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] [main.permissions.listuser]
ask = "Bridge Users" ask = "Bridge Users"
type = "tags" type = "tags"
help = "Access to use the bridge to chat with a WhatsApp account." help = "Access to use the bridge to chat with a WhatsApp account."
[main.permissions.listadmin] [main.permissions.listadmin]
ask = "Bride Administrators" ask = "Bridge Administrators"
type = "tags" type = "tags"
help = "User level and some additional administration tools." 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] [main.bridge]
name = "Puppetting Bridge Settings" name = "Puppetting Bridge Settings"
@ -81,7 +82,9 @@ services = ["__APP__"]
name = "Portal Rooms & Encryption Settings" name = "Portal Rooms & Encryption Settings"
[privacy.portal_rooms.text] [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" type = "markdown"
[privacy.portal_rooms.encryption] [privacy.portal_rooms.encryption]

View file

@ -51,14 +51,22 @@ function get__listadmin {
EOF EOF
} }
function get__role { function set__listuser {
cat <<EOF role="user"
choices: ["admin", "user", "relay"] set_permissions
default: "user"
EOF
} }
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. set -o noglob # Disable globbing to avoid expansions when passing * as value.
declare values="list$role" declare values="list$role"
newValues="${!values}" # Here we expand the dynamic variable we created in the previous line. ! Does the trick 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" ] if [ -n "$newValues" ]
then 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. # 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' ) 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. # 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" ynh_systemd_action --service_name=$app --action="start"
# Re-apply permissions to avoid wrong syntax "domain.tld,domain2.tld: admin" # Re-apply permissions to avoid wrong syntax "domain.tld,domain2.tld: admin"
role="user" yunohost app config get mautrix_whatsapp main.permissions.listuser
yunohost app config set mautrix_whatsapp usermanagement.config.role yunohost app config set mautrix_whatsapp main.permissions.listuser
role="admin" yunohost app config get mautrix_whatsapp main.permissions.listrelay
yunohost app config set mautrix_whatsapp usermanagement.config.role yunohost app config set mautrix_whatsapp main.permissions.listrelay
role="relay" yunohost app config get mautrix_whatsapp main.permissions.listadmin
yunohost app config set mautrix_whatsapp usermanagement.config.role yunohost app config set mautrix_whatsapp main.permissions.listadmin
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT