diff --git a/data/helpers.d/setting b/data/helpers.d/setting index 0e432d916..502da1ed7 100644 --- a/data/helpers.d/setting +++ b/data/helpers.d/setting @@ -261,32 +261,51 @@ ynh_permission_delete() { yunohost tools shell -c "from yunohost.permission import permission_delete; permission_delete('$app.$permission', sync_perm=False)" } -# Add a path managed by the SSO +# Manage urls related to a permission # -# usage: ynh_permission_add_url --permission "permission" --url "url" ["url" ...] +# usage: ynh_permission_urls --permission "permission" --add "url" ["url" ...] --remove "url" ["url" ...] # | arg: permission - the name for the permission (by default a permission named "main" is removed automatically when the app is removed) -# | arg: urls - (optional) a list of FULL urls for the permission (e.g. domain.tld/apps/admin) +# | arg: add - (optional) a list of FULL urls to add to the permission (e.g. domain.tld/apps/admin) +# | arg: remove - (optional) a list of FULL urls to remove from the permission (e.g. other.tld/apps/admin) # -ynh_permission_add_url() { - declare -Ar args_array=([p]=permission= [u]=urls= ) +ynh_permission_urls() { + declare -Ar args_array=([p]=permission= [a]=add= [r]=remove=) local permission - local urls + local add + local remove ynh_handle_getopts_args "$@" - yunohost tools shell -c "from yunohost.permission import permission_urls; permission_urls('$app.$permission', add=['${urls//';'/"','"}'], sync_perm=False)" + if [[ -n ${add:-} ]]; then + add=",add=['${add//';'/"','"}']" + fi + if [[ -n ${remove:-} ]]; then + remove=",remove=['${remove//';'/"','"}']" + fi + + yunohost tools shell -c "from yunohost.permission import permission_urls; permission_urls('$app.$permission' ${add:-} ${remove:-})" } -# Remove a path managed by the SSO +# Update a permission for the app # -# usage: ynh_permission_del_path --app "app" --permission "permission" --url "url" ["url" ...] -# | arg: permission - the name for the permission (by default a permission named "main" is removed automatically when the app is removed) -# | arg: urls - (optional) a list of FULL urls for the permission (e.g. domain.tld/apps/admin) +# usage: ynh_permission_update --permission "permission" --add "group" ["group" ...] --remove "group" ["group" ...] +# | arg: permission - the name for the permission (by default a permission named "main" already exist) +# | arg: add - the list of group or users to enable add to the permission +# | arg: remove - the list of group or users to remove from the permission # -ynh_permission_remove_url() { - declare -Ar args_array=([p]=permission= [u]=urls= ) +# example: ynh_permission_update --permission admin --add samdoe --remove all_users +ynh_permission_update() { + declare -Ar args_array=( [p]=permission= [a]=add= [r]=remove= ) local permission - local urls + local add + local remove ynh_handle_getopts_args "$@" - yunohost tools shell -c "from yunohost.permission import permission_urls; permission_urls('$app.$permission', remove=['${url//';'/"','"}'], sync_perm=False)" + if [[ -n ${add:-} ]]; then + add="--add ${add//';'/" "}" + fi + if [[ -n ${remove:-} ]]; then + remove="--remove ${remove//';'/" "} " + fi + + yunohost user permission update "$app.$permission" ${add:-} ${remove:-} }