Show More
@@ -0,0 +1,106 b'' | |||||
|
1 | # -*- coding: utf-8 -*- | |||
|
2 | """ | |||
|
3 | package.rhodecode.controllers.admin.ldap_settings | |||
|
4 | ~~~~~~~~~~~~~~ | |||
|
5 | ||||
|
6 | ldap controller for RhodeCode | |||
|
7 | :created_on: Nov 26, 2010 | |||
|
8 | :author: marcink | |||
|
9 | :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> | |||
|
10 | :license: GPLv3, see COPYING for more details. | |||
|
11 | """ | |||
|
12 | # This program is free software; you can redistribute it and/or | |||
|
13 | # modify it under the terms of the GNU General Public License | |||
|
14 | # as published by the Free Software Foundation; version 2 | |||
|
15 | # of the License or (at your opinion) any later version of the license. | |||
|
16 | # | |||
|
17 | # This program is distributed in the hope that it will be useful, | |||
|
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
20 | # GNU General Public License for more details. | |||
|
21 | # | |||
|
22 | # You should have received a copy of the GNU General Public License | |||
|
23 | # along with this program; if not, write to the Free Software | |||
|
24 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |||
|
25 | # MA 02110-1301, USA. | |||
|
26 | import logging | |||
|
27 | import formencode | |||
|
28 | import traceback | |||
|
29 | ||||
|
30 | from formencode import htmlfill | |||
|
31 | ||||
|
32 | from pylons import request, response, session, tmpl_context as c, url | |||
|
33 | from pylons.controllers.util import abort, redirect | |||
|
34 | from pylons.i18n.translation import _ | |||
|
35 | ||||
|
36 | from rhodecode.lib.base import BaseController, render | |||
|
37 | from rhodecode.lib import helpers as h | |||
|
38 | from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator | |||
|
39 | from rhodecode.lib.auth_ldap import LdapImportError | |||
|
40 | from rhodecode.model.settings import SettingsModel | |||
|
41 | from rhodecode.model.forms import LdapSettingsForm | |||
|
42 | from sqlalchemy.exc import DatabaseError | |||
|
43 | ||||
|
44 | log = logging.getLogger(__name__) | |||
|
45 | ||||
|
46 | ||||
|
47 | ||||
|
48 | class LdapSettingsController(BaseController): | |||
|
49 | ||||
|
50 | @LoginRequired() | |||
|
51 | @HasPermissionAllDecorator('hg.admin') | |||
|
52 | def __before__(self): | |||
|
53 | c.admin_user = session.get('admin_user') | |||
|
54 | c.admin_username = session.get('admin_username') | |||
|
55 | super(LdapSettingsController, self).__before__() | |||
|
56 | ||||
|
57 | def index(self): | |||
|
58 | defaults = SettingsModel().get_ldap_settings() | |||
|
59 | ||||
|
60 | return htmlfill.render( | |||
|
61 | render('admin/ldap/ldap.html'), | |||
|
62 | defaults=defaults, | |||
|
63 | encoding="UTF-8", | |||
|
64 | force_defaults=True,) | |||
|
65 | ||||
|
66 | def ldap_settings(self): | |||
|
67 | """ | |||
|
68 | POST ldap create and store ldap settings | |||
|
69 | """ | |||
|
70 | ||||
|
71 | settings_model = SettingsModel() | |||
|
72 | _form = LdapSettingsForm()() | |||
|
73 | ||||
|
74 | try: | |||
|
75 | form_result = _form.to_python(dict(request.POST)) | |||
|
76 | try: | |||
|
77 | ||||
|
78 | for k, v in form_result.items(): | |||
|
79 | if k.startswith('ldap_'): | |||
|
80 | setting = settings_model.get(k) | |||
|
81 | setting.app_settings_value = v | |||
|
82 | self.sa.add(setting) | |||
|
83 | ||||
|
84 | self.sa.commit() | |||
|
85 | h.flash(_('Ldap settings updated successfully'), | |||
|
86 | category='success') | |||
|
87 | except (DatabaseError,): | |||
|
88 | raise | |||
|
89 | except LdapImportError: | |||
|
90 | h.flash(_('Unable to activate ldap. The "ldap-python" library ' | |||
|
91 | 'is missing.'), category='warning') | |||
|
92 | ||||
|
93 | except formencode.Invalid, errors: | |||
|
94 | ||||
|
95 | return htmlfill.render( | |||
|
96 | render('admin/ldap/ldap.html'), | |||
|
97 | defaults=errors.value, | |||
|
98 | errors=errors.error_dict or {}, | |||
|
99 | prefix_error=False, | |||
|
100 | encoding="UTF-8") | |||
|
101 | except Exception: | |||
|
102 | log.error(traceback.format_exc()) | |||
|
103 | h.flash(_('error occured during update of ldap settings'), | |||
|
104 | category='error') | |||
|
105 | ||||
|
106 | return redirect(url('ldap_home')) |
@@ -0,0 +1,73 b'' | |||||
|
1 | ## -*- coding: utf-8 -*- | |||
|
2 | <%inherit file="/base/base.html"/> | |||
|
3 | ||||
|
4 | <%def name="title()"> | |||
|
5 | ${_('LDAP administration')} - ${c.rhodecode_name} | |||
|
6 | </%def> | |||
|
7 | ||||
|
8 | <%def name="breadcrumbs_links()"> | |||
|
9 | ${h.link_to(_('Admin'),h.url('admin_home'))} | |||
|
10 | » | |||
|
11 | ${_('Ldap')} | |||
|
12 | </%def> | |||
|
13 | ||||
|
14 | <%def name="page_nav()"> | |||
|
15 | ${self.menu('admin')} | |||
|
16 | </%def> | |||
|
17 | ||||
|
18 | <%def name="main()"> | |||
|
19 | <div class="box"> | |||
|
20 | <!-- box / title --> | |||
|
21 | <div class="title"> | |||
|
22 | ${self.breadcrumbs()} | |||
|
23 | </div> | |||
|
24 | <h3>${_('LDAP administration')}</h3> | |||
|
25 | ${h.form(url('ldap_settings'))} | |||
|
26 | <div class="form"> | |||
|
27 | <div class="fields"> | |||
|
28 | ||||
|
29 | <div class="field"> | |||
|
30 | <div class="label label-checkbox"><label for="ldap_active">${_('Enable ldap')}</label></div> | |||
|
31 | <div class="checkboxes"><div class="checkbox">${h.checkbox('ldap_active',True,class_='small')}</div></div> | |||
|
32 | </div> | |||
|
33 | <div class="field"> | |||
|
34 | <div class="label"><label for="ldap_host">${_('Host')}</label></div> | |||
|
35 | <div class="input">${h.text('ldap_host',class_='small')}</div> | |||
|
36 | </div> | |||
|
37 | <div class="field"> | |||
|
38 | <div class="label"><label for="ldap_port">${_('Port')}</label></div> | |||
|
39 | <div class="input">${h.text('ldap_port',class_='small')}</div> | |||
|
40 | </div> | |||
|
41 | <div class="field"> | |||
|
42 | <div class="label label-checkbox"><label for="ldap_ldaps">${_('Enable LDAPS')}</label></div> | |||
|
43 | <div class="checkboxes"><div class="checkbox">${h.checkbox('ldap_ldaps',True,class_='small')}</div></div> | |||
|
44 | </div> | |||
|
45 | <div class="field"> | |||
|
46 | <div class="label"><label for="ldap_dn_user">${_('Account')}</label></div> | |||
|
47 | <div class="input">${h.text('ldap_dn_user',class_='small')}</div> | |||
|
48 | </div> | |||
|
49 | <div class="field"> | |||
|
50 | <div class="label"><label for="ldap_dn_pass">${_('Password')}</label></div> | |||
|
51 | <div class="input">${h.password('ldap_dn_pass',class_='small')}</div> | |||
|
52 | </div> | |||
|
53 | <div class="field"> | |||
|
54 | <div class="label"><label for="ldap_base_dn">${_('Base DN')}</label></div> | |||
|
55 | <div class="input">${h.text('ldap_base_dn',class_='small')}</div> | |||
|
56 | </div> | |||
|
57 | ||||
|
58 | <div class="buttons"> | |||
|
59 | ${h.submit('save','Save',class_="ui-button ui-widget ui-state-default ui-corner-all")} | |||
|
60 | </div> | |||
|
61 | </div> | |||
|
62 | </div> | |||
|
63 | ${h.end_form()} | |||
|
64 | </div> | |||
|
65 | </%def> | |||
|
66 | ||||
|
67 | ||||
|
68 | ||||
|
69 | ||||
|
70 | ||||
|
71 | ||||
|
72 | ||||
|
73 |
@@ -0,0 +1,7 b'' | |||||
|
1 | from rhodecode.tests import * | |||
|
2 | ||||
|
3 | class TestLdapSettingsController(TestController): | |||
|
4 | ||||
|
5 | def test_index(self): | |||
|
6 | response = self.app.get(url(controller='admin/ldap_settings', action='index')) | |||
|
7 | # Test response... |
@@ -85,7 +85,13 b' def make_map(config):' | |||||
85 |
|
85 | |||
86 | #ADMIN PERMISSIONS REST ROUTES |
|
86 | #ADMIN PERMISSIONS REST ROUTES | |
87 | map.resource('permission', 'permissions', controller='admin/permissions', path_prefix='/_admin') |
|
87 | map.resource('permission', 'permissions', controller='admin/permissions', path_prefix='/_admin') | |
88 | map.connect('permissions_ldap', '/_admin/permissions_ldap', controller='admin/permissions', action='ldap') |
|
88 | ||
|
89 | ||||
|
90 | ##ADMIN LDAP SETTINGS | |||
|
91 | map.connect('ldap_settings', '/_admin/ldap', controller='admin/ldap_settings', | |||
|
92 | action='ldap_settings', conditions=dict(method=["POST"])) | |||
|
93 | map.connect('ldap_home', '/_admin/ldap', controller='admin/ldap_settings',) | |||
|
94 | ||||
89 |
|
95 | |||
90 |
|
96 | |||
91 | #ADMIN SETTINGS REST ROUTES |
|
97 | #ADMIN SETTINGS REST ROUTES |
@@ -110,7 +110,6 b' class PermissionsController(BaseControll' | |||||
110 | c.register_choices = self.register_choices |
|
110 | c.register_choices = self.register_choices | |
111 | c.create_choices = self.create_choices |
|
111 | c.create_choices = self.create_choices | |
112 | defaults = errors.value |
|
112 | defaults = errors.value | |
113 | defaults.update(SettingsModel().get_ldap_settings()) |
|
|||
114 |
|
113 | |||
115 | return htmlfill.render( |
|
114 | return htmlfill.render( | |
116 | render('admin/permissions/permissions.html'), |
|
115 | render('admin/permissions/permissions.html'), | |
@@ -151,7 +150,7 b' class PermissionsController(BaseControll' | |||||
151 | default_user = UserModel().get_by_username('default') |
|
150 | default_user = UserModel().get_by_username('default') | |
152 | defaults = {'_method':'put', |
|
151 | defaults = {'_method':'put', | |
153 | 'anonymous':default_user.active} |
|
152 | 'anonymous':default_user.active} | |
154 | defaults.update(SettingsModel().get_ldap_settings()) |
|
153 | ||
155 | for p in default_user.user_perms: |
|
154 | for p in default_user.user_perms: | |
156 | if p.permission.permission_name.startswith('repository.'): |
|
155 | if p.permission.permission_name.startswith('repository.'): | |
157 | defaults['default_perm'] = p.permission.permission_name |
|
156 | defaults['default_perm'] = p.permission.permission_name | |
@@ -169,50 +168,3 b' class PermissionsController(BaseControll' | |||||
169 | force_defaults=True,) |
|
168 | force_defaults=True,) | |
170 | else: |
|
169 | else: | |
171 | return redirect(url('admin_home')) |
|
170 | return redirect(url('admin_home')) | |
172 |
|
||||
173 |
|
||||
174 | def ldap(self, id_user='default'): |
|
|||
175 | """ |
|
|||
176 | POST ldap create and store ldap settings |
|
|||
177 | """ |
|
|||
178 |
|
||||
179 | settings_model = SettingsModel() |
|
|||
180 | _form = LdapSettingsForm()() |
|
|||
181 |
|
||||
182 | try: |
|
|||
183 | form_result = _form.to_python(dict(request.POST)) |
|
|||
184 | try: |
|
|||
185 |
|
||||
186 | for k, v in form_result.items(): |
|
|||
187 | if k.startswith('ldap_'): |
|
|||
188 | setting = settings_model.get(k) |
|
|||
189 | setting.app_settings_value = v |
|
|||
190 | self.sa.add(setting) |
|
|||
191 |
|
||||
192 | self.sa.commit() |
|
|||
193 | h.flash(_('Ldap settings updated successfully'), |
|
|||
194 | category='success') |
|
|||
195 | except: |
|
|||
196 | raise |
|
|||
197 | except LdapImportError: |
|
|||
198 | h.flash(_('Unable to activate ldap. The "ldap-python" library ' |
|
|||
199 | 'is missing.'), |
|
|||
200 | category='warning') |
|
|||
201 |
|
||||
202 | except formencode.Invalid, errors: |
|
|||
203 | c.perms_choices = self.perms_choices |
|
|||
204 | c.register_choices = self.register_choices |
|
|||
205 | c.create_choices = self.create_choices |
|
|||
206 |
|
||||
207 | return htmlfill.render( |
|
|||
208 | render('admin/permissions/permissions.html'), |
|
|||
209 | defaults=errors.value, |
|
|||
210 | errors=errors.error_dict or {}, |
|
|||
211 | prefix_error=False, |
|
|||
212 | encoding="UTF-8") |
|
|||
213 | except Exception: |
|
|||
214 | log.error(traceback.format_exc()) |
|
|||
215 | h.flash(_('error occured during update of ldap settings'), |
|
|||
216 | category='error') |
|
|||
217 |
|
||||
218 | return redirect(url('edit_permission', id=id_user)) |
|
@@ -479,6 +479,13 b' margin:0;' | |||||
479 | padding:12px 9px 7px 24px; |
|
479 | padding:12px 9px 7px 24px; | |
480 | } |
|
480 | } | |
481 |
|
481 | |||
|
482 | #header #header-inner #quick li ul li a.ldap,#header #header-inner #quick li ul li a.ldap:hover { | |||
|
483 | background:#FFF url("../images/icons/server_key.png") no-repeat 4px 9px; | |||
|
484 | width:167px; | |||
|
485 | margin:0; | |||
|
486 | padding:12px 9px 7px 24px; | |||
|
487 | } | |||
|
488 | ||||
482 | #header #header-inner #quick li ul li a.fork,#header #header-inner #quick li ul li a.fork:hover { |
|
489 | #header #header-inner #quick li ul li a.fork,#header #header-inner #quick li ul li a.fork:hover { | |
483 | background:#FFF url("../images/icons/arrow_divide.png") no-repeat 4px 9px; |
|
490 | background:#FFF url("../images/icons/arrow_divide.png") no-repeat 4px 9px; | |
484 | width:167px; |
|
491 | width:167px; |
@@ -73,47 +73,6 b'' | |||||
73 | </div> |
|
73 | </div> | |
74 | </div> |
|
74 | </div> | |
75 | ${h.end_form()} |
|
75 | ${h.end_form()} | |
76 | ##LDAP |
|
|||
77 | <h3>${_('LDAP settings')}</h3> |
|
|||
78 | ${h.form(url('permissions_ldap',id_iser='default'),method='put')} |
|
|||
79 | <div class="form"> |
|
|||
80 | <div class="fields"> |
|
|||
81 |
|
||||
82 | <div class="field"> |
|
|||
83 | <div class="label label-checkbox"><label for="ldap_active">${_('Enable ldap')}</label></div> |
|
|||
84 | <div class="checkboxes"><div class="checkbox">${h.checkbox('ldap_active',True,class_='small')}</div></div> |
|
|||
85 | </div> |
|
|||
86 | <div class="field"> |
|
|||
87 | <div class="label"><label for="ldap_host">${_('Host')}</label></div> |
|
|||
88 | <div class="input">${h.text('ldap_host',class_='small')}</div> |
|
|||
89 | </div> |
|
|||
90 | <div class="field"> |
|
|||
91 | <div class="label"><label for="ldap_port">${_('Port')}</label></div> |
|
|||
92 | <div class="input">${h.text('ldap_port',class_='small')}</div> |
|
|||
93 | </div> |
|
|||
94 | <div class="field"> |
|
|||
95 | <div class="label label-checkbox"><label for="ldap_ldaps">${_('Enable LDAPS')}</label></div> |
|
|||
96 | <div class="checkboxes"><div class="checkbox">${h.checkbox('ldap_ldaps',True,class_='small')}</div></div> |
|
|||
97 | </div> |
|
|||
98 | <div class="field"> |
|
|||
99 | <div class="label"><label for="ldap_dn_user">${_('Account')}</label></div> |
|
|||
100 | <div class="input">${h.text('ldap_dn_user',class_='small')}</div> |
|
|||
101 | </div> |
|
|||
102 | <div class="field"> |
|
|||
103 | <div class="label"><label for="ldap_dn_pass">${_('Password')}</label></div> |
|
|||
104 | <div class="input">${h.password('ldap_dn_pass',class_='small')}</div> |
|
|||
105 | </div> |
|
|||
106 | <div class="field"> |
|
|||
107 | <div class="label"><label for="ldap_base_dn">${_('Base DN')}</label></div> |
|
|||
108 | <div class="input">${h.text('ldap_base_dn',class_='small')}</div> |
|
|||
109 | </div> |
|
|||
110 |
|
||||
111 | <div class="buttons"> |
|
|||
112 | ${h.submit('save','Save',class_="ui-button ui-widget ui-state-default ui-corner-all")} |
|
|||
113 | </div> |
|
|||
114 | </div> |
|
|||
115 | </div> |
|
|||
116 | ${h.end_form()} |
|
|||
117 | </div> |
|
76 | </div> | |
118 | </%def> |
|
77 | </%def> | |
119 |
|
78 |
@@ -204,13 +204,18 b'' | |||||
204 | %if h.HasPermissionAll('hg.admin')('access admin main page'): |
|
204 | %if h.HasPermissionAll('hg.admin')('access admin main page'): | |
205 | <li> |
|
205 | <li> | |
206 | ${h.link_to(_('admin'),h.url('admin_home'),class_='admin')} |
|
206 | ${h.link_to(_('admin'),h.url('admin_home'),class_='admin')} | |
|
207 | <%def name="admin_menu()"> | |||
207 | <ul> |
|
208 | <ul> | |
208 | <li>${h.link_to(_('journal'),h.url('admin_home'),class_='journal')}</li> |
|
209 | <li>${h.link_to(_('journal'),h.url('admin_home'),class_='journal')}</li> | |
209 | <li>${h.link_to(_('repositories'),h.url('repos'),class_='repos')}</li> |
|
210 | <li>${h.link_to(_('repositories'),h.url('repos'),class_='repos')}</li> | |
210 | <li>${h.link_to(_('users'),h.url('users'),class_='users')}</li> |
|
211 | <li>${h.link_to(_('users'),h.url('users'),class_='users')}</li> | |
211 | <li>${h.link_to(_('permissions'),h.url('edit_permission',id='default'),class_='permissions')}</li> |
|
212 | <li>${h.link_to(_('permissions'),h.url('edit_permission',id='default'),class_='permissions')}</li> | |
|
213 | <li>${h.link_to(_('ldap'),h.url('ldap_home'),class_='ldap')}</li> | |||
212 | <li class="last">${h.link_to(_('settings'),h.url('admin_settings'),class_='settings')}</li> |
|
214 | <li class="last">${h.link_to(_('settings'),h.url('admin_settings'),class_='settings')}</li> | |
213 | </ul> |
|
215 | </ul> | |
|
216 | </%def> | |||
|
217 | ||||
|
218 | ${admin_menu()} | |||
214 | </li> |
|
219 | </li> | |
215 | %endif |
|
220 | %endif | |
216 |
|
221 | |||
@@ -274,17 +279,10 b'' | |||||
274 | <img src="/images/icons/cog_edit.png" alt="${_('Admin')}" /> |
|
279 | <img src="/images/icons/cog_edit.png" alt="${_('Admin')}" /> | |
275 | </span> |
|
280 | </span> | |
276 | <span>${_('Admin')}</span> |
|
281 | <span>${_('Admin')}</span> | |
277 |
</a> |
|
282 | </a> | |
278 | <ul> |
|
283 | ${admin_menu()} | |
279 | <li>${h.link_to(_('journal'),h.url('admin_home'),class_='journal')}</li> |
|
|||
280 | <li>${h.link_to(_('repositories'),h.url('repos'),class_='repos')}</li> |
|
|||
281 | <li>${h.link_to(_('users'),h.url('users'),class_='users')}</li> |
|
|||
282 | <li>${h.link_to(_('permissions'),h.url('edit_permission',id='default'),class_='permissions')}</li> |
|
|||
283 | <li class="last">${h.link_to(_('settings'),h.url('admin_settings'),class_='settings')}</li> |
|
|||
284 | </ul> |
|
|||
285 | </li> |
|
284 | </li> | |
286 | %endif |
|
285 | %endif | |
287 |
|
||||
288 | </ul> |
|
286 | </ul> | |
289 | %endif |
|
287 | %endif | |
290 | </%def> |
|
288 | </%def> |
General Comments 0
You need to be logged in to leave comments.
Login now