mirror of
https://github.com/YunoHost-Apps/hextris_ynh.git
synced 2024-09-03 19:16:05 +02:00
Migration using experimental helper (#14)
* Create _common.sh * Use experimental helper in upgrade
This commit is contained in:
parent
54c84ab0ac
commit
8e98e49d33
2 changed files with 61 additions and 4 deletions
52
scripts/_common.sh
Normal file
52
scripts/_common.sh
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# COMMON VARIABLES
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# PERSONAL HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# EXPERIMENTAL HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# FUTURE OFFICIAL HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Check if a permission exists
|
||||||
|
#
|
||||||
|
# While waiting for this new helper https://github.com/YunoHost/yunohost/pull/905
|
||||||
|
# We have to use another one because the new helper use a new YunoHost command, not available for now.
|
||||||
|
#
|
||||||
|
# usage: ynh_permission_has_user --permission=permission --user=user
|
||||||
|
# | arg: -p, --permission - the permission to check
|
||||||
|
# | arg: -u, --user - the user seek in the permission
|
||||||
|
#
|
||||||
|
# example: ynh_permission_has_user --permission=main --user=visitors
|
||||||
|
#
|
||||||
|
# Requires YunoHost version 3.7.1 or higher.
|
||||||
|
ynh_permission_has_user() {
|
||||||
|
local legacy_args=pu
|
||||||
|
# Declare an array to define the options of this helper.
|
||||||
|
declare -Ar args_array=( [p]=permission= [u]=user= )
|
||||||
|
local permission
|
||||||
|
local user
|
||||||
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
|
||||||
|
if ! ynh_permission_exists --permission=$permission
|
||||||
|
then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# List all permissions
|
||||||
|
# Filter only the required permission with a multiline sed (Here a cut from the permission to the next one), remove the url and his value
|
||||||
|
perm="$(yunohost user permission list --full --output-as plain | sed --quiet "/^#$app.$permission/,/^#[[:alnum:]]/p" | sed "/^##url/,+1d")"
|
||||||
|
# Remove all lines starting by # (got from the plain output before)
|
||||||
|
allowed_users="$(echo "$perm" | grep --invert-match '^#')"
|
||||||
|
# Grep the list of users an return the result if the user is indeed into the list
|
||||||
|
echo "$allowed_users" | grep --quiet --word "$user"
|
||||||
|
}
|
|
@ -6,6 +6,7 @@
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
source _common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -37,13 +38,17 @@ if [ -z "$final_path" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Migrate from legacy permission system
|
# Migrate from legacy permission system
|
||||||
|
|
||||||
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
|
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
|
||||||
|
|
||||||
if [ -n "$is_public" ]; then
|
if [ -n "$is_public" ]; then
|
||||||
|
# Removing skipped/unprotected_uris under certain conditions, remove the visitors group added during the migration process of 3.7
|
||||||
|
# Remove skipped_uris. If the app was public, add visitors again to the main permission
|
||||||
|
if ynh_permission_has_user --permission=main --user=visitors
|
||||||
|
then
|
||||||
ynh_app_setting_delete --app=$app --key=skipped_uris
|
ynh_app_setting_delete --app=$app --key=skipped_uris
|
||||||
if [ $is_public -eq 1 ]; then
|
|
||||||
ynh_permission_update --permission "main" --add "visitors"
|
ynh_permission_update --permission "main" --add "visitors"
|
||||||
|
else
|
||||||
|
ynh_app_setting_delete --app=$app --key=skipped_uris
|
||||||
fi
|
fi
|
||||||
ynh_app_setting_delete --app=$app --key=is_public
|
ynh_app_setting_delete --app=$app --key=is_public
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Reference in a new issue