##// END OF EJS Templates
Fixed #161 form saves the create repository permission....
Fixed #161 form saves the create repository permission. routing update for users to support second form posting. models updates

File last commit:

r1245:5f2fbab7 beta
r1266:a1bcfe58 beta
Show More
ldap_settings.py
124 lines | 4.5 KiB | text/x-python | PythonLexer
fixes #77 moved out ldap config to it's own section
r769 # -*- coding: utf-8 -*-
"""
updated docs on every controller
r861 rhodecode.controllers.admin.ldap_settings
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fixes #77 moved out ldap config to it's own section
r769
ldap controller for RhodeCode
source code cleanup: remove trailing white space, normalize file endings
r1203
fixes #77 moved out ldap config to it's own section
r769 :created_on: Nov 26, 2010
:author: marcink
source code cleanup: remove trailing white space, normalize file endings
r1203 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
fixes #77 moved out ldap config to it's own section
r769 :license: GPLv3, see COPYING for more details.
"""
fixed license issue #149
r1206 # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
source code cleanup: remove trailing white space, normalize file endings
r1203 #
fixes #77 moved out ldap config to it's own section
r769 # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
source code cleanup: remove trailing white space, normalize file endings
r1203 #
fixes #77 moved out ldap config to it's own section
r769 # You should have received a copy of the GNU General Public License
fixed license issue #149
r1206 # along with this program. If not, see <http://www.gnu.org/licenses/>.
fixes #77 moved out ldap config to it's own section
r769 import logging
import formencode
import traceback
from formencode import htmlfill
from pylons import request, response, session, tmpl_context as c, url
from pylons.controllers.util import abort, redirect
from pylons.i18n.translation import _
from rhodecode.lib.base import BaseController, render
from rhodecode.lib import helpers as h
from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
from rhodecode.lib.auth_ldap import LdapImportError
from rhodecode.model.settings import SettingsModel
from rhodecode.model.forms import LdapSettingsForm
from sqlalchemy.exc import DatabaseError
log = logging.getLogger(__name__)
class LdapSettingsController(BaseController):
PEP8ify - controllers
r1245 search_scope_choices = [('BASE', _('BASE'),),
Thayne Harbaugh
Improve LDAP authentication...
r991 ('ONELEVEL', _('ONELEVEL'),),
PEP8ify - controllers
r1245 ('SUBTREE', _('SUBTREE'),),
Thayne Harbaugh
Improve LDAP authentication...
r991 ]
search_scope_default = 'SUBTREE'
PEP8ify - controllers
r1245 tls_reqcert_choices = [('NEVER', _('NEVER'),),
('ALLOW', _('ALLOW'),),
('TRY', _('TRY'),),
Thayne Harbaugh
Improve LDAP authentication...
r991 ('DEMAND', _('DEMAND'),),
PEP8ify - controllers
r1245 ('HARD', _('HARD'),),
Thayne Harbaugh
Improve LDAP authentication...
r991 ]
tls_reqcert_default = 'DEMAND'
fixes #77 moved out ldap config to it's own section
r769 @LoginRequired()
@HasPermissionAllDecorator('hg.admin')
def __before__(self):
c.admin_user = session.get('admin_user')
c.admin_username = session.get('admin_username')
Thayne Harbaugh
Improve LDAP authentication...
r991 c.search_scope_choices = self.search_scope_choices
PEP8ify - controllers
r1245 c.tls_reqcert_choices = self.tls_reqcert_choices
fixes #77 moved out ldap config to it's own section
r769 super(LdapSettingsController, self).__before__()
def index(self):
defaults = SettingsModel().get_ldap_settings()
Thayne Harbaugh
Improve LDAP authentication...
r991 c.search_scope_cur = defaults.get('ldap_search_scope')
PEP8ify - controllers
r1245 c.tls_reqcert_cur = defaults.get('ldap_tls_reqcert')
fixes #77 moved out ldap config to it's own section
r769
return htmlfill.render(
render('admin/ldap/ldap.html'),
defaults=defaults,
encoding="UTF-8",
force_defaults=True,)
def ldap_settings(self):
fixed spelling mistakes, and some minor docs bugs
r860 """POST ldap create and store ldap settings"""
fixes #77 moved out ldap config to it's own section
r769
settings_model = SettingsModel()
Thayne Harbaugh
Improve LDAP authentication...
r991 _form = LdapSettingsForm([x[0] for x in self.tls_reqcert_choices],
[x[0] for x in self.search_scope_choices])()
fixes #77 moved out ldap config to it's own section
r769
try:
form_result = _form.to_python(dict(request.POST))
try:
for k, v in form_result.items():
if k.startswith('ldap_'):
setting = settings_model.get(k)
setting.app_settings_value = v
self.sa.add(setting)
self.sa.commit()
h.flash(_('Ldap settings updated successfully'),
category='success')
except (DatabaseError,):
raise
except LdapImportError:
fixed warning message
r772 h.flash(_('Unable to activate ldap. The "python-ldap" library '
fixes #77 moved out ldap config to it's own section
r769 'is missing.'), category='warning')
except formencode.Invalid, errors:
Thayne Harbaugh
Improve LDAP authentication...
r991 c.search_scope_cur = self.search_scope_default
PEP8ify - controllers
r1245 c.tls_reqcert_cur = self.search_scope_default
Thayne Harbaugh
Improve LDAP authentication...
r991
fixes #77 moved out ldap config to it's own section
r769 return htmlfill.render(
render('admin/ldap/ldap.html'),
defaults=errors.value,
errors=errors.error_dict or {},
prefix_error=False,
encoding="UTF-8")
except Exception:
log.error(traceback.format_exc())
fixed spelling mistakes, and some minor docs bugs
r860 h.flash(_('error occurred during update of ldap settings'),
fixes #77 moved out ldap config to it's own section
r769 category='error')
return redirect(url('ldap_home'))