Mercurial > kallithea
comparison rhodecode/controllers/admin/settings.py @ 779:389d02a5df52 beta
Added isanonymous decorator for checking permissions for anonymous access
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 27 Nov 2010 15:50:25 +0100 |
parents | d92fc9b5e6f9 |
children | 9caca00de2b0 |
comparison
equal
deleted
inserted
replaced
778:c3fab5b06af3 | 779:389d02a5df52 |
---|---|
1 #!/usr/bin/env python | 1 # -*- coding: utf-8 -*- |
2 # encoding: utf-8 | 2 """ |
3 # settings controller for pylons | 3 package.rhodecode.controllers.admin.settings |
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> | 4 ~~~~~~~~~~~~~~ |
5 # | 5 settings controller for rhodecode admin |
6 | |
7 :created_on: Jul 14, 2010 | |
8 :author: marcink | |
9 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> | |
10 :license: GPLv3, see COPYING for more details. | |
11 """ | |
6 # This program is free software; you can redistribute it and/or | 12 # This program is free software; you can redistribute it and/or |
7 # modify it under the terms of the GNU General Public License | 13 # modify it under the terms of the GNU General Public License |
8 # as published by the Free Software Foundation; version 2 | 14 # as published by the Free Software Foundation; version 2 |
9 # of the License or (at your opinion) any later version of the license. | 15 # of the License or (at your opinion) any later version of the license. |
10 # | 16 # |
15 # | 21 # |
16 # You should have received a copy of the GNU General Public License | 22 # You should have received a copy of the GNU General Public License |
17 # along with this program; if not, write to the Free Software | 23 # along with this program; if not, write to the Free Software |
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | 24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
19 # MA 02110-1301, USA. | 25 # MA 02110-1301, USA. |
20 """ | 26 |
21 Created on July 14, 2010 | |
22 settings controller for pylons | |
23 @author: marcink | |
24 """ | |
25 from formencode import htmlfill | 27 from formencode import htmlfill |
26 from pylons import request, session, tmpl_context as c, url, app_globals as g, \ | 28 from pylons import request, session, tmpl_context as c, url, app_globals as g, \ |
27 config | 29 config |
28 from pylons.controllers.util import abort, redirect | 30 from pylons.controllers.util import abort, redirect |
29 from pylons.i18n.translation import _ | 31 from pylons.i18n.translation import _ |
30 from rhodecode.lib import helpers as h | 32 from rhodecode.lib import helpers as h |
31 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator, \ | 33 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator, \ |
32 HasPermissionAnyDecorator | 34 HasPermissionAnyDecorator, NotAnonymous |
33 from rhodecode.lib.base import BaseController, render | 35 from rhodecode.lib.base import BaseController, render |
34 from rhodecode.lib.celerylib import tasks, run_task | 36 from rhodecode.lib.celerylib import tasks, run_task |
35 from rhodecode.lib.utils import repo2db_mapper, invalidate_cache, \ | 37 from rhodecode.lib.utils import repo2db_mapper, invalidate_cache, \ |
36 set_rhodecode_config | 38 set_rhodecode_config |
37 from rhodecode.model.db import RhodeCodeUi, Repository | 39 from rhodecode.model.db import RhodeCodeUi, Repository |
234 @HasPermissionAllDecorator('hg.admin') | 236 @HasPermissionAllDecorator('hg.admin') |
235 def edit(self, setting_id, format='html'): | 237 def edit(self, setting_id, format='html'): |
236 """GET /admin/settings/setting_id/edit: Form to edit an existing item""" | 238 """GET /admin/settings/setting_id/edit: Form to edit an existing item""" |
237 # url('admin_edit_setting', setting_id=ID) | 239 # url('admin_edit_setting', setting_id=ID) |
238 | 240 |
239 | 241 @NotAnonymous() |
240 def my_account(self): | 242 def my_account(self): |
241 """ | 243 """ |
242 GET /_admin/my_account Displays info about my account | 244 GET /_admin/my_account Displays info about my account |
243 """ | 245 """ |
244 | |
245 # url('admin_settings_my_account') | 246 # url('admin_settings_my_account') |
247 | |
246 c.user = UserModel().get(c.rhodecode_user.user_id, cache=False) | 248 c.user = UserModel().get(c.rhodecode_user.user_id, cache=False) |
247 all_repos = self.sa.query(Repository)\ | 249 all_repos = self.sa.query(Repository)\ |
248 .filter(Repository.user_id == c.user.user_id)\ | 250 .filter(Repository.user_id == c.user.user_id)\ |
249 .order_by(func.lower(Repository.repo_name))\ | 251 .order_by(func.lower(Repository.repo_name))\ |
250 .all() | 252 .all() |
278 'email':c.rhodecode_user.email})() | 280 'email':c.rhodecode_user.email})() |
279 form_result = {} | 281 form_result = {} |
280 try: | 282 try: |
281 form_result = _form.to_python(dict(request.POST)) | 283 form_result = _form.to_python(dict(request.POST)) |
282 user_model.update_my_account(uid, form_result) | 284 user_model.update_my_account(uid, form_result) |
283 h.flash(_('Your account was updated succesfully'), | 285 h.flash(_('Your account was updated successfully'), |
284 category='success') | 286 category='success') |
285 | 287 |
286 except formencode.Invalid, errors: | 288 except formencode.Invalid, errors: |
287 c.user = user_model.get(c.rhodecode_user.user_id, cache=False) | 289 c.user = user_model.get(c.rhodecode_user.user_id, cache=False) |
288 c.user = UserModel().get(c.rhodecode_user.user_id, cache=False) | 290 c.user = UserModel().get(c.rhodecode_user.user_id, cache=False) |
298 errors=errors.error_dict or {}, | 300 errors=errors.error_dict or {}, |
299 prefix_error=False, | 301 prefix_error=False, |
300 encoding="UTF-8") | 302 encoding="UTF-8") |
301 except Exception: | 303 except Exception: |
302 log.error(traceback.format_exc()) | 304 log.error(traceback.format_exc()) |
303 h.flash(_('error occured during update of user %s') \ | 305 h.flash(_('error occurred during update of user %s') \ |
304 % form_result.get('username'), category='error') | 306 % form_result.get('username'), category='error') |
305 | 307 |
306 return redirect(url('my_account')) | 308 return redirect(url('my_account')) |
307 | 309 |
310 @NotAnonymous() | |
308 @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository') | 311 @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository') |
309 def create_repository(self): | 312 def create_repository(self): |
310 """GET /_admin/create_repository: Form to create a new item""" | 313 """GET /_admin/create_repository: Form to create a new item""" |
311 new_repo = request.GET.get('repo', '') | 314 new_repo = request.GET.get('repo', '') |
312 c.new_repo = h.repo_name_slug(new_repo) | 315 c.new_repo = h.repo_name_slug(new_repo) |