Mercurial > kallithea
comparison rhodecode/controllers/admin/settings.py @ 2031:82a88013a3fd
merge 1.3 into stable
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 26 Feb 2012 17:25:09 +0200 |
parents | 752b0a7b7679 a76e9bacbedc |
children | ecd59c28f432 |
comparison
equal
deleted
inserted
replaced
2005:ab0e122b38a7 | 2031:82a88013a3fd |
---|---|
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) 2010-2012 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 modify | 13 # This program is free software: you can redistribute it and/or modify |
14 # it under the terms of the GNU General Public License as published by | 14 # it under the terms of the GNU General Public License as published by |
15 # the Free Software Foundation, either version 3 of the License, or | 15 # the Free Software Foundation, either version 3 of the License, or |
38 HasPermissionAnyDecorator, NotAnonymous | 38 HasPermissionAnyDecorator, NotAnonymous |
39 from rhodecode.lib.base import BaseController, render | 39 from rhodecode.lib.base import BaseController, render |
40 from rhodecode.lib.celerylib import tasks, run_task | 40 from rhodecode.lib.celerylib import tasks, run_task |
41 from rhodecode.lib.utils import repo2db_mapper, invalidate_cache, \ | 41 from rhodecode.lib.utils import repo2db_mapper, invalidate_cache, \ |
42 set_rhodecode_config, repo_name_slug | 42 set_rhodecode_config, repo_name_slug |
43 from rhodecode.model.db import RhodeCodeUi, Repository, Group, \ | 43 from rhodecode.model.db import RhodeCodeUi, Repository, RepoGroup, \ |
44 RhodeCodeSettings | 44 RhodeCodeSetting |
45 from rhodecode.model.forms import UserForm, ApplicationSettingsForm, \ | 45 from rhodecode.model.forms import UserForm, ApplicationSettingsForm, \ |
46 ApplicationUiSettingsForm | 46 ApplicationUiSettingsForm |
47 from rhodecode.model.scm import ScmModel | 47 from rhodecode.model.scm import ScmModel |
48 from rhodecode.model.user import UserModel | 48 from rhodecode.model.user import UserModel |
49 from rhodecode.model.db import User | 49 from rhodecode.model.db import User |
50 from rhodecode.model.notification import EmailNotificationModel | |
51 from rhodecode.model.meta import Session | |
50 | 52 |
51 log = logging.getLogger(__name__) | 53 log = logging.getLogger(__name__) |
52 | 54 |
53 | 55 |
54 class SettingsController(BaseController): | 56 class SettingsController(BaseController): |
67 @HasPermissionAllDecorator('hg.admin') | 69 @HasPermissionAllDecorator('hg.admin') |
68 def index(self, format='html'): | 70 def index(self, format='html'): |
69 """GET /admin/settings: All items in the collection""" | 71 """GET /admin/settings: All items in the collection""" |
70 # url('admin_settings') | 72 # url('admin_settings') |
71 | 73 |
72 defaults = RhodeCodeSettings.get_app_settings() | 74 defaults = RhodeCodeSetting.get_app_settings() |
73 defaults.update(self.get_hg_ui_settings()) | 75 defaults.update(self.get_hg_ui_settings()) |
74 return htmlfill.render( | 76 return htmlfill.render( |
75 render('admin/settings/settings.html'), | 77 render('admin/settings/settings.html'), |
76 defaults=defaults, | 78 defaults=defaults, |
77 encoding="UTF-8", | 79 encoding="UTF-8", |
97 # h.form(url('admin_setting', setting_id=ID), | 99 # h.form(url('admin_setting', setting_id=ID), |
98 # method='put') | 100 # method='put') |
99 # url('admin_setting', setting_id=ID) | 101 # url('admin_setting', setting_id=ID) |
100 if setting_id == 'mapping': | 102 if setting_id == 'mapping': |
101 rm_obsolete = request.POST.get('destroy', False) | 103 rm_obsolete = request.POST.get('destroy', False) |
102 log.debug('Rescanning directories with destroy=%s', rm_obsolete) | 104 log.debug('Rescanning directories with destroy=%s' % rm_obsolete) |
103 initial = ScmModel().repo_scan() | 105 initial = ScmModel().repo_scan() |
104 log.debug('invalidating all repositories') | 106 log.debug('invalidating all repositories') |
105 for repo_name in initial.keys(): | 107 for repo_name in initial.keys(): |
106 invalidate_cache('get_repo_cached_%s' % repo_name) | 108 invalidate_cache('get_repo_cached_%s' % repo_name) |
107 | 109 |
122 application_form = ApplicationSettingsForm()() | 124 application_form = ApplicationSettingsForm()() |
123 try: | 125 try: |
124 form_result = application_form.to_python(dict(request.POST)) | 126 form_result = application_form.to_python(dict(request.POST)) |
125 | 127 |
126 try: | 128 try: |
127 hgsettings1 = RhodeCodeSettings.get_by_name('title') | 129 hgsettings1 = RhodeCodeSetting.get_by_name('title') |
128 hgsettings1.app_settings_value = \ | 130 hgsettings1.app_settings_value = \ |
129 form_result['rhodecode_title'] | 131 form_result['rhodecode_title'] |
130 | 132 |
131 hgsettings2 = RhodeCodeSettings.get_by_name('realm') | 133 hgsettings2 = RhodeCodeSetting.get_by_name('realm') |
132 hgsettings2.app_settings_value = \ | 134 hgsettings2.app_settings_value = \ |
133 form_result['rhodecode_realm'] | 135 form_result['rhodecode_realm'] |
134 | 136 |
135 hgsettings3 = RhodeCodeSettings.get_by_name('ga_code') | 137 hgsettings3 = RhodeCodeSetting.get_by_name('ga_code') |
136 hgsettings3.app_settings_value = \ | 138 hgsettings3.app_settings_value = \ |
137 form_result['rhodecode_ga_code'] | 139 form_result['rhodecode_ga_code'] |
138 | 140 |
139 self.sa.add(hgsettings1) | 141 self.sa.add(hgsettings1) |
140 self.sa.add(hgsettings2) | 142 self.sa.add(hgsettings2) |
224 defaults=errors.value, | 226 defaults=errors.value, |
225 errors=errors.error_dict or {}, | 227 errors=errors.error_dict or {}, |
226 prefix_error=False, | 228 prefix_error=False, |
227 encoding="UTF-8") | 229 encoding="UTF-8") |
228 | 230 |
229 | |
230 if setting_id == 'hooks': | 231 if setting_id == 'hooks': |
231 ui_key = request.POST.get('new_hook_ui_key') | 232 ui_key = request.POST.get('new_hook_ui_key') |
232 ui_value = request.POST.get('new_hook_ui_value') | 233 ui_value = request.POST.get('new_hook_ui_value') |
233 try: | 234 try: |
234 | 235 |
235 if ui_value and ui_key: | 236 if ui_value and ui_key: |
236 RhodeCodeUi.create_or_update_hook(ui_key, ui_value) | 237 RhodeCodeUi.create_or_update_hook(ui_key, ui_value) |
237 h.flash(_('Added new hook'), | 238 h.flash(_('Added new hook'), |
238 category='success') | 239 category='success') |
239 | 240 |
240 # check for edits | 241 # check for edits |
241 update = False | 242 update = False |
242 _d = request.POST.dict_of_lists() | 243 _d = request.POST.dict_of_lists() |
243 for k, v in zip(_d.get('hook_ui_key',[]), _d.get('hook_ui_value_new',[])): | 244 for k, v in zip(_d.get('hook_ui_key', []), |
245 _d.get('hook_ui_value_new', [])): | |
244 RhodeCodeUi.create_or_update_hook(k, v) | 246 RhodeCodeUi.create_or_update_hook(k, v) |
245 update = True | 247 update = True |
246 | 248 |
247 if update: | 249 if update: |
248 h.flash(_('Updated hooks'), category='success') | 250 h.flash(_('Updated hooks'), category='success') |
249 | 251 Session.commit() |
250 except: | 252 except: |
251 log.error(traceback.format_exc()) | 253 log.error(traceback.format_exc()) |
252 h.flash(_('error occurred during hook creation'), | 254 h.flash(_('error occurred during hook creation'), |
253 category='error') | 255 category='error') |
254 | 256 |
255 return redirect(url('admin_edit_setting', setting_id='hooks')) | 257 return redirect(url('admin_edit_setting', setting_id='hooks')) |
256 | 258 |
259 if setting_id == 'email': | |
260 test_email = request.POST.get('test_email') | |
261 test_email_subj = 'RhodeCode TestEmail' | |
262 test_email_body = 'RhodeCode Email test' | |
263 | |
264 test_email_html_body = EmailNotificationModel()\ | |
265 .get_email_tmpl(EmailNotificationModel.TYPE_DEFAULT, | |
266 body=test_email_body) | |
267 | |
268 recipients = [test_email] if [test_email] else None | |
269 | |
270 run_task(tasks.send_email, recipients, test_email_subj, | |
271 test_email_body, test_email_html_body) | |
272 | |
273 h.flash(_('Email task created'), category='success') | |
257 return redirect(url('admin_settings')) | 274 return redirect(url('admin_settings')) |
258 | 275 |
259 @HasPermissionAllDecorator('hg.admin') | 276 @HasPermissionAllDecorator('hg.admin') |
260 def delete(self, setting_id): | 277 def delete(self, setting_id): |
261 """DELETE /admin/settings/setting_id: Delete an existing item""" | 278 """DELETE /admin/settings/setting_id: Delete an existing item""" |
266 # method='delete') | 283 # method='delete') |
267 # url('admin_setting', setting_id=ID) | 284 # url('admin_setting', setting_id=ID) |
268 if setting_id == 'hooks': | 285 if setting_id == 'hooks': |
269 hook_id = request.POST.get('hook_id') | 286 hook_id = request.POST.get('hook_id') |
270 RhodeCodeUi.delete(hook_id) | 287 RhodeCodeUi.delete(hook_id) |
271 | 288 |
272 | 289 |
273 @HasPermissionAllDecorator('hg.admin') | 290 @HasPermissionAllDecorator('hg.admin') |
274 def show(self, setting_id, format='html'): | 291 def show(self, setting_id, format='html'): |
275 """ | 292 """ |
276 GET /admin/settings/setting_id: Show a specific item""" | 293 GET /admin/settings/setting_id: Show a specific item""" |
277 # url('admin_setting', setting_id=ID) | 294 # url('admin_setting', setting_id=ID) |
337 try: | 354 try: |
338 form_result = _form.to_python(dict(request.POST)) | 355 form_result = _form.to_python(dict(request.POST)) |
339 user_model.update_my_account(uid, form_result) | 356 user_model.update_my_account(uid, form_result) |
340 h.flash(_('Your account was updated successfully'), | 357 h.flash(_('Your account was updated successfully'), |
341 category='success') | 358 category='success') |
342 | 359 Session.commit() |
343 except formencode.Invalid, errors: | 360 except formencode.Invalid, errors: |
344 c.user = User.get(self.rhodecode_user.user_id) | 361 c.user = User.get(self.rhodecode_user.user_id) |
345 all_repos = self.sa.query(Repository)\ | 362 all_repos = self.sa.query(Repository)\ |
346 .filter(Repository.user_id == c.user.user_id)\ | 363 .filter(Repository.user_id == c.user.user_id)\ |
347 .order_by(func.lower(Repository.repo_name))\ | 364 .order_by(func.lower(Repository.repo_name))\ |
364 @NotAnonymous() | 381 @NotAnonymous() |
365 @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository') | 382 @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository') |
366 def create_repository(self): | 383 def create_repository(self): |
367 """GET /_admin/create_repository: Form to create a new item""" | 384 """GET /_admin/create_repository: Form to create a new item""" |
368 | 385 |
369 c.repo_groups = Group.groups_choices() | 386 c.repo_groups = RepoGroup.groups_choices() |
370 c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups) | 387 c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups) |
371 | 388 |
372 new_repo = request.GET.get('repo', '') | 389 new_repo = request.GET.get('repo', '') |
373 c.new_repo = repo_name_slug(new_repo) | 390 c.new_repo = repo_name_slug(new_repo) |
374 | 391 |