annotate rhodecode/controllers/admin/settings.py @ 1217:a3b2b4b4e440

fixes for issue #149
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 05 Apr 2011 18:04:06 +0200
parents 93b980ebee55
children bf263968da47
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
779
389d02a5df52 Added isanonymous decorator for checking permissions for anonymous access
Marcin Kuzminski <marcin@python-works.com>
parents: 765
diff changeset
1 # -*- coding: utf-8 -*-
389d02a5df52 Added isanonymous decorator for checking permissions for anonymous access
Marcin Kuzminski <marcin@python-works.com>
parents: 765
diff changeset
2 """
860
5f7731e3ab4d fixed spelling mistakes, and some minor docs bugs
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
3 rhodecode.controllers.admin.settings
5f7731e3ab4d fixed spelling mistakes, and some minor docs bugs
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5f7731e3ab4d fixed spelling mistakes, and some minor docs bugs
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
5
779
389d02a5df52 Added isanonymous decorator for checking permissions for anonymous access
Marcin Kuzminski <marcin@python-works.com>
parents: 765
diff changeset
6 settings controller for rhodecode admin
389d02a5df52 Added isanonymous decorator for checking permissions for anonymous access
Marcin Kuzminski <marcin@python-works.com>
parents: 765
diff changeset
7
389d02a5df52 Added isanonymous decorator for checking permissions for anonymous access
Marcin Kuzminski <marcin@python-works.com>
parents: 765
diff changeset
8 :created_on: Jul 14, 2010
389d02a5df52 Added isanonymous decorator for checking permissions for anonymous access
Marcin Kuzminski <marcin@python-works.com>
parents: 765
diff changeset
9 :author: marcink
389d02a5df52 Added isanonymous decorator for checking permissions for anonymous access
Marcin Kuzminski <marcin@python-works.com>
parents: 765
diff changeset
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
389d02a5df52 Added isanonymous decorator for checking permissions for anonymous access
Marcin Kuzminski <marcin@python-works.com>
parents: 765
diff changeset
11 :license: GPLv3, see COPYING for more details.
389d02a5df52 Added isanonymous decorator for checking permissions for anonymous access
Marcin Kuzminski <marcin@python-works.com>
parents: 765
diff changeset
12 """
1217
a3b2b4b4e440 fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1136
diff changeset
13 # This program is free software: you can redistribute it and/or modify
a3b2b4b4e440 fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1136
diff changeset
14 # it under the terms of the GNU General Public License as published by
a3b2b4b4e440 fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1136
diff changeset
15 # the Free Software Foundation, either version 3 of the License, or
a3b2b4b4e440 fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1136
diff changeset
16 # (at your option) any later version.
a3b2b4b4e440 fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1136
diff changeset
17 #
346
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 # This program is distributed in the hope that it will be useful,
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 # GNU General Public License for more details.
1217
a3b2b4b4e440 fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1136
diff changeset
22 #
346
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 # You should have received a copy of the GNU General Public License
1217
a3b2b4b4e440 fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1136
diff changeset
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
779
389d02a5df52 Added isanonymous decorator for checking permissions for anonymous access
Marcin Kuzminski <marcin@python-works.com>
parents: 765
diff changeset
25
346
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 from formencode import htmlfill
350
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 348
diff changeset
27 from pylons import request, session, tmpl_context as c, url, app_globals as g, \
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 348
diff changeset
28 config
346
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 from pylons.controllers.util import abort, redirect
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 from pylons.i18n.translation import _
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 537
diff changeset
31 from rhodecode.lib import helpers as h
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 537
diff changeset
32 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator, \
779
389d02a5df52 Added isanonymous decorator for checking permissions for anonymous access
Marcin Kuzminski <marcin@python-works.com>
parents: 765
diff changeset
33 HasPermissionAnyDecorator, NotAnonymous
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 537
diff changeset
34 from rhodecode.lib.base import BaseController, render
705
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
35 from rhodecode.lib.celerylib import tasks, run_task
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 537
diff changeset
36 from rhodecode.lib.utils import repo2db_mapper, invalidate_cache, \
756
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
37 set_rhodecode_config
705
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
38 from rhodecode.model.db import RhodeCodeUi, Repository
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 537
diff changeset
39 from rhodecode.model.forms import UserForm, ApplicationSettingsForm, \
388
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
40 ApplicationUiSettingsForm
691
7486da5f0628 Refactor codes for scm model
Marcin Kuzminski <marcin@python-works.com>
parents: 687
diff changeset
41 from rhodecode.model.scm import ScmModel
705
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
42 from rhodecode.model.settings import SettingsModel
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
43 from rhodecode.model.user import UserModel
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 661
diff changeset
44 from sqlalchemy import func
346
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45 import formencode
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46 import logging
350
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 348
diff changeset
47 import traceback
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
48
346
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49 log = logging.getLogger(__name__)
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52 class SettingsController(BaseController):
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53 """REST Controller styled on the Atom Publishing Protocol"""
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
54 # To properly map this controller, ensure your config/routing.py
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55 # file has a resource setup:
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56 # map.resource('setting', 'settings', controller='admin/settings',
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57 # path_prefix='/admin', name_prefix='admin_')
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60 @LoginRequired()
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61 def __before__(self):
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 c.admin_user = session.get('admin_user')
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63 c.admin_username = session.get('admin_username')
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64 super(SettingsController, self).__before__()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
65
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
66
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
67 @HasPermissionAllDecorator('hg.admin')
346
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68 def index(self, format='html'):
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69 """GET /admin/settings: All items in the collection"""
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70 # url('admin_settings')
350
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 348
diff changeset
71
756
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
72 defaults = SettingsModel().get_app_settings()
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
73 defaults.update(self.get_hg_ui_settings())
350
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 348
diff changeset
74 return htmlfill.render(
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 348
diff changeset
75 render('admin/settings/settings.html'),
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 348
diff changeset
76 defaults=defaults,
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 348
diff changeset
77 encoding="UTF-8",
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 348
diff changeset
78 force_defaults=False
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
79 )
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
80
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
81 @HasPermissionAllDecorator('hg.admin')
346
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
82 def create(self):
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
83 """POST /admin/settings: Create a new item"""
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
84 # url('admin_settings')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
85
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
86 @HasPermissionAllDecorator('hg.admin')
346
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
87 def new(self, format='html'):
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
88 """GET /admin/settings/new: Form to create a new item"""
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89 # url('admin_new_setting')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
90
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
91 @HasPermissionAllDecorator('hg.admin')
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
92 def update(self, setting_id):
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
93 """PUT /admin/settings/setting_id: Update an existing item"""
346
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
94 # Forms posted to this method should contain a hidden field:
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95 # <input type="hidden" name="_method" value="PUT" />
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96 # Or using helpers:
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
97 # h.form(url('admin_setting', setting_id=ID),
346
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98 # method='put')
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
99 # url('admin_setting', setting_id=ID)
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
100 if setting_id == 'mapping':
348
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 346
diff changeset
101 rm_obsolete = request.POST.get('destroy', False)
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 346
diff changeset
102 log.debug('Rescanning directories with destroy=%s', rm_obsolete)
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 346
diff changeset
103
691
7486da5f0628 Refactor codes for scm model
Marcin Kuzminski <marcin@python-works.com>
parents: 687
diff changeset
104 initial = ScmModel().repo_scan(g.paths[0][1], g.baseui)
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 661
diff changeset
105 for repo_name in initial.keys():
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 661
diff changeset
106 invalidate_cache('get_repo_cached_%s' % repo_name)
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 661
diff changeset
107
348
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 346
diff changeset
108 repo2db_mapper(initial, rm_obsolete)
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 661
diff changeset
109
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
110 h.flash(_('Repositories successfully rescanned'), category='success')
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
111
467
3fc3ce53659b starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents: 446
diff changeset
112 if setting_id == 'whoosh':
756
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
113 repo_location = self.get_hg_ui_settings()['paths_root_path']
489
460ad816820d fixed bug when new repo had no last commiter,
Marcin Kuzminski <marcin@python-works.com>
parents: 473
diff changeset
114 full_index = request.POST.get('full_index', False)
460ad816820d fixed bug when new repo had no last commiter,
Marcin Kuzminski <marcin@python-works.com>
parents: 473
diff changeset
115 task = run_task(tasks.whoosh_index, repo_location, full_index)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
116
467
3fc3ce53659b starting celery branch
Marcin Kuzminski <marcin@python-works.com>
parents: 446
diff changeset
117 h.flash(_('Whoosh reindex task scheduled'), category='success')
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
118 if setting_id == 'global':
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
119
350
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 348
diff changeset
120 application_form = ApplicationSettingsForm()()
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 348
diff changeset
121 try:
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 348
diff changeset
122 form_result = application_form.to_python(dict(request.POST))
705
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
123 settings_model = SettingsModel()
350
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 348
diff changeset
124 try:
705
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
125 hgsettings1 = settings_model.get('title')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
126 hgsettings1.app_settings_value = form_result['rhodecode_title']
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
127
709
a23b686fb14d bugfix for application name
Marcin Kuzminski <marcin@python-works.com>
parents: 705
diff changeset
128 hgsettings2 = settings_model.get('realm')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
129 hgsettings2.app_settings_value = form_result['rhodecode_realm']
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
130
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
131
381
55377fdc1fc6 cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 380
diff changeset
132 self.sa.add(hgsettings1)
55377fdc1fc6 cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 380
diff changeset
133 self.sa.add(hgsettings2)
350
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 348
diff changeset
134 self.sa.commit()
548
b75b77ef649d renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
135 set_rhodecode_config(config)
350
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 348
diff changeset
136 h.flash(_('Updated application settings'),
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 348
diff changeset
137 category='success')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
138
350
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 348
diff changeset
139 except:
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 348
diff changeset
140 log.error(traceback.format_exc())
1136
93b980ebee55 changes for release 1.1.5
Marcin Kuzminski <marcin@python-works.com>
parents: 860
diff changeset
141 h.flash(_('error occurred during updating'
93b980ebee55 changes for release 1.1.5
Marcin Kuzminski <marcin@python-works.com>
parents: 860
diff changeset
142 ' application settings'), category='error')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
143
350
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 348
diff changeset
144 self.sa.rollback()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
145
350
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 348
diff changeset
146
564
ba7e24cd4786 refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
147 except formencode.Invalid, errors:
350
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 348
diff changeset
148 return htmlfill.render(
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 348
diff changeset
149 render('admin/settings/settings.html'),
359
339d1368c10d new style error display for settings, added flash msg for repo rescan
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
150 defaults=errors.value,
339d1368c10d new style error display for settings, added flash msg for repo rescan
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
151 errors=errors.error_dict or {},
339d1368c10d new style error display for settings, added flash msg for repo rescan
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
152 prefix_error=False,
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
153 encoding="UTF-8")
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
154
388
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
155 if setting_id == 'mercurial':
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
156 application_form = ApplicationUiSettingsForm()()
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
157 try:
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
158 form_result = application_form.to_python(dict(request.POST))
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
159
388
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
160 try:
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
161
549
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 548
diff changeset
162 hgsettings1 = self.sa.query(RhodeCodeUi)\
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 548
diff changeset
163 .filter(RhodeCodeUi.ui_key == 'push_ssl').one()
388
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
164 hgsettings1.ui_value = form_result['web_push_ssl']
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
165
549
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 548
diff changeset
166 hgsettings2 = self.sa.query(RhodeCodeUi)\
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 548
diff changeset
167 .filter(RhodeCodeUi.ui_key == '/').one()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
168 hgsettings2.ui_value = form_result['paths_root_path']
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
169
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
170
395
e8af467b5a60 Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 388
diff changeset
171 #HOOKS
549
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 548
diff changeset
172 hgsettings3 = self.sa.query(RhodeCodeUi)\
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 548
diff changeset
173 .filter(RhodeCodeUi.ui_key == 'changegroup.update').one()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
174 hgsettings3.ui_active = bool(form_result['hooks_changegroup_update'])
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
175
549
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 548
diff changeset
176 hgsettings4 = self.sa.query(RhodeCodeUi)\
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 548
diff changeset
177 .filter(RhodeCodeUi.ui_key == 'changegroup.repo_size').one()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
178 hgsettings4.ui_active = bool(form_result['hooks_changegroup_repo_size'])
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
179
661
673de12e6bf6 added option to enable/disable of logger hooks from admin panel.
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
180 hgsettings5 = self.sa.query(RhodeCodeUi)\
673de12e6bf6 added option to enable/disable of logger hooks from admin panel.
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
181 .filter(RhodeCodeUi.ui_key == 'pretxnchangegroup.push_logger').one()
673de12e6bf6 added option to enable/disable of logger hooks from admin panel.
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
182 hgsettings5.ui_active = bool(form_result['hooks_pretxnchangegroup_push_logger'])
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
183
661
673de12e6bf6 added option to enable/disable of logger hooks from admin panel.
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
184 hgsettings6 = self.sa.query(RhodeCodeUi)\
673de12e6bf6 added option to enable/disable of logger hooks from admin panel.
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
185 .filter(RhodeCodeUi.ui_key == 'preoutgoing.pull_logger').one()
673de12e6bf6 added option to enable/disable of logger hooks from admin panel.
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
186 hgsettings6.ui_active = bool(form_result['hooks_preoutgoing_pull_logger'])
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
187
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
188
388
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
189 self.sa.add(hgsettings1)
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
190 self.sa.add(hgsettings2)
395
e8af467b5a60 Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 388
diff changeset
191 self.sa.add(hgsettings3)
e8af467b5a60 Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 388
diff changeset
192 self.sa.add(hgsettings4)
661
673de12e6bf6 added option to enable/disable of logger hooks from admin panel.
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
193 self.sa.add(hgsettings5)
673de12e6bf6 added option to enable/disable of logger hooks from admin panel.
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
194 self.sa.add(hgsettings6)
388
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
195 self.sa.commit()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
196
396
9416269860c9 little css update, and flash messages
Marcin Kuzminski <marcin@python-works.com>
parents: 395
diff changeset
197 h.flash(_('Updated mercurial settings'),
388
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
198 category='success')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
199
388
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
200 except:
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
201 log.error(traceback.format_exc())
537
48be953851fc extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents: 489
diff changeset
202 h.flash(_('error occurred during updating application settings'),
388
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
203 category='error')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
204
388
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
205 self.sa.rollback()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
206
388
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
207
564
ba7e24cd4786 refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
208 except formencode.Invalid, errors:
388
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
209 return htmlfill.render(
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
210 render('admin/settings/settings.html'),
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
211 defaults=errors.value,
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
212 errors=errors.error_dict or {},
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
213 prefix_error=False,
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
214 encoding="UTF-8")
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
215
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
216
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
217
348
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 346
diff changeset
218 return redirect(url('admin_settings'))
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
219
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
220 @HasPermissionAllDecorator('hg.admin')
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
221 def delete(self, setting_id):
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
222 """DELETE /admin/settings/setting_id: Delete an existing item"""
346
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
223 # Forms posted to this method should contain a hidden field:
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
224 # <input type="hidden" name="_method" value="DELETE" />
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
225 # Or using helpers:
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
226 # h.form(url('admin_setting', setting_id=ID),
346
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
227 # method='delete')
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
228 # url('admin_setting', setting_id=ID)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
229
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
230 @HasPermissionAllDecorator('hg.admin')
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
231 def show(self, setting_id, format='html'):
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
232 """GET /admin/settings/setting_id: Show a specific item"""
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
233 # url('admin_setting', setting_id=ID)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
234
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
235 @HasPermissionAllDecorator('hg.admin')
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
236 def edit(self, setting_id, format='html'):
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
237 """GET /admin/settings/setting_id/edit: Form to edit an existing item"""
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
238 # url('admin_edit_setting', setting_id=ID)
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
239
779
389d02a5df52 Added isanonymous decorator for checking permissions for anonymous access
Marcin Kuzminski <marcin@python-works.com>
parents: 765
diff changeset
240 @NotAnonymous()
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
241 def my_account(self):
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
242 """
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
243 GET /_admin/my_account Displays info about my account
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
244 """
779
389d02a5df52 Added isanonymous decorator for checking permissions for anonymous access
Marcin Kuzminski <marcin@python-works.com>
parents: 765
diff changeset
245 # url('admin_settings_my_account')
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 661
diff changeset
246
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
247 c.user = UserModel().get(c.rhodecode_user.user_id, cache=False)
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 661
diff changeset
248 all_repos = self.sa.query(Repository)\
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 661
diff changeset
249 .filter(Repository.user_id == c.user.user_id)\
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 661
diff changeset
250 .order_by(func.lower(Repository.repo_name))\
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 661
diff changeset
251 .all()
765
d92fc9b5e6f9 bugfix, when user had no repos he would see all repos in my account
Marcin Kuzminski <marcin@python-works.com>
parents: 756
diff changeset
252
691
7486da5f0628 Refactor codes for scm model
Marcin Kuzminski <marcin@python-works.com>
parents: 687
diff changeset
253 c.user_repos = ScmModel().get_repos(all_repos)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
254
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
255 if c.user.username == 'default':
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
256 h.flash(_("You can't edit this user since it's"
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
257 " crucial for entire application"), category='warning')
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
258 return redirect(url('users'))
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
259
832
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 829
diff changeset
260 defaults = c.user.get_dict()
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
261 return htmlfill.render(
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
262 render('admin/users/user_edit_my_account.html'),
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
263 defaults=defaults,
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
264 encoding="UTF-8",
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
265 force_defaults=False
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
266 )
346
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
267
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
268 def my_account_update(self):
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
269 """PUT /_admin/my_account_update: Update an existing item"""
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
270 # Forms posted to this method should contain a hidden field:
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
271 # <input type="hidden" name="_method" value="PUT" />
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
272 # Or using helpers:
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
273 # h.form(url('admin_settings_my_account_update'),
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
274 # method='put')
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
275 # url('admin_settings_my_account_update', id=ID)
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
276 user_model = UserModel()
548
b75b77ef649d renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
277 uid = c.rhodecode_user.user_id
489
460ad816820d fixed bug when new repo had no last commiter,
Marcin Kuzminski <marcin@python-works.com>
parents: 473
diff changeset
278 _form = UserForm(edit=True, old_data={'user_id':uid,
548
b75b77ef649d renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
279 'email':c.rhodecode_user.email})()
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
280 form_result = {}
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
281 try:
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
282 form_result = _form.to_python(dict(request.POST))
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
283 user_model.update_my_account(uid, form_result)
779
389d02a5df52 Added isanonymous decorator for checking permissions for anonymous access
Marcin Kuzminski <marcin@python-works.com>
parents: 765
diff changeset
284 h.flash(_('Your account was updated successfully'),
396
9416269860c9 little css update, and flash messages
Marcin Kuzminski <marcin@python-works.com>
parents: 395
diff changeset
285 category='success')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
286
564
ba7e24cd4786 refactor codes and setup for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
287 except formencode.Invalid, errors:
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
288 c.user = user_model.get(c.rhodecode_user.user_id, cache=False)
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
289 c.user = UserModel().get(c.rhodecode_user.user_id, cache=False)
687
b9442a8b5e02 fixed admin settings form resubmition bug.
Marcin Kuzminski <marcin@python-works.com>
parents: 673
diff changeset
290 all_repos = self.sa.query(Repository)\
b9442a8b5e02 fixed admin settings form resubmition bug.
Marcin Kuzminski <marcin@python-works.com>
parents: 673
diff changeset
291 .filter(Repository.user_id == c.user.user_id)\
b9442a8b5e02 fixed admin settings form resubmition bug.
Marcin Kuzminski <marcin@python-works.com>
parents: 673
diff changeset
292 .order_by(func.lower(Repository.repo_name))\
b9442a8b5e02 fixed admin settings form resubmition bug.
Marcin Kuzminski <marcin@python-works.com>
parents: 673
diff changeset
293 .all()
691
7486da5f0628 Refactor codes for scm model
Marcin Kuzminski <marcin@python-works.com>
parents: 687
diff changeset
294 c.user_repos = ScmModel().get_repos(all_repos)
687
b9442a8b5e02 fixed admin settings form resubmition bug.
Marcin Kuzminski <marcin@python-works.com>
parents: 673
diff changeset
295
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
296 return htmlfill.render(
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
297 render('admin/users/user_edit_my_account.html'),
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
298 defaults=errors.value,
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
299 errors=errors.error_dict or {},
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
300 prefix_error=False,
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
301 encoding="UTF-8")
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
302 except Exception:
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
303 log.error(traceback.format_exc())
779
389d02a5df52 Added isanonymous decorator for checking permissions for anonymous access
Marcin Kuzminski <marcin@python-works.com>
parents: 765
diff changeset
304 h.flash(_('error occurred during update of user %s') \
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
305 % form_result.get('username'), category='error')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
306
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 359
diff changeset
307 return redirect(url('my_account'))
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
308
779
389d02a5df52 Added isanonymous decorator for checking permissions for anonymous access
Marcin Kuzminski <marcin@python-works.com>
parents: 765
diff changeset
309 @NotAnonymous()
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 396
diff changeset
310 @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository')
380
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 371
diff changeset
311 def create_repository(self):
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 371
diff changeset
312 """GET /_admin/create_repository: Form to create a new item"""
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 371
diff changeset
313 new_repo = request.GET.get('repo', '')
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 371
diff changeset
314 c.new_repo = h.repo_name_slug(new_repo)
346
51362853ac3b added settings rest controllers for admin, updated routes with easier submodule handling
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
315
380
ca54622e39a1 Added separate create repository views for non administrative users.
Marcin Kuzminski <marcin@python-works.com>
parents: 371
diff changeset
316 return render('admin/repos/repo_add_create_repository.html')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 564
diff changeset
317
756
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
318 def get_hg_ui_settings(self):
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
319 ret = self.sa.query(RhodeCodeUi).all()
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
320
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
321 if not ret:
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
322 raise Exception('Could not get application ui settings !')
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
323 settings = {}
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
324 for each in ret:
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
325 k = each.ui_key
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
326 v = each.ui_value
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
327 if k == '/':
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
328 k = 'root_path'
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
329
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
330 if k.find('.') != -1:
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
331 k = k.replace('.', '_')
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
332
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
333 if each.ui_section == 'hooks':
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
334 v = each.ui_active
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
335
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
336 settings[each.ui_section + '_' + k] = v
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
337
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 709
diff changeset
338 return settings