diff --git a/rhodecode/config/routing.py b/rhodecode/config/routing.py --- a/rhodecode/config/routing.py +++ b/rhodecode/config/routing.py @@ -374,6 +374,10 @@ def make_map(config): '/user_groups/{user_group_id}/edit/advanced', action='edit_advanced', conditions={'method': ['GET']}) + m.connect('edit_user_group_advanced_sync', + '/user_groups/{user_group_id}/edit/advanced/sync', + action='edit_advanced_set_synchronization', conditions={'method': ['POST']}) + m.connect('edit_user_group_members', '/user_groups/{user_group_id}/edit/members', jsroute=True, action='user_group_members', conditions={'method': ['GET']}) diff --git a/rhodecode/controllers/admin/user_groups.py b/rhodecode/controllers/admin/user_groups.py --- a/rhodecode/controllers/admin/user_groups.py +++ b/rhodecode/controllers/admin/user_groups.py @@ -117,7 +117,7 @@ class UserGroupsController(BaseControlle def user_group_actions(user_group_id, user_group_name): return _render("user_group_actions", user_group_id, user_group_name) - ## json generate + # json generate group_iter = UserGroupList(UserGroup.query().all(), perm_set=['usergroup.admin']) @@ -129,6 +129,7 @@ class UserGroupsController(BaseControlle "group_name_raw": user_gr.users_group_name, "desc": h.escape(user_gr.user_group_description), "members": len(user_gr.members), + "sync": user_gr.group_data.get('extern_type'), "active": h.bool2icon(user_gr.users_group_active), "owner": h.escape(h.link_to_user(user_gr.user.username)), "action": user_group_actions( @@ -431,7 +432,6 @@ class UserGroupsController(BaseControlle prefix_error=False, encoding="UTF-8", force_defaults=False) - except Exception: log.exception("Exception during permissions saving") h.flash(_('An error occurred during permissions saving'), @@ -459,6 +459,36 @@ class UserGroupsController(BaseControlle return render('admin/user_groups/user_group_edit.mako') @HasUserGroupPermissionAnyDecorator('usergroup.admin') + def edit_advanced_set_synchronization(self, user_group_id): + user_group_id = safe_int(user_group_id) + user_group = UserGroup.get_or_404(user_group_id) + + existing = user_group.group_data.get('extern_type') + + if existing: + new_state = user_group.group_data + new_state['extern_type'] = None + else: + new_state = user_group.group_data + new_state['extern_type'] = 'manual' + new_state['extern_type_set_by'] = c.rhodecode_user.username + + try: + user_group.group_data = new_state + Session().add(user_group) + Session().commit() + + h.flash(_('User Group synchronization updated successfully'), + category='success') + except Exception: + log.exception("Exception during sync settings saving") + h.flash(_('An error occurred during synchronization update'), + category='error') + + return redirect( + url('edit_user_group_advanced', user_group_id=user_group_id)) + + @HasUserGroupPermissionAnyDecorator('usergroup.admin') @XHRRequired() @jsonify def user_group_members(self, user_group_id): diff --git a/rhodecode/model/user_group.py b/rhodecode/model/user_group.py --- a/rhodecode/model/user_group.py +++ b/rhodecode/model/user_group.py @@ -501,8 +501,8 @@ class UserGroupModel(BaseModel): if not existing_group: desc = 'Automatically created from plugin:%s' % extern_type # we use first admin account to set the owner of the group - existing_group = UserGroupModel().create(gr, desc, owner, - group_data={'extern_type': extern_type}) + existing_group = UserGroupModel().create( + gr, desc, owner, group_data={'extern_type': extern_type}) # we can only add users to special groups created via plugins managed = 'extern_type' in existing_group.group_data @@ -511,8 +511,7 @@ class UserGroupModel(BaseModel): UserGroupModel().add_user_to_group(existing_group, user) else: log.debug('Skipping addition to group %s since it is ' - 'not managed by auth plugins' % gr) - + 'not set to be automatically synchronized' % gr) def change_groups(self, user, groups): """ diff --git a/rhodecode/templates/admin/user_groups/user_group_edit_advanced.mako b/rhodecode/templates/admin/user_groups/user_group_edit_advanced.mako --- a/rhodecode/templates/admin/user_groups/user_group_edit_advanced.mako +++ b/rhodecode/templates/admin/user_groups/user_group_edit_advanced.mako @@ -6,6 +6,8 @@ (_('Created on'), h.format_date(c.user_group.created_on), '', '',), (_('Members'), len(c.group_members_obj),'', [x for x in c.group_members_obj]), + (_('Automatic member sync'), 'Yes' if c.user_group.group_data.get('extern_type') else 'No', '', '',), + (_('Assigned to repositories'), len(c.group_to_repos),'', [x for x in c.group_to_repos]), (_('Assigned to repo groups'), len(c.group_to_repo_groups), '', [x for x in c.group_to_repo_groups]), @@ -19,8 +21,55 @@
+ ${_('This group is set to be automatically synchronised.')}
+ ${_('Each member will be added or removed from this groups once they interact with RhodeCode system.')}
+ ${_('This group synchronization was set by')}: ${sync_type}
+
+ ${_('This group is not set to be automatically synchronised')} +
+ % endif + +