Show More
@@ -1,106 +1,106 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """ |
|
2 | """ | |
3 | package.rhodecode.controllers.admin.ldap_settings |
|
3 | package.rhodecode.controllers.admin.ldap_settings | |
4 | ~~~~~~~~~~~~~~ |
|
4 | ~~~~~~~~~~~~~~ | |
5 |
|
5 | |||
6 | ldap controller for RhodeCode |
|
6 | ldap controller for RhodeCode | |
7 | :created_on: Nov 26, 2010 |
|
7 | :created_on: Nov 26, 2010 | |
8 | :author: marcink |
|
8 | :author: marcink | |
9 | :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
|
9 | :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> | |
10 | :license: GPLv3, see COPYING for more details. |
|
10 | :license: GPLv3, see COPYING for more details. | |
11 | """ |
|
11 | """ | |
12 | # This program is free software; you can redistribute it and/or |
|
12 | # This program is free software; you can redistribute it and/or | |
13 | # modify it under the terms of the GNU General Public License |
|
13 | # modify it under the terms of the GNU General Public License | |
14 | # as published by the Free Software Foundation; version 2 |
|
14 | # as published by the Free Software Foundation; version 2 | |
15 | # of the License or (at your opinion) any later version of the license. |
|
15 | # of the License or (at your opinion) any later version of the license. | |
16 | # |
|
16 | # | |
17 | # This program is distributed in the hope that it will be useful, |
|
17 | # This program is distributed in the hope that it will be useful, | |
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | # GNU General Public License for more details. |
|
20 | # GNU General Public License for more details. | |
21 | # |
|
21 | # | |
22 | # You should have received a copy of the GNU General Public License |
|
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 |
|
23 | # along with this program; if not, write to the Free Software | |
24 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
24 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
25 | # MA 02110-1301, USA. |
|
25 | # MA 02110-1301, USA. | |
26 | import logging |
|
26 | import logging | |
27 | import formencode |
|
27 | import formencode | |
28 | import traceback |
|
28 | import traceback | |
29 |
|
29 | |||
30 | from formencode import htmlfill |
|
30 | from formencode import htmlfill | |
31 |
|
31 | |||
32 | from pylons import request, response, session, tmpl_context as c, url |
|
32 | from pylons import request, response, session, tmpl_context as c, url | |
33 | from pylons.controllers.util import abort, redirect |
|
33 | from pylons.controllers.util import abort, redirect | |
34 | from pylons.i18n.translation import _ |
|
34 | from pylons.i18n.translation import _ | |
35 |
|
35 | |||
36 | from rhodecode.lib.base import BaseController, render |
|
36 | from rhodecode.lib.base import BaseController, render | |
37 | from rhodecode.lib import helpers as h |
|
37 | from rhodecode.lib import helpers as h | |
38 | from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator |
|
38 | from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator | |
39 | from rhodecode.lib.auth_ldap import LdapImportError |
|
39 | from rhodecode.lib.auth_ldap import LdapImportError | |
40 | from rhodecode.model.settings import SettingsModel |
|
40 | from rhodecode.model.settings import SettingsModel | |
41 | from rhodecode.model.forms import LdapSettingsForm |
|
41 | from rhodecode.model.forms import LdapSettingsForm | |
42 | from sqlalchemy.exc import DatabaseError |
|
42 | from sqlalchemy.exc import DatabaseError | |
43 |
|
43 | |||
44 | log = logging.getLogger(__name__) |
|
44 | log = logging.getLogger(__name__) | |
45 |
|
45 | |||
46 |
|
46 | |||
47 |
|
47 | |||
48 | class LdapSettingsController(BaseController): |
|
48 | class LdapSettingsController(BaseController): | |
49 |
|
49 | |||
50 | @LoginRequired() |
|
50 | @LoginRequired() | |
51 | @HasPermissionAllDecorator('hg.admin') |
|
51 | @HasPermissionAllDecorator('hg.admin') | |
52 | def __before__(self): |
|
52 | def __before__(self): | |
53 | c.admin_user = session.get('admin_user') |
|
53 | c.admin_user = session.get('admin_user') | |
54 | c.admin_username = session.get('admin_username') |
|
54 | c.admin_username = session.get('admin_username') | |
55 | super(LdapSettingsController, self).__before__() |
|
55 | super(LdapSettingsController, self).__before__() | |
56 |
|
56 | |||
57 | def index(self): |
|
57 | def index(self): | |
58 | defaults = SettingsModel().get_ldap_settings() |
|
58 | defaults = SettingsModel().get_ldap_settings() | |
59 |
|
59 | |||
60 | return htmlfill.render( |
|
60 | return htmlfill.render( | |
61 | render('admin/ldap/ldap.html'), |
|
61 | render('admin/ldap/ldap.html'), | |
62 | defaults=defaults, |
|
62 | defaults=defaults, | |
63 | encoding="UTF-8", |
|
63 | encoding="UTF-8", | |
64 | force_defaults=True,) |
|
64 | force_defaults=True,) | |
65 |
|
65 | |||
66 | def ldap_settings(self): |
|
66 | def ldap_settings(self): | |
67 | """ |
|
67 | """ | |
68 | POST ldap create and store ldap settings |
|
68 | POST ldap create and store ldap settings | |
69 | """ |
|
69 | """ | |
70 |
|
70 | |||
71 | settings_model = SettingsModel() |
|
71 | settings_model = SettingsModel() | |
72 | _form = LdapSettingsForm()() |
|
72 | _form = LdapSettingsForm()() | |
73 |
|
73 | |||
74 | try: |
|
74 | try: | |
75 | form_result = _form.to_python(dict(request.POST)) |
|
75 | form_result = _form.to_python(dict(request.POST)) | |
76 | try: |
|
76 | try: | |
77 |
|
77 | |||
78 | for k, v in form_result.items(): |
|
78 | for k, v in form_result.items(): | |
79 | if k.startswith('ldap_'): |
|
79 | if k.startswith('ldap_'): | |
80 | setting = settings_model.get(k) |
|
80 | setting = settings_model.get(k) | |
81 | setting.app_settings_value = v |
|
81 | setting.app_settings_value = v | |
82 | self.sa.add(setting) |
|
82 | self.sa.add(setting) | |
83 |
|
83 | |||
84 | self.sa.commit() |
|
84 | self.sa.commit() | |
85 | h.flash(_('Ldap settings updated successfully'), |
|
85 | h.flash(_('Ldap settings updated successfully'), | |
86 | category='success') |
|
86 | category='success') | |
87 | except (DatabaseError,): |
|
87 | except (DatabaseError,): | |
88 | raise |
|
88 | raise | |
89 | except LdapImportError: |
|
89 | except LdapImportError: | |
90 |
h.flash(_('Unable to activate ldap. The " |
|
90 | h.flash(_('Unable to activate ldap. The "python-ldap" library ' | |
91 | 'is missing.'), category='warning') |
|
91 | 'is missing.'), category='warning') | |
92 |
|
92 | |||
93 | except formencode.Invalid, errors: |
|
93 | except formencode.Invalid, errors: | |
94 |
|
94 | |||
95 | return htmlfill.render( |
|
95 | return htmlfill.render( | |
96 | render('admin/ldap/ldap.html'), |
|
96 | render('admin/ldap/ldap.html'), | |
97 | defaults=errors.value, |
|
97 | defaults=errors.value, | |
98 | errors=errors.error_dict or {}, |
|
98 | errors=errors.error_dict or {}, | |
99 | prefix_error=False, |
|
99 | prefix_error=False, | |
100 | encoding="UTF-8") |
|
100 | encoding="UTF-8") | |
101 | except Exception: |
|
101 | except Exception: | |
102 | log.error(traceback.format_exc()) |
|
102 | log.error(traceback.format_exc()) | |
103 | h.flash(_('error occured during update of ldap settings'), |
|
103 | h.flash(_('error occured during update of ldap settings'), | |
104 | category='error') |
|
104 | category='error') | |
105 |
|
105 | |||
106 | return redirect(url('ldap_home')) |
|
106 | return redirect(url('ldap_home')) |
General Comments 0
You need to be logged in to leave comments.
Login now