##// END OF EJS Templates
admin, email test: fix test for test_email recipients
Mads Kiilerich -
r3140:105a0374 beta
parent child Browse files
Show More
@@ -1,516 +1,516
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) 2010-2012 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
16 # (at your option) any later version.
16 # (at your option) any later version.
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, see <http://www.gnu.org/licenses/>.
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25
25
26 import logging
26 import logging
27 import traceback
27 import traceback
28 import formencode
28 import formencode
29 import pkg_resources
29 import pkg_resources
30 import platform
30 import platform
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, check_git_version
44 set_rhodecode_config, repo_name_slug, check_git_version
45 from rhodecode.model.db import RhodeCodeUi, Repository, RepoGroup, \
45 from rhodecode.model.db import RhodeCodeUi, Repository, RepoGroup, \
46 RhodeCodeSetting, PullRequest, PullRequestReviewers
46 RhodeCodeSetting, PullRequest, PullRequestReviewers
47 from rhodecode.model.forms import UserForm, ApplicationSettingsForm, \
47 from rhodecode.model.forms import UserForm, ApplicationSettingsForm, \
48 ApplicationUiSettingsForm, ApplicationVisualisationForm
48 ApplicationUiSettingsForm, ApplicationVisualisationForm
49 from rhodecode.model.scm import ScmModel
49 from rhodecode.model.scm import ScmModel
50 from rhodecode.model.user import UserModel
50 from rhodecode.model.user import UserModel
51 from rhodecode.model.db import User
51 from rhodecode.model.db import User
52 from rhodecode.model.notification import EmailNotificationModel
52 from rhodecode.model.notification import EmailNotificationModel
53 from rhodecode.model.meta import Session
53 from rhodecode.model.meta import Session
54 from rhodecode.lib.utils2 import str2bool
54 from rhodecode.lib.utils2 import str2bool
55
55
56 log = logging.getLogger(__name__)
56 log = logging.getLogger(__name__)
57
57
58
58
59 class SettingsController(BaseController):
59 class SettingsController(BaseController):
60 """REST Controller styled on the Atom Publishing Protocol"""
60 """REST Controller styled on the Atom Publishing Protocol"""
61 # To properly map this controller, ensure your config/routing.py
61 # To properly map this controller, ensure your config/routing.py
62 # file has a resource setup:
62 # file has a resource setup:
63 # map.resource('setting', 'settings', controller='admin/settings',
63 # map.resource('setting', 'settings', controller='admin/settings',
64 # path_prefix='/admin', name_prefix='admin_')
64 # path_prefix='/admin', name_prefix='admin_')
65
65
66 @LoginRequired()
66 @LoginRequired()
67 def __before__(self):
67 def __before__(self):
68 c.admin_user = session.get('admin_user')
68 c.admin_user = session.get('admin_user')
69 c.admin_username = session.get('admin_username')
69 c.admin_username = session.get('admin_username')
70 c.modules = sorted([(p.project_name, p.version)
70 c.modules = sorted([(p.project_name, p.version)
71 for p in pkg_resources.working_set]
71 for p in pkg_resources.working_set]
72 + [('git', check_git_version())],
72 + [('git', check_git_version())],
73 key=lambda k: k[0].lower())
73 key=lambda k: k[0].lower())
74 c.py_version = platform.python_version()
74 c.py_version = platform.python_version()
75 c.platform = platform.platform()
75 c.platform = platform.platform()
76 super(SettingsController, self).__before__()
76 super(SettingsController, self).__before__()
77
77
78 @HasPermissionAllDecorator('hg.admin')
78 @HasPermissionAllDecorator('hg.admin')
79 def index(self, format='html'):
79 def index(self, format='html'):
80 """GET /admin/settings: All items in the collection"""
80 """GET /admin/settings: All items in the collection"""
81 # url('admin_settings')
81 # url('admin_settings')
82
82
83 defaults = RhodeCodeSetting.get_app_settings()
83 defaults = RhodeCodeSetting.get_app_settings()
84 defaults.update(self._get_hg_ui_settings())
84 defaults.update(self._get_hg_ui_settings())
85
85
86 return htmlfill.render(
86 return htmlfill.render(
87 render('admin/settings/settings.html'),
87 render('admin/settings/settings.html'),
88 defaults=defaults,
88 defaults=defaults,
89 encoding="UTF-8",
89 encoding="UTF-8",
90 force_defaults=False
90 force_defaults=False
91 )
91 )
92
92
93 @HasPermissionAllDecorator('hg.admin')
93 @HasPermissionAllDecorator('hg.admin')
94 def create(self):
94 def create(self):
95 """POST /admin/settings: Create a new item"""
95 """POST /admin/settings: Create a new item"""
96 # url('admin_settings')
96 # url('admin_settings')
97
97
98 @HasPermissionAllDecorator('hg.admin')
98 @HasPermissionAllDecorator('hg.admin')
99 def new(self, format='html'):
99 def new(self, format='html'):
100 """GET /admin/settings/new: Form to create a new item"""
100 """GET /admin/settings/new: Form to create a new item"""
101 # url('admin_new_setting')
101 # url('admin_new_setting')
102
102
103 @HasPermissionAllDecorator('hg.admin')
103 @HasPermissionAllDecorator('hg.admin')
104 def update(self, setting_id):
104 def update(self, setting_id):
105 """PUT /admin/settings/setting_id: Update an existing item"""
105 """PUT /admin/settings/setting_id: Update an existing item"""
106 # Forms posted to this method should contain a hidden field:
106 # Forms posted to this method should contain a hidden field:
107 # <input type="hidden" name="_method" value="PUT" />
107 # <input type="hidden" name="_method" value="PUT" />
108 # Or using helpers:
108 # Or using helpers:
109 # h.form(url('admin_setting', setting_id=ID),
109 # h.form(url('admin_setting', setting_id=ID),
110 # method='put')
110 # method='put')
111 # url('admin_setting', setting_id=ID)
111 # url('admin_setting', setting_id=ID)
112
112
113 if setting_id == 'mapping':
113 if setting_id == 'mapping':
114 rm_obsolete = request.POST.get('destroy', False)
114 rm_obsolete = request.POST.get('destroy', False)
115 log.debug('Rescanning directories with destroy=%s' % rm_obsolete)
115 log.debug('Rescanning directories with destroy=%s' % rm_obsolete)
116 initial = ScmModel().repo_scan()
116 initial = ScmModel().repo_scan()
117 log.debug('invalidating all repositories')
117 log.debug('invalidating all repositories')
118 for repo_name in initial.keys():
118 for repo_name in initial.keys():
119 invalidate_cache('get_repo_cached_%s' % repo_name)
119 invalidate_cache('get_repo_cached_%s' % repo_name)
120
120
121 added, removed = repo2db_mapper(initial, rm_obsolete)
121 added, removed = repo2db_mapper(initial, rm_obsolete)
122
122
123 h.flash(_('Repositories successfully'
123 h.flash(_('Repositories successfully'
124 ' rescanned added: %s,removed: %s') % (added, removed),
124 ' rescanned added: %s,removed: %s') % (added, removed),
125 category='success')
125 category='success')
126
126
127 if setting_id == 'whoosh':
127 if setting_id == 'whoosh':
128 repo_location = self._get_hg_ui_settings()['paths_root_path']
128 repo_location = self._get_hg_ui_settings()['paths_root_path']
129 full_index = request.POST.get('full_index', False)
129 full_index = request.POST.get('full_index', False)
130 run_task(tasks.whoosh_index, repo_location, full_index)
130 run_task(tasks.whoosh_index, repo_location, full_index)
131 h.flash(_('Whoosh reindex task scheduled'), category='success')
131 h.flash(_('Whoosh reindex task scheduled'), category='success')
132
132
133 if setting_id == 'global':
133 if setting_id == 'global':
134
134
135 application_form = ApplicationSettingsForm()()
135 application_form = ApplicationSettingsForm()()
136 try:
136 try:
137 form_result = application_form.to_python(dict(request.POST))
137 form_result = application_form.to_python(dict(request.POST))
138 except formencode.Invalid, errors:
138 except formencode.Invalid, errors:
139 return htmlfill.render(
139 return htmlfill.render(
140 render('admin/settings/settings.html'),
140 render('admin/settings/settings.html'),
141 defaults=errors.value,
141 defaults=errors.value,
142 errors=errors.error_dict or {},
142 errors=errors.error_dict or {},
143 prefix_error=False,
143 prefix_error=False,
144 encoding="UTF-8"
144 encoding="UTF-8"
145 )
145 )
146
146
147 try:
147 try:
148 sett1 = RhodeCodeSetting.get_by_name_or_create('title')
148 sett1 = RhodeCodeSetting.get_by_name_or_create('title')
149 sett1.app_settings_value = form_result['rhodecode_title']
149 sett1.app_settings_value = form_result['rhodecode_title']
150 Session().add(sett1)
150 Session().add(sett1)
151
151
152 sett2 = RhodeCodeSetting.get_by_name_or_create('realm')
152 sett2 = RhodeCodeSetting.get_by_name_or_create('realm')
153 sett2.app_settings_value = form_result['rhodecode_realm']
153 sett2.app_settings_value = form_result['rhodecode_realm']
154 Session().add(sett2)
154 Session().add(sett2)
155
155
156 sett3 = RhodeCodeSetting.get_by_name_or_create('ga_code')
156 sett3 = RhodeCodeSetting.get_by_name_or_create('ga_code')
157 sett3.app_settings_value = form_result['rhodecode_ga_code']
157 sett3.app_settings_value = form_result['rhodecode_ga_code']
158 Session().add(sett3)
158 Session().add(sett3)
159
159
160 Session().commit()
160 Session().commit()
161 set_rhodecode_config(config)
161 set_rhodecode_config(config)
162 h.flash(_('Updated application settings'), category='success')
162 h.flash(_('Updated application settings'), category='success')
163
163
164 except Exception:
164 except Exception:
165 log.error(traceback.format_exc())
165 log.error(traceback.format_exc())
166 h.flash(_('error occurred during updating '
166 h.flash(_('error occurred during updating '
167 'application settings'),
167 'application settings'),
168 category='error')
168 category='error')
169
169
170 if setting_id == 'visual':
170 if setting_id == 'visual':
171
171
172 application_form = ApplicationVisualisationForm()()
172 application_form = ApplicationVisualisationForm()()
173 try:
173 try:
174 form_result = application_form.to_python(dict(request.POST))
174 form_result = application_form.to_python(dict(request.POST))
175 except formencode.Invalid, errors:
175 except formencode.Invalid, errors:
176 return htmlfill.render(
176 return htmlfill.render(
177 render('admin/settings/settings.html'),
177 render('admin/settings/settings.html'),
178 defaults=errors.value,
178 defaults=errors.value,
179 errors=errors.error_dict or {},
179 errors=errors.error_dict or {},
180 prefix_error=False,
180 prefix_error=False,
181 encoding="UTF-8"
181 encoding="UTF-8"
182 )
182 )
183
183
184 try:
184 try:
185 sett1 = RhodeCodeSetting.get_by_name_or_create('show_public_icon')
185 sett1 = RhodeCodeSetting.get_by_name_or_create('show_public_icon')
186 sett1.app_settings_value = \
186 sett1.app_settings_value = \
187 form_result['rhodecode_show_public_icon']
187 form_result['rhodecode_show_public_icon']
188 Session().add(sett1)
188 Session().add(sett1)
189
189
190 sett2 = RhodeCodeSetting.get_by_name_or_create('show_private_icon')
190 sett2 = RhodeCodeSetting.get_by_name_or_create('show_private_icon')
191 sett2.app_settings_value = \
191 sett2.app_settings_value = \
192 form_result['rhodecode_show_private_icon']
192 form_result['rhodecode_show_private_icon']
193 Session().add(sett2)
193 Session().add(sett2)
194
194
195 sett3 = RhodeCodeSetting.get_by_name_or_create('stylify_metatags')
195 sett3 = RhodeCodeSetting.get_by_name_or_create('stylify_metatags')
196 sett3.app_settings_value = \
196 sett3.app_settings_value = \
197 form_result['rhodecode_stylify_metatags']
197 form_result['rhodecode_stylify_metatags']
198 Session().add(sett3)
198 Session().add(sett3)
199
199
200 sett4 = RhodeCodeSetting.get_by_name_or_create('lightweight_dashboard')
200 sett4 = RhodeCodeSetting.get_by_name_or_create('lightweight_dashboard')
201 sett4.app_settings_value = \
201 sett4.app_settings_value = \
202 form_result['rhodecode_lightweight_dashboard']
202 form_result['rhodecode_lightweight_dashboard']
203 Session().add(sett4)
203 Session().add(sett4)
204
204
205 Session().commit()
205 Session().commit()
206 set_rhodecode_config(config)
206 set_rhodecode_config(config)
207 h.flash(_('Updated visualisation settings'),
207 h.flash(_('Updated visualisation settings'),
208 category='success')
208 category='success')
209
209
210 except Exception:
210 except Exception:
211 log.error(traceback.format_exc())
211 log.error(traceback.format_exc())
212 h.flash(_('error occurred during updating '
212 h.flash(_('error occurred during updating '
213 'visualisation settings'),
213 'visualisation settings'),
214 category='error')
214 category='error')
215
215
216 if setting_id == 'vcs':
216 if setting_id == 'vcs':
217 application_form = ApplicationUiSettingsForm()()
217 application_form = ApplicationUiSettingsForm()()
218 try:
218 try:
219 form_result = application_form.to_python(dict(request.POST))
219 form_result = application_form.to_python(dict(request.POST))
220 except formencode.Invalid, errors:
220 except formencode.Invalid, errors:
221 return htmlfill.render(
221 return htmlfill.render(
222 render('admin/settings/settings.html'),
222 render('admin/settings/settings.html'),
223 defaults=errors.value,
223 defaults=errors.value,
224 errors=errors.error_dict or {},
224 errors=errors.error_dict or {},
225 prefix_error=False,
225 prefix_error=False,
226 encoding="UTF-8"
226 encoding="UTF-8"
227 )
227 )
228
228
229 try:
229 try:
230 # fix namespaces for hooks and extensions
230 # fix namespaces for hooks and extensions
231 _f = lambda s: s.replace('.', '_')
231 _f = lambda s: s.replace('.', '_')
232
232
233 sett = RhodeCodeUi.get_by_key('push_ssl')
233 sett = RhodeCodeUi.get_by_key('push_ssl')
234 sett.ui_value = form_result['web_push_ssl']
234 sett.ui_value = form_result['web_push_ssl']
235 Session().add(sett)
235 Session().add(sett)
236
236
237 sett = RhodeCodeUi.get_by_key('/')
237 sett = RhodeCodeUi.get_by_key('/')
238 sett.ui_value = form_result['paths_root_path']
238 sett.ui_value = form_result['paths_root_path']
239 Session().add(sett)
239 Session().add(sett)
240
240
241 #HOOKS
241 #HOOKS
242 sett = RhodeCodeUi.get_by_key(RhodeCodeUi.HOOK_UPDATE)
242 sett = RhodeCodeUi.get_by_key(RhodeCodeUi.HOOK_UPDATE)
243 sett.ui_active = form_result[_f('hooks_%s' %
243 sett.ui_active = form_result[_f('hooks_%s' %
244 RhodeCodeUi.HOOK_UPDATE)]
244 RhodeCodeUi.HOOK_UPDATE)]
245 Session().add(sett)
245 Session().add(sett)
246
246
247 sett = RhodeCodeUi.get_by_key(RhodeCodeUi.HOOK_REPO_SIZE)
247 sett = RhodeCodeUi.get_by_key(RhodeCodeUi.HOOK_REPO_SIZE)
248 sett.ui_active = form_result[_f('hooks_%s' %
248 sett.ui_active = form_result[_f('hooks_%s' %
249 RhodeCodeUi.HOOK_REPO_SIZE)]
249 RhodeCodeUi.HOOK_REPO_SIZE)]
250 Session().add(sett)
250 Session().add(sett)
251
251
252 sett = RhodeCodeUi.get_by_key(RhodeCodeUi.HOOK_PUSH)
252 sett = RhodeCodeUi.get_by_key(RhodeCodeUi.HOOK_PUSH)
253 sett.ui_active = form_result[_f('hooks_%s' %
253 sett.ui_active = form_result[_f('hooks_%s' %
254 RhodeCodeUi.HOOK_PUSH)]
254 RhodeCodeUi.HOOK_PUSH)]
255 Session().add(sett)
255 Session().add(sett)
256
256
257 sett = RhodeCodeUi.get_by_key(RhodeCodeUi.HOOK_PULL)
257 sett = RhodeCodeUi.get_by_key(RhodeCodeUi.HOOK_PULL)
258 sett.ui_active = form_result[_f('hooks_%s' %
258 sett.ui_active = form_result[_f('hooks_%s' %
259 RhodeCodeUi.HOOK_PULL)]
259 RhodeCodeUi.HOOK_PULL)]
260
260
261 Session().add(sett)
261 Session().add(sett)
262
262
263 ## EXTENSIONS
263 ## EXTENSIONS
264 sett = RhodeCodeUi.get_by_key('largefiles')
264 sett = RhodeCodeUi.get_by_key('largefiles')
265 if not sett:
265 if not sett:
266 #make one if it's not there !
266 #make one if it's not there !
267 sett = RhodeCodeUi()
267 sett = RhodeCodeUi()
268 sett.ui_key = 'largefiles'
268 sett.ui_key = 'largefiles'
269 sett.ui_section = 'extensions'
269 sett.ui_section = 'extensions'
270 sett.ui_active = form_result[_f('extensions_largefiles')]
270 sett.ui_active = form_result[_f('extensions_largefiles')]
271 Session().add(sett)
271 Session().add(sett)
272
272
273 sett = RhodeCodeUi.get_by_key('hgsubversion')
273 sett = RhodeCodeUi.get_by_key('hgsubversion')
274 if not sett:
274 if not sett:
275 #make one if it's not there !
275 #make one if it's not there !
276 sett = RhodeCodeUi()
276 sett = RhodeCodeUi()
277 sett.ui_key = 'hgsubversion'
277 sett.ui_key = 'hgsubversion'
278 sett.ui_section = 'extensions'
278 sett.ui_section = 'extensions'
279
279
280 sett.ui_active = form_result[_f('extensions_hgsubversion')]
280 sett.ui_active = form_result[_f('extensions_hgsubversion')]
281 Session().add(sett)
281 Session().add(sett)
282
282
283 # sett = RhodeCodeUi.get_by_key('hggit')
283 # sett = RhodeCodeUi.get_by_key('hggit')
284 # if not sett:
284 # if not sett:
285 # #make one if it's not there !
285 # #make one if it's not there !
286 # sett = RhodeCodeUi()
286 # sett = RhodeCodeUi()
287 # sett.ui_key = 'hggit'
287 # sett.ui_key = 'hggit'
288 # sett.ui_section = 'extensions'
288 # sett.ui_section = 'extensions'
289 #
289 #
290 # sett.ui_active = form_result[_f('extensions_hggit')]
290 # sett.ui_active = form_result[_f('extensions_hggit')]
291 # Session().add(sett)
291 # Session().add(sett)
292
292
293 Session().commit()
293 Session().commit()
294
294
295 h.flash(_('Updated VCS settings'), category='success')
295 h.flash(_('Updated VCS settings'), category='success')
296
296
297 except Exception:
297 except Exception:
298 log.error(traceback.format_exc())
298 log.error(traceback.format_exc())
299 h.flash(_('error occurred during updating '
299 h.flash(_('error occurred during updating '
300 'application settings'), category='error')
300 'application settings'), category='error')
301
301
302 if setting_id == 'hooks':
302 if setting_id == 'hooks':
303 ui_key = request.POST.get('new_hook_ui_key')
303 ui_key = request.POST.get('new_hook_ui_key')
304 ui_value = request.POST.get('new_hook_ui_value')
304 ui_value = request.POST.get('new_hook_ui_value')
305 try:
305 try:
306
306
307 if ui_value and ui_key:
307 if ui_value and ui_key:
308 RhodeCodeUi.create_or_update_hook(ui_key, ui_value)
308 RhodeCodeUi.create_or_update_hook(ui_key, ui_value)
309 h.flash(_('Added new hook'),
309 h.flash(_('Added new hook'),
310 category='success')
310 category='success')
311
311
312 # check for edits
312 # check for edits
313 update = False
313 update = False
314 _d = request.POST.dict_of_lists()
314 _d = request.POST.dict_of_lists()
315 for k, v in zip(_d.get('hook_ui_key', []),
315 for k, v in zip(_d.get('hook_ui_key', []),
316 _d.get('hook_ui_value_new', [])):
316 _d.get('hook_ui_value_new', [])):
317 RhodeCodeUi.create_or_update_hook(k, v)
317 RhodeCodeUi.create_or_update_hook(k, v)
318 update = True
318 update = True
319
319
320 if update:
320 if update:
321 h.flash(_('Updated hooks'), category='success')
321 h.flash(_('Updated hooks'), category='success')
322 Session().commit()
322 Session().commit()
323 except Exception:
323 except Exception:
324 log.error(traceback.format_exc())
324 log.error(traceback.format_exc())
325 h.flash(_('error occurred during hook creation'),
325 h.flash(_('error occurred during hook creation'),
326 category='error')
326 category='error')
327
327
328 return redirect(url('admin_edit_setting', setting_id='hooks'))
328 return redirect(url('admin_edit_setting', setting_id='hooks'))
329
329
330 if setting_id == 'email':
330 if setting_id == 'email':
331 test_email = request.POST.get('test_email')
331 test_email = request.POST.get('test_email')
332 test_email_subj = 'RhodeCode TestEmail'
332 test_email_subj = 'RhodeCode TestEmail'
333 test_email_body = 'RhodeCode Email test'
333 test_email_body = 'RhodeCode Email test'
334
334
335 test_email_html_body = EmailNotificationModel()\
335 test_email_html_body = EmailNotificationModel()\
336 .get_email_tmpl(EmailNotificationModel.TYPE_DEFAULT,
336 .get_email_tmpl(EmailNotificationModel.TYPE_DEFAULT,
337 body=test_email_body)
337 body=test_email_body)
338
338
339 recipients = [test_email] if [test_email] else None
339 recipients = [test_email] if test_email else None
340
340
341 run_task(tasks.send_email, recipients, test_email_subj,
341 run_task(tasks.send_email, recipients, test_email_subj,
342 test_email_body, test_email_html_body)
342 test_email_body, test_email_html_body)
343
343
344 h.flash(_('Email task created'), category='success')
344 h.flash(_('Email task created'), category='success')
345 return redirect(url('admin_settings'))
345 return redirect(url('admin_settings'))
346
346
347 @HasPermissionAllDecorator('hg.admin')
347 @HasPermissionAllDecorator('hg.admin')
348 def delete(self, setting_id):
348 def delete(self, setting_id):
349 """DELETE /admin/settings/setting_id: Delete an existing item"""
349 """DELETE /admin/settings/setting_id: Delete an existing item"""
350 # Forms posted to this method should contain a hidden field:
350 # Forms posted to this method should contain a hidden field:
351 # <input type="hidden" name="_method" value="DELETE" />
351 # <input type="hidden" name="_method" value="DELETE" />
352 # Or using helpers:
352 # Or using helpers:
353 # h.form(url('admin_setting', setting_id=ID),
353 # h.form(url('admin_setting', setting_id=ID),
354 # method='delete')
354 # method='delete')
355 # url('admin_setting', setting_id=ID)
355 # url('admin_setting', setting_id=ID)
356 if setting_id == 'hooks':
356 if setting_id == 'hooks':
357 hook_id = request.POST.get('hook_id')
357 hook_id = request.POST.get('hook_id')
358 RhodeCodeUi.delete(hook_id)
358 RhodeCodeUi.delete(hook_id)
359 Session().commit()
359 Session().commit()
360
360
361 @HasPermissionAllDecorator('hg.admin')
361 @HasPermissionAllDecorator('hg.admin')
362 def show(self, setting_id, format='html'):
362 def show(self, setting_id, format='html'):
363 """
363 """
364 GET /admin/settings/setting_id: Show a specific item"""
364 GET /admin/settings/setting_id: Show a specific item"""
365 # url('admin_setting', setting_id=ID)
365 # url('admin_setting', setting_id=ID)
366
366
367 @HasPermissionAllDecorator('hg.admin')
367 @HasPermissionAllDecorator('hg.admin')
368 def edit(self, setting_id, format='html'):
368 def edit(self, setting_id, format='html'):
369 """
369 """
370 GET /admin/settings/setting_id/edit: Form to
370 GET /admin/settings/setting_id/edit: Form to
371 edit an existing item"""
371 edit an existing item"""
372 # url('admin_edit_setting', setting_id=ID)
372 # url('admin_edit_setting', setting_id=ID)
373
373
374 c.hooks = RhodeCodeUi.get_builtin_hooks()
374 c.hooks = RhodeCodeUi.get_builtin_hooks()
375 c.custom_hooks = RhodeCodeUi.get_custom_hooks()
375 c.custom_hooks = RhodeCodeUi.get_custom_hooks()
376
376
377 return htmlfill.render(
377 return htmlfill.render(
378 render('admin/settings/hooks.html'),
378 render('admin/settings/hooks.html'),
379 defaults={},
379 defaults={},
380 encoding="UTF-8",
380 encoding="UTF-8",
381 force_defaults=False
381 force_defaults=False
382 )
382 )
383
383
384 @NotAnonymous()
384 @NotAnonymous()
385 def my_account(self):
385 def my_account(self):
386 """
386 """
387 GET /_admin/my_account Displays info about my account
387 GET /_admin/my_account Displays info about my account
388 """
388 """
389 # url('admin_settings_my_account')
389 # url('admin_settings_my_account')
390
390
391 c.user = User.get(self.rhodecode_user.user_id)
391 c.user = User.get(self.rhodecode_user.user_id)
392 all_repos = Session().query(Repository)\
392 all_repos = Session().query(Repository)\
393 .filter(Repository.user_id == c.user.user_id)\
393 .filter(Repository.user_id == c.user.user_id)\
394 .order_by(func.lower(Repository.repo_name)).all()
394 .order_by(func.lower(Repository.repo_name)).all()
395
395
396 c.user_repos = ScmModel().get_repos(all_repos)
396 c.user_repos = ScmModel().get_repos(all_repos)
397
397
398 if c.user.username == 'default':
398 if c.user.username == 'default':
399 h.flash(_("You can't edit this user since it's"
399 h.flash(_("You can't edit this user since it's"
400 " crucial for entire application"), category='warning')
400 " crucial for entire application"), category='warning')
401 return redirect(url('users'))
401 return redirect(url('users'))
402
402
403 defaults = c.user.get_dict()
403 defaults = c.user.get_dict()
404
404
405 c.form = htmlfill.render(
405 c.form = htmlfill.render(
406 render('admin/users/user_edit_my_account_form.html'),
406 render('admin/users/user_edit_my_account_form.html'),
407 defaults=defaults,
407 defaults=defaults,
408 encoding="UTF-8",
408 encoding="UTF-8",
409 force_defaults=False
409 force_defaults=False
410 )
410 )
411 return render('admin/users/user_edit_my_account.html')
411 return render('admin/users/user_edit_my_account.html')
412
412
413 @NotAnonymous()
413 @NotAnonymous()
414 def my_account_update(self):
414 def my_account_update(self):
415 """PUT /_admin/my_account_update: Update an existing item"""
415 """PUT /_admin/my_account_update: Update an existing item"""
416 # Forms posted to this method should contain a hidden field:
416 # Forms posted to this method should contain a hidden field:
417 # <input type="hidden" name="_method" value="PUT" />
417 # <input type="hidden" name="_method" value="PUT" />
418 # Or using helpers:
418 # Or using helpers:
419 # h.form(url('admin_settings_my_account_update'),
419 # h.form(url('admin_settings_my_account_update'),
420 # method='put')
420 # method='put')
421 # url('admin_settings_my_account_update', id=ID)
421 # url('admin_settings_my_account_update', id=ID)
422 uid = self.rhodecode_user.user_id
422 uid = self.rhodecode_user.user_id
423 email = self.rhodecode_user.email
423 email = self.rhodecode_user.email
424 _form = UserForm(edit=True,
424 _form = UserForm(edit=True,
425 old_data={'user_id': uid, 'email': email})()
425 old_data={'user_id': uid, 'email': email})()
426 form_result = {}
426 form_result = {}
427 try:
427 try:
428 form_result = _form.to_python(dict(request.POST))
428 form_result = _form.to_python(dict(request.POST))
429 UserModel().update_my_account(uid, form_result)
429 UserModel().update_my_account(uid, form_result)
430 h.flash(_('Your account was updated successfully'),
430 h.flash(_('Your account was updated successfully'),
431 category='success')
431 category='success')
432 Session().commit()
432 Session().commit()
433 except formencode.Invalid, errors:
433 except formencode.Invalid, errors:
434 c.user = User.get(self.rhodecode_user.user_id)
434 c.user = User.get(self.rhodecode_user.user_id)
435
435
436 c.form = htmlfill.render(
436 c.form = htmlfill.render(
437 render('admin/users/user_edit_my_account_form.html'),
437 render('admin/users/user_edit_my_account_form.html'),
438 defaults=errors.value,
438 defaults=errors.value,
439 errors=errors.error_dict or {},
439 errors=errors.error_dict or {},
440 prefix_error=False,
440 prefix_error=False,
441 encoding="UTF-8")
441 encoding="UTF-8")
442 return render('admin/users/user_edit_my_account.html')
442 return render('admin/users/user_edit_my_account.html')
443 except Exception:
443 except Exception:
444 log.error(traceback.format_exc())
444 log.error(traceback.format_exc())
445 h.flash(_('error occurred during update of user %s') \
445 h.flash(_('error occurred during update of user %s') \
446 % form_result.get('username'), category='error')
446 % form_result.get('username'), category='error')
447
447
448 return redirect(url('my_account'))
448 return redirect(url('my_account'))
449
449
450 @NotAnonymous()
450 @NotAnonymous()
451 def my_account_my_repos(self):
451 def my_account_my_repos(self):
452 all_repos = Session().query(Repository)\
452 all_repos = Session().query(Repository)\
453 .filter(Repository.user_id == self.rhodecode_user.user_id)\
453 .filter(Repository.user_id == self.rhodecode_user.user_id)\
454 .order_by(func.lower(Repository.repo_name))\
454 .order_by(func.lower(Repository.repo_name))\
455 .all()
455 .all()
456 c.user_repos = ScmModel().get_repos(all_repos)
456 c.user_repos = ScmModel().get_repos(all_repos)
457 return render('admin/users/user_edit_my_account_repos.html')
457 return render('admin/users/user_edit_my_account_repos.html')
458
458
459 @NotAnonymous()
459 @NotAnonymous()
460 def my_account_my_pullrequests(self):
460 def my_account_my_pullrequests(self):
461 c.my_pull_requests = PullRequest.query()\
461 c.my_pull_requests = PullRequest.query()\
462 .filter(PullRequest.user_id==
462 .filter(PullRequest.user_id==
463 self.rhodecode_user.user_id)\
463 self.rhodecode_user.user_id)\
464 .all()
464 .all()
465 c.participate_in_pull_requests = \
465 c.participate_in_pull_requests = \
466 [x.pull_request for x in PullRequestReviewers.query()\
466 [x.pull_request for x in PullRequestReviewers.query()\
467 .filter(PullRequestReviewers.user_id==
467 .filter(PullRequestReviewers.user_id==
468 self.rhodecode_user.user_id)\
468 self.rhodecode_user.user_id)\
469 .all()]
469 .all()]
470 return render('admin/users/user_edit_my_account_pullrequests.html')
470 return render('admin/users/user_edit_my_account_pullrequests.html')
471
471
472 @NotAnonymous()
472 @NotAnonymous()
473 @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository')
473 @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository')
474 def create_repository(self):
474 def create_repository(self):
475 """GET /_admin/create_repository: Form to create a new item"""
475 """GET /_admin/create_repository: Form to create a new item"""
476
476
477 c.repo_groups = RepoGroup.groups_choices(check_perms=True)
477 c.repo_groups = RepoGroup.groups_choices(check_perms=True)
478 c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
478 c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
479 choices, c.landing_revs = ScmModel().get_repo_landing_revs()
479 choices, c.landing_revs = ScmModel().get_repo_landing_revs()
480
480
481 new_repo = request.GET.get('repo', '')
481 new_repo = request.GET.get('repo', '')
482 c.new_repo = repo_name_slug(new_repo)
482 c.new_repo = repo_name_slug(new_repo)
483
483
484 ## apply the defaults from defaults page
484 ## apply the defaults from defaults page
485 defaults = RhodeCodeSetting.get_default_repo_settings(strip_prefix=True)
485 defaults = RhodeCodeSetting.get_default_repo_settings(strip_prefix=True)
486 return htmlfill.render(
486 return htmlfill.render(
487 render('admin/repos/repo_add_create_repository.html'),
487 render('admin/repos/repo_add_create_repository.html'),
488 defaults=defaults,
488 defaults=defaults,
489 errors={},
489 errors={},
490 prefix_error=False,
490 prefix_error=False,
491 encoding="UTF-8"
491 encoding="UTF-8"
492 )
492 )
493
493
494 def _get_hg_ui_settings(self):
494 def _get_hg_ui_settings(self):
495 ret = RhodeCodeUi.query().all()
495 ret = RhodeCodeUi.query().all()
496
496
497 if not ret:
497 if not ret:
498 raise Exception('Could not get application ui settings !')
498 raise Exception('Could not get application ui settings !')
499 settings = {}
499 settings = {}
500 for each in ret:
500 for each in ret:
501 k = each.ui_key
501 k = each.ui_key
502 v = each.ui_value
502 v = each.ui_value
503 if k == '/':
503 if k == '/':
504 k = 'root_path'
504 k = 'root_path'
505
505
506 if k == 'push_ssl':
506 if k == 'push_ssl':
507 v = str2bool(v)
507 v = str2bool(v)
508
508
509 if k.find('.') != -1:
509 if k.find('.') != -1:
510 k = k.replace('.', '_')
510 k = k.replace('.', '_')
511
511
512 if each.ui_section in ['hooks', 'extensions']:
512 if each.ui_section in ['hooks', 'extensions']:
513 v = each.ui_active
513 v = each.ui_active
514
514
515 settings[each.ui_section + '_' + k] = v
515 settings[each.ui_section + '_' + k] = v
516 return settings
516 return settings
General Comments 0
You need to be logged in to leave comments. Login now