mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge pull request #905 from YunoHost/add-permission-helpers
add ynh_permission_has_user
This commit is contained in:
commit
85df8b6545
4 changed files with 70 additions and 0 deletions
|
@ -296,6 +296,13 @@ user:
|
|||
help: Display all info known about each permission, including the full user list of each group it is granted to.
|
||||
action: store_true
|
||||
|
||||
### user_permission_info()
|
||||
info:
|
||||
action_help: Get information about a specific permission
|
||||
api: GET /users/permissions/<permission>
|
||||
arguments:
|
||||
permission:
|
||||
help: Name of the permission to fetch info about
|
||||
|
||||
### user_permission_update()
|
||||
update:
|
||||
|
|
|
@ -178,6 +178,8 @@ ynh_webpath_register () {
|
|||
#
|
||||
# Requires YunoHost version 3.7.0 or higher.
|
||||
ynh_permission_create() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=pua
|
||||
declare -Ar args_array=( [p]=permission= [u]=url= [a]=allowed= )
|
||||
local permission
|
||||
local url
|
||||
|
@ -206,6 +208,8 @@ ynh_permission_create() {
|
|||
#
|
||||
# Requires YunoHost version 3.7.0 or higher.
|
||||
ynh_permission_delete() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=p
|
||||
declare -Ar args_array=( [p]=permission= )
|
||||
local permission
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
@ -220,6 +224,8 @@ ynh_permission_delete() {
|
|||
#
|
||||
# Requires YunoHost version 3.7.0 or higher.
|
||||
ynh_permission_exists() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=p
|
||||
declare -Ar args_array=( [p]=permission= )
|
||||
local permission
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
@ -235,6 +241,8 @@ ynh_permission_exists() {
|
|||
#
|
||||
# Requires YunoHost version 3.7.0 or higher.
|
||||
ynh_permission_url() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=pu
|
||||
declare -Ar args_array=([p]=permission= [u]=url=)
|
||||
local permission
|
||||
local url
|
||||
|
@ -260,6 +268,8 @@ ynh_permission_url() {
|
|||
# example: ynh_permission_update --permission admin --add samdoe --remove all_users
|
||||
# Requires YunoHost version 3.7.0 or higher.
|
||||
ynh_permission_update() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=par
|
||||
declare -Ar args_array=( [p]=permission= [a]=add= [r]=remove= )
|
||||
local permission
|
||||
local add
|
||||
|
@ -275,3 +285,29 @@ ynh_permission_update() {
|
|||
|
||||
yunohost user permission update "$app.$permission" ${add:-} ${remove:-}
|
||||
}
|
||||
|
||||
# Check if a permission exists
|
||||
#
|
||||
# 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
|
||||
|
||||
yunohost user permission info "$app.$permission" | grep -w -q "$user"
|
||||
}
|
||||
|
|
|
@ -196,6 +196,28 @@ def user_permission_reset(operation_logger, permission, sync_perm=True):
|
|||
|
||||
return new_permission
|
||||
|
||||
|
||||
def user_permission_info(permission):
|
||||
"""
|
||||
Return informations about a specific permission
|
||||
|
||||
Keyword argument:
|
||||
permission -- Name of the permission (e.g. mail or nextcloud or wordpress.editors)
|
||||
"""
|
||||
|
||||
# By default, manipulate main permission
|
||||
if "." not in permission:
|
||||
permission = permission + ".main"
|
||||
|
||||
# Fetch existing permission
|
||||
|
||||
existing_permission = user_permission_list(full=True)["permissions"].get(permission, None)
|
||||
if existing_permission is None:
|
||||
raise YunohostError('permission_not_found', permission=permission)
|
||||
|
||||
return existing_permission
|
||||
|
||||
|
||||
#
|
||||
#
|
||||
# The followings methods are *not* directly exposed.
|
||||
|
|
|
@ -780,6 +780,11 @@ def user_permission_reset(permission, sync_perm=True):
|
|||
sync_perm=sync_perm)
|
||||
|
||||
|
||||
def user_permission_info(permission):
|
||||
import yunohost.permission
|
||||
return yunohost.permission.user_permission_info(permission)
|
||||
|
||||
|
||||
#
|
||||
# SSH subcategory
|
||||
#
|
||||
|
|
Loading…
Add table
Reference in a new issue