mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Rename variables
This commit is contained in:
parent
b38d1a495e
commit
9aecacd995
3 changed files with 31 additions and 31 deletions
|
@ -241,11 +241,11 @@ ynh_webpath_register () {
|
||||||
#
|
#
|
||||||
# example: ynh_permission_create --permission admin --url /admin --allowed alice bob
|
# example: ynh_permission_create --permission admin --url /admin --allowed alice bob
|
||||||
#
|
#
|
||||||
# usage: ynh_permission_create --permission "permission" [--url "url"] [--allowed group1 group2] [--is_protected "true"|"false"]
|
# usage: ynh_permission_create --permission "permission" [--url "url"] [--allowed group1 group2] [--protected "true"|"false"]
|
||||||
# | arg: permission - the name for the permission (by default a permission named "main" already exist)
|
# | arg: permission - the name for the permission (by default a permission named "main" already exist)
|
||||||
# | arg: url - (optional) URL for which access will be allowed/forbidden
|
# | arg: url - (optional) URL for which access will be allowed/forbidden
|
||||||
# | arg: allowed - (optional) A list of group/user to allow for the permission
|
# | arg: allowed - (optional) A list of group/user to allow for the permission
|
||||||
# | arg: is_protected - (optional) Define if this permission is protected. If it is protected the administrator
|
# | arg: protected - (optional) Define if this permission is protected. If it is protected the administrator
|
||||||
# | won't be able to add or remove the visitors group of this permission.
|
# | won't be able to add or remove the visitors group of this permission.
|
||||||
# | By default it's 'true' (for the permission different than 'main').
|
# | By default it's 'true' (for the permission different than 'main').
|
||||||
#
|
#
|
||||||
|
@ -262,11 +262,11 @@ ynh_webpath_register () {
|
||||||
#
|
#
|
||||||
# Requires YunoHost version 3.7.0 or higher.
|
# Requires YunoHost version 3.7.0 or higher.
|
||||||
ynh_permission_create() {
|
ynh_permission_create() {
|
||||||
declare -Ar args_array=( [p]=permission= [u]=url= [a]=allowed= [p]=is_protected= )
|
declare -Ar args_array=( [p]=permission= [u]=url= [a]=allowed= [p]=protected= )
|
||||||
local permission
|
local permission
|
||||||
local url
|
local url
|
||||||
local allowed
|
local allowed
|
||||||
local is_protected
|
local protected
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
|
|
||||||
if [[ -n ${url:-} ]]; then
|
if [[ -n ${url:-} ]]; then
|
||||||
|
@ -277,15 +277,15 @@ ynh_permission_create() {
|
||||||
if [[ -n ${allowed:-} ]]; then
|
if [[ -n ${allowed:-} ]]; then
|
||||||
allowed=",allowed=['${allowed//';'/"','"}']"
|
allowed=",allowed=['${allowed//';'/"','"}']"
|
||||||
fi
|
fi
|
||||||
if [ -n ${is_protected} ]; then
|
if [ -n ${protected} ]; then
|
||||||
if [ $is_protected == "true" ]; then
|
if [ $protected == "true" ]; then
|
||||||
is_protected=",is_protected=True"
|
protected=",protected=True"
|
||||||
else
|
else
|
||||||
is_protected=",is_protected=False"
|
protected=",protected=False"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
yunohost tools shell -c "from yunohost.permission import permission_create; permission_create('$app.$permission', url=$url ${allowed:-} ${is_protected:-} , sync_perm=False)"
|
yunohost tools shell -c "from yunohost.permission import permission_create; permission_create('$app.$permission', url=$url ${allowed:-} ${protected:-} , sync_perm=False)"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Remove a permission for the app (note that when the app is removed all permission is automatically removed)
|
# Remove a permission for the app (note that when the app is removed all permission is automatically removed)
|
||||||
|
@ -343,21 +343,21 @@ ynh_permission_url() {
|
||||||
|
|
||||||
# Update a permission for the app
|
# Update a permission for the app
|
||||||
#
|
#
|
||||||
# usage: ynh_permission_update --permission "permission" --add "group" ["group" ...] --remove "group" ["group" ...] [--is_protected "true"|"false"]
|
# usage: ynh_permission_update --permission "permission" --add "group" ["group" ...] --remove "group" ["group" ...] [--protected "true"|"false"]
|
||||||
# | arg: permission - the name for the permission (by default a permission named "main" already exist)
|
# | 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: 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
|
# | arg: remove - the list of group or users to remove from the permission
|
||||||
# | arg: is_protected - (optional) Define if this permission is protected. If it is protected the administrator
|
# | arg: protected - (optional) Define if this permission is protected. If it is protected the administrator
|
||||||
# | won't be able to add or remove the visitors group of this permission.
|
# | won't be able to add or remove the visitors group of this permission.
|
||||||
#
|
#
|
||||||
# example: ynh_permission_update --permission admin --add samdoe --remove all_users
|
# example: ynh_permission_update --permission admin --add samdoe --remove all_users
|
||||||
# Requires YunoHost version 3.7.0 or higher.
|
# Requires YunoHost version 3.7.0 or higher.
|
||||||
ynh_permission_update() {
|
ynh_permission_update() {
|
||||||
declare -Ar args_array=( [p]=permission= [a]=add= [r]=remove= [p]=is_protected= )
|
declare -Ar args_array=( [p]=permission= [a]=add= [r]=remove= [p]=protected= )
|
||||||
local permission
|
local permission
|
||||||
local add
|
local add
|
||||||
local remove
|
local remove
|
||||||
local is_protected
|
local protected
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
|
|
||||||
if [[ -n ${add:-} ]]; then
|
if [[ -n ${add:-} ]]; then
|
||||||
|
@ -366,13 +366,13 @@ ynh_permission_update() {
|
||||||
if [[ -n ${remove:-} ]]; then
|
if [[ -n ${remove:-} ]]; then
|
||||||
remove=",remove=['${remove//';'/"','"}']"
|
remove=",remove=['${remove//';'/"','"}']"
|
||||||
fi
|
fi
|
||||||
if [ -n ${is_protected} ]; then
|
if [ -n ${protected} ]; then
|
||||||
if [ $is_protected == "true" ]; then
|
if [ $protected == "true" ]; then
|
||||||
is_protected=",is_protected=True"
|
protected=",protected=True"
|
||||||
else
|
else
|
||||||
is_protected=",is_protected=False"
|
protected=",protected=False"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
yunohost tools shell -c "from yunohost.permission import user_permission_update; user_permission_update('$app.$permission', ${add:-} ${remove} ${is_protected:-} , force=True, sync_perm=False)"
|
yunohost tools shell -c "from yunohost.permission import user_permission_update; user_permission_update('$app.$permission', ${add:-} ${remove} ${protected:-} , force=True, sync_perm=False)"
|
||||||
}
|
}
|
||||||
|
|
|
@ -750,7 +750,7 @@ def app_install(operation_logger, app, label=None, args=None, no_remove_on_failu
|
||||||
|
|
||||||
# Initialize the main permission for the app
|
# Initialize the main permission for the app
|
||||||
# After the install, if apps don't have a domain and path defined, the default url '/' is removed from the permission
|
# After the install, if apps don't have a domain and path defined, the default url '/' is removed from the permission
|
||||||
permission_create(app_instance_name+".main", url="/", allowed=["all_users"], is_protected=False)
|
permission_create(app_instance_name+".main", url="/", allowed=["all_users"], protected=False)
|
||||||
|
|
||||||
# Execute the app install script
|
# Execute the app install script
|
||||||
install_failed = True
|
install_failed = True
|
||||||
|
|
|
@ -82,7 +82,7 @@ def user_permission_list(short=False, full=False, ignore_system_perms=False):
|
||||||
return {'permissions': permissions}
|
return {'permissions': permissions}
|
||||||
|
|
||||||
@is_unit_operation()
|
@is_unit_operation()
|
||||||
def user_permission_update(operation_logger, permission, add=None, remove=None, is_protected=None, force=False, sync_perm=True):
|
def user_permission_update(operation_logger, permission, add=None, remove=None, protected=None, force=False, sync_perm=True):
|
||||||
"""
|
"""
|
||||||
Allow or Disallow a user or group to a permission for a specific application
|
Allow or Disallow a user or group to a permission for a specific application
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ def user_permission_update(operation_logger, permission, add=None, remove=None,
|
||||||
permission -- Name of the permission (e.g. mail or or wordpress or wordpress.editors)
|
permission -- Name of the permission (e.g. mail or or wordpress or wordpress.editors)
|
||||||
add -- List of groups or usernames to add to this permission
|
add -- List of groups or usernames to add to this permission
|
||||||
remove -- List of groups or usernames to remove from to this permission
|
remove -- List of groups or usernames to remove from to this permission
|
||||||
is_protected -- (optional) Define if the permission can be added/removed to the visitor group
|
protected -- (optional) Define if the permission can be added/removed to the visitor group
|
||||||
force -- (optional) Give the possibility to add/remove access from the visitor group to a protected permission
|
force -- (optional) Give the possibility to add/remove access from the visitor group to a protected permission
|
||||||
"""
|
"""
|
||||||
from yunohost.user import user_group_list
|
from yunohost.user import user_group_list
|
||||||
|
@ -174,7 +174,7 @@ def user_permission_update(operation_logger, permission, add=None, remove=None,
|
||||||
|
|
||||||
operation_logger.start()
|
operation_logger.start()
|
||||||
|
|
||||||
new_permission = _update_ldap_group_permission(permission=permission, allowed=new_allowed_groups, is_protected=is_protected, sync_perm=sync_perm)
|
new_permission = _update_ldap_group_permission(permission=permission, allowed=new_allowed_groups, protected=protected, sync_perm=sync_perm)
|
||||||
|
|
||||||
logger.debug(m18n.n('permission_updated', permission=permission))
|
logger.debug(m18n.n('permission_updated', permission=permission))
|
||||||
|
|
||||||
|
@ -225,7 +225,7 @@ def user_permission_reset(operation_logger, permission, sync_perm=True):
|
||||||
|
|
||||||
|
|
||||||
@is_unit_operation()
|
@is_unit_operation()
|
||||||
def permission_create(operation_logger, permission, url=None, allowed=None, is_protected=True, sync_perm=True):
|
def permission_create(operation_logger, permission, url=None, allowed=None, protected=True, sync_perm=True):
|
||||||
"""
|
"""
|
||||||
Create a new permission for a specific application
|
Create a new permission for a specific application
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ def permission_create(operation_logger, permission, url=None, allowed=None, is_p
|
||||||
permission -- Name of the permission (e.g. mail or nextcloud or wordpress.editors)
|
permission -- Name of the permission (e.g. mail or nextcloud or wordpress.editors)
|
||||||
url -- (optional) URL for which access will be allowed/forbidden
|
url -- (optional) URL for which access will be allowed/forbidden
|
||||||
allowed -- (optional) A list of group/user to allow for the permission
|
allowed -- (optional) A list of group/user to allow for the permission
|
||||||
is_protected -- (optional) Define if the permission can be added/removed to the visitor group
|
protected -- (optional) Define if the permission can be added/removed to the visitor group
|
||||||
|
|
||||||
If provided, 'url' is assumed to be relative to the app domain/path if they
|
If provided, 'url' is assumed to be relative to the app domain/path if they
|
||||||
start with '/'. For example:
|
start with '/'. For example:
|
||||||
|
@ -297,7 +297,7 @@ def permission_create(operation_logger, permission, url=None, allowed=None, is_p
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise YunohostError('permission_creation_failed', permission=permission, error=e)
|
raise YunohostError('permission_creation_failed', permission=permission, error=e)
|
||||||
|
|
||||||
new_permission = _update_ldap_group_permission(permission=permission, allowed=allowed, is_protected=is_protected, sync_perm=sync_perm)
|
new_permission = _update_ldap_group_permission(permission=permission, allowed=allowed, protected=protected, sync_perm=sync_perm)
|
||||||
|
|
||||||
logger.debug(m18n.n('permission_created', permission=permission))
|
logger.debug(m18n.n('permission_created', permission=permission))
|
||||||
return new_permission
|
return new_permission
|
||||||
|
@ -435,7 +435,7 @@ def permission_sync_to_user():
|
||||||
os.system('nscd --invalidate=group')
|
os.system('nscd --invalidate=group')
|
||||||
|
|
||||||
|
|
||||||
def _update_ldap_group_permission(permission, allowed, is_protected=None, sync_perm=True):
|
def _update_ldap_group_permission(permission, allowed, protected=None, sync_perm=True):
|
||||||
"""
|
"""
|
||||||
Internal function that will rewrite user permission
|
Internal function that will rewrite user permission
|
||||||
|
|
||||||
|
@ -463,13 +463,13 @@ def _update_ldap_group_permission(permission, allowed, is_protected=None, sync_p
|
||||||
|
|
||||||
allowed = [allowed] if not isinstance(allowed, list) else allowed
|
allowed = [allowed] if not isinstance(allowed, list) else allowed
|
||||||
|
|
||||||
if is_protected is None:
|
if protected is None:
|
||||||
is_protected = existing_permission["protected"]
|
protected = existing_permission["protected"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ldap.update('cn=%s,ou=permission' % permission,
|
ldap.update('cn=%s,ou=permission' % permission,
|
||||||
{'groupPermission': ['cn=' + g + ',ou=groups,dc=yunohost,dc=org' for g in allowed],
|
{'groupPermission': ['cn=' + g + ',ou=groups,dc=yunohost,dc=org' for g in allowed],
|
||||||
'isProtected': "TRUE" if is_protected else "FALSE"})
|
'isProtected': "TRUE" if protected else "FALSE"})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise YunohostError('permission_update_failed', permission=permission, error=e)
|
raise YunohostError('permission_update_failed', permission=permission, error=e)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue