# HG changeset patch # User RhodeCode Admin # Date 2021-05-24 21:47:29 # Node ID 63f392fccbb954fce1f07c62c2dea96168b70d8c # Parent 7a5e2fc4731d177c96bd9abcf254438099b9579f api: added proper full permission flush on API calls when creating repos and repo groups. - This allows a full flush and multiple calls made via API diff --git a/rhodecode/api/views/repo_group_api.py b/rhodecode/api/views/repo_group_api.py --- a/rhodecode/api/views/repo_group_api.py +++ b/rhodecode/api/views/repo_group_api.py @@ -232,6 +232,9 @@ def create_repo_group( user=apiuser) Session().commit() + + PermissionModel().trigger_permission_flush() + return { 'msg': 'Created new repo group `%s`' % validated_group_name, 'repo_group': repo_group.get_api_data() diff --git a/rhodecode/apps/admin/views/repo_groups.py b/rhodecode/apps/admin/views/repo_groups.py --- a/rhodecode/apps/admin/views/repo_groups.py +++ b/rhodecode/apps/admin/views/repo_groups.py @@ -349,13 +349,7 @@ class AdminRepoGroupsView(BaseAppView, D % repo_group_name, category='error') raise HTTPFound(h.route_path('home')) - affected_user_ids = [self._rhodecode_user.user_id] - if copy_permissions: - user_group_perms = repo_group.permissions(expand_from_user_groups=True) - copy_perms = [perm['user_id'] for perm in user_group_perms] - # also include those newly created by copy - affected_user_ids.extend(copy_perms) - PermissionModel().trigger_permission_flush(affected_user_ids) + PermissionModel().trigger_permission_flush() raise HTTPFound( h.route_path('repo_group_home', diff --git a/rhodecode/apps/admin/views/repositories.py b/rhodecode/apps/admin/views/repositories.py --- a/rhodecode/apps/admin/views/repositories.py +++ b/rhodecode/apps/admin/views/repositories.py @@ -242,11 +242,7 @@ class AdminReposView(BaseAppView, DataGr repo_name = form_result.get('repo_name_full') - affected_user_ids = [self._rhodecode_user.user_id] - if copy_permissions: - # permission flush is done in repo creating - pass - PermissionModel().trigger_permission_flush(affected_user_ids) + PermissionModel().trigger_permission_flush() raise HTTPFound( h.route_path('repo_creating', repo_name=repo_name, diff --git a/rhodecode/integrations/types/base.py b/rhodecode/integrations/types/base.py --- a/rhodecode/integrations/types/base.py +++ b/rhodecode/integrations/types/base.py @@ -131,7 +131,7 @@ class IntegrationTypeBase(object): :param event: :return: bool """ - allowed_events = self.settings['events'] + allowed_events = self.settings.get('events') or [] if event.name not in allowed_events: log.debug('event ignored: %r event %s not in allowed set of events %s', event, event.name, allowed_events) diff --git a/rhodecode/lib/celerylib/tasks.py b/rhodecode/lib/celerylib/tasks.py --- a/rhodecode/lib/celerylib/tasks.py +++ b/rhodecode/lib/celerylib/tasks.py @@ -38,6 +38,7 @@ from rhodecode.lib import hooks_base from rhodecode.lib.utils2 import safe_int, str2bool, aslist from rhodecode.model.db import ( Session, IntegrityError, true, Repository, RepoGroup, User) +from rhodecode.model.permission import PermissionModel @async_task(ignore_result=True, base=RequestContextTask) @@ -216,6 +217,9 @@ def create_repo(form_data, cur_user): repo=audit_logger.RepoWrap(repo_name=repo_name, repo_id=repo_id)) Session().commit() + + PermissionModel().trigger_permission_flush() + except Exception as e: log.warning('Exception occurred when creating repository, ' 'doing cleanup...', exc_info=True)