annotate rhodecode/controllers/admin/ldap_settings.py @ 902:07a6e8c65526 beta

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