Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trigger hooks when adding or removing user into group #1696

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down