# HG changeset patch # User Marcin Kuzminski # Date 2018-10-25 09:20:26 # Node ID 379025856c41f9083596756f008fdf53e8f4216e # Parent afc7a9c498dc17351375ae023db30692714f22a2 permissions: flush members of user groups permissions to clear caches. - we could get into a state that permissions isn't changed/showed immidiatelly based on the members of user groups which permissions we change. diff --git a/rhodecode/apps/repo_group/views/repo_group_permissions.py b/rhodecode/apps/repo_group/views/repo_group_permissions.py --- a/rhodecode/apps/repo_group/views/repo_group_permissions.py +++ b/rhodecode/apps/repo_group/views/repo_group_permissions.py @@ -29,6 +29,8 @@ from rhodecode.lib import helpers as h from rhodecode.lib import audit_logger from rhodecode.lib.auth import ( LoginRequired, HasRepoGroupPermissionAnyDecorator, CSRFRequired) +from rhodecode.lib.utils2 import safe_int +from rhodecode.model.db import UserGroup from rhodecode.model.repo_group import RepoGroupModel from rhodecode.model.forms import RepoGroupPermsForm from rhodecode.model.meta import Session @@ -101,6 +103,11 @@ class RepoGroupPermissionsView(RepoGroup for change in changes['added'] + changes['updated'] + changes['deleted']: if change['type'] == 'user': affected_user_ids.append(change['id']) + if change['type'] == 'user_group': + user_group = UserGroup.get(safe_int(change['id'])) + if user_group: + group_members_ids = [x.user_id for x in user_group.members] + affected_user_ids.extend(group_members_ids) events.trigger(events.UserPermissionsChange(affected_user_ids)) diff --git a/rhodecode/apps/repository/views/repo_permissions.py b/rhodecode/apps/repository/views/repo_permissions.py --- a/rhodecode/apps/repository/views/repo_permissions.py +++ b/rhodecode/apps/repository/views/repo_permissions.py @@ -29,6 +29,8 @@ from rhodecode.lib import helpers as h from rhodecode.lib import audit_logger from rhodecode.lib.auth import ( LoginRequired, HasRepoPermissionAnyDecorator, CSRFRequired) +from rhodecode.lib.utils2 import safe_int +from rhodecode.model.db import UserGroup from rhodecode.model.forms import RepoPermsForm from rhodecode.model.meta import Session from rhodecode.model.repo import RepoModel @@ -88,6 +90,11 @@ class RepoSettingsPermissionsView(RepoAp for change in changes['added'] + changes['updated'] + changes['deleted']: if change['type'] == 'user': affected_user_ids.append(change['id']) + if change['type'] == 'user_group': + user_group = UserGroup.get(safe_int(change['id'])) + if user_group: + group_members_ids = [x.user_id for x in user_group.members] + affected_user_ids.extend(group_members_ids) events.trigger(events.UserPermissionsChange(affected_user_ids)) diff --git a/rhodecode/apps/user_group/views/__init__.py b/rhodecode/apps/user_group/views/__init__.py --- a/rhodecode/apps/user_group/views/__init__.py +++ b/rhodecode/apps/user_group/views/__init__.py @@ -40,8 +40,8 @@ from rhodecode.apps._base import UserGro from rhodecode.lib.auth import ( LoginRequired, HasUserGroupPermissionAnyDecorator, CSRFRequired) from rhodecode.lib import helpers as h, audit_logger -from rhodecode.lib.utils2 import str2bool -from rhodecode.model.db import User +from rhodecode.lib.utils2 import str2bool, safe_int +from rhodecode.model.db import User, UserGroup from rhodecode.model.meta import Session from rhodecode.model.user_group import UserGroupModel @@ -377,6 +377,11 @@ class UserGroupsView(UserGroupAppView): for change in changes['added'] + changes['updated'] + changes['deleted']: if change['type'] == 'user': affected_user_ids.append(change['id']) + if change['type'] == 'user_group': + user_group = UserGroup.get(safe_int(change['id'])) + if user_group: + group_members_ids = [x.user_id for x in user_group.members] + affected_user_ids.extend(group_members_ids) events.trigger(events.UserPermissionsChange(affected_user_ids))