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

Set permissions

This commit is contained in:
ericgaspar 2021-11-26 19:10:55 +01:00
parent 311768b916
commit 2210ca525b
No known key found for this signature in database
GPG key ID: 574F281483054D44
2 changed files with 13 additions and 62 deletions

View file

@ -159,31 +159,17 @@ chown -R $app: "$final_path/"{tpl_c,admin/stdout.log}
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
#================================================= #=================================================
ynh_script_progression --message="Configuring Permissions..." ynh_script_progression --message="Configuring permissions..." --weight=1
ynh_permission_update --permission="main" --add="visitors"
ynh_permission_create --permission="admin" --allowed="$admin" --url="/admin"
# This is a fake permission without any URL.
# The purpose of this permission is only to trigger hooks post_app_add/removeaccess when it's modified.
# We can't use a real permission for now because the actual permision system doesn't support regex.
ynh_permission_create --permission="create poll" --allowed="visitors"
# Make app public if necessary # Make app public if necessary
if [ $is_public -eq 1 ] if [ $is_public -eq 1 ]
then then
if [ "$path_url" == "/" ]; then ynh_permission_update --permission="main" --add="visitors"
# If the path is /, clear it to prevent any error with the regex.
path_url=""
fi
# Modify the domain to be used in a regex
domain_regex=$(echo "$domain" | sed 's@-@.@g')
ynh_app_setting_set --app=$app --key=unprotected_regex --value="$domain_regex$path_url/create_poll.php?.*$","$domain_regex$path_url/adminstuds.php?.*"
else
ynh_permission_update --permission="create poll" --remove="visitors"
fi fi
# Only the admin can access the admin panel of the app (if the app has an admin panel)
ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================

View file

@ -19,7 +19,6 @@ app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path) path_url=$(ynh_app_setting_get --app=$app --key=path)
admin=$(ynh_app_setting_get --app=$app --key=admin) admin=$(ynh_app_setting_get --app=$app --key=admin)
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
final_path=$(ynh_app_setting_get --app=$app --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
language=$(ynh_app_setting_get --app=$app --key=language) language=$(ynh_app_setting_get --app=$app --key=language)
db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
@ -60,50 +59,16 @@ if [ -z "$is_public" ]; then
ynh_app_setting_delete --app=$app --key=public_site ynh_app_setting_delete --app=$app --key=public_site
fi fi
# Fix is_public as a boolean value # Cleaning legacy permissions
if [ "$is_public" = "Yes" ]; then if ynh_legacy_permissions_exists; then
ynh_app_setting_set --app=$app --key=is_public --value=1 ynh_legacy_permissions_delete_all
is_public=1
elif [ "$is_public" = "No" ]; then ynh_app_setting_delete --app=$app --key=is_public
ynh_app_setting_set --app=$app --key=is_public --value=0
is_public=0
fi fi
skipped_uris=$(ynh_app_setting_get --app=$app --key=skipped_uris) if ! ynh_permission_exists --permission="admin"; then
# Create the required permissions
# Unused with the permission system ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin
if [ ! -z "$skipped_uris" ]; then
ynh_app_setting_delete --app=$app --key=skipped_uris
fi
protected_regex=$(ynh_app_setting_get --app=$app --key=protected_regex)
# Unused with the permission system
if [ ! -z "$protected_regex" ]; then
ynh_app_setting_delete --app=$app --key=protected_regex
fi
# Create the permission "upload images" only if it doesn't exist.
if ! ynh_permission_exists --permission="create poll"
then
# This is a fake permission without any URL.
# The purpose of this permission is only to trigger hooks post_app_add/removeaccess when it's modified.
# We can't use a real permission for now because the actual permision system doesn't support regex.
ynh_permission_create --permission="create poll" --allowed="visitors"
# Make app public if necessary
if [ $is_public -eq 1 ]
then
if [ "$path_url" == "/" ]; then
# If the path is /, clear it to prevent any error with the regex.
path_url=""
fi
# Modify the domain to be used in a regex
domain_regex=$(echo "$domain" | sed 's@-@.@g')
ynh_app_setting_set --app=$app --key=unprotected_regex --value="$domain_regex$path_url/create_poll.php?.*$","$domain_regex$path_url/adminstuds.php?.*"
else
ynh_permission_update --permission="create poll" --remove="visitors"
fi
fi fi
# If db_name doesn't exist, create it # If db_name doesn't exist, create it