# HG changeset patch # User Marcin Kuzminski # Date 2018-07-11 11:27:17 # Node ID 3939ff15aaa0eee174d33ac5ae46b4f1a4e05d7b # Parent dd2ef7545292cdc070785de40d6ab7489d46a7a5 caches: flush permission caches when editing affected objects so we can reach them right after changes. diff --git a/rhodecode/apps/repo_group/views/repo_group_settings.py b/rhodecode/apps/repo_group/views/repo_group_settings.py --- a/rhodecode/apps/repo_group/views/repo_group_settings.py +++ b/rhodecode/apps/repo_group/views/repo_group_settings.py @@ -24,6 +24,7 @@ import deform from pyramid.view import view_config from pyramid.httpexceptions import HTTPFound +from rhodecode import events from rhodecode.apps._base import RepoGroupAppView from rhodecode.forms import RcForm from rhodecode.lib import helpers as h @@ -31,7 +32,7 @@ from rhodecode.lib import audit_logger from rhodecode.lib.auth import ( LoginRequired, HasPermissionAll, HasRepoGroupPermissionAny, HasRepoGroupPermissionAnyDecorator, CSRFRequired) -from rhodecode.model.db import Session, RepoGroup +from rhodecode.model.db import Session, RepoGroup, User from rhodecode.model.scm import RepoGroupList from rhodecode.model.repo_group import RepoGroupModel from rhodecode.model.validation_schema.schemas import repo_group_schema @@ -72,8 +73,6 @@ class RepoGroupSettingsView(RepoGroupApp if add_parent_group: c.repo_groups_choices.append(parent_group.group_id) c.repo_groups.append(RepoGroup._generate_choice(parent_group)) - - return c def _can_create_repo_group(self, parent_group_id=None): @@ -179,5 +178,12 @@ class RepoGroupSettingsView(RepoGroupApp h.flash(_('Error occurred during update of repository group %s') % old_repo_group_name, category='error') + name_changed = old_repo_group_name != new_repo_group_name + if name_changed: + owner = User.get_by_username(schema_data['repo_group_owner']) + owner_id = owner.user_id if owner else self._rhodecode_user.user_id + events.trigger(events.UserPermissionsChange([ + self._rhodecode_user.user_id, owner_id])) + raise HTTPFound( h.route_path('edit_repo_group', repo_group_name=new_repo_group_name)) diff --git a/rhodecode/apps/repository/views/repo_settings.py b/rhodecode/apps/repository/views/repo_settings.py --- a/rhodecode/apps/repository/views/repo_settings.py +++ b/rhodecode/apps/repository/views/repo_settings.py @@ -24,13 +24,14 @@ import deform from pyramid.httpexceptions import HTTPFound from pyramid.view import view_config +from rhodecode import events from rhodecode.apps._base import RepoAppView from rhodecode.forms import RcForm from rhodecode.lib import helpers as h from rhodecode.lib import audit_logger from rhodecode.lib.auth import ( LoginRequired, HasRepoPermissionAnyDecorator, CSRFRequired) -from rhodecode.model.db import RepositoryField, RepoGroup, Repository +from rhodecode.model.db import RepositoryField, RepoGroup, Repository, User from rhodecode.model.meta import Session from rhodecode.model.repo import RepoModel from rhodecode.model.scm import RepoGroupList, ScmModel @@ -71,8 +72,6 @@ class RepoSettingsView(RepoAppView): c.personal_repo_group = c.auth_user.personal_repo_group c.repo_fields = RepositoryField.query()\ .filter(RepositoryField.repository == self.db_repo).all() - - return c def _get_schema(self, c, old_values=None): @@ -176,6 +175,13 @@ class RepoSettingsView(RepoAppView): h.flash(_('Error occurred during update of repository {}').format( old_repo_name), category='error') + name_changed = old_repo_name != new_repo_name + if name_changed: + owner = User.get_by_username(schema_data['repo_owner']) + owner_id = owner.user_id if owner else self._rhodecode_user.user_id + events.trigger(events.UserPermissionsChange([ + self._rhodecode_user.user_id, owner_id])) + raise HTTPFound( h.route_path('edit_repo', repo_name=new_repo_name)) 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 @@ -140,6 +140,9 @@ class UserGroupsView(UserGroupAppView): user_group = self.db_user_group user_group_id = user_group.users_group_id + old_user_group_name = self.db_user_group_name + new_user_group_name = old_user_group_name + c = self.load_default_context() c.user_group = user_group c.group_members_obj = [x.user for x in c.user_group.members] @@ -152,7 +155,7 @@ class UserGroupsView(UserGroupAppView): old_data=c.user_group.get_dict(), allow_disabled=True)() old_values = c.user_group.get_api_data() - user_group_name = self.request.POST.get('users_group_name') + try: form_result = users_group_form.to_python(self.request.POST) pstruct = peppercorn.parse(self.request.POST.items()) @@ -160,7 +163,7 @@ class UserGroupsView(UserGroupAppView): user_group, added_members, removed_members = \ UserGroupModel().update(c.user_group, form_result) - updated_user_group = form_result['users_group_name'] + new_user_group_name = form_result['users_group_name'] for user_id in added_members: user = User.get(user_id) @@ -182,12 +185,20 @@ class UserGroupsView(UserGroupAppView): 'user_group.edit', action_data={'old_data': old_values}, user=self._rhodecode_user) - h.flash(_('Updated user group %s') % updated_user_group, + h.flash(_('Updated user group %s') % new_user_group_name, category='success') affected_user_ids = [] for user_id in added_members + removed_members: affected_user_ids.append(user_id) + + name_changed = old_user_group_name != new_user_group_name + if name_changed: + owner = User.get_by_username(form_result['user']) + owner_id = owner.user_id if owner else self._rhodecode_user.user_id + affected_user_ids.append(self._rhodecode_user.user_id) + affected_user_ids.append(owner_id) + events.trigger(events.UserPermissionsChange(affected_user_ids)) Session().commit() @@ -211,7 +222,7 @@ class UserGroupsView(UserGroupAppView): except Exception: log.exception("Exception during update of user group") h.flash(_('Error occurred during update of user group %s') - % user_group_name, category='error') + % new_user_group_name, category='error') raise HTTPFound( h.route_path('edit_user_group', user_group_id=user_group_id))