annotate rhodecode/controllers/admin/users_groups.py @ 3715:25dbbdae3ed9 beta

consistent handling of grant/revoke of permissions widgets - use 1 method for users and for users groups - use common JS for ajax revoke - cleanup code
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 08 Apr 2013 23:49:08 +0200
parents 7e3d89d9d3a2
children 87e6960e250b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 """
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 rhodecode.controllers.admin.users_groups
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5
3410
5f1850e4712a "Users groups" is grammatically incorrect English - rename to "user groups"
Mads Kiilerich <madski@unity3d.com>
parents: 2987
diff changeset
6 User Groups crud controller for pylons
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1117
diff changeset
7
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 :created_on: Jan 25, 2011
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 :author: marcink
1824
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 :license: GPLv3, see COPYING for more details.
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 """
1206
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
13 # This program is free software: you can redistribute it and/or modify
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
14 # it under the terms of the GNU General Public License as published by
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
15 # the Free Software Foundation, either version 3 of the License, or
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
16 # (at your option) any later version.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1117
diff changeset
17 #
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 # This program is distributed in the hope that it will be useful,
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 # GNU General Public License for more details.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1117
diff changeset
22 #
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 # You should have received a copy of the GNU General Public License
1206
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 import logging
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27 import traceback
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28 import formencode
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 from formencode import htmlfill
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31 from pylons import request, session, tmpl_context as c, url, config
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32 from pylons.controllers.util import abort, redirect
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 from pylons.i18n.translation import _
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34
2109
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2063
diff changeset
35 from rhodecode.lib import helpers as h
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
36 from rhodecode.lib.exceptions import UserGroupsAssignedException
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
37 from rhodecode.lib.utils2 import safe_unicode, str2bool, safe_int
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
38 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator,\
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
39 HasUserGroupPermissionAnyDecorator
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40 from rhodecode.lib.base import BaseController, render
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
41 from rhodecode.model.scm import UserGroupList
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
42 from rhodecode.model.users_group import UserGroupModel
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
43 from rhodecode.model.repo import RepoModel
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
44 from rhodecode.model.db import User, UserGroup, UserGroupToPerm,\
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
45 UserGroupRepoToPerm, UserGroupRepoGroupToPerm
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
46 from rhodecode.model.forms import UserGroupForm, UserGroupPermsForm
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
47 from rhodecode.model.meta import Session
2375
bc2d8c03c050 Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
48 from rhodecode.lib.utils import action_logger
2987
4150c45b5f7f Implemented #638 permissions overview to groups
Marcin Kuzminski <marcin@python-works.com>
parents: 2709
diff changeset
49 from sqlalchemy.orm import joinedload
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
50 from webob.exc import HTTPInternalServerError
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52 log = logging.getLogger(__name__)
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53
1245
5f2fbab7c429 PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
54
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55 class UsersGroupsController(BaseController):
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56 """REST Controller styled on the Atom Publishing Protocol"""
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57 # To properly map this controller, ensure your config/routing.py
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58 # file has a resource setup:
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59 # map.resource('users_group', 'users_groups')
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61 @LoginRequired()
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 def __before__(self):
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63 super(UsersGroupsController, self).__before__()
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64 c.available_permissions = config['available_permissions']
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
66 def __load_data(self, user_group_id):
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
67 ugroup_repo_perms = UserGroupRepoToPerm.query()\
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
68 .options(joinedload(UserGroupRepoToPerm.permission))\
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
69 .options(joinedload(UserGroupRepoToPerm.repository))\
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
70 .filter(UserGroupRepoToPerm.users_group_id == user_group_id)\
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
71 .all()
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
72
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
73 for gr in ugroup_repo_perms:
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
74 c.users_group.permissions['repositories'][gr.repository.repo_name] \
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
75 = gr.permission.permission_name
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
76
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
77 ugroup_group_perms = UserGroupRepoGroupToPerm.query()\
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
78 .options(joinedload(UserGroupRepoGroupToPerm.permission))\
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
79 .options(joinedload(UserGroupRepoGroupToPerm.group))\
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
80 .filter(UserGroupRepoGroupToPerm.users_group_id == user_group_id)\
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
81 .all()
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
82
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
83 for gr in ugroup_group_perms:
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
84 c.users_group.permissions['repositories_groups'][gr.group.group_name] \
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
85 = gr.permission.permission_name
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
86
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
87 c.group_members_obj = sorted((x.user for x in c.users_group.members),
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
88 key=lambda u: u.username.lower())
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
89
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
90 c.group_members = [(x.user_id, x.username) for x in c.group_members_obj]
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
91 c.available_members = sorted(((x.user_id, x.username) for x in
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
92 User.query().all()),
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
93 key=lambda u: u[1].lower())
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
94 repo_model = RepoModel()
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
95 c.users_array = repo_model.get_users_js()
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
96
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
97 # commented out due to not now supporting assignment for user group
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
98 # on user group
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
99 c.users_groups_array = "[]" # repo_model.get_users_groups_js()
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
100 c.available_permissions = config['available_permissions']
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
101
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
102 def __load_defaults(self, user_group_id):
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
103 """
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
104 Load defaults settings for edit, and update
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
105
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
106 :param user_group_id:
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
107 """
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
108 user_group = UserGroup.get_or_404(user_group_id)
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
109 data = user_group.get_dict()
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
110
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
111 ug_model = UserGroupModel()
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
112
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
113 data.update({
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
114 'create_repo_perm': ug_model.has_perm(user_group,
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
115 'hg.create.repository'),
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
116 'fork_repo_perm': ug_model.has_perm(user_group,
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
117 'hg.fork.repository'),
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
118 })
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
119
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
120 # fill user group users
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
121 for p in user_group.user_user_group_to_perm:
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
122 data.update({'u_perm_%s' % p.user.username:
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
123 p.permission.permission_name})
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
124
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
125 return data
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
126
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
127 def index(self, format='html'):
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
128 """GET /users_groups: All items in the collection"""
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
129 # url('users_groups')
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
130
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
131 group_iter = UserGroupList(UserGroup().query().all(),
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
132 perm_set=['usergroup.admin'])
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
133 sk = lambda g: g.users_group_name
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
134 c.users_groups_list = sorted(group_iter, key=sk)
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
135 return render('admin/users_groups/users_groups.html')
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
136
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
137 @HasPermissionAllDecorator('hg.admin')
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
138 def create(self):
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
139 """POST /users_groups: Create a new item"""
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
140 # url('users_groups')
1436
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
141
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
142 users_group_form = UserGroupForm()()
959
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
143 try:
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
144 form_result = users_group_form.to_python(dict(request.POST))
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
145 UserGroupModel().create(name=form_result['users_group_name'],
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
146 owner=self.rhodecode_user.user_id,
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
147 active=form_result['users_group_active'])
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
148
2375
bc2d8c03c050 Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
149 gr = form_result['users_group_name']
bc2d8c03c050 Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
150 action_logger(self.rhodecode_user,
bc2d8c03c050 Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
151 'admin_created_users_group:%s' % gr,
bc2d8c03c050 Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
152 None, self.ip_addr, self.sa)
3565
a8f2d78d14ea consistently capitalize initial letter in flash messages
Mads Kiilerich <madski@unity3d.com>
parents: 3417
diff changeset
153 h.flash(_('Created user group %s') % gr, category='success')
2662
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2375
diff changeset
154 Session().commit()
959
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
155 except formencode.Invalid, errors:
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
156 return htmlfill.render(
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
157 render('admin/users_groups/users_group_add.html'),
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
158 defaults=errors.value,
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
159 errors=errors.error_dict or {},
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
160 prefix_error=False,
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
161 encoding="UTF-8")
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
162 except Exception:
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
163 log.error(traceback.format_exc())
3565
a8f2d78d14ea consistently capitalize initial letter in flash messages
Mads Kiilerich <madski@unity3d.com>
parents: 3417
diff changeset
164 h.flash(_('Error occurred during creation of user group %s') \
959
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
165 % request.POST.get('users_group_name'), category='error')
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
166
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
167 return redirect(url('users_groups'))
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
168
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
169 @HasPermissionAllDecorator('hg.admin')
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
170 def new(self, format='html'):
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
171 """GET /users_groups/new: Form to create a new item"""
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
172 # url('new_users_group')
959
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
173 return render('admin/users_groups/users_group_add.html')
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
174
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
175 @HasUserGroupPermissionAnyDecorator('usergroup.admin')
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
176 def update(self, id):
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
177 """PUT /users_groups/id: Update an existing item"""
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
178 # Forms posted to this method should contain a hidden field:
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
179 # <input type="hidden" name="_method" value="PUT" />
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
180 # Or using helpers:
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
181 # h.form(url('users_group', id=ID),
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
182 # method='put')
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
183 # url('users_group', id=ID)
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
184
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
185 c.users_group = UserGroup.get_or_404(id)
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
186 self.__load_data(id)
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
187
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
188 available_members = [safe_unicode(x[0]) for x in c.available_members]
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
189
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
190 users_group_form = UserGroupForm(edit=True,
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
191 old_data=c.users_group.get_dict(),
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
192 available_members=available_members)()
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
193
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
194 try:
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
195 form_result = users_group_form.to_python(request.POST)
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
196 UserGroupModel().update(c.users_group, form_result)
2375
bc2d8c03c050 Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
197 gr = form_result['users_group_name']
bc2d8c03c050 Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
198 action_logger(self.rhodecode_user,
bc2d8c03c050 Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
199 'admin_updated_users_group:%s' % gr,
bc2d8c03c050 Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
200 None, self.ip_addr, self.sa)
3565
a8f2d78d14ea consistently capitalize initial letter in flash messages
Mads Kiilerich <madski@unity3d.com>
parents: 3417
diff changeset
201 h.flash(_('Updated user group %s') % gr, category='success')
2662
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2375
diff changeset
202 Session().commit()
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
203 except formencode.Invalid, errors:
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
204 ug_model = UserGroupModel()
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
205 defaults = errors.value
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
206 e = errors.error_dict or {}
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
207 defaults.update({
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
208 'create_repo_perm': ug_model.has_perm(id,
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
209 'hg.create.repository'),
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
210 'fork_repo_perm': ug_model.has_perm(id,
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
211 'hg.fork.repository'),
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
212 '_method': 'put'
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
213 })
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
214
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
215 return htmlfill.render(
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
216 render('admin/users_groups/users_group_edit.html'),
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
217 defaults=defaults,
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
218 errors=e,
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
219 prefix_error=False,
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
220 encoding="UTF-8")
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
221 except Exception:
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
222 log.error(traceback.format_exc())
3565
a8f2d78d14ea consistently capitalize initial letter in flash messages
Mads Kiilerich <madski@unity3d.com>
parents: 3417
diff changeset
223 h.flash(_('Error occurred during update of user group %s') \
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
224 % request.POST.get('users_group_name'), category='error')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
225
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
226 return redirect(url('edit_users_group', id=id))
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
227
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
228 @HasUserGroupPermissionAnyDecorator('usergroup.admin')
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
229 def delete(self, id):
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
230 """DELETE /users_groups/id: Delete an existing item"""
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
231 # Forms posted to this method should contain a hidden field:
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
232 # <input type="hidden" name="_method" value="DELETE" />
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
233 # Or using helpers:
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
234 # h.form(url('users_group', id=ID),
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
235 # method='delete')
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
236 # url('users_group', id=ID)
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
237 usr_gr = UserGroup.get_or_404(id)
973
9be6d46c72d6 #56 implemented users groups deletes
Marcin Kuzminski <marcin@python-works.com>
parents: 972
diff changeset
238 try:
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
239 UserGroupModel().delete(usr_gr)
2662
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2375
diff changeset
240 Session().commit()
3565
a8f2d78d14ea consistently capitalize initial letter in flash messages
Mads Kiilerich <madski@unity3d.com>
parents: 3417
diff changeset
241 h.flash(_('Successfully deleted user group'), category='success')
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
242 except UserGroupsAssignedException, e:
1435
a62af7d509ee fixes #228 - added detection of assigned groups to prevent errors on sqlite
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
243 h.flash(e, category='error')
973
9be6d46c72d6 #56 implemented users groups deletes
Marcin Kuzminski <marcin@python-works.com>
parents: 972
diff changeset
244 except Exception:
2063
d9ba58526712 fixed #373 missing cascade drop on user_group_to_perm table
Marcin Kuzminski <marcin@python-works.com>
parents: 1952
diff changeset
245 log.error(traceback.format_exc())
3410
5f1850e4712a "Users groups" is grammatically incorrect English - rename to "user groups"
Mads Kiilerich <madski@unity3d.com>
parents: 2987
diff changeset
246 h.flash(_('An error occurred during deletion of user group'),
973
9be6d46c72d6 #56 implemented users groups deletes
Marcin Kuzminski <marcin@python-works.com>
parents: 972
diff changeset
247 category='error')
9be6d46c72d6 #56 implemented users groups deletes
Marcin Kuzminski <marcin@python-works.com>
parents: 972
diff changeset
248 return redirect(url('users_groups'))
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
249
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
250 @HasUserGroupPermissionAnyDecorator('usergroup.admin')
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
251 def set_user_group_perm_member(self, id):
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
252 """
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
253 grant permission for given usergroup
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
254
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
255 :param id:
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
256 """
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
257 user_group = UserGroup.get_or_404(id)
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
258 form = UserGroupPermsForm()().to_python(request.POST)
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
259
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
260 # set the permissions !
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
261 UserGroupModel()._update_permissions(user_group, form['perms_new'],
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
262 form['perms_updates'])
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
263 #TODO: implement this
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
264 #action_logger(self.rhodecode_user, 'admin_changed_repo_permissions',
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
265 # repo_name, self.ip_addr, self.sa)
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
266 Session().commit()
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
267 h.flash(_('User Group permissions updated'), category='success')
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
268 return redirect(url('edit_users_group', id=id))
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
269
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
270 @HasUserGroupPermissionAnyDecorator('usergroup.admin')
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
271 def delete_user_group_perm_member(self, id):
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
272 """
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
273 DELETE an existing repository group permission user
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
274
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
275 :param group_name:
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
276 """
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
277 try:
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
278 obj_type = request.POST.get('obj_type')
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
279 obj_id = None
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
280 if obj_type == 'user':
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
281 obj_id = safe_int(request.POST.get('user_id'))
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
282 elif obj_type == 'user_group':
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
283 obj_id = safe_int(request.POST.get('user_group_id'))
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
284
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
285 if not c.rhodecode_user.is_admin:
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
286 if obj_type == 'user' and c.rhodecode_user.user_id == obj_id:
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
287 msg = _('Cannot revoke permission for yourself as admin')
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
288 h.flash(msg, category='warning')
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
289 raise Exception('revoke admin permission on self')
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
290 if obj_type == 'user':
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
291 UserGroupModel().revoke_user_permission(user_group=id,
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
292 user=obj_id)
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
293 elif obj_type == 'user_group':
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
294 pass
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
295 Session().commit()
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
296 except Exception:
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
297 log.error(traceback.format_exc())
3715
25dbbdae3ed9 consistent handling of grant/revoke of permissions widgets
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
298 h.flash(_('An error occurred during revoking of permission'),
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
299 category='error')
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
300 raise HTTPInternalServerError()
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
301
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
302 def show(self, id, format='html'):
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
303 """GET /users_groups/id: Show a specific item"""
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
304 # url('users_group', id=ID)
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
305
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
306 @HasUserGroupPermissionAnyDecorator('usergroup.admin')
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
307 def edit(self, id, format='html'):
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
308 """GET /users_groups/id/edit: Form to edit an existing item"""
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
309 # url('edit_users_group', id=ID)
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
310
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
311 c.users_group = UserGroup.get_or_404(id)
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
312 self.__load_data(id)
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
313
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
314 defaults = self.__load_defaults(id)
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
315
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
316 return htmlfill.render(
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
317 render('admin/users_groups/users_group_edit.html'),
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
318 defaults=defaults,
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
319 encoding="UTF-8",
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
320 force_defaults=False
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
321 )
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
322
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
323 @HasUserGroupPermissionAnyDecorator('usergroup.admin')
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
324 def update_perm(self, id):
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
325 """PUT /users_perm/id: Update an existing item"""
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
326 # url('users_group_perm', id=ID, method='put')
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
327
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
328 users_group = UserGroup.get_or_404(id)
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
329 grant_create_perm = str2bool(request.POST.get('create_repo_perm'))
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
330 grant_fork_perm = str2bool(request.POST.get('fork_repo_perm'))
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
331 inherit_perms = str2bool(request.POST.get('inherit_default_permissions'))
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
332
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
333 usergroup_model = UserGroupModel()
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
334
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
335 try:
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
336 users_group.inherit_default_permissions = inherit_perms
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
337 Session().add(users_group)
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
338
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
339 if grant_create_perm:
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
340 usergroup_model.revoke_perm(id, 'hg.create.none')
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
341 usergroup_model.grant_perm(id, 'hg.create.repository')
3410
5f1850e4712a "Users groups" is grammatically incorrect English - rename to "user groups"
Mads Kiilerich <madski@unity3d.com>
parents: 2987
diff changeset
342 h.flash(_("Granted 'repository create' permission to user group"),
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
343 category='success')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
344 else:
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
345 usergroup_model.revoke_perm(id, 'hg.create.repository')
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
346 usergroup_model.grant_perm(id, 'hg.create.none')
3410
5f1850e4712a "Users groups" is grammatically incorrect English - rename to "user groups"
Mads Kiilerich <madski@unity3d.com>
parents: 2987
diff changeset
347 h.flash(_("Revoked 'repository create' permission to user group"),
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
348 category='success')
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
349
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
350 if grant_fork_perm:
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
351 usergroup_model.revoke_perm(id, 'hg.fork.none')
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
352 usergroup_model.grant_perm(id, 'hg.fork.repository')
3410
5f1850e4712a "Users groups" is grammatically incorrect English - rename to "user groups"
Mads Kiilerich <madski@unity3d.com>
parents: 2987
diff changeset
353 h.flash(_("Granted 'repository fork' permission to user group"),
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
354 category='success')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
355 else:
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
356 usergroup_model.revoke_perm(id, 'hg.fork.repository')
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3410
diff changeset
357 usergroup_model.grant_perm(id, 'hg.fork.none')
3410
5f1850e4712a "Users groups" is grammatically incorrect English - rename to "user groups"
Mads Kiilerich <madski@unity3d.com>
parents: 2987
diff changeset
358 h.flash(_("Revoked 'repository fork' permission to user group"),
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
359 category='success')
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
360
2662
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2375
diff changeset
361 Session().commit()
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
362 except Exception:
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
363 log.error(traceback.format_exc())
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
364 h.flash(_('An error occurred during permissions saving'),
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
365 category='error')
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
366
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
367 return redirect(url('edit_users_group', id=id))