Mercurial > kallithea
annotate rhodecode/controllers/admin/users.py @ 3712:08cf7741e5e1 beta
removed obsolete admin_user tmpl context variables
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 08 Apr 2013 02:59:50 +0200 |
parents | 32cb8d45f330 |
children | 21412a6c3854 |
rev | line source |
---|---|
853
f67868ef6cd2
some docs updates on controller
Marcin Kuzminski <marcin@python-works.com>
parents:
832
diff
changeset
|
1 # -*- coding: utf-8 -*- |
f67868ef6cd2
some docs updates on controller
Marcin Kuzminski <marcin@python-works.com>
parents:
832
diff
changeset
|
2 """ |
f67868ef6cd2
some docs updates on controller
Marcin Kuzminski <marcin@python-works.com>
parents:
832
diff
changeset
|
3 rhodecode.controllers.admin.users |
f67868ef6cd2
some docs updates on controller
Marcin Kuzminski <marcin@python-works.com>
parents:
832
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
f67868ef6cd2
some docs updates on controller
Marcin Kuzminski <marcin@python-works.com>
parents:
832
diff
changeset
|
5 |
f67868ef6cd2
some docs updates on controller
Marcin Kuzminski <marcin@python-works.com>
parents:
832
diff
changeset
|
6 Users 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 |
853
f67868ef6cd2
some docs updates on controller
Marcin Kuzminski <marcin@python-works.com>
parents:
832
diff
changeset
|
8 :created_on: Apr 4, 2010 |
f67868ef6cd2
some docs updates on controller
Marcin Kuzminski <marcin@python-works.com>
parents:
832
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> |
853
f67868ef6cd2
some docs updates on controller
Marcin Kuzminski <marcin@python-works.com>
parents:
832
diff
changeset
|
11 :license: GPLv3, see COPYING for more details. |
f67868ef6cd2
some docs updates on controller
Marcin Kuzminski <marcin@python-works.com>
parents:
832
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 # |
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
18 # This program is distributed in the hope that it will be useful, |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
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 # |
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
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/>. |
853
f67868ef6cd2
some docs updates on controller
Marcin Kuzminski <marcin@python-works.com>
parents:
832
diff
changeset
|
25 |
f67868ef6cd2
some docs updates on controller
Marcin Kuzminski <marcin@python-works.com>
parents:
832
diff
changeset
|
26 import logging |
f67868ef6cd2
some docs updates on controller
Marcin Kuzminski <marcin@python-works.com>
parents:
832
diff
changeset
|
27 import traceback |
f67868ef6cd2
some docs updates on controller
Marcin Kuzminski <marcin@python-works.com>
parents:
832
diff
changeset
|
28 import formencode |
2658
80d837028c40
implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents:
2570
diff
changeset
|
29 from pylons import response |
371
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
357
diff
changeset
|
30 |
305
61be6dcd49a0
protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
304
diff
changeset
|
31 from formencode import htmlfill |
895
62c04c5cc971
Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
32 from pylons import request, session, tmpl_context as c, url, config |
1824
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
33 from pylons.controllers.util import redirect |
238
a55c17874486
Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents:
235
diff
changeset
|
34 from pylons.i18n.translation import _ |
853
f67868ef6cd2
some docs updates on controller
Marcin Kuzminski <marcin@python-works.com>
parents:
832
diff
changeset
|
35 |
2709
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
36 import rhodecode |
1245
5f2fbab7c429
PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
37 from rhodecode.lib.exceptions import DefaultUserException, \ |
5f2fbab7c429
PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
38 UserOwnsReposException |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
39 from rhodecode.lib import helpers as h |
2658
80d837028c40
implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents:
2570
diff
changeset
|
40 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator, \ |
2435
751c1c56e080
#478 permissions overview for admin in user edit view
Marcin Kuzminski <marcin@python-works.com>
parents:
2375
diff
changeset
|
41 AuthUser |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
42 from rhodecode.lib.base import BaseController, render |
853
f67868ef6cd2
some docs updates on controller
Marcin Kuzminski <marcin@python-works.com>
parents:
832
diff
changeset
|
43 |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
44 from rhodecode.model.db import User, UserEmailMap, UserIpMap |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
45 from rhodecode.model.forms import UserForm |
713
1bb0fcdec895
fixed #72 show warning on removal when user still is owner of existing repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
46 from rhodecode.model.user import UserModel |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1644
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:
2155
diff
changeset
|
48 from rhodecode.lib.utils import action_logger |
2658
80d837028c40
implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents:
2570
diff
changeset
|
49 from rhodecode.lib.compat import json |
2709
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
50 from rhodecode.lib.utils2 import datetime_to_time, str2bool |
371
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
357
diff
changeset
|
51 |
47
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
52 log = logging.getLogger(__name__) |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
53 |
1245
5f2fbab7c429
PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
54 |
47
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
55 class UsersController(BaseController): |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
56 """REST Controller styled on the Atom Publishing Protocol""" |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
57 # To properly map this controller, ensure your config/routing.py |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
58 # file has a resource setup: |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
59 # map.resource('user', 'users') |
673
dd532af216d9
#49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
60 |
235
fcab58c43ea1
Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
61 @LoginRequired() |
305
61be6dcd49a0
protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
304
diff
changeset
|
62 @HasPermissionAllDecorator('hg.admin') |
47
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
63 def __before__(self): |
191
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
151
diff
changeset
|
64 super(UsersController, self).__before__() |
895
62c04c5cc971
Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
65 c.available_permissions = config['available_permissions'] |
239
b18f89d6d17f
Adde draft for permissions systems, made all needed decorators, and checks. For future usage in the system.
Marcin Kuzminski <marcin@python-works.com>
parents:
238
diff
changeset
|
66 |
47
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
67 def index(self, format='html'): |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
68 """GET /users: All items in the collection""" |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
69 # url('users') |
673
dd532af216d9
#49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
70 |
2658
80d837028c40
implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents:
2570
diff
changeset
|
71 c.users_list = User.query().order_by(User.username).all() |
80d837028c40
implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents:
2570
diff
changeset
|
72 |
80d837028c40
implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents:
2570
diff
changeset
|
73 users_data = [] |
80d837028c40
implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents:
2570
diff
changeset
|
74 total_records = len(c.users_list) |
2663
cc8d7d450d15
No more raw html inside users controller.
Marcin Kuzminski <marcin@python-works.com>
parents:
2662
diff
changeset
|
75 _tmpl_lookup = rhodecode.CONFIG['pylons.app_globals'].mako_lookup |
cc8d7d450d15
No more raw html inside users controller.
Marcin Kuzminski <marcin@python-works.com>
parents:
2662
diff
changeset
|
76 template = _tmpl_lookup.get_template('data_table/_dt_elements.html') |
cc8d7d450d15
No more raw html inside users controller.
Marcin Kuzminski <marcin@python-works.com>
parents:
2662
diff
changeset
|
77 |
cc8d7d450d15
No more raw html inside users controller.
Marcin Kuzminski <marcin@python-works.com>
parents:
2662
diff
changeset
|
78 grav_tmpl = lambda user_email, size: ( |
cc8d7d450d15
No more raw html inside users controller.
Marcin Kuzminski <marcin@python-works.com>
parents:
2662
diff
changeset
|
79 template.get_def("user_gravatar") |
2674
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2663
diff
changeset
|
80 .render(user_email, size, _=_, h=h, c=c)) |
2663
cc8d7d450d15
No more raw html inside users controller.
Marcin Kuzminski <marcin@python-works.com>
parents:
2662
diff
changeset
|
81 |
cc8d7d450d15
No more raw html inside users controller.
Marcin Kuzminski <marcin@python-works.com>
parents:
2662
diff
changeset
|
82 user_lnk = lambda user_id, username: ( |
cc8d7d450d15
No more raw html inside users controller.
Marcin Kuzminski <marcin@python-works.com>
parents:
2662
diff
changeset
|
83 template.get_def("user_name") |
2674
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2663
diff
changeset
|
84 .render(user_id, username, _=_, h=h, c=c)) |
2663
cc8d7d450d15
No more raw html inside users controller.
Marcin Kuzminski <marcin@python-works.com>
parents:
2662
diff
changeset
|
85 |
cc8d7d450d15
No more raw html inside users controller.
Marcin Kuzminski <marcin@python-works.com>
parents:
2662
diff
changeset
|
86 user_actions = lambda user_id, username: ( |
cc8d7d450d15
No more raw html inside users controller.
Marcin Kuzminski <marcin@python-works.com>
parents:
2662
diff
changeset
|
87 template.get_def("user_actions") |
2674
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2663
diff
changeset
|
88 .render(user_id, username, _=_, h=h, c=c)) |
2663
cc8d7d450d15
No more raw html inside users controller.
Marcin Kuzminski <marcin@python-works.com>
parents:
2662
diff
changeset
|
89 |
2658
80d837028c40
implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents:
2570
diff
changeset
|
90 for user in c.users_list: |
2699
4eef5eeb81a3
fixed sorting by last_login in users admin page
Marcin Kuzminski <marcin@python-works.com>
parents:
2674
diff
changeset
|
91 |
2658
80d837028c40
implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents:
2570
diff
changeset
|
92 users_data.append({ |
2663
cc8d7d450d15
No more raw html inside users controller.
Marcin Kuzminski <marcin@python-works.com>
parents:
2662
diff
changeset
|
93 "gravatar": grav_tmpl(user. email, 24), |
2658
80d837028c40
implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents:
2570
diff
changeset
|
94 "raw_username": user.username, |
2663
cc8d7d450d15
No more raw html inside users controller.
Marcin Kuzminski <marcin@python-works.com>
parents:
2662
diff
changeset
|
95 "username": user_lnk(user.user_id, user.username), |
2658
80d837028c40
implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents:
2570
diff
changeset
|
96 "firstname": user.name, |
80d837028c40
implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents:
2570
diff
changeset
|
97 "lastname": user.lastname, |
80d837028c40
implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents:
2570
diff
changeset
|
98 "last_login": h.fmt_date(user.last_login), |
2699
4eef5eeb81a3
fixed sorting by last_login in users admin page
Marcin Kuzminski <marcin@python-works.com>
parents:
2674
diff
changeset
|
99 "last_login_raw": datetime_to_time(user.last_login), |
3627
32cb8d45f330
helpers: show boolean value of value as icon, not just the True and False singletons
Mads Kiilerich <madski@unity3d.com>
parents:
3565
diff
changeset
|
100 "active": h.boolicon(user.active), |
32cb8d45f330
helpers: show boolean value of value as icon, not just the True and False singletons
Mads Kiilerich <madski@unity3d.com>
parents:
3565
diff
changeset
|
101 "admin": h.boolicon(user.admin), |
32cb8d45f330
helpers: show boolean value of value as icon, not just the True and False singletons
Mads Kiilerich <madski@unity3d.com>
parents:
3565
diff
changeset
|
102 "ldap": h.boolicon(bool(user.ldap_dn)), |
2663
cc8d7d450d15
No more raw html inside users controller.
Marcin Kuzminski <marcin@python-works.com>
parents:
2662
diff
changeset
|
103 "action": user_actions(user.user_id, user.username), |
2658
80d837028c40
implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents:
2570
diff
changeset
|
104 }) |
80d837028c40
implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents:
2570
diff
changeset
|
105 |
80d837028c40
implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents:
2570
diff
changeset
|
106 c.data = json.dumps({ |
80d837028c40
implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents:
2570
diff
changeset
|
107 "totalRecords": total_records, |
80d837028c40
implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents:
2570
diff
changeset
|
108 "startIndex": 0, |
80d837028c40
implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents:
2570
diff
changeset
|
109 "sort": None, |
80d837028c40
implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents:
2570
diff
changeset
|
110 "dir": "asc", |
80d837028c40
implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents:
2570
diff
changeset
|
111 "records": users_data |
80d837028c40
implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents:
2570
diff
changeset
|
112 }) |
80d837028c40
implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents:
2570
diff
changeset
|
113 |
127
20dc7a5eb748
Html changes and cleanups, made folders for html templates, implemented tags and branches pages
Marcin Kuzminski <marcin@python-works.com>
parents:
101
diff
changeset
|
114 return render('admin/users/users.html') |
673
dd532af216d9
#49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
115 |
47
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
116 def create(self): |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
117 """POST /users: Create a new item""" |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
118 # url('users') |
673
dd532af216d9
#49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
119 |
235
fcab58c43ea1
Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
120 user_model = UserModel() |
1644 | 121 user_form = UserForm()() |
50
73f413946c14
user managment implementation continued update/delete/create works
Marcin Kuzminski <marcin@python-blog.com>
parents:
49
diff
changeset
|
122 try: |
1644 | 123 form_result = user_form.to_python(dict(request.POST)) |
235
fcab58c43ea1
Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
124 user_model.create(form_result) |
2375
bc2d8c03c050
Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
125 usr = form_result['username'] |
bc2d8c03c050
Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
126 action_logger(self.rhodecode_user, 'admin_created_user:%s' % usr, |
bc2d8c03c050
Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
127 None, self.ip_addr, self.sa) |
3565
a8f2d78d14ea
consistently capitalize initial letter in flash messages
Mads Kiilerich <madski@unity3d.com>
parents:
3125
diff
changeset
|
128 h.flash(_('Created user %s') % usr, |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
129 category='success') |
2662
91c442a489bb
sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents:
2658
diff
changeset
|
130 Session().commit() |
564
ba7e24cd4786
refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
548
diff
changeset
|
131 except formencode.Invalid, errors: |
235
fcab58c43ea1
Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
132 return htmlfill.render( |
357
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
133 render('admin/users/user_add.html'), |
235
fcab58c43ea1
Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
134 defaults=errors.value, |
357
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
135 errors=errors.error_dict or {}, |
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
136 prefix_error=False, |
673
dd532af216d9
#49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
137 encoding="UTF-8") |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
138 except Exception: |
357
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
139 log.error(traceback.format_exc()) |
3565
a8f2d78d14ea
consistently capitalize initial letter in flash messages
Mads Kiilerich <madski@unity3d.com>
parents:
3125
diff
changeset
|
140 h.flash(_('Error occurred during creation of user %s') \ |
673
dd532af216d9
#49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
141 % request.POST.get('username'), category='error') |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
142 return redirect(url('users')) |
673
dd532af216d9
#49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
143 |
47
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
144 def new(self, format='html'): |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
145 """GET /users/new: Form to create a new item""" |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
146 # url('new_user') |
127
20dc7a5eb748
Html changes and cleanups, made folders for html templates, implemented tags and branches pages
Marcin Kuzminski <marcin@python-works.com>
parents:
101
diff
changeset
|
147 return render('admin/users/user_add.html') |
47
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
148 |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
149 def update(self, id): |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
150 """PUT /users/id: Update an existing item""" |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
151 # Forms posted to this method should contain a hidden field: |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
152 # <input type="hidden" name="_method" value="PUT" /> |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
153 # Or using helpers: |
1266
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1245
diff
changeset
|
154 # h.form(url('update_user', id=ID), |
47
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
155 # method='put') |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
156 # url('user', id=ID) |
235
fcab58c43ea1
Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
157 user_model = UserModel() |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
564
diff
changeset
|
158 c.user = user_model.get(id) |
3021
b2b93614a7cd
Implemented #658 Changing username in LDAP-Mode should not be allowed.
Marcin Kuzminski <marcin@python-works.com>
parents:
2709
diff
changeset
|
159 c.ldap_dn = c.user.ldap_dn |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
160 c.perm_user = AuthUser(user_id=id, ip_addr=self.ip_addr) |
1245
5f2fbab7c429
PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
161 _form = UserForm(edit=True, old_data={'user_id': id, |
5f2fbab7c429
PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
162 'email': c.user.email})() |
357
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
163 form_result = {} |
50
73f413946c14
user managment implementation continued update/delete/create works
Marcin Kuzminski <marcin@python-blog.com>
parents:
49
diff
changeset
|
164 try: |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
165 form_result = _form.to_python(dict(request.POST)) |
3021
b2b93614a7cd
Implemented #658 Changing username in LDAP-Mode should not be allowed.
Marcin Kuzminski <marcin@python-works.com>
parents:
2709
diff
changeset
|
166 skip_attrs = [] |
b2b93614a7cd
Implemented #658 Changing username in LDAP-Mode should not be allowed.
Marcin Kuzminski <marcin@python-works.com>
parents:
2709
diff
changeset
|
167 if c.ldap_dn: |
b2b93614a7cd
Implemented #658 Changing username in LDAP-Mode should not be allowed.
Marcin Kuzminski <marcin@python-works.com>
parents:
2709
diff
changeset
|
168 #forbid updating username for ldap accounts |
b2b93614a7cd
Implemented #658 Changing username in LDAP-Mode should not be allowed.
Marcin Kuzminski <marcin@python-works.com>
parents:
2709
diff
changeset
|
169 skip_attrs = ['username'] |
b2b93614a7cd
Implemented #658 Changing username in LDAP-Mode should not be allowed.
Marcin Kuzminski <marcin@python-works.com>
parents:
2709
diff
changeset
|
170 user_model.update(id, form_result, skip_attrs=skip_attrs) |
2375
bc2d8c03c050
Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
171 usr = form_result['username'] |
bc2d8c03c050
Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
172 action_logger(self.rhodecode_user, 'admin_updated_user:%s' % usr, |
bc2d8c03c050
Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
173 None, self.ip_addr, self.sa) |
1266
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1245
diff
changeset
|
174 h.flash(_('User updated successfully'), category='success') |
2662
91c442a489bb
sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents:
2658
diff
changeset
|
175 Session().commit() |
564
ba7e24cd4786
refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
548
diff
changeset
|
176 except formencode.Invalid, errors: |
2479
9225597688f4
Added validation into user email map
Marcin Kuzminski <marcin@python-works.com>
parents:
2467
diff
changeset
|
177 c.user_email_map = UserEmailMap.query()\ |
9225597688f4
Added validation into user email map
Marcin Kuzminski <marcin@python-works.com>
parents:
2467
diff
changeset
|
178 .filter(UserEmailMap.user == c.user).all() |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
179 c.user_ip_map = UserIpMap.query()\ |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
180 .filter(UserIpMap.user == c.user).all() |
2479
9225597688f4
Added validation into user email map
Marcin Kuzminski <marcin@python-works.com>
parents:
2467
diff
changeset
|
181 defaults = errors.value |
1266
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1245
diff
changeset
|
182 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:
2699
diff
changeset
|
183 defaults.update({ |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
184 'create_repo_perm': user_model.has_perm(id, 'hg.create.repository'), |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
185 'fork_repo_perm': user_model.has_perm(id, 'hg.fork.repository'), |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
186 '_method': 'put' |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
187 }) |
235
fcab58c43ea1
Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
188 return htmlfill.render( |
357
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
189 render('admin/users/user_edit.html'), |
2479
9225597688f4
Added validation into user email map
Marcin Kuzminski <marcin@python-works.com>
parents:
2467
diff
changeset
|
190 defaults=defaults, |
1266
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1245
diff
changeset
|
191 errors=e, |
357
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
192 prefix_error=False, |
673
dd532af216d9
#49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
193 encoding="UTF-8") |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
194 except Exception: |
357
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
195 log.error(traceback.format_exc()) |
3565
a8f2d78d14ea
consistently capitalize initial letter in flash messages
Mads Kiilerich <madski@unity3d.com>
parents:
3125
diff
changeset
|
196 h.flash(_('Error occurred during update of user %s') \ |
357
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
197 % form_result.get('username'), category='error') |
2709
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
198 return redirect(url('edit_user', id=id)) |
673
dd532af216d9
#49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
199 |
47
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
200 def delete(self, id): |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
201 """DELETE /users/id: Delete an existing item""" |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
202 # Forms posted to this method should contain a hidden field: |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
203 # <input type="hidden" name="_method" value="DELETE" /> |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
204 # Or using helpers: |
1266
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1245
diff
changeset
|
205 # h.form(url('delete_user', id=ID), |
47
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
206 # method='delete') |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
207 # url('user', id=ID) |
2709
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
208 usr = User.get_or_404(id) |
48
8e250e86a670
Css fixes, implemented removal of users, and display draft
Marcin Kuzminski <marcin@python-blog.com>
parents:
47
diff
changeset
|
209 try: |
2709
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
210 UserModel().delete(usr) |
2662
91c442a489bb
sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents:
2658
diff
changeset
|
211 Session().commit() |
3565
a8f2d78d14ea
consistently capitalize initial letter in flash messages
Mads Kiilerich <madski@unity3d.com>
parents:
3125
diff
changeset
|
212 h.flash(_('Successfully deleted user'), category='success') |
713
1bb0fcdec895
fixed #72 show warning on removal when user still is owner of existing repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
213 except (UserOwnsReposException, DefaultUserException), e: |
2155
24d906650cc0
Don't cast to string on warning about deleting an user who still owns repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
214 h.flash(e, category='warning') |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
215 except Exception: |
2155
24d906650cc0
Don't cast to string on warning about deleting an user who still owns repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
216 log.error(traceback.format_exc()) |
860
5f7731e3ab4d
fixed spelling mistakes, and some minor docs bugs
Marcin Kuzminski <marcin@python-works.com>
parents:
853
diff
changeset
|
217 h.flash(_('An error occurred during deletion of user'), |
673
dd532af216d9
#49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
218 category='error') |
48
8e250e86a670
Css fixes, implemented removal of users, and display draft
Marcin Kuzminski <marcin@python-blog.com>
parents:
47
diff
changeset
|
219 return redirect(url('users')) |
673
dd532af216d9
#49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
220 |
47
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
221 def show(self, id, format='html'): |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
222 """GET /users/id: Show a specific item""" |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
223 # url('user', id=ID) |
673
dd532af216d9
#49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
224 |
47
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
225 def edit(self, id, format='html'): |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
226 """GET /users/id/edit: Form to edit an existing item""" |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
227 # url('edit_user', id=ID) |
2496
fddd8e3fc157
use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents:
2479
diff
changeset
|
228 c.user = User.get_or_404(id) |
fddd8e3fc157
use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents:
2479
diff
changeset
|
229 |
318
fdf9f6ee5217
Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
305
diff
changeset
|
230 if c.user.username == 'default': |
673
dd532af216d9
#49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
231 h.flash(_("You can't edit this user"), category='warning') |
318
fdf9f6ee5217
Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
305
diff
changeset
|
232 return redirect(url('users')) |
2709
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
233 |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
234 c.perm_user = AuthUser(user_id=id, ip_addr=self.ip_addr) |
895
62c04c5cc971
Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
235 c.user.permissions = {} |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1644
diff
changeset
|
236 c.granted_permissions = UserModel().fill_perms(c.user)\ |
1245
5f2fbab7c429
PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
237 .permissions['global'] |
2330
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
238 c.user_email_map = UserEmailMap.query()\ |
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
239 .filter(UserEmailMap.user == c.user).all() |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
240 c.user_ip_map = UserIpMap.query()\ |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
241 .filter(UserIpMap.user == c.user).all() |
2709
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
242 user_model = UserModel() |
3021
b2b93614a7cd
Implemented #658 Changing username in LDAP-Mode should not be allowed.
Marcin Kuzminski <marcin@python-works.com>
parents:
2709
diff
changeset
|
243 c.ldap_dn = c.user.ldap_dn |
832
634596f81cfd
new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
829
diff
changeset
|
244 defaults = c.user.get_dict() |
2709
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
245 defaults.update({ |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
246 'create_repo_perm': user_model.has_perm(id, 'hg.create.repository'), |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
247 'fork_repo_perm': user_model.has_perm(id, 'hg.fork.repository'), |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
248 }) |
895
62c04c5cc971
Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
249 |
50
73f413946c14
user managment implementation continued update/delete/create works
Marcin Kuzminski <marcin@python-blog.com>
parents:
49
diff
changeset
|
250 return htmlfill.render( |
127
20dc7a5eb748
Html changes and cleanups, made folders for html templates, implemented tags and branches pages
Marcin Kuzminski <marcin@python-works.com>
parents:
101
diff
changeset
|
251 render('admin/users/user_edit.html'), |
70
9a2affee4a45
Updated defaults bug of htmlfill + changed routing
Marcin Kuzminski <marcin@python-blog.com>
parents:
65
diff
changeset
|
252 defaults=defaults, |
50
73f413946c14
user managment implementation continued update/delete/create works
Marcin Kuzminski <marcin@python-blog.com>
parents:
49
diff
changeset
|
253 encoding="UTF-8", |
73f413946c14
user managment implementation continued update/delete/create works
Marcin Kuzminski <marcin@python-blog.com>
parents:
49
diff
changeset
|
254 force_defaults=False |
673
dd532af216d9
#49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
255 ) |
1266
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1245
diff
changeset
|
256 |
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1245
diff
changeset
|
257 def update_perm(self, id): |
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1245
diff
changeset
|
258 """PUT /users_perm/id: Update an existing item""" |
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1245
diff
changeset
|
259 # url('user_perm', id=ID, method='put') |
2709
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
260 usr = User.get_or_404(id) |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
261 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:
2699
diff
changeset
|
262 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:
2699
diff
changeset
|
263 inherit_perms = str2bool(request.POST.get('inherit_default_permissions')) |
1266
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1245
diff
changeset
|
264 |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1644
diff
changeset
|
265 user_model = UserModel() |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1758
diff
changeset
|
266 |
2709
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
267 try: |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
268 usr.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:
2699
diff
changeset
|
269 Session().add(usr) |
1266
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1245
diff
changeset
|
270 |
2709
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
271 if grant_create_perm: |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
272 user_model.revoke_perm(usr, 'hg.create.none') |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
273 user_model.grant_perm(usr, 'hg.create.repository') |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
274 h.flash(_("Granted 'repository create' permission to user"), |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
275 category='success') |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
276 else: |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
277 user_model.revoke_perm(usr, 'hg.create.repository') |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
278 user_model.grant_perm(usr, 'hg.create.none') |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
279 h.flash(_("Revoked 'repository create' permission to user"), |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
280 category='success') |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
281 |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
282 if grant_fork_perm: |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
283 user_model.revoke_perm(usr, 'hg.fork.none') |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
284 user_model.grant_perm(usr, 'hg.fork.repository') |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
285 h.flash(_("Granted 'repository fork' permission to user"), |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
286 category='success') |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
287 else: |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
288 user_model.revoke_perm(usr, 'hg.fork.repository') |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
289 user_model.grant_perm(usr, 'hg.fork.none') |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
290 h.flash(_("Revoked 'repository fork' permission to user"), |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
291 category='success') |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
292 |
2662
91c442a489bb
sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents:
2658
diff
changeset
|
293 Session().commit() |
2709
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
294 except Exception: |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2699
diff
changeset
|
295 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:
2699
diff
changeset
|
296 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:
2699
diff
changeset
|
297 category='error') |
1266
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1245
diff
changeset
|
298 return redirect(url('edit_user', id=id)) |
2330
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
299 |
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
300 def add_email(self, id): |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2436
diff
changeset
|
301 """POST /user_emails:Add an existing item""" |
2330
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
302 # url('user_emails', id=ID, method='put') |
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
303 |
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
304 email = request.POST.get('new_email') |
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
305 user_model = UserModel() |
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
306 |
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
307 try: |
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
308 user_model.add_extra_email(id, email) |
2662
91c442a489bb
sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents:
2658
diff
changeset
|
309 Session().commit() |
2570 | 310 h.flash(_("Added email %s to user") % email, category='success') |
2479
9225597688f4
Added validation into user email map
Marcin Kuzminski <marcin@python-works.com>
parents:
2467
diff
changeset
|
311 except formencode.Invalid, error: |
9225597688f4
Added validation into user email map
Marcin Kuzminski <marcin@python-works.com>
parents:
2467
diff
changeset
|
312 msg = error.error_dict['email'] |
9225597688f4
Added validation into user email map
Marcin Kuzminski <marcin@python-works.com>
parents:
2467
diff
changeset
|
313 h.flash(msg, category='error') |
2330
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
314 except Exception: |
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
315 log.error(traceback.format_exc()) |
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
316 h.flash(_('An error occurred during email saving'), |
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
317 category='error') |
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
318 return redirect(url('edit_user', id=id)) |
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
319 |
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
320 def delete_email(self, id): |
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
321 """DELETE /user_emails_delete/id: Delete an existing item""" |
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
322 # url('user_emails_delete', id=ID, method='delete') |
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
323 user_model = UserModel() |
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
324 user_model.delete_extra_email(id, request.POST.get('del_email')) |
2662
91c442a489bb
sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents:
2658
diff
changeset
|
325 Session().commit() |
2330
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
326 h.flash(_("Removed email from user"), category='success') |
b0fef8a77568
Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents:
2155
diff
changeset
|
327 return redirect(url('edit_user', id=id)) |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
328 |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
329 def add_ip(self, id): |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
330 """POST /user_ips:Add an existing item""" |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
331 # url('user_ips', id=ID, method='put') |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
332 |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
333 ip = request.POST.get('new_ip') |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
334 user_model = UserModel() |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
335 |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
336 try: |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
337 user_model.add_extra_ip(id, ip) |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
338 Session().commit() |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
339 h.flash(_("Added ip %s to user") % ip, category='success') |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
340 except formencode.Invalid, error: |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
341 msg = error.error_dict['ip'] |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
342 h.flash(msg, category='error') |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
343 except Exception: |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
344 log.error(traceback.format_exc()) |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
345 h.flash(_('An error occurred during ip saving'), |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
346 category='error') |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
347 if 'default_user' in request.POST: |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
348 return redirect(url('edit_permission', id='default')) |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
349 return redirect(url('edit_user', id=id)) |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
350 |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
351 def delete_ip(self, id): |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
352 """DELETE /user_ips_delete/id: Delete an existing item""" |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
353 # url('user_ips_delete', id=ID, method='delete') |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
354 user_model = UserModel() |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
355 user_model.delete_extra_ip(id, request.POST.get('del_ip')) |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
356 Session().commit() |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
357 h.flash(_("Removed ip from user"), category='success') |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
358 if 'default_user' in request.POST: |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
359 return redirect(url('edit_permission', id='default')) |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3021
diff
changeset
|
360 return redirect(url('edit_user', id=id)) |