Show More
@@ -1,359 +1,359 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """ |
|
2 | """ | |
3 | rhodecode.controllers.admin.settings |
|
3 | rhodecode.controllers.admin.settings | |
4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
5 |
|
5 | |||
6 | settings controller for rhodecode admin |
|
6 | settings controller for rhodecode admin | |
7 |
|
7 | |||
8 | :created_on: Jul 14, 2010 |
|
8 | :created_on: Jul 14, 2010 | |
9 | :author: marcink |
|
9 | :author: marcink | |
10 | :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com> |
|
10 | :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com> | |
11 | :license: GPLv3, see COPYING for more details. |
|
11 | :license: GPLv3, see COPYING for more details. | |
12 | """ |
|
12 | """ | |
13 | # This program is free software; you can redistribute it and/or |
|
13 | # This program is free software; you can redistribute it and/or | |
14 | # modify it under the terms of the GNU General Public License |
|
14 | # modify it under the terms of the GNU General Public License | |
15 | # as published by the Free Software Foundation; version 2 |
|
15 | # as published by the Free Software Foundation; version 2 | |
16 | # of the License or (at your opinion) any later version of the license. |
|
16 | # of the License or (at your opinion) any later version of the license. | |
17 | # |
|
17 | # | |
18 | # This program is distributed in the hope that it will be useful, |
|
18 | # This program is distributed in the hope that it will be useful, | |
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 | # GNU General Public License for more details. |
|
21 | # GNU General Public License for more details. | |
22 | # |
|
22 | # | |
23 | # You should have received a copy of the GNU General Public License |
|
23 | # You should have received a copy of the GNU General Public License | |
24 | # along with this program; if not, write to the Free Software |
|
24 | # along with this program; if not, write to the Free Software | |
25 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
25 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
26 | # MA 02110-1301, USA. |
|
26 | # MA 02110-1301, USA. | |
27 |
|
27 | |||
28 | import logging |
|
28 | import logging | |
29 | import traceback |
|
29 | import traceback | |
30 | import formencode |
|
30 | import formencode | |
31 |
|
31 | |||
32 | from sqlalchemy import func |
|
32 | from sqlalchemy import func | |
33 | from formencode import htmlfill |
|
33 | from formencode import htmlfill | |
34 | from pylons import request, session, tmpl_context as c, url, config |
|
34 | from pylons import request, session, tmpl_context as c, url, config | |
35 | from pylons.controllers.util import abort, redirect |
|
35 | from pylons.controllers.util import abort, redirect | |
36 | from pylons.i18n.translation import _ |
|
36 | from pylons.i18n.translation import _ | |
37 |
|
37 | |||
38 | from rhodecode.lib import helpers as h |
|
38 | from rhodecode.lib import helpers as h | |
39 | from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator, \ |
|
39 | from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator, \ | |
40 | HasPermissionAnyDecorator, NotAnonymous |
|
40 | HasPermissionAnyDecorator, NotAnonymous | |
41 | from rhodecode.lib.base import BaseController, render |
|
41 | from rhodecode.lib.base import BaseController, render | |
42 | from rhodecode.lib.celerylib import tasks, run_task |
|
42 | from rhodecode.lib.celerylib import tasks, run_task | |
43 | from rhodecode.lib.utils import repo2db_mapper, invalidate_cache, \ |
|
43 | from rhodecode.lib.utils import repo2db_mapper, invalidate_cache, \ | |
44 | set_rhodecode_config, repo_name_slug |
|
44 | set_rhodecode_config, repo_name_slug | |
45 | from rhodecode.model.db import RhodeCodeUi, Repository, Group |
|
45 | from rhodecode.model.db import RhodeCodeUi, Repository, Group | |
46 | from rhodecode.model.forms import UserForm, ApplicationSettingsForm, \ |
|
46 | from rhodecode.model.forms import UserForm, ApplicationSettingsForm, \ | |
47 | ApplicationUiSettingsForm |
|
47 | ApplicationUiSettingsForm | |
48 | from rhodecode.model.scm import ScmModel |
|
48 | from rhodecode.model.scm import ScmModel | |
49 | from rhodecode.model.settings import SettingsModel |
|
49 | from rhodecode.model.settings import SettingsModel | |
50 | from rhodecode.model.user import UserModel |
|
50 | from rhodecode.model.user import UserModel | |
51 |
|
51 | |||
52 | log = logging.getLogger(__name__) |
|
52 | log = logging.getLogger(__name__) | |
53 |
|
53 | |||
54 |
|
54 | |||
55 | class SettingsController(BaseController): |
|
55 | class SettingsController(BaseController): | |
56 | """REST Controller styled on the Atom Publishing Protocol""" |
|
56 | """REST Controller styled on the Atom Publishing Protocol""" | |
57 | # To properly map this controller, ensure your config/routing.py |
|
57 | # To properly map this controller, ensure your config/routing.py | |
58 | # file has a resource setup: |
|
58 | # file has a resource setup: | |
59 | # map.resource('setting', 'settings', controller='admin/settings', |
|
59 | # map.resource('setting', 'settings', controller='admin/settings', | |
60 | # path_prefix='/admin', name_prefix='admin_') |
|
60 | # path_prefix='/admin', name_prefix='admin_') | |
61 |
|
61 | |||
62 |
|
62 | |||
63 | @LoginRequired() |
|
63 | @LoginRequired() | |
64 | def __before__(self): |
|
64 | def __before__(self): | |
65 | c.admin_user = session.get('admin_user') |
|
65 | c.admin_user = session.get('admin_user') | |
66 | c.admin_username = session.get('admin_username') |
|
66 | c.admin_username = session.get('admin_username') | |
67 | super(SettingsController, self).__before__() |
|
67 | super(SettingsController, self).__before__() | |
68 |
|
68 | |||
69 |
|
69 | |||
70 | @HasPermissionAllDecorator('hg.admin') |
|
70 | @HasPermissionAllDecorator('hg.admin') | |
71 | def index(self, format='html'): |
|
71 | def index(self, format='html'): | |
72 | """GET /admin/settings: All items in the collection""" |
|
72 | """GET /admin/settings: All items in the collection""" | |
73 | # url('admin_settings') |
|
73 | # url('admin_settings') | |
74 |
|
74 | |||
75 | defaults = SettingsModel().get_app_settings() |
|
75 | defaults = SettingsModel().get_app_settings() | |
76 | defaults.update(self.get_hg_ui_settings()) |
|
76 | defaults.update(self.get_hg_ui_settings()) | |
77 | return htmlfill.render( |
|
77 | return htmlfill.render( | |
78 | render('admin/settings/settings.html'), |
|
78 | render('admin/settings/settings.html'), | |
79 | defaults=defaults, |
|
79 | defaults=defaults, | |
80 | encoding="UTF-8", |
|
80 | encoding="UTF-8", | |
81 | force_defaults=False |
|
81 | force_defaults=False | |
82 | ) |
|
82 | ) | |
83 |
|
83 | |||
84 | @HasPermissionAllDecorator('hg.admin') |
|
84 | @HasPermissionAllDecorator('hg.admin') | |
85 | def create(self): |
|
85 | def create(self): | |
86 | """POST /admin/settings: Create a new item""" |
|
86 | """POST /admin/settings: Create a new item""" | |
87 | # url('admin_settings') |
|
87 | # url('admin_settings') | |
88 |
|
88 | |||
89 | @HasPermissionAllDecorator('hg.admin') |
|
89 | @HasPermissionAllDecorator('hg.admin') | |
90 | def new(self, format='html'): |
|
90 | def new(self, format='html'): | |
91 | """GET /admin/settings/new: Form to create a new item""" |
|
91 | """GET /admin/settings/new: Form to create a new item""" | |
92 | # url('admin_new_setting') |
|
92 | # url('admin_new_setting') | |
93 |
|
93 | |||
94 | @HasPermissionAllDecorator('hg.admin') |
|
94 | @HasPermissionAllDecorator('hg.admin') | |
95 | def update(self, setting_id): |
|
95 | def update(self, setting_id): | |
96 | """PUT /admin/settings/setting_id: Update an existing item""" |
|
96 | """PUT /admin/settings/setting_id: Update an existing item""" | |
97 | # Forms posted to this method should contain a hidden field: |
|
97 | # Forms posted to this method should contain a hidden field: | |
98 | # <input type="hidden" name="_method" value="PUT" /> |
|
98 | # <input type="hidden" name="_method" value="PUT" /> | |
99 | # Or using helpers: |
|
99 | # Or using helpers: | |
100 | # h.form(url('admin_setting', setting_id=ID), |
|
100 | # h.form(url('admin_setting', setting_id=ID), | |
101 | # method='put') |
|
101 | # method='put') | |
102 | # url('admin_setting', setting_id=ID) |
|
102 | # url('admin_setting', setting_id=ID) | |
103 | if setting_id == 'mapping': |
|
103 | if setting_id == 'mapping': | |
104 | rm_obsolete = request.POST.get('destroy', False) |
|
104 | rm_obsolete = request.POST.get('destroy', False) | |
105 | log.debug('Rescanning directories with destroy=%s', rm_obsolete) |
|
105 | log.debug('Rescanning directories with destroy=%s', rm_obsolete) | |
106 | initial = ScmModel().repo_scan() |
|
106 | initial = ScmModel().repo_scan() | |
107 | log.debug('invalidating all repositories') |
|
107 | log.debug('invalidating all repositories') | |
108 | for repo_name in initial.keys(): |
|
108 | for repo_name in initial.keys(): | |
109 | invalidate_cache('get_repo_cached_%s' % repo_name) |
|
109 | invalidate_cache('get_repo_cached_%s' % repo_name) | |
110 |
|
110 | |||
111 | added, removed = repo2db_mapper(initial, rm_obsolete) |
|
111 | added, removed = repo2db_mapper(initial, rm_obsolete) | |
112 |
|
112 | |||
113 | h.flash(_('Repositories successfully' |
|
113 | h.flash(_('Repositories successfully' | |
114 | ' rescanned added: %s,removed: %s') % (added, removed) |
|
114 | ' rescanned added: %s,removed: %s') % (added, removed) | |
115 | , category='success') |
|
115 | , category='success') | |
116 |
|
116 | |||
117 | if setting_id == 'whoosh': |
|
117 | if setting_id == 'whoosh': | |
118 | repo_location = self.get_hg_ui_settings()['paths_root_path'] |
|
118 | repo_location = self.get_hg_ui_settings()['paths_root_path'] | |
119 | full_index = request.POST.get('full_index', False) |
|
119 | full_index = request.POST.get('full_index', False) | |
120 |
|
|
120 | run_task(tasks.whoosh_index, repo_location, full_index) | |
121 |
|
121 | |||
122 | h.flash(_('Whoosh reindex task scheduled'), category='success') |
|
122 | h.flash(_('Whoosh reindex task scheduled'), category='success') | |
123 | if setting_id == 'global': |
|
123 | if setting_id == 'global': | |
124 |
|
124 | |||
125 | application_form = ApplicationSettingsForm()() |
|
125 | application_form = ApplicationSettingsForm()() | |
126 | try: |
|
126 | try: | |
127 | form_result = application_form.to_python(dict(request.POST)) |
|
127 | form_result = application_form.to_python(dict(request.POST)) | |
128 | settings_model = SettingsModel() |
|
128 | settings_model = SettingsModel() | |
129 |
|
129 | |||
130 | try: |
|
130 | try: | |
131 | hgsettings1 = settings_model.get('title') |
|
131 | hgsettings1 = settings_model.get('title') | |
132 | hgsettings1.app_settings_value = form_result['rhodecode_title'] |
|
132 | hgsettings1.app_settings_value = form_result['rhodecode_title'] | |
133 |
|
133 | |||
134 | hgsettings2 = settings_model.get('realm') |
|
134 | hgsettings2 = settings_model.get('realm') | |
135 | hgsettings2.app_settings_value = form_result['rhodecode_realm'] |
|
135 | hgsettings2.app_settings_value = form_result['rhodecode_realm'] | |
136 |
|
136 | |||
137 | hgsettings3 = settings_model.get('ga_code') |
|
137 | hgsettings3 = settings_model.get('ga_code') | |
138 | hgsettings3.app_settings_value = form_result['rhodecode_ga_code'] |
|
138 | hgsettings3.app_settings_value = form_result['rhodecode_ga_code'] | |
139 |
|
139 | |||
140 |
|
140 | |||
141 |
|
141 | |||
142 | self.sa.add(hgsettings1) |
|
142 | self.sa.add(hgsettings1) | |
143 | self.sa.add(hgsettings2) |
|
143 | self.sa.add(hgsettings2) | |
144 | self.sa.add(hgsettings3) |
|
144 | self.sa.add(hgsettings3) | |
145 | self.sa.commit() |
|
145 | self.sa.commit() | |
146 | set_rhodecode_config(config) |
|
146 | set_rhodecode_config(config) | |
147 | h.flash(_('Updated application settings'), |
|
147 | h.flash(_('Updated application settings'), | |
148 | category='success') |
|
148 | category='success') | |
149 |
|
149 | |||
150 | except: |
|
150 | except Exception: | |
151 | log.error(traceback.format_exc()) |
|
151 | log.error(traceback.format_exc()) | |
152 | h.flash(_('error occurred during updating application settings'), |
|
152 | h.flash(_('error occurred during updating application settings'), | |
153 | category='error') |
|
153 | category='error') | |
154 |
|
154 | |||
155 | self.sa.rollback() |
|
155 | self.sa.rollback() | |
156 |
|
156 | |||
157 |
|
157 | |||
158 | except formencode.Invalid, errors: |
|
158 | except formencode.Invalid, errors: | |
159 | return htmlfill.render( |
|
159 | return htmlfill.render( | |
160 | render('admin/settings/settings.html'), |
|
160 | render('admin/settings/settings.html'), | |
161 | defaults=errors.value, |
|
161 | defaults=errors.value, | |
162 | errors=errors.error_dict or {}, |
|
162 | errors=errors.error_dict or {}, | |
163 | prefix_error=False, |
|
163 | prefix_error=False, | |
164 | encoding="UTF-8") |
|
164 | encoding="UTF-8") | |
165 |
|
165 | |||
166 | if setting_id == 'mercurial': |
|
166 | if setting_id == 'mercurial': | |
167 | application_form = ApplicationUiSettingsForm()() |
|
167 | application_form = ApplicationUiSettingsForm()() | |
168 | try: |
|
168 | try: | |
169 | form_result = application_form.to_python(dict(request.POST)) |
|
169 | form_result = application_form.to_python(dict(request.POST)) | |
170 |
|
170 | |||
171 | try: |
|
171 | try: | |
172 |
|
172 | |||
173 | hgsettings1 = self.sa.query(RhodeCodeUi)\ |
|
173 | hgsettings1 = self.sa.query(RhodeCodeUi)\ | |
174 | .filter(RhodeCodeUi.ui_key == 'push_ssl').one() |
|
174 | .filter(RhodeCodeUi.ui_key == 'push_ssl').one() | |
175 | hgsettings1.ui_value = form_result['web_push_ssl'] |
|
175 | hgsettings1.ui_value = form_result['web_push_ssl'] | |
176 |
|
176 | |||
177 | hgsettings2 = self.sa.query(RhodeCodeUi)\ |
|
177 | hgsettings2 = self.sa.query(RhodeCodeUi)\ | |
178 | .filter(RhodeCodeUi.ui_key == '/').one() |
|
178 | .filter(RhodeCodeUi.ui_key == '/').one() | |
179 | hgsettings2.ui_value = form_result['paths_root_path'] |
|
179 | hgsettings2.ui_value = form_result['paths_root_path'] | |
180 |
|
180 | |||
181 |
|
181 | |||
182 | #HOOKS |
|
182 | #HOOKS | |
183 | hgsettings3 = self.sa.query(RhodeCodeUi)\ |
|
183 | hgsettings3 = self.sa.query(RhodeCodeUi)\ | |
184 | .filter(RhodeCodeUi.ui_key == 'changegroup.update').one() |
|
184 | .filter(RhodeCodeUi.ui_key == 'changegroup.update').one() | |
185 | hgsettings3.ui_active = bool(form_result['hooks_changegroup_update']) |
|
185 | hgsettings3.ui_active = bool(form_result['hooks_changegroup_update']) | |
186 |
|
186 | |||
187 | hgsettings4 = self.sa.query(RhodeCodeUi)\ |
|
187 | hgsettings4 = self.sa.query(RhodeCodeUi)\ | |
188 | .filter(RhodeCodeUi.ui_key == 'changegroup.repo_size').one() |
|
188 | .filter(RhodeCodeUi.ui_key == 'changegroup.repo_size').one() | |
189 | hgsettings4.ui_active = bool(form_result['hooks_changegroup_repo_size']) |
|
189 | hgsettings4.ui_active = bool(form_result['hooks_changegroup_repo_size']) | |
190 |
|
190 | |||
191 | hgsettings5 = self.sa.query(RhodeCodeUi)\ |
|
191 | hgsettings5 = self.sa.query(RhodeCodeUi)\ | |
192 | .filter(RhodeCodeUi.ui_key == 'pretxnchangegroup.push_logger').one() |
|
192 | .filter(RhodeCodeUi.ui_key == 'pretxnchangegroup.push_logger').one() | |
193 | hgsettings5.ui_active = bool(form_result['hooks_pretxnchangegroup_push_logger']) |
|
193 | hgsettings5.ui_active = bool(form_result['hooks_pretxnchangegroup_push_logger']) | |
194 |
|
194 | |||
195 | hgsettings6 = self.sa.query(RhodeCodeUi)\ |
|
195 | hgsettings6 = self.sa.query(RhodeCodeUi)\ | |
196 | .filter(RhodeCodeUi.ui_key == 'preoutgoing.pull_logger').one() |
|
196 | .filter(RhodeCodeUi.ui_key == 'preoutgoing.pull_logger').one() | |
197 | hgsettings6.ui_active = bool(form_result['hooks_preoutgoing_pull_logger']) |
|
197 | hgsettings6.ui_active = bool(form_result['hooks_preoutgoing_pull_logger']) | |
198 |
|
198 | |||
199 |
|
199 | |||
200 | self.sa.add(hgsettings1) |
|
200 | self.sa.add(hgsettings1) | |
201 | self.sa.add(hgsettings2) |
|
201 | self.sa.add(hgsettings2) | |
202 | self.sa.add(hgsettings3) |
|
202 | self.sa.add(hgsettings3) | |
203 | self.sa.add(hgsettings4) |
|
203 | self.sa.add(hgsettings4) | |
204 | self.sa.add(hgsettings5) |
|
204 | self.sa.add(hgsettings5) | |
205 | self.sa.add(hgsettings6) |
|
205 | self.sa.add(hgsettings6) | |
206 | self.sa.commit() |
|
206 | self.sa.commit() | |
207 |
|
207 | |||
208 | h.flash(_('Updated mercurial settings'), |
|
208 | h.flash(_('Updated mercurial settings'), | |
209 | category='success') |
|
209 | category='success') | |
210 |
|
210 | |||
211 | except: |
|
211 | except: | |
212 | log.error(traceback.format_exc()) |
|
212 | log.error(traceback.format_exc()) | |
213 | h.flash(_('error occurred during updating application settings'), |
|
213 | h.flash(_('error occurred during updating application settings'), | |
214 | category='error') |
|
214 | category='error') | |
215 |
|
215 | |||
216 | self.sa.rollback() |
|
216 | self.sa.rollback() | |
217 |
|
217 | |||
218 |
|
218 | |||
219 | except formencode.Invalid, errors: |
|
219 | except formencode.Invalid, errors: | |
220 | return htmlfill.render( |
|
220 | return htmlfill.render( | |
221 | render('admin/settings/settings.html'), |
|
221 | render('admin/settings/settings.html'), | |
222 | defaults=errors.value, |
|
222 | defaults=errors.value, | |
223 | errors=errors.error_dict or {}, |
|
223 | errors=errors.error_dict or {}, | |
224 | prefix_error=False, |
|
224 | prefix_error=False, | |
225 | encoding="UTF-8") |
|
225 | encoding="UTF-8") | |
226 |
|
226 | |||
227 |
|
227 | |||
228 |
|
228 | |||
229 | return redirect(url('admin_settings')) |
|
229 | return redirect(url('admin_settings')) | |
230 |
|
230 | |||
231 | @HasPermissionAllDecorator('hg.admin') |
|
231 | @HasPermissionAllDecorator('hg.admin') | |
232 | def delete(self, setting_id): |
|
232 | def delete(self, setting_id): | |
233 | """DELETE /admin/settings/setting_id: Delete an existing item""" |
|
233 | """DELETE /admin/settings/setting_id: Delete an existing item""" | |
234 | # Forms posted to this method should contain a hidden field: |
|
234 | # Forms posted to this method should contain a hidden field: | |
235 | # <input type="hidden" name="_method" value="DELETE" /> |
|
235 | # <input type="hidden" name="_method" value="DELETE" /> | |
236 | # Or using helpers: |
|
236 | # Or using helpers: | |
237 | # h.form(url('admin_setting', setting_id=ID), |
|
237 | # h.form(url('admin_setting', setting_id=ID), | |
238 | # method='delete') |
|
238 | # method='delete') | |
239 | # url('admin_setting', setting_id=ID) |
|
239 | # url('admin_setting', setting_id=ID) | |
240 |
|
240 | |||
241 | @HasPermissionAllDecorator('hg.admin') |
|
241 | @HasPermissionAllDecorator('hg.admin') | |
242 | def show(self, setting_id, format='html'): |
|
242 | def show(self, setting_id, format='html'): | |
243 | """GET /admin/settings/setting_id: Show a specific item""" |
|
243 | """GET /admin/settings/setting_id: Show a specific item""" | |
244 | # url('admin_setting', setting_id=ID) |
|
244 | # url('admin_setting', setting_id=ID) | |
245 |
|
245 | |||
246 | @HasPermissionAllDecorator('hg.admin') |
|
246 | @HasPermissionAllDecorator('hg.admin') | |
247 | def edit(self, setting_id, format='html'): |
|
247 | def edit(self, setting_id, format='html'): | |
248 | """GET /admin/settings/setting_id/edit: Form to edit an existing item""" |
|
248 | """GET /admin/settings/setting_id/edit: Form to edit an existing item""" | |
249 | # url('admin_edit_setting', setting_id=ID) |
|
249 | # url('admin_edit_setting', setting_id=ID) | |
250 |
|
250 | |||
251 | @NotAnonymous() |
|
251 | @NotAnonymous() | |
252 | def my_account(self): |
|
252 | def my_account(self): | |
253 | """ |
|
253 | """ | |
254 | GET /_admin/my_account Displays info about my account |
|
254 | GET /_admin/my_account Displays info about my account | |
255 | """ |
|
255 | """ | |
256 | # url('admin_settings_my_account') |
|
256 | # url('admin_settings_my_account') | |
257 |
|
257 | |||
258 | c.user = UserModel().get(self.rhodecode_user.user_id, cache=False) |
|
258 | c.user = UserModel().get(self.rhodecode_user.user_id, cache=False) | |
259 | all_repos = [r.repo_name for r in self.sa.query(Repository)\ |
|
259 | all_repos = [r.repo_name for r in self.sa.query(Repository)\ | |
260 | .filter(Repository.user_id == c.user.user_id)\ |
|
260 | .filter(Repository.user_id == c.user.user_id)\ | |
261 | .order_by(func.lower(Repository.repo_name)).all()] |
|
261 | .order_by(func.lower(Repository.repo_name)).all()] | |
262 | c.user_repos = ScmModel().get_repos(all_repos) |
|
262 | c.user_repos = ScmModel().get_repos(all_repos) | |
263 |
|
263 | |||
264 | if c.user.username == 'default': |
|
264 | if c.user.username == 'default': | |
265 | h.flash(_("You can't edit this user since it's" |
|
265 | h.flash(_("You can't edit this user since it's" | |
266 | " crucial for entire application"), category='warning') |
|
266 | " crucial for entire application"), category='warning') | |
267 | return redirect(url('users')) |
|
267 | return redirect(url('users')) | |
268 |
|
268 | |||
269 | defaults = c.user.get_dict() |
|
269 | defaults = c.user.get_dict() | |
270 | return htmlfill.render( |
|
270 | return htmlfill.render( | |
271 | render('admin/users/user_edit_my_account.html'), |
|
271 | render('admin/users/user_edit_my_account.html'), | |
272 | defaults=defaults, |
|
272 | defaults=defaults, | |
273 | encoding="UTF-8", |
|
273 | encoding="UTF-8", | |
274 | force_defaults=False |
|
274 | force_defaults=False | |
275 | ) |
|
275 | ) | |
276 |
|
276 | |||
277 | def my_account_update(self): |
|
277 | def my_account_update(self): | |
278 | """PUT /_admin/my_account_update: Update an existing item""" |
|
278 | """PUT /_admin/my_account_update: Update an existing item""" | |
279 | # Forms posted to this method should contain a hidden field: |
|
279 | # Forms posted to this method should contain a hidden field: | |
280 | # <input type="hidden" name="_method" value="PUT" /> |
|
280 | # <input type="hidden" name="_method" value="PUT" /> | |
281 | # Or using helpers: |
|
281 | # Or using helpers: | |
282 | # h.form(url('admin_settings_my_account_update'), |
|
282 | # h.form(url('admin_settings_my_account_update'), | |
283 | # method='put') |
|
283 | # method='put') | |
284 | # url('admin_settings_my_account_update', id=ID) |
|
284 | # url('admin_settings_my_account_update', id=ID) | |
285 | user_model = UserModel() |
|
285 | user_model = UserModel() | |
286 | uid = self.rhodecode_user.user_id |
|
286 | uid = self.rhodecode_user.user_id | |
287 | _form = UserForm(edit=True, old_data={'user_id':uid, |
|
287 | _form = UserForm(edit=True, old_data={'user_id':uid, | |
288 | 'email':self.rhodecode_user.email})() |
|
288 | 'email':self.rhodecode_user.email})() | |
289 | form_result = {} |
|
289 | form_result = {} | |
290 | try: |
|
290 | try: | |
291 | form_result = _form.to_python(dict(request.POST)) |
|
291 | form_result = _form.to_python(dict(request.POST)) | |
292 | user_model.update_my_account(uid, form_result) |
|
292 | user_model.update_my_account(uid, form_result) | |
293 | h.flash(_('Your account was updated successfully'), |
|
293 | h.flash(_('Your account was updated successfully'), | |
294 | category='success') |
|
294 | category='success') | |
295 |
|
295 | |||
296 | except formencode.Invalid, errors: |
|
296 | except formencode.Invalid, errors: | |
297 | c.user = user_model.get(self.rhodecode_user.user_id, cache=False) |
|
297 | c.user = user_model.get(self.rhodecode_user.user_id, cache=False) | |
298 | c.user = UserModel().get(self.rhodecode_user.user_id, cache=False) |
|
298 | c.user = UserModel().get(self.rhodecode_user.user_id, cache=False) | |
299 | all_repos = self.sa.query(Repository)\ |
|
299 | all_repos = self.sa.query(Repository)\ | |
300 | .filter(Repository.user_id == c.user.user_id)\ |
|
300 | .filter(Repository.user_id == c.user.user_id)\ | |
301 | .order_by(func.lower(Repository.repo_name))\ |
|
301 | .order_by(func.lower(Repository.repo_name))\ | |
302 | .all() |
|
302 | .all() | |
303 | c.user_repos = ScmModel().get_repos(all_repos) |
|
303 | c.user_repos = ScmModel().get_repos(all_repos) | |
304 |
|
304 | |||
305 | return htmlfill.render( |
|
305 | return htmlfill.render( | |
306 | render('admin/users/user_edit_my_account.html'), |
|
306 | render('admin/users/user_edit_my_account.html'), | |
307 | defaults=errors.value, |
|
307 | defaults=errors.value, | |
308 | errors=errors.error_dict or {}, |
|
308 | errors=errors.error_dict or {}, | |
309 | prefix_error=False, |
|
309 | prefix_error=False, | |
310 | encoding="UTF-8") |
|
310 | encoding="UTF-8") | |
311 | except Exception: |
|
311 | except Exception: | |
312 | log.error(traceback.format_exc()) |
|
312 | log.error(traceback.format_exc()) | |
313 | h.flash(_('error occurred during update of user %s') \ |
|
313 | h.flash(_('error occurred during update of user %s') \ | |
314 | % form_result.get('username'), category='error') |
|
314 | % form_result.get('username'), category='error') | |
315 |
|
315 | |||
316 | return redirect(url('my_account')) |
|
316 | return redirect(url('my_account')) | |
317 |
|
317 | |||
318 | @NotAnonymous() |
|
318 | @NotAnonymous() | |
319 | @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository') |
|
319 | @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository') | |
320 | def create_repository(self): |
|
320 | def create_repository(self): | |
321 | """GET /_admin/create_repository: Form to create a new item""" |
|
321 | """GET /_admin/create_repository: Form to create a new item""" | |
322 |
|
322 | |||
323 | c.repo_groups = [('', '')] |
|
323 | c.repo_groups = [('', '')] | |
324 | parents_link = lambda k:h.literal('»'.join( |
|
324 | parents_link = lambda k:h.literal('»'.join( | |
325 | map(lambda k:k.group_name, |
|
325 | map(lambda k:k.group_name, | |
326 | k.parents + [k]) |
|
326 | k.parents + [k]) | |
327 | ) |
|
327 | ) | |
328 | ) |
|
328 | ) | |
329 |
|
329 | |||
330 | c.repo_groups.extend([(x.group_id, parents_link(x)) for \ |
|
330 | c.repo_groups.extend([(x.group_id, parents_link(x)) for \ | |
331 | x in self.sa.query(Group).all()]) |
|
331 | x in self.sa.query(Group).all()]) | |
332 | c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups) |
|
332 | c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups) | |
333 |
|
333 | |||
334 | new_repo = request.GET.get('repo', '') |
|
334 | new_repo = request.GET.get('repo', '') | |
335 | c.new_repo = repo_name_slug(new_repo) |
|
335 | c.new_repo = repo_name_slug(new_repo) | |
336 |
|
336 | |||
337 | return render('admin/repos/repo_add_create_repository.html') |
|
337 | return render('admin/repos/repo_add_create_repository.html') | |
338 |
|
338 | |||
339 | def get_hg_ui_settings(self): |
|
339 | def get_hg_ui_settings(self): | |
340 | ret = self.sa.query(RhodeCodeUi).all() |
|
340 | ret = self.sa.query(RhodeCodeUi).all() | |
341 |
|
341 | |||
342 | if not ret: |
|
342 | if not ret: | |
343 | raise Exception('Could not get application ui settings !') |
|
343 | raise Exception('Could not get application ui settings !') | |
344 | settings = {} |
|
344 | settings = {} | |
345 | for each in ret: |
|
345 | for each in ret: | |
346 | k = each.ui_key |
|
346 | k = each.ui_key | |
347 | v = each.ui_value |
|
347 | v = each.ui_value | |
348 | if k == '/': |
|
348 | if k == '/': | |
349 | k = 'root_path' |
|
349 | k = 'root_path' | |
350 |
|
350 | |||
351 | if k.find('.') != -1: |
|
351 | if k.find('.') != -1: | |
352 | k = k.replace('.', '_') |
|
352 | k = k.replace('.', '_') | |
353 |
|
353 | |||
354 | if each.ui_section == 'hooks': |
|
354 | if each.ui_section == 'hooks': | |
355 | v = each.ui_active |
|
355 | v = each.ui_active | |
356 |
|
356 | |||
357 | settings[each.ui_section + '_' + k] = v |
|
357 | settings[each.ui_section + '_' + k] = v | |
358 |
|
358 | |||
359 | return settings |
|
359 | return settings |
General Comments 0
You need to be logged in to leave comments.
Login now