mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
trigger hooks when adding or removing user into group
This commit is contained in:
parent
c5953b5420
commit
51787a2f8b
1 changed files with 36 additions and 0 deletions
36
src/user.py
36
src/user.py
|
@ -1137,6 +1137,7 @@ def user_group_update(
|
||||||
):
|
):
|
||||||
from yunohost.permission import permission_sync_to_user
|
from yunohost.permission import permission_sync_to_user
|
||||||
from yunohost.utils.ldap import _get_ldap_interface, _ldap_path_extract
|
from yunohost.utils.ldap import _get_ldap_interface, _ldap_path_extract
|
||||||
|
from yunohost.hook import hook_callback
|
||||||
|
|
||||||
existing_users = list(user_list()["users"].keys())
|
existing_users = list(user_list()["users"].keys())
|
||||||
|
|
||||||
|
@ -1176,6 +1177,11 @@ def user_group_update(
|
||||||
new_group_members = copy.copy(current_group_members)
|
new_group_members = copy.copy(current_group_members)
|
||||||
new_attr_dict = {}
|
new_attr_dict = {}
|
||||||
|
|
||||||
|
# Group permissions
|
||||||
|
current_group_permissions = [
|
||||||
|
_ldap_path_extract(p, "cn") for p in group.get("permission", [])
|
||||||
|
]
|
||||||
|
|
||||||
if add:
|
if add:
|
||||||
users_to_add = [add] if not isinstance(add, list) else add
|
users_to_add = [add] if not isinstance(add, list) else add
|
||||||
|
|
||||||
|
@ -1289,6 +1295,36 @@ def user_group_update(
|
||||||
if sync_perm:
|
if sync_perm:
|
||||||
permission_sync_to_user()
|
permission_sync_to_user()
|
||||||
|
|
||||||
|
if add and users_to_add:
|
||||||
|
for permission in current_group_permissions:
|
||||||
|
app = permission.split(".")[0]
|
||||||
|
sub_permission = permission.split(".")[1]
|
||||||
|
|
||||||
|
hook_callback(
|
||||||
|
"post_app_addaccess",
|
||||||
|
args=[
|
||||||
|
app,
|
||||||
|
",".join(users_to_add),
|
||||||
|
sub_permission,
|
||||||
|
""
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
if remove and users_to_remove:
|
||||||
|
for permission in current_group_permissions:
|
||||||
|
app = permission.split(".")[0]
|
||||||
|
sub_permission = permission.split(".")[1]
|
||||||
|
|
||||||
|
hook_callback(
|
||||||
|
"post_app_removeaccess",
|
||||||
|
args=[
|
||||||
|
app,
|
||||||
|
",".join(users_to_remove),
|
||||||
|
sub_permission,
|
||||||
|
""
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
if not from_import:
|
if not from_import:
|
||||||
if groupname != "all_users":
|
if groupname != "all_users":
|
||||||
if not new_attr_dict:
|
if not new_attr_dict:
|
||||||
|
|
Loading…
Add table
Reference in a new issue