diff --git a/rhodecode/apps/admin/__init__.py b/rhodecode/apps/admin/__init__.py --- a/rhodecode/apps/admin/__init__.py +++ b/rhodecode/apps/admin/__init__.py @@ -162,6 +162,14 @@ def admin_routes(config): name='edit_user_ips_delete', pattern='/users/{user_id:\d+}/edit/ips/delete') + # user perms + config.add_route( + name='edit_user_perms_summary', + pattern='/users/{user_id:\d+}/edit/permissions_summary') + config.add_route( + name='edit_user_perms_summary_json', + pattern='/users/{user_id:\d+}/edit/permissions_summary/json') + # user groups management config.add_route( name='edit_user_groups_management', @@ -189,6 +197,14 @@ def admin_routes(config): name='user_group_members_data', pattern='/user_groups/{user_group_id:\d+}/members') + # user groups perms + config.add_route( + name='edit_user_group_perms_summary', + pattern='/user_groups/{user_group_id:\d+}/edit/permissions_summary') + config.add_route( + name='edit_user_group_perms_summary_json', + pattern='/user_groups/{user_group_id:\d+}/edit/permissions_summary/json') + def includeme(config): settings = config.get_settings() diff --git a/rhodecode/apps/admin/views/user_groups.py b/rhodecode/apps/admin/views/user_groups.py --- a/rhodecode/apps/admin/views/user_groups.py +++ b/rhodecode/apps/admin/views/user_groups.py @@ -24,9 +24,7 @@ import datetime from pyramid.httpexceptions import HTTPFound from pyramid.view import view_config -from rhodecode.lib.helpers import Page from rhodecode.model.scm import UserGroupList -from rhodecode_tools.lib.ext_json import json from rhodecode.apps._base import BaseAppView, DataGridAppView from rhodecode.lib.auth import ( @@ -35,10 +33,10 @@ from rhodecode.lib.auth import ( from rhodecode.lib import helpers as h from rhodecode.lib.utils import PartialRenderer from rhodecode.lib.utils2 import safe_int, safe_unicode -from rhodecode.model.auth_token import AuthTokenModel -from rhodecode.model.user import UserModel from rhodecode.model.user_group import UserGroupModel -from rhodecode.model.db import User, UserGroup, UserGroupMember, or_, count +from rhodecode.model.db import ( + joinedload, or_, count, User, UserGroup, UserGroupMember, + UserGroupRepoToPerm, UserGroupRepoGroupToPerm) from rhodecode.model.meta import Session log = logging.getLogger(__name__) @@ -201,3 +199,58 @@ class AdminUserGroupsView(BaseAppView, D return { 'members': group_members } + + def _get_perms_summary(self, user_group_id): + permissions = { + 'repositories': {}, + 'repositories_groups': {}, + } + ugroup_repo_perms = UserGroupRepoToPerm.query()\ + .options(joinedload(UserGroupRepoToPerm.permission))\ + .options(joinedload(UserGroupRepoToPerm.repository))\ + .filter(UserGroupRepoToPerm.users_group_id == user_group_id)\ + .all() + + for gr in ugroup_repo_perms: + permissions['repositories'][gr.repository.repo_name] \ + = gr.permission.permission_name + + ugroup_group_perms = UserGroupRepoGroupToPerm.query()\ + .options(joinedload(UserGroupRepoGroupToPerm.permission))\ + .options(joinedload(UserGroupRepoGroupToPerm.group))\ + .filter(UserGroupRepoGroupToPerm.users_group_id == user_group_id)\ + .all() + + for gr in ugroup_group_perms: + permissions['repositories_groups'][gr.group.group_name] \ + = gr.permission.permission_name + return permissions + + @LoginRequired() + @HasUserGroupPermissionAnyDecorator('usergroup.admin') + @view_config( + route_name='edit_user_group_perms_summary', request_method='GET', + renderer='rhodecode:templates/admin/user_groups/user_group_edit.mako') + def user_group_perms_summary(self): + c = self.load_default_context() + + user_group_id = self.request.matchdict.get('user_group_id') + c.user_group = UserGroup.get_or_404(user_group_id) + + c.active = 'perms_summary' + + c.permissions = self._get_perms_summary(c.user_group.users_group_id) + return self._get_template_context(c) + + @LoginRequired() + @HasUserGroupPermissionAnyDecorator('usergroup.admin') + @view_config( + route_name='edit_user_group_perms_summary_json', request_method='GET', + renderer='json_ext') + def user_group_perms_summary(self): + self.load_default_context() + + user_group_id = self.request.matchdict.get('user_group_id') + user_group = UserGroup.get_or_404(user_group_id) + + return self._get_perms_summary(user_group.users_group_id) diff --git a/rhodecode/apps/admin/views/users.py b/rhodecode/apps/admin/views/users.py --- a/rhodecode/apps/admin/views/users.py +++ b/rhodecode/apps/admin/views/users.py @@ -635,3 +635,36 @@ class AdminUsersView(BaseAppView, DataGr c.filter_term = filter_term return self._get_template_context(c) + @LoginRequired() + @HasPermissionAllDecorator('hg.admin') + @view_config( + route_name='edit_user_perms_summary', request_method='GET', + renderer='rhodecode:templates/admin/users/user_edit.mako') + def user_perms_summary(self): + _ = self.request.translate + c = self.load_default_context() + + user_id = self.request.matchdict.get('user_id') + c.user = User.get_or_404(user_id) + self._redirect_for_default_user(c.user.username) + + c.active = 'perms_summary' + c.perm_user = c.user.AuthUser(ip_addr=self.request.remote_addr) + + return self._get_template_context(c) + + @LoginRequired() + @HasPermissionAllDecorator('hg.admin') + @view_config( + route_name='edit_user_perms_summary_json', request_method='GET', + renderer='json_ext') + def user_perms_summary_json(self): + self.load_default_context() + + user_id = self.request.matchdict.get('user_id') + user = User.get_or_404(user_id) + self._redirect_for_default_user(user.username) + + perm_user = user.AuthUser(ip_addr=self.request.remote_addr) + + return perm_user.permissions diff --git a/rhodecode/config/routing.py b/rhodecode/config/routing.py --- a/rhodecode/config/routing.py +++ b/rhodecode/config/routing.py @@ -271,9 +271,6 @@ def make_map(config): m.connect('edit_user_global_perms', '/users/{user_id}/edit/global_permissions', action='update_global_perms', conditions={'method': ['PUT']}) - m.connect('edit_user_perms_summary', '/users/{user_id}/edit/permissions_summary', - action='edit_perms_summary', conditions={'method': ['GET']}) - # ADMIN USER GROUPS REST ROUTES with rmap.submapper(path_prefix=ADMIN_PREFIX, controller='admin/user_groups') as m: @@ -296,9 +293,6 @@ def make_map(config): m.connect('edit_user_group_global_perms', '/user_groups/{user_group_id}/edit/global_permissions', action='update_global_perms', conditions={'method': ['PUT']}) - m.connect('edit_user_group_perms_summary', - '/user_groups/{user_group_id}/edit/permissions_summary', - action='edit_perms_summary', conditions={'method': ['GET']}) m.connect('edit_user_group_perms', '/user_groups/{user_group_id}/edit/permissions', 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 @@ -297,36 +297,7 @@ class UserGroupsController(BaseControlle h.flash(_('User Group permissions updated'), category='success') return redirect(url('edit_user_group_perms', user_group_id=user_group_id)) - @HasUserGroupPermissionAnyDecorator('usergroup.admin') - def edit_perms_summary(self, user_group_id): - user_group_id = safe_int(user_group_id) - c.user_group = UserGroup.get_or_404(user_group_id) - c.active = 'perms_summary' - permissions = { - 'repositories': {}, - 'repositories_groups': {}, - } - ugroup_repo_perms = UserGroupRepoToPerm.query()\ - .options(joinedload(UserGroupRepoToPerm.permission))\ - .options(joinedload(UserGroupRepoToPerm.repository))\ - .filter(UserGroupRepoToPerm.users_group_id == user_group_id)\ - .all() - for gr in ugroup_repo_perms: - permissions['repositories'][gr.repository.repo_name] \ - = gr.permission.permission_name - - ugroup_group_perms = UserGroupRepoGroupToPerm.query()\ - .options(joinedload(UserGroupRepoGroupToPerm.permission))\ - .options(joinedload(UserGroupRepoGroupToPerm.group))\ - .filter(UserGroupRepoGroupToPerm.users_group_id == user_group_id)\ - .all() - - for gr in ugroup_group_perms: - permissions['repositories_groups'][gr.group.group_name] \ - = gr.permission.permission_name - c.permissions = permissions - return render('admin/user_groups/user_group_edit.mako') @HasUserGroupPermissionAnyDecorator('usergroup.admin') def edit_global_perms(self, user_group_id): diff --git a/rhodecode/controllers/admin/users.py b/rhodecode/controllers/admin/users.py --- a/rhodecode/controllers/admin/users.py +++ b/rhodecode/controllers/admin/users.py @@ -488,16 +488,4 @@ class UsersController(BaseController): category='error') return redirect(url('edit_user_global_perms', user_id=user_id)) - @HasPermissionAllDecorator('hg.admin') - def edit_perms_summary(self, user_id): - user_id = safe_int(user_id) - c.user = User.get_or_404(user_id) - if c.user.username == User.DEFAULT_USER: - h.flash(_("You can't edit this user"), category='warning') - return redirect(h.route_path('users')) - c.active = 'perms_summary' - c.perm_user = AuthUser(user_id=user_id, ip_addr=self.ip_addr) - - return render('admin/users/user_edit.mako') - diff --git a/rhodecode/public/js/rhodecode/routes.js b/rhodecode/public/js/rhodecode/routes.js --- a/rhodecode/public/js/rhodecode/routes.js +++ b/rhodecode/public/js/rhodecode/routes.js @@ -72,12 +72,16 @@ function registerRCRoutes() { pyroutes.register('edit_user_ips', '/_admin/users/%(user_id)s/edit/ips', ['user_id']); pyroutes.register('edit_user_ips_add', '/_admin/users/%(user_id)s/edit/ips/new', ['user_id']); pyroutes.register('edit_user_ips_delete', '/_admin/users/%(user_id)s/edit/ips/delete', ['user_id']); + pyroutes.register('edit_user_perms_summary', '/_admin/users/%(user_id)s/edit/permissions_summary', ['user_id']); + pyroutes.register('edit_user_perms_summary_json', '/_admin/users/%(user_id)s/edit/permissions_summary/json', ['user_id']); pyroutes.register('edit_user_groups_management', '/_admin/users/%(user_id)s/edit/groups_management', ['user_id']); pyroutes.register('edit_user_groups_management_updates', '/_admin/users/%(user_id)s/edit/edit_user_groups_management/updates', ['user_id']); pyroutes.register('edit_user_audit_logs', '/_admin/users/%(user_id)s/edit/audit', ['user_id']); pyroutes.register('user_groups', '/_admin/user_groups', []); pyroutes.register('user_groups_data', '/_admin/user_groups_data', []); pyroutes.register('user_group_members_data', '/_admin/user_groups/%(user_group_id)s/members', ['user_group_id']); + pyroutes.register('edit_user_group_perms_summary', '/_admin/user_groups/%(user_group_id)s/edit/permissions_summary', ['user_group_id']); + pyroutes.register('edit_user_group_perms_summary_json', '/_admin/user_groups/%(user_group_id)s/edit/permissions_summary/json', ['user_group_id']); pyroutes.register('channelstream_connect', '/_admin/channelstream/connect', []); pyroutes.register('channelstream_subscribe', '/_admin/channelstream/subscribe', []); pyroutes.register('channelstream_proxy', '/_channelstream', []); diff --git a/rhodecode/templates/admin/user_groups/user_group_edit.mako b/rhodecode/templates/admin/user_groups/user_group_edit.mako --- a/rhodecode/templates/admin/user_groups/user_group_edit.mako +++ b/rhodecode/templates/admin/user_groups/user_group_edit.mako @@ -34,7 +34,7 @@