annotate rhodecode/controllers/admin/users.py @ 2031:82a88013a3fd

merge 1.3 into stable
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 26 Feb 2012 17:25:09 +0200
parents bf263968da47 89efedac4e6c
children dc2584ba5fbc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 357
diff changeset
29
305
61be6dcd49a0 protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 304
diff changeset
30 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
31 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
32 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
33 from pylons.i18n.translation import _
853
f67868ef6cd2 some docs updates on controller
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
34
1245
5f2fbab7c429 PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
35 from rhodecode.lib.exceptions import DefaultUserException, \
5f2fbab7c429 PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
36 UserOwnsReposException
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 537
diff changeset
37 from rhodecode.lib import helpers as h
1117
6eb5bb24a948 Major rewrite of auth objects. Moved parts of filling user data into user model.
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
38 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 537
diff changeset
39 from rhodecode.lib.base import BaseController, render
853
f67868ef6cd2 some docs updates on controller
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
40
1824
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
41 from rhodecode.model.db import User, Permission
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 537
diff changeset
42 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
43 from rhodecode.model.user import UserModel
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1644
diff changeset
44 from rhodecode.model.meta import Session
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 357
diff changeset
45
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
46 log = logging.getLogger(__name__)
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
47
1245
5f2fbab7c429 PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
48
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
49 class UsersController(BaseController):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
50 """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
51 # 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
52 # file has a resource setup:
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
53 # 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
54
235
fcab58c43ea1 Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
55 @LoginRequired()
305
61be6dcd49a0 protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 304
diff changeset
56 @HasPermissionAllDecorator('hg.admin')
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
57 def __before__(self):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
58 c.admin_user = session.get('admin_user')
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
59 c.admin_username = session.get('admin_username')
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
60 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
61 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
62
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
63 def index(self, format='html'):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
64 """GET /users: All items in the collection"""
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
65 # 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
66
dd532af216d9 #49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
67 c.users_list = self.sa.query(User).all()
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
68 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
69
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
70 def create(self):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
71 """POST /users: Create a new item"""
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
72 # 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
73
235
fcab58c43ea1 Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
74 user_model = UserModel()
1644
59c26a9aba63 typo fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
75 user_form = UserForm()()
50
73f413946c14 user managment implementation continued update/delete/create works
Marcin Kuzminski <marcin@python-blog.com>
parents: 49
diff changeset
76 try:
1644
59c26a9aba63 typo fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
77 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
78 user_model.create(form_result)
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
79 h.flash(_('created user %s') % form_result['username'],
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
80 category='success')
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1644
diff changeset
81 Session.commit()
548
b75b77ef649d renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
82 #action_logger(self.rhodecode_user, 'new_user', '', '', self.sa)
564
ba7e24cd4786 refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents: 548
diff changeset
83 except formencode.Invalid, errors:
235
fcab58c43ea1 Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
84 return htmlfill.render(
357
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
85 render('admin/users/user_add.html'),
235
fcab58c43ea1 Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
86 defaults=errors.value,
357
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
87 errors=errors.error_dict or {},
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
88 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
89 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
90 except Exception:
357
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
91 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
92 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
93 % 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
94 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
95
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
96 def new(self, format='html'):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
97 """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
98 # 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
99 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
100
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
101 def update(self, id):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
102 """PUT /users/id: Update an existing item"""
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
103 # 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
104 # <input type="hidden" name="_method" value="PUT" />
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
105 # Or using helpers:
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
106 # 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
107 # method='put')
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
108 # url('user', id=ID)
235
fcab58c43ea1 Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
109 user_model = UserModel()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
110 c.user = user_model.get(id)
673
dd532af216d9 #49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
111
1245
5f2fbab7c429 PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
112 _form = UserForm(edit=True, old_data={'user_id': id,
5f2fbab7c429 PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
113 'email': c.user.email})()
357
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
114 form_result = {}
50
73f413946c14 user managment implementation continued update/delete/create works
Marcin Kuzminski <marcin@python-blog.com>
parents: 49
diff changeset
115 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
116 form_result = _form.to_python(dict(request.POST))
235
fcab58c43ea1 Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
117 user_model.update(id, form_result)
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
118 h.flash(_('User updated successfully'), category='success')
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1644
diff changeset
119 Session.commit()
564
ba7e24cd4786 refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents: 548
diff changeset
120 except formencode.Invalid, errors:
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
121 e = errors.error_dict or {}
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
122 perm = Permission.get_by_key('hg.create.repository')
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1644
diff changeset
123 e.update({'create_repo_perm': user_model.has_perm(id, perm)})
235
fcab58c43ea1 Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
124 return htmlfill.render(
357
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
125 render('admin/users/user_edit.html'),
235
fcab58c43ea1 Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
126 defaults=errors.value,
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
127 errors=e,
357
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
128 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
129 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
130 except Exception:
357
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
131 log.error(traceback.format_exc())
853
f67868ef6cd2 some docs updates on controller
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
132 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
133 % form_result.get('username'), category='error')
673
dd532af216d9 #49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
134
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
135 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
136
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
137 def delete(self, id):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
138 """DELETE /users/id: Delete an existing item"""
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
139 # 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
140 # <input type="hidden" name="_method" value="DELETE" />
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
141 # Or using helpers:
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
142 # 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
143 # method='delete')
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
144 # url('user', id=ID)
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
145 user_model = UserModel()
48
8e250e86a670 Css fixes, implemented removal of users, and display draft
Marcin Kuzminski <marcin@python-blog.com>
parents: 47
diff changeset
146 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
147 user_model.delete(id)
895
62c04c5cc971 Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents: 860
diff changeset
148 h.flash(_('successfully deleted user'), category='success')
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1644
diff changeset
149 Session.commit()
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
150 except (UserOwnsReposException, DefaultUserException), e:
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
151 h.flash(str(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
152 except Exception:
860
5f7731e3ab4d fixed spelling mistakes, and some minor docs bugs
Marcin Kuzminski <marcin@python-works.com>
parents: 853
diff changeset
153 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
154 category='error')
48
8e250e86a670 Css fixes, implemented removal of users, and display draft
Marcin Kuzminski <marcin@python-blog.com>
parents: 47
diff changeset
155 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
156
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
157 def show(self, id, format='html'):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
158 """GET /users/id: Show a specific item"""
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
159 # 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
160
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
161 def edit(self, id, format='html'):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
162 """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
163 # url('edit_user', id=ID)
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1644
diff changeset
164 c.user = User.get(id)
476
8ba65e4c4e4c added journal icon and made active links in journal, fixed edit user bug when given wrong id
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
165 if not c.user:
8ba65e4c4e4c added journal icon and made active links in journal, fixed edit user bug when given wrong id
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
166 return redirect(url('users'))
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
167 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
168 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
169 return redirect(url('users'))
895
62c04c5cc971 Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents: 860
diff changeset
170 c.user.permissions = {}
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1644
diff changeset
171 c.granted_permissions = UserModel().fill_perms(c.user)\
1245
5f2fbab7c429 PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
172 .permissions['global']
673
dd532af216d9 #49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
173
832
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 829
diff changeset
174 defaults = c.user.get_dict()
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
175 perm = Permission.get_by_key('hg.create.repository')
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1644
diff changeset
176 defaults.update({'create_repo_perm': UserModel().has_perm(id, perm)})
895
62c04c5cc971 Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents: 860
diff changeset
177
50
73f413946c14 user managment implementation continued update/delete/create works
Marcin Kuzminski <marcin@python-blog.com>
parents: 49
diff changeset
178 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
179 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
180 defaults=defaults,
50
73f413946c14 user managment implementation continued update/delete/create works
Marcin Kuzminski <marcin@python-blog.com>
parents: 49
diff changeset
181 encoding="UTF-8",
73f413946c14 user managment implementation continued update/delete/create works
Marcin Kuzminski <marcin@python-blog.com>
parents: 49
diff changeset
182 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
183 )
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
184
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
185 def update_perm(self, id):
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
186 """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
187 # url('user_perm', id=ID, method='put')
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
188
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
189 grant_perm = request.POST.get('create_repo_perm', False)
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1644
diff changeset
190 user_model = UserModel()
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
191
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
192 if grant_perm:
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
193 perm = Permission.get_by_key('hg.create.none')
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1644
diff changeset
194 user_model.revoke_perm(id, perm)
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
195
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
196 perm = Permission.get_by_key('hg.create.repository')
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1644
diff changeset
197 user_model.grant_perm(id, perm)
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
198 h.flash(_("Granted 'repository create' permission to user"),
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
199 category='success')
1758
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
200 Session.commit()
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
201 else:
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
202 perm = Permission.get_by_key('hg.create.repository')
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1644
diff changeset
203 user_model.revoke_perm(id, perm)
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
204
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
205 perm = Permission.get_by_key('hg.create.none')
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1644
diff changeset
206 user_model.grant_perm(id, perm)
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
207 h.flash(_("Revoked 'repository create' permission to user"),
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
208 category='success')
1758
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
209 Session.commit()
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
210 return redirect(url('edit_user', id=id))