From 51787a2f8b9a90616537e28f956ddf8866afa55c Mon Sep 17 00:00:00 2001 From: Emmanuel Averty Date: Fri, 11 Aug 2023 12:05:30 +0200 Subject: [PATCH] trigger hooks when adding or removing user into group --- src/user.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/user.py b/src/user.py index 1b1b75261..e7341bf09 100644 --- a/src/user.py +++ b/src/user.py @@ -1137,6 +1137,7 @@ def user_group_update( ): from yunohost.permission import permission_sync_to_user from yunohost.utils.ldap import _get_ldap_interface, _ldap_path_extract + from yunohost.hook import hook_callback existing_users = list(user_list()["users"].keys()) @@ -1176,6 +1177,11 @@ def user_group_update( new_group_members = copy.copy(current_group_members) new_attr_dict = {} + # Group permissions + current_group_permissions = [ + _ldap_path_extract(p, "cn") for p in group.get("permission", []) + ] + if add: users_to_add = [add] if not isinstance(add, list) else add @@ -1289,6 +1295,36 @@ def user_group_update( if sync_perm: 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 groupname != "all_users": if not new_attr_dict: