# HG changeset patch # User Marcin Kuzminski # Date 2010-11-26 08:32:40 # Node ID 4bdcc08b04c42a71b433ae521684ec29fdccb08e # Parent 75802dfad88bd8cb4689807371652deecabe4f55 fixes #77 moved out ldap config to it's own section diff --git a/rhodecode/config/routing.py b/rhodecode/config/routing.py --- a/rhodecode/config/routing.py +++ b/rhodecode/config/routing.py @@ -85,7 +85,13 @@ def make_map(config): #ADMIN PERMISSIONS REST ROUTES map.resource('permission', 'permissions', controller='admin/permissions', path_prefix='/_admin') - map.connect('permissions_ldap', '/_admin/permissions_ldap', controller='admin/permissions', action='ldap') + + + ##ADMIN LDAP SETTINGS + map.connect('ldap_settings', '/_admin/ldap', controller='admin/ldap_settings', + action='ldap_settings', conditions=dict(method=["POST"])) + map.connect('ldap_home', '/_admin/ldap', controller='admin/ldap_settings',) + #ADMIN SETTINGS REST ROUTES diff --git a/rhodecode/controllers/admin/ldap_settings.py b/rhodecode/controllers/admin/ldap_settings.py new file mode 100644 --- /dev/null +++ b/rhodecode/controllers/admin/ldap_settings.py @@ -0,0 +1,106 @@ +# -*- coding: utf-8 -*- +""" + package.rhodecode.controllers.admin.ldap_settings + ~~~~~~~~~~~~~~ + + ldap controller for RhodeCode + :created_on: Nov 26, 2010 + :author: marcink + :copyright: (C) 2009-2010 Marcin Kuzminski + :license: GPLv3, see COPYING for more details. +""" +# 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; version 2 +# of the License or (at your opinion) any later version of the license. +# +# 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. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. +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): + + @LoginRequired() + @HasPermissionAllDecorator('hg.admin') + def __before__(self): + c.admin_user = session.get('admin_user') + c.admin_username = session.get('admin_username') + super(LdapSettingsController, self).__before__() + + def index(self): + defaults = SettingsModel().get_ldap_settings() + + return htmlfill.render( + render('admin/ldap/ldap.html'), + defaults=defaults, + encoding="UTF-8", + force_defaults=True,) + + def ldap_settings(self): + """ + POST ldap create and store ldap settings + """ + + settings_model = SettingsModel() + _form = LdapSettingsForm()() + + 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: + h.flash(_('Unable to activate ldap. The "ldap-python" library ' + 'is missing.'), category='warning') + + except formencode.Invalid, errors: + + 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()) + h.flash(_('error occured during update of ldap settings'), + category='error') + + return redirect(url('ldap_home')) diff --git a/rhodecode/controllers/admin/permissions.py b/rhodecode/controllers/admin/permissions.py --- a/rhodecode/controllers/admin/permissions.py +++ b/rhodecode/controllers/admin/permissions.py @@ -110,7 +110,6 @@ class PermissionsController(BaseControll c.register_choices = self.register_choices c.create_choices = self.create_choices defaults = errors.value - defaults.update(SettingsModel().get_ldap_settings()) return htmlfill.render( render('admin/permissions/permissions.html'), @@ -151,7 +150,7 @@ class PermissionsController(BaseControll default_user = UserModel().get_by_username('default') defaults = {'_method':'put', 'anonymous':default_user.active} - defaults.update(SettingsModel().get_ldap_settings()) + for p in default_user.user_perms: if p.permission.permission_name.startswith('repository.'): defaults['default_perm'] = p.permission.permission_name @@ -169,50 +168,3 @@ class PermissionsController(BaseControll force_defaults=True,) else: return redirect(url('admin_home')) - - - def ldap(self, id_user='default'): - """ - POST ldap create and store ldap settings - """ - - settings_model = SettingsModel() - _form = LdapSettingsForm()() - - 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: - raise - except LdapImportError: - h.flash(_('Unable to activate ldap. The "ldap-python" library ' - 'is missing.'), - category='warning') - - except formencode.Invalid, errors: - c.perms_choices = self.perms_choices - c.register_choices = self.register_choices - c.create_choices = self.create_choices - - return htmlfill.render( - render('admin/permissions/permissions.html'), - defaults=errors.value, - errors=errors.error_dict or {}, - prefix_error=False, - encoding="UTF-8") - except Exception: - log.error(traceback.format_exc()) - h.flash(_('error occured during update of ldap settings'), - category='error') - - return redirect(url('edit_permission', id=id_user)) diff --git a/rhodecode/public/css/style.css b/rhodecode/public/css/style.css --- a/rhodecode/public/css/style.css +++ b/rhodecode/public/css/style.css @@ -479,6 +479,13 @@ margin:0; padding:12px 9px 7px 24px; } +#header #header-inner #quick li ul li a.ldap,#header #header-inner #quick li ul li a.ldap:hover { +background:#FFF url("../images/icons/server_key.png") no-repeat 4px 9px; +width:167px; +margin:0; +padding:12px 9px 7px 24px; +} + #header #header-inner #quick li ul li a.fork,#header #header-inner #quick li ul li a.fork:hover { background:#FFF url("../images/icons/arrow_divide.png") no-repeat 4px 9px; width:167px; diff --git a/rhodecode/templates/admin/ldap/ldap.html b/rhodecode/templates/admin/ldap/ldap.html new file mode 100644 --- /dev/null +++ b/rhodecode/templates/admin/ldap/ldap.html @@ -0,0 +1,73 @@ +## -*- coding: utf-8 -*- +<%inherit file="/base/base.html"/> + +<%def name="title()"> + ${_('LDAP administration')} - ${c.rhodecode_name} + + +<%def name="breadcrumbs_links()"> + ${h.link_to(_('Admin'),h.url('admin_home'))} + » + ${_('Ldap')} + + +<%def name="page_nav()"> + ${self.menu('admin')} + + +<%def name="main()"> +
+ +
+ ${self.breadcrumbs()} +
+

${_('LDAP administration')}

+ ${h.form(url('ldap_settings'))} +
+
+ +
+
+
${h.checkbox('ldap_active',True,class_='small')}
+
+
+
+
${h.text('ldap_host',class_='small')}
+
+
+
+
${h.text('ldap_port',class_='small')}
+
+
+
+
${h.checkbox('ldap_ldaps',True,class_='small')}
+
+
+
+
${h.text('ldap_dn_user',class_='small')}
+
+
+
+
${h.password('ldap_dn_pass',class_='small')}
+
+
+
+
${h.text('ldap_base_dn',class_='small')}
+
+ +
+ ${h.submit('save','Save',class_="ui-button ui-widget ui-state-default ui-corner-all")} +
+
+
+ ${h.end_form()} +
+ + + + + + + + + diff --git a/rhodecode/templates/admin/permissions/permissions.html b/rhodecode/templates/admin/permissions/permissions.html --- a/rhodecode/templates/admin/permissions/permissions.html +++ b/rhodecode/templates/admin/permissions/permissions.html @@ -73,47 +73,6 @@ ${h.end_form()} - ##LDAP -

${_('LDAP settings')}

- ${h.form(url('permissions_ldap',id_iser='default'),method='put')} -
-
- -
-
-
${h.checkbox('ldap_active',True,class_='small')}
-
-
-
-
${h.text('ldap_host',class_='small')}
-
-
-
-
${h.text('ldap_port',class_='small')}
-
-
-
-
${h.checkbox('ldap_ldaps',True,class_='small')}
-
-
-
-
${h.text('ldap_dn_user',class_='small')}
-
-
-
-
${h.password('ldap_dn_pass',class_='small')}
-
-
-
-
${h.text('ldap_base_dn',class_='small')}
-
- -
- ${h.submit('save','Save',class_="ui-button ui-widget ui-state-default ui-corner-all")} -
-
-
- ${h.end_form()} diff --git a/rhodecode/templates/base/base.html b/rhodecode/templates/base/base.html --- a/rhodecode/templates/base/base.html +++ b/rhodecode/templates/base/base.html @@ -204,13 +204,18 @@ %if h.HasPermissionAll('hg.admin')('access admin main page'):
  • ${h.link_to(_('admin'),h.url('admin_home'),class_='admin')} + <%def name="admin_menu()">
    • ${h.link_to(_('journal'),h.url('admin_home'),class_='journal')}
    • ${h.link_to(_('repositories'),h.url('repos'),class_='repos')}
    • ${h.link_to(_('users'),h.url('users'),class_='users')}
    • ${h.link_to(_('permissions'),h.url('edit_permission',id='default'),class_='permissions')}
    • +
    • ${h.link_to(_('ldap'),h.url('ldap_home'),class_='ldap')}
    • ${h.link_to(_('settings'),h.url('admin_settings'),class_='settings')}
    + + + ${admin_menu()}
  • %endif @@ -274,17 +279,10 @@ ${_('Admin')} ${_('Admin')} - - + + ${admin_menu()} %endif - %endif diff --git a/rhodecode/tests/functional/test_admin_ldap_settings.py b/rhodecode/tests/functional/test_admin_ldap_settings.py new file mode 100644 --- /dev/null +++ b/rhodecode/tests/functional/test_admin_ldap_settings.py @@ -0,0 +1,7 @@ +from rhodecode.tests import * + +class TestLdapSettingsController(TestController): + + def test_index(self): + response = self.app.get(url(controller='admin/ldap_settings', action='index')) + # Test response...