##// END OF EJS Templates
Added new application settings,Push ssl and repositories path
marcink -
r388:3bcf9529 default
parent child Browse files
Show More
@@ -61,6 +61,7 b' def load_environment(global_conf, app_co'
61 sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.')
61 sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.')
62
62
63 init_model(sa_engine_db1)
63 init_model(sa_engine_db1)
64 #init baseui
64 config['pylons.app_globals'].baseui = make_ui('db')
65 config['pylons.app_globals'].baseui = make_ui('db')
65
66
66 repo2db_mapper(_get_repos_cached_initial(config['pylons.app_globals'], initial))
67 repo2db_mapper(_get_repos_cached_initial(config['pylons.app_globals'], initial))
@@ -32,9 +32,10 b' from pylons_app.lib.auth import LoginReq'
32 HasPermissionAnyDecorator
32 HasPermissionAnyDecorator
33 from pylons_app.lib.base import BaseController, render
33 from pylons_app.lib.base import BaseController, render
34 from pylons_app.lib.utils import repo2db_mapper, invalidate_cache, \
34 from pylons_app.lib.utils import repo2db_mapper, invalidate_cache, \
35 set_hg_app_config, get_hg_settings
35 set_hg_app_config, get_hg_settings, get_hg_ui_settings, make_ui
36 from pylons_app.model.db import User, UserLog, HgAppSettings
36 from pylons_app.model.db import User, UserLog, HgAppSettings, HgAppUi
37 from pylons_app.model.forms import UserForm, ApplicationSettingsForm
37 from pylons_app.model.forms import UserForm, ApplicationSettingsForm, \
38 ApplicationUiSettingsForm
38 from pylons_app.model.hg_model import HgModel
39 from pylons_app.model.hg_model import HgModel
39 from pylons_app.model.user_model import UserModel
40 from pylons_app.model.user_model import UserModel
40 import formencode
41 import formencode
@@ -65,7 +66,7 b' class SettingsController(BaseController)'
65 # url('admin_settings')
66 # url('admin_settings')
66
67
67 defaults = get_hg_settings()
68 defaults = get_hg_settings()
68
69 defaults.update(get_hg_ui_settings())
69 return htmlfill.render(
70 return htmlfill.render(
70 render('admin/settings/settings.html'),
71 render('admin/settings/settings.html'),
71 defaults=defaults,
72 defaults=defaults,
@@ -108,10 +109,12 b' class SettingsController(BaseController)'
108 form_result = application_form.to_python(dict(request.POST))
109 form_result = application_form.to_python(dict(request.POST))
109
110
110 try:
111 try:
111 hgsettings1 = self.sa.query(HgAppSettings).filter(HgAppSettings.app_settings_name == 'title').one()
112 hgsettings1 = self.sa.query(HgAppSettings)\
113 .filter(HgAppSettings.app_settings_name == 'title').one()
112 hgsettings1.app_settings_value = form_result['hg_app_title']
114 hgsettings1.app_settings_value = form_result['hg_app_title']
113
115
114 hgsettings2 = self.sa.query(HgAppSettings).filter(HgAppSettings.app_settings_name == 'realm').one()
116 hgsettings2 = self.sa.query(HgAppSettings)\
117 .filter(HgAppSettings.app_settings_name == 'realm').one()
115 hgsettings2.app_settings_value = form_result['hg_app_realm']
118 hgsettings2.app_settings_value = form_result['hg_app_realm']
116
119
117
120
@@ -137,6 +140,46 b' class SettingsController(BaseController)'
137 errors=errors.error_dict or {},
140 errors=errors.error_dict or {},
138 prefix_error=False,
141 prefix_error=False,
139 encoding="UTF-8")
142 encoding="UTF-8")
143
144 if setting_id == 'mercurial':
145 application_form = ApplicationUiSettingsForm()()
146 try:
147 form_result = application_form.to_python(dict(request.POST))
148
149 try:
150
151 hgsettings1 = self.sa.query(HgAppUi)\
152 .filter(HgAppUi.ui_key == 'push_ssl').one()
153 hgsettings1.ui_value = form_result['web_push_ssl']
154
155 hgsettings2 = self.sa.query(HgAppUi)\
156 .filter(HgAppUi.ui_key == '/').one()
157 hgsettings2.ui_value = form_result['paths_root_path']
158
159 self.sa.add(hgsettings1)
160 self.sa.add(hgsettings2)
161 self.sa.commit()
162
163 h.flash(_('Updated application settings'),
164 category='success')
165
166 except:
167 log.error(traceback.format_exc())
168 h.flash(_('error occured during updating application settings'),
169 category='error')
170
171 self.sa.rollback()
172
173
174 except formencode.Invalid as errors:
175 return htmlfill.render(
176 render('admin/settings/settings.html'),
177 defaults=errors.value,
178 errors=errors.error_dict or {},
179 prefix_error=False,
180 encoding="UTF-8")
181
182
140
183
141 return redirect(url('admin_settings'))
184 return redirect(url('admin_settings'))
142
185
@@ -112,6 +112,23 b' def get_hg_settings():'
112
112
113 return settings
113 return settings
114
114
115 def get_hg_ui_settings():
116 try:
117 sa = meta.Session
118 ret = sa.query(HgAppUi).all()
119 finally:
120 meta.Session.remove()
121
122 if not ret:
123 raise Exception('Could not get application ui settings !')
124 settings = {}
125 for each in ret:
126 k = each.ui_key if each.ui_key != '/' else 'root_path'
127 settings[each.ui_section + '_' + k] = each.ui_value
128
129 return settings
130
131 #propagated from mercurial documentation
115 ui_sections = ['alias', 'auth',
132 ui_sections = ['alias', 'auth',
116 'decode/encode', 'defaults',
133 'decode/encode', 'defaults',
117 'diff', 'email',
134 'diff', 'email',
@@ -132,27 +149,27 b" def make_ui(read_from='file', path=None,"
132 @param checkpaths: check the path
149 @param checkpaths: check the path
133 @param read_from: read from 'file' or 'db'
150 @param read_from: read from 'file' or 'db'
134 """
151 """
135 #propagated from mercurial documentation
136
152
137 baseui = ui.ui()
153 baseui = ui.ui()
138
154
139
140 if read_from == 'file':
155 if read_from == 'file':
141 if not os.path.isfile(path):
156 if not os.path.isfile(path):
142 log.warning('Unable to read config file %s' % path)
157 log.warning('Unable to read config file %s' % path)
143 return False
158 return False
144
159 log.debug('reading hgrc from %s', path)
145 cfg = config.config()
160 cfg = config.config()
146 cfg.read(path)
161 cfg.read(path)
147 for section in ui_sections:
162 for section in ui_sections:
148 for k, v in cfg.items(section):
163 for k, v in cfg.items(section):
149 baseui.setconfig(section, k, v)
164 baseui.setconfig(section, k, v)
165 log.debug('settings ui from file[%s]%s:%s', section, k, v)
150 if checkpaths:check_repo_dir(cfg.items('paths'))
166 if checkpaths:check_repo_dir(cfg.items('paths'))
151
167
152
168
153 elif read_from == 'db':
169 elif read_from == 'db':
154 hg_ui = get_hg_ui_cached()
170 hg_ui = get_hg_ui_cached()
155 for ui_ in hg_ui:
171 for ui_ in hg_ui:
172 log.debug('settings ui from db[%s]%s:%s', ui_.ui_section, ui_.ui_key, ui_.ui_value)
156 baseui.setconfig(ui_.ui_section, ui_.ui_key, ui_.ui_value)
173 baseui.setconfig(ui_.ui_section, ui_.ui_key, ui_.ui_value)
157
174
158
175
@@ -25,7 +25,6 b' from formencode.validators import Unicod'
25 from pylons import session
25 from pylons import session
26 from pylons.i18n.translation import _
26 from pylons.i18n.translation import _
27 from pylons_app.lib.auth import get_crypt_password
27 from pylons_app.lib.auth import get_crypt_password
28 import pylons_app.lib.helpers as h
29 from pylons_app.model import meta
28 from pylons_app.model import meta
30 from pylons_app.model.db import User, Repository
29 from pylons_app.model.db import User, Repository
31 from sqlalchemy.exc import OperationalError
30 from sqlalchemy.exc import OperationalError
@@ -34,6 +33,8 b' from webhelpers.pylonslib.secure_form im'
34 import datetime
33 import datetime
35 import formencode
34 import formencode
36 import logging
35 import logging
36 import os
37 import pylons_app.lib.helpers as h
37 log = logging.getLogger(__name__)
38 log = logging.getLogger(__name__)
38
39
39
40
@@ -218,7 +219,21 b' class ValidSettings(formencode.validator'
218 if value.has_key('user'):
219 if value.has_key('user'):
219 del['value']['user']
220 del['value']['user']
220
221
221 return value
222 return value
223
224 class ValidPath(formencode.validators.FancyValidator):
225 def to_python(self, value, state):
226 isdir = os.path.isdir(value.replace('*', ''))
227 if (value.endswith('/*') or value.endswith('/**')) and isdir:
228 return value
229 elif not isdir:
230 msg = _('This is not a valid path')
231 else:
232 msg = _('You need to specify * or ** at the end of path (ie. /tmp/*)')
233
234 raise formencode.Invalid(msg, value, state,
235 error_dict={'paths_root_path':msg})
236
222 #===============================================================================
237 #===============================================================================
223 # FORMS
238 # FORMS
224 #===============================================================================
239 #===============================================================================
@@ -302,5 +317,12 b' def ApplicationSettingsForm():'
302
317
303 return _ApplicationSettingsForm
318 return _ApplicationSettingsForm
304
319
320 def ApplicationUiSettingsForm():
321 class _ApplicationUiSettingsForm(formencode.Schema):
322 allow_extra_fields = True
323 filter_extra_fields = False
324 web_push_ssl = OneOf(['true', 'false'], if_missing='false')
325 paths_root_path = All(ValidPath(), UnicodeString(strip=True, min=3, not_empty=True))
326
327 return _ApplicationUiSettingsForm
305
328
306
@@ -57,7 +57,7 b''
57
57
58 <div class="field">
58 <div class="field">
59 <div class="label">
59 <div class="label">
60 <label for="input-small">${_('Application name')}:</label>
60 <label for="hg_app_title">${_('Application name')}:</label>
61 </div>
61 </div>
62 <div class="input">
62 <div class="input">
63 ${h.text('hg_app_title',size=30)}
63 ${h.text('hg_app_title',size=30)}
@@ -66,7 +66,7 b''
66
66
67 <div class="field">
67 <div class="field">
68 <div class="label">
68 <div class="label">
69 <label for="input-small">${_('Realm text')}:</label>
69 <label for="hg_app_realm">${_('Realm text')}:</label>
70 </div>
70 </div>
71 <div class="input">
71 <div class="input">
72 ${h.text('hg_app_realm',size=30)}
72 ${h.text('hg_app_realm',size=30)}
@@ -79,6 +79,51 b''
79 </div>
79 </div>
80 </div>
80 </div>
81 ${h.end_form()}
81 ${h.end_form()}
82
83 <h3>${_('Mercurial settings')}</h3>
84 ${h.form(url('admin_setting', setting_id='mercurial'),method='put')}
85 <div class="form">
86 <!-- fields -->
87
88 <div class="fields">
89
90 <div class="field">
91 <div class="label label-checkbox">
92 <label for="web_push_ssl">${_('Push ssl')}:</label>
93 </div>
94 <div class="checkboxes">
95 <div class="checkbox">
96 ${h.checkbox('web_push_ssl','true')}
97 <label for="web_push_ssl">${_('require ssl for pushing')}</label>
98 </div>
99 </div>
100 </div>
101
102 <div class="field">
103 <div class="label">
104 <label for="paths_root_path">${_('Repositories location')}:</label>
105 </div>
106 <div class="input">
107 ${h.text('paths_root_path',size=30,disabled="disabled")}
108 <span id="path_unlock" class="tooltip" tooltip_title="${h.tooltip(_('This a crucial application setting. If You really sure you need to change this, you must restart application in order to make this settings take effect. Click this label to unlock.'))}">
109 ${_('unlock')}</span>
110 </div>
111 </div>
112
113 <div class="buttons">
114 ${h.submit('save','save settings',class_="ui-button ui-widget ui-state-default ui-corner-all")}
115 </div>
116 </div>
117 </div>
118 ${h.end_form()}
119
120 <script type="text/javascript">
121 YAHOO.util.Event.onDOMReady(function(){
122 YAHOO.util.Event.addListener('path_unlock','click',function(){
123 YAHOO.util.Dom.get('paths_root_path').disabled=false;
124 });
125 });
126 </script>
82
127
83 </div>
128 </div>
84 </%def>
129 </%def>
General Comments 0
You need to be logged in to leave comments. Login now