annotate kallithea/controllers/admin/users.py @ 4208:ad38f9f93b3b kallithea-2.2.5-rebrand

Correct licensing information in individual files. The top-level license file is now LICENSE.md. Also, in various places where there should have been joint copyright holders listed, a single copyright holder was listed. It does not appear easy to add a link to a large list of copyright holders in these places, so it simply refers to the fact that various authors hold copyright. In future, if an easy method is discovered to link to a list from those places, we should do so. Finally, text is added to LICENSE.md to point to where the full list of copyright holders is, and that Kallithea as a whole is GPLv3'd.
author Bradley M. Kuhn <bkuhn@sfconservancy.org>
date Wed, 21 May 2014 16:59:37 -0400
parents d208416c84c6
children de26de99ac5b
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 -*-
1206
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
2 # 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
3 # 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
4 # 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
5 # (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
6 #
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
7 # 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
8 # 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
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
10 # 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
11 #
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
12 # 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
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
14 """
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
15 kallithea.controllers.admin.users
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
17
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
18 Users crud controller for pylons
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
19
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
20 :created_on: Apr 4, 2010
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
21 :author: marcink
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
22 :copyright: (c) 2013 RhodeCode GmbH.
4208
ad38f9f93b3b Correct licensing information in individual files.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4197
diff changeset
23 :license: GPLv3, see LICENSE.md for more details.
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
24 """
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 _
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
35 from sqlalchemy.sql.expression import func
853
f67868ef6cd2 some docs updates on controller
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
36
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
37 import kallithea
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
38 from kallithea.lib.exceptions import DefaultUserException, \
4074
3b136af34329 Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents: 3960
diff changeset
39 UserOwnsReposException, UserCreationError
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
40 from kallithea.lib import helpers as h
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
41 from kallithea.lib.auth import LoginRequired, HasPermissionAllDecorator, \
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
42 AuthUser, generate_api_key
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
43 import kallithea.lib.auth_modules.auth_rhodecode
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
44 from kallithea.lib import auth_modules
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
45 from kallithea.lib.base import BaseController, render
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
46 from kallithea.model.api_key import ApiKeyModel
853
f67868ef6cd2 some docs updates on controller
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
47
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
48 from kallithea.model.db import User, UserEmailMap, UserIpMap, UserToPerm
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
49 from kallithea.model.forms import UserForm, CustomDefaultPermissionsForm
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
50 from kallithea.model.user import UserModel
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
51 from kallithea.model.meta import Session
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
52 from kallithea.lib.utils import action_logger
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
53 from kallithea.lib.compat import json
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
54 from kallithea.lib.utils2 import datetime_to_time, str2bool, safe_int
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 357
diff changeset
55
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
56 log = logging.getLogger(__name__)
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
57
1245
5f2fbab7c429 PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
58
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
59 class UsersController(BaseController):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
60 """REST Controller styled on the Atom Publishing Protocol"""
673
dd532af216d9 #49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
61
235
fcab58c43ea1 Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
62 @LoginRequired()
305
61be6dcd49a0 protected admin controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 304
diff changeset
63 @HasPermissionAllDecorator('hg.admin')
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
64 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
65 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
66 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
67
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
68 def index(self, format='html'):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
69 """GET /users: All items in the collection"""
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
70 # 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
71
3799
a732bbc40c7e hide listing of default user
Marcin Kuzminski <marcin@python-works.com>
parents: 3736
diff changeset
72 c.users_list = User.query().order_by(User.username)\
a732bbc40c7e hide listing of default user
Marcin Kuzminski <marcin@python-works.com>
parents: 3736
diff changeset
73 .filter(User.username != User.DEFAULT_USER)\
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
74 .order_by(func.lower(User.username))\
3799
a732bbc40c7e hide listing of default user
Marcin Kuzminski <marcin@python-works.com>
parents: 3736
diff changeset
75 .all()
2658
80d837028c40 implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
76
80d837028c40 implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
77 users_data = []
80d837028c40 implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
78 total_records = len(c.users_list)
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
79 _tmpl_lookup = kallithea.CONFIG['pylons.app_globals'].mako_lookup
2663
cc8d7d450d15 No more raw html inside users controller.
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
80 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
81
cc8d7d450d15 No more raw html inside users controller.
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
82 grav_tmpl = lambda user_email, size: (
cc8d7d450d15 No more raw html inside users controller.
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
83 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
84 .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
85
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
86 username = lambda user_id, username: (
2663
cc8d7d450d15 No more raw html inside users controller.
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
87 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
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
cc8d7d450d15 No more raw html inside users controller.
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
90 user_actions = lambda user_id, username: (
cc8d7d450d15 No more raw html inside users controller.
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
91 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
92 .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
93
2658
80d837028c40 implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
94 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
95
2658
80d837028c40 implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
96 users_data.append({
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
97 "gravatar": grav_tmpl(user. email, 20),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
98 "raw_name": user.username,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
99 "username": username(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
100 "firstname": user.name,
80d837028c40 implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
101 "lastname": user.lastname,
80d837028c40 implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
102 "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
103 "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
104 "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
105 "admin": h.boolicon(user.admin),
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
106 "extern_type": user.extern_type,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
107 "extern_name": user.extern_name,
2663
cc8d7d450d15 No more raw html inside users controller.
Marcin Kuzminski <marcin@python-works.com>
parents: 2662
diff changeset
108 "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
109 })
80d837028c40 implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
110
80d837028c40 implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
111 c.data = json.dumps({
80d837028c40 implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
112 "totalRecords": total_records,
80d837028c40 implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
113 "startIndex": 0,
80d837028c40 implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
114 "sort": None,
80d837028c40 implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
115 "dir": "asc",
80d837028c40 implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
116 "records": users_data
80d837028c40 implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
117 })
80d837028c40 implemented admin panel Users table with YUI datatable
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
118
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
119 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
120
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
121 def create(self):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
122 """POST /users: Create a new item"""
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
123 # url('users')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
124 c.default_extern_type = auth_modules.auth_rhodecode.RhodeCodeAuthPlugin.name
235
fcab58c43ea1 Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
125 user_model = UserModel()
1644
59c26a9aba63 typo fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
126 user_form = UserForm()()
50
73f413946c14 user managment implementation continued update/delete/create works
Marcin Kuzminski <marcin@python-blog.com>
parents: 49
diff changeset
127 try:
1644
59c26a9aba63 typo fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
128 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
129 user_model.create(form_result)
2375
bc2d8c03c050 Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2155
diff changeset
130 usr = form_result['username']
4197
d208416c84c6 Rename rhodecode_user to authuser - it is an AuthUser instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4187
diff changeset
131 action_logger(self.authuser, 'admin_created_user:%s' % usr,
2375
bc2d8c03c050 Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2155
diff changeset
132 None, self.ip_addr, self.sa)
3565
a8f2d78d14ea consistently capitalize initial letter in flash messages
Mads Kiilerich <madski@unity3d.com>
parents: 3125
diff changeset
133 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
134 category='success')
2662
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2658
diff changeset
135 Session().commit()
564
ba7e24cd4786 refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents: 548
diff changeset
136 except formencode.Invalid, errors:
235
fcab58c43ea1 Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
137 return htmlfill.render(
357
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
138 render('admin/users/user_add.html'),
235
fcab58c43ea1 Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
139 defaults=errors.value,
357
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
140 errors=errors.error_dict or {},
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
141 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
142 encoding="UTF-8")
4074
3b136af34329 Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents: 3960
diff changeset
143 except UserCreationError, e:
3b136af34329 Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents: 3960
diff changeset
144 h.flash(e, '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
145 except Exception:
357
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
146 log.error(traceback.format_exc())
3565
a8f2d78d14ea consistently capitalize initial letter in flash messages
Mads Kiilerich <madski@unity3d.com>
parents: 3125
diff changeset
147 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
148 % 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
149 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
150
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
151 def new(self, format='html'):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
152 """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
153 # url('new_user')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
154 c.default_extern_type = auth_modules.auth_rhodecode.RhodeCodeAuthPlugin.name
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
155 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
156
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
157 def update(self, id):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
158 """PUT /users/id: Update an existing item"""
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
159 # 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
160 # <input type="hidden" name="_method" value="PUT" />
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
161 # Or using helpers:
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
162 # 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
163 # method='put')
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
164 # url('user', id=ID)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
165 c.active = 'profile'
235
fcab58c43ea1 Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
166 user_model = UserModel()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
167 c.user = user_model.get(id)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
168 c.extern_type = c.user.extern_type
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
169 c.extern_name = c.user.extern_name
3125
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3021
diff changeset
170 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
171 _form = UserForm(edit=True, old_data={'user_id': id,
5f2fbab7c429 PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
172 'email': c.user.email})()
357
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
173 form_result = {}
50
73f413946c14 user managment implementation continued update/delete/create works
Marcin Kuzminski <marcin@python-blog.com>
parents: 49
diff changeset
174 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
175 form_result = _form.to_python(dict(request.POST))
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
176 skip_attrs = ['extern_type', 'extern_name']
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
177 #TODO: plugin should define if username can be updated
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
178 if c.extern_type != "rhodecode":
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
179 # forbid updating username for external accounts
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
180 skip_attrs.append('username')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
181
3021
b2b93614a7cd Implemented #658 Changing username in LDAP-Mode should not be allowed.
Marcin Kuzminski <marcin@python-works.com>
parents: 2709
diff changeset
182 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
183 usr = form_result['username']
4197
d208416c84c6 Rename rhodecode_user to authuser - it is an AuthUser instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4187
diff changeset
184 action_logger(self.authuser, 'admin_updated_user:%s' % usr,
2375
bc2d8c03c050 Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2155
diff changeset
185 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
186 h.flash(_('User updated successfully'), category='success')
2662
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2658
diff changeset
187 Session().commit()
564
ba7e24cd4786 refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents: 548
diff changeset
188 except formencode.Invalid, errors:
2479
9225597688f4 Added validation into user email map
Marcin Kuzminski <marcin@python-works.com>
parents: 2467
diff changeset
189 defaults = errors.value
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
190 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
191 defaults.update({
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
192 'create_repo_perm': user_model.has_perm(id,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
193 'hg.create.repository'),
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2699
diff changeset
194 '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
195 '_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
196 })
235
fcab58c43ea1 Fixed access to repos and users.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
197 return htmlfill.render(
357
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
198 render('admin/users/user_edit.html'),
2479
9225597688f4 Added validation into user email map
Marcin Kuzminski <marcin@python-works.com>
parents: 2467
diff changeset
199 defaults=defaults,
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
200 errors=e,
357
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
201 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
202 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
203 except Exception:
357
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
204 log.error(traceback.format_exc())
3565
a8f2d78d14ea consistently capitalize initial letter in flash messages
Mads Kiilerich <madski@unity3d.com>
parents: 3125
diff changeset
205 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
206 % 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
207 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
208
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
209 def delete(self, id):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
210 """DELETE /users/id: Delete an existing item"""
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
211 # 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
212 # <input type="hidden" name="_method" value="DELETE" />
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
213 # Or using helpers:
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
214 # 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
215 # method='delete')
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
216 # 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
217 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
218 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
219 UserModel().delete(usr)
2662
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2658
diff changeset
220 Session().commit()
3565
a8f2d78d14ea consistently capitalize initial letter in flash messages
Mads Kiilerich <madski@unity3d.com>
parents: 3125
diff changeset
221 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
222 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
223 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
224 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
225 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
226 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
227 category='error')
48
8e250e86a670 Css fixes, implemented removal of users, and display draft
Marcin Kuzminski <marcin@python-blog.com>
parents: 47
diff changeset
228 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
229
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
230 def show(self, id, format='html'):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
231 """GET /users/id: Show a specific item"""
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
232 # url('user', id=ID)
3731
21412a6c3854 throw 404s on empty show functions in ADMIN controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 3712
diff changeset
233 User.get_or_404(-1)
673
dd532af216d9 #49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
234
47
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
235 def edit(self, id, format='html'):
f6ac79182600 Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
236 """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
237 # url('edit_user', id=ID)
2496
fddd8e3fc157 use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents: 2479
diff changeset
238 c.user = User.get_or_404(id)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
239 if c.user.username == User.DEFAULT_USER:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
240 h.flash(_("You can't edit this user"), category='warning')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
241 return redirect(url('users'))
2496
fddd8e3fc157 use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents: 2479
diff changeset
242
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
243 c.active = 'profile'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
244 c.extern_type = c.user.extern_type
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
245 c.extern_name = c.user.extern_name
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
246 c.perm_user = AuthUser(user_id=id, ip_addr=self.ip_addr)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
247
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
248 defaults = c.user.get_dict()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
249 return htmlfill.render(
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
250 render('admin/users/user_edit.html'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
251 defaults=defaults,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
252 encoding="UTF-8",
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
253 force_defaults=False)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
254
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
255 def edit_advanced(self, id):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
256 c.user = User.get_or_404(id)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
257 if c.user.username == User.DEFAULT_USER:
673
dd532af216d9 #49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
258 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
259 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
260
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
261 c.active = 'advanced'
3125
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3021
diff changeset
262 c.perm_user = AuthUser(user_id=id, ip_addr=self.ip_addr)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
263
3736
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
264 umodel = UserModel()
832
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 829
diff changeset
265 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
266 defaults.update({
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
267 'create_repo_perm': umodel.has_perm(c.user, 'hg.create.repository'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
268 'create_user_group_perm': umodel.has_perm(c.user,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
269 'hg.usergroup.create.true'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
270 'fork_repo_perm': umodel.has_perm(c.user, 'hg.fork.repository'),
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 })
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
272 return htmlfill.render(
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
273 render('admin/users/user_edit.html'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
274 defaults=defaults,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
275 encoding="UTF-8",
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
276 force_defaults=False)
895
62c04c5cc971 Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents: 860
diff changeset
277
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
278 def edit_api_keys(self, id):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
279 c.user = User.get_or_404(id)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
280 if c.user.username == User.DEFAULT_USER:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
281 h.flash(_("You can't edit this user"), category='warning')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
282 return redirect(url('users'))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
283
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
284 c.active = 'api_keys'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
285 show_expired = True
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
286 c.lifetime_values = [
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
287 (str(-1), _('forever')),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
288 (str(5), _('5 minutes')),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
289 (str(60), _('1 hour')),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
290 (str(60 * 24), _('1 day')),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
291 (str(60 * 24 * 30), _('1 month')),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
292 ]
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
293 c.lifetime_options = [(c.lifetime_values, _("Lifetime"))]
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
294 c.user_api_keys = ApiKeyModel().get_api_keys(c.user.user_id,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
295 show_expired=show_expired)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
296 defaults = c.user.get_dict()
50
73f413946c14 user managment implementation continued update/delete/create works
Marcin Kuzminski <marcin@python-blog.com>
parents: 49
diff changeset
297 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
298 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
299 defaults=defaults,
50
73f413946c14 user managment implementation continued update/delete/create works
Marcin Kuzminski <marcin@python-blog.com>
parents: 49
diff changeset
300 encoding="UTF-8",
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
301 force_defaults=False)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
302
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
303 def add_api_key(self, id):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
304 c.user = User.get_or_404(id)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
305 if c.user.username == User.DEFAULT_USER:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
306 h.flash(_("You can't edit this user"), category='warning')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
307 return redirect(url('users'))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
308
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
309 lifetime = safe_int(request.POST.get('lifetime'), -1)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
310 description = request.POST.get('description')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
311 new_api_key = ApiKeyModel().create(c.user.user_id, description, lifetime)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
312 Session().commit()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
313 h.flash(_("Api key successfully created"), category='success')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
314 return redirect(url('edit_user_api_keys', id=c.user.user_id))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
315
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
316 def delete_api_key(self, id):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
317 c.user = User.get_or_404(id)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
318 if c.user.username == User.DEFAULT_USER:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
319 h.flash(_("You can't edit this user"), category='warning')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
320 return redirect(url('users'))
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
321
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
322 api_key = request.POST.get('del_api_key')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
323 if request.POST.get('del_api_key_builtin'):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
324 user = User.get(c.user.user_id)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
325 if user:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
326 user.api_key = generate_api_key(user.username)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
327 Session().add(user)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
328 Session().commit()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
329 h.flash(_("Api key successfully reset"), category='success')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
330 elif api_key:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
331 ApiKeyModel().delete(api_key, c.user.user_id)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
332 Session().commit()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
333 h.flash(_("Api key successfully deleted"), category='success')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
334
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
335 return redirect(url('edit_user_api_keys', id=c.user.user_id))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
336
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
337 def update_account(self, id):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
338 pass
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
339
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
340 def edit_perms(self, id):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
341 c.user = User.get_or_404(id)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
342 if c.user.username == User.DEFAULT_USER:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
343 h.flash(_("You can't edit this user"), category='warning')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
344 return redirect(url('users'))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
345
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
346 c.active = 'perms'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
347 c.perm_user = AuthUser(user_id=id, ip_addr=self.ip_addr)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
348
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
349 umodel = UserModel()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
350 defaults = c.user.get_dict()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
351 defaults.update({
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
352 'create_repo_perm': umodel.has_perm(c.user, 'hg.create.repository'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
353 'create_user_group_perm': umodel.has_perm(c.user,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
354 'hg.usergroup.create.true'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
355 'fork_repo_perm': umodel.has_perm(c.user, 'hg.fork.repository'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
356 })
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
357 return htmlfill.render(
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
358 render('admin/users/user_edit.html'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
359 defaults=defaults,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
360 encoding="UTF-8",
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
361 force_defaults=False)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
362
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
363 def update_perms(self, id):
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
364 """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
365 # url('user_perm', id=ID, method='put')
3736
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
366 user = User.get_or_404(id)
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
367
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2699
diff changeset
368 try:
3736
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
369 form = CustomDefaultPermissionsForm()()
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
370 form_result = form.to_python(request.POST)
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
371
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
372 inherit_perms = form_result['inherit_default_permissions']
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
373 user.inherit_default_permissions = inherit_perms
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
374 Session().add(user)
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
375 user_model = UserModel()
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
376
3736
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
377 defs = UserToPerm.query()\
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
378 .filter(UserToPerm.user == user)\
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
379 .all()
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
380 for ug in defs:
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
381 Session().delete(ug)
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
382
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
383 if form_result['create_repo_perm']:
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
384 user_model.grant_perm(id, 'hg.create.repository')
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2699
diff changeset
385 else:
3736
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
386 user_model.grant_perm(id, 'hg.create.none')
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
387 if form_result['create_user_group_perm']:
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
388 user_model.grant_perm(id, 'hg.usergroup.create.true')
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2699
diff changeset
389 else:
3736
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
390 user_model.grant_perm(id, 'hg.usergroup.create.false')
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
391 if form_result['fork_repo_perm']:
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
392 user_model.grant_perm(id, 'hg.fork.repository')
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
393 else:
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
394 user_model.grant_perm(id, 'hg.fork.none')
87e6960e250b Iteration on default permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 3731
diff changeset
395 h.flash(_("Updated permissions"), category='success')
2662
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2658
diff changeset
396 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
397 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
398 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
399 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
400 category='error')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
401 return redirect(url('edit_user_perms', id=id))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
402
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
403 def edit_emails(self, id):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
404 c.user = User.get_or_404(id)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
405 if c.user.username == User.DEFAULT_USER:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
406 h.flash(_("You can't edit this user"), category='warning')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
407 return redirect(url('users'))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
408
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
409 c.active = 'emails'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
410 c.user_email_map = UserEmailMap.query()\
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
411 .filter(UserEmailMap.user == c.user).all()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
412
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
413 defaults = c.user.get_dict()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
414 return htmlfill.render(
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
415 render('admin/users/user_edit.html'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
416 defaults=defaults,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
417 encoding="UTF-8",
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
418 force_defaults=False)
2330
b0fef8a77568 Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents: 2155
diff changeset
419
b0fef8a77568 Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents: 2155
diff changeset
420 def add_email(self, id):
2467
4419551b2915 Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents: 2436
diff changeset
421 """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
422 # 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
423
b0fef8a77568 Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents: 2155
diff changeset
424 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
425 user_model = UserModel()
b0fef8a77568 Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents: 2155
diff changeset
426
b0fef8a77568 Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents: 2155
diff changeset
427 try:
b0fef8a77568 Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents: 2155
diff changeset
428 user_model.add_extra_email(id, email)
2662
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2658
diff changeset
429 Session().commit()
2570
94ae02ca5f00 i18n improve
Takumi IINO <trot.thunder@gmail.com>
parents: 2545
diff changeset
430 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
431 except formencode.Invalid, error:
9225597688f4 Added validation into user email map
Marcin Kuzminski <marcin@python-works.com>
parents: 2467
diff changeset
432 msg = error.error_dict['email']
9225597688f4 Added validation into user email map
Marcin Kuzminski <marcin@python-works.com>
parents: 2467
diff changeset
433 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
434 except Exception:
b0fef8a77568 Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents: 2155
diff changeset
435 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
436 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
437 category='error')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
438 return redirect(url('edit_user_emails', id=id))
2330
b0fef8a77568 Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents: 2155
diff changeset
439
b0fef8a77568 Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents: 2155
diff changeset
440 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
441 """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
442 # url('user_emails_delete', id=ID, method='delete')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
443 email_id = request.POST.get('del_email_id')
2330
b0fef8a77568 Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents: 2155
diff changeset
444 user_model = UserModel()
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
445 user_model.delete_extra_email(id, email_id)
2662
91c442a489bb sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents: 2658
diff changeset
446 Session().commit()
2330
b0fef8a77568 Added simple UI for admin to manage emails map
Marcin Kuzminski <marcin@python-works.com>
parents: 2155
diff changeset
447 h.flash(_("Removed email from user"), category='success')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
448 return redirect(url('edit_user_emails', id=id))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
449
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
450 def edit_ips(self, id):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
451 c.user = User.get_or_404(id)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
452 if c.user.username == User.DEFAULT_USER:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
453 h.flash(_("You can't edit this user"), category='warning')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
454 return redirect(url('users'))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
455
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
456 c.active = 'ips'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
457 c.user_ip_map = UserIpMap.query()\
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
458 .filter(UserIpMap.user == c.user).all()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
459
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
460 c.inherit_default_ips = c.user.inherit_default_permissions
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
461 c.default_user_ip_map = UserIpMap.query()\
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
462 .filter(UserIpMap.user == User.get_default_user()).all()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
463
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
464 defaults = c.user.get_dict()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
465 return htmlfill.render(
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
466 render('admin/users/user_edit.html'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
467 defaults=defaults,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
468 encoding="UTF-8",
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
469 force_defaults=False)
3125
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3021
diff changeset
470
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3021
diff changeset
471 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
472 """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
473 # 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
474
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3021
diff changeset
475 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
476 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
477
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3021
diff changeset
478 try:
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3021
diff changeset
479 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
480 Session().commit()
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
481 h.flash(_("Added ip %s to user whitelist") % ip, category='success')
3125
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3021
diff changeset
482 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
483 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
484 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
485 except Exception:
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3021
diff changeset
486 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
487 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
488 category='error')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
489
3125
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3021
diff changeset
490 if 'default_user' in request.POST:
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
491 return redirect(url('admin_permissions_ips'))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
492 return redirect(url('edit_user_ips', 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
493
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3021
diff changeset
494 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
495 """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
496 # url('user_ips_delete', id=ID, method='delete')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
497 ip_id = request.POST.get('del_ip_id')
3125
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3021
diff changeset
498 user_model = UserModel()
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
499 user_model.delete_extra_ip(id, ip_id)
3125
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3021
diff changeset
500 Session().commit()
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
501 h.flash(_("Removed ip address from user whitelist"), category='success')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
502
3125
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3021
diff changeset
503 if 'default_user' in request.POST:
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
504 return redirect(url('admin_permissions_ips'))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4074
diff changeset
505 return redirect(url('edit_user_ips', id=id))