[Zope3-checkins] SVN: ldapauth/trunk/browser/ Added LDAP server synchronisation view

Roger Ineichen roger at projekt01.ch
Wed Jul 21 19:51:29 EDT 2004


Log message for revision 26671:
  Added LDAP server synchronisation view


Changed:
  U   ldapauth/trunk/browser/manager.pt
  U   ldapauth/trunk/browser/source.zcml
  A   ldapauth/trunk/browser/sync.pt
  A   ldapauth/trunk/browser/sync.py


-=-
Modified: ldapauth/trunk/browser/manager.pt
===================================================================
--- ldapauth/trunk/browser/manager.pt	2004-07-21 23:46:55 UTC (rev 26670)
+++ ldapauth/trunk/browser/manager.pt	2004-07-21 23:51:29 UTC (rev 26671)
@@ -14,7 +14,7 @@
       </thead>
       <tbody>
         <metal:block tal:repeat="info python:view.getUserInfos()">
-					<tr tal:define="oddrow repeat/info/odd; url info/url"
+					<tr tal:define="oddrow repeat/info/odd; url info/login"
               tal:attributes="class python:oddrow and 'even' or 'odd'" >
 						<td><a href="#"
 									 tal:attributes="href

Modified: ldapauth/trunk/browser/source.zcml
===================================================================
--- ldapauth/trunk/browser/source.zcml	2004-07-21 23:46:55 UTC (rev 26670)
+++ ldapauth/trunk/browser/source.zcml	2004-07-21 23:51:29 UTC (rev 26671)
@@ -19,7 +19,7 @@
          instead of the inherited Contents view from the ocntainer. -->
     <page
         for="ldapauth.interfaces.ILDAPBasedPrincipalSource"
-        name="contents.html"
+        name="source.html"
         attribute="contents"
         class=".source.PrincipalSource"
         menu="zmi_views" title="Contents"
@@ -34,6 +34,15 @@
         menu="zmi_views" title="Manager"
         permission="zope.ManageContent"/>
 
+    <!-- Sync data form LDAP server. -->
+    <page
+        for="ldapauth.interfaces.ILDAPBasedPrincipalSource"
+        name="sync.html"
+        attribute="sync"
+        class=".sync.SyncLDAPView"
+        menu="zmi_views" title="Sync"
+        permission="zope.ManageContent"/>
+
     <editform 
         schema="ldapauth.interfaces.ILDAPBasedPrincipalSource" 
         label="Edit LDAP-based Principal Source" 

Added: ldapauth/trunk/browser/sync.pt
===================================================================
--- ldapauth/trunk/browser/sync.pt	2004-07-21 23:46:55 UTC (rev 26670)
+++ ldapauth/trunk/browser/sync.pt	2004-07-21 23:51:29 UTC (rev 26671)
@@ -0,0 +1,69 @@
+<html metal:use-macro="views/standard_macros/view">
+<body>
+<div metal:fill-slot="body">
+  <div metal:define-macro="contents"
+			 tal:define="hostinfo view/getHostInfo;
+			 						 syncreport view/loadPrincipalFromLDAP">
+
+		<form name="ldapSyncForm" method="POST" action="."
+          tal:attributes="action request/URL">
+
+			<table id="sortable" class="listing" summary="LDAP sync listing"
+						 i18n:attributes="summary">
+				<thead>
+					<tr>
+						<th i18n:translate="">Desription</th>
+						<th i18n:translate="">Data</th>
+					</tr>
+				</thead>
+				<tbody>
+					<tr>
+						<td i18n:translate="">Hostname</td>
+						<td><span tal:content="python:hostinfo['host']">host</span></td>
+					</tr>
+					<tr>
+						<td i18n:translate="">Port</td>
+						<td><span tal:content="python:hostinfo['port']">port</span></td>
+					</tr>
+					<tr>
+						<td i18n:translate="">Login attribute name</td>
+						<td><span tal:content="python:hostinfo['login_attribute']">login_attribute</span></td>
+					</tr>
+					<tr>
+						<td i18n:translate="">Base DN</td>
+						<td><span tal:content="python:hostinfo['basedn']">basedn</span></td>
+					</tr>
+					<tr>
+						<td i18n:translate="">Manager DN</td>
+						<td><span tal:content="python:hostinfo['manager_dn']">manager_dn</span></td>
+					</tr>
+					<tr>
+						<td i18n:translate="">Show the synchronized principals</td>
+						<td><input type="checkbox" value="" name="trace"></td>
+					</tr>
+				</tbody>
+			</table>
+
+			<input type="hidden" value="Run" name="runsync">
+			<input type="submit" value="sync" name="submit">
+	
+			<table id="sortable" class="listing" summary="LDAP Sync Report listing"
+						 i18n:attributes="summary"
+						 tal:condition="syncreport">
+				<thead>
+					<tr>
+						<th i18n:translate="">Traceback</th>
+					</tr>
+				</thead>
+				<tbody>
+					<tr tal:repeat="line syncreport" >
+						<td><span tal:content="structure line">principal info</span>&nbsp;</td>
+					</tr>
+				</tbody>
+			</table>
+
+		</form>
+  </div>
+</div>
+</body>
+</html>


Property changes on: ldapauth/trunk/browser/sync.pt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: ldapauth/trunk/browser/sync.py
===================================================================
--- ldapauth/trunk/browser/sync.py	2004-07-21 23:46:55 UTC (rev 26670)
+++ ldapauth/trunk/browser/sync.py	2004-07-21 23:51:29 UTC (rev 26671)
@@ -0,0 +1,80 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Synchronisation view
+
+$Id: sync.py $
+"""
+
+from zope.security.proxy import trustedRemoveSecurityProxy
+
+from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
+from zope.app.publisher.browser import BrowserView
+from zope.app.i18n import ZopeMessageIDFactory as _
+
+from ldapauth.interfaces import ILDAPBasedPrincipalSource
+
+
+
+class SyncLDAPView(BrowserView):
+
+    __used_for__ = ILDAPBasedPrincipalSource
+
+    error = ""
+
+    def __init__(self, context, request):
+        self.context = context
+        self.request = request
+
+    def getHostInfo(self):
+        """Returns a dict with host information."""
+        infoDict = {}
+        infoDict['host'] = self.context.host
+        infoDict['port'] = self.context.port
+        infoDict['basedn'] = self.context.basedn
+        infoDict['login_attribute'] = self.context.login_attribute
+        infoDict['manager_dn'] = self.context.manager_dn
+        return infoDict
+
+    def loadPrincipalFromLDAP(self):
+        """Get all principals from the LDAP server and add it to the cache."""
+        runtest = self.request.get('runsync', None)
+        if runtest == "Run":
+            trace = self.request.get("trace", None)
+            try:
+                principals = self.context.getPrincipals(name='')
+            except:
+                msg = _("Error during the synchronisation from the LDAP server.")
+                self.error = msg
+    
+            if trace != None:
+                infoList = []
+                counter = len(principals)
+                infoList.append("""%s principals form LDAP server successfully synchronized!
+                                """ % counter
+                               )
+                for principal in principals:
+                    info = trustedRemoveSecurityProxy(principal)
+                    entry = "%s, %s, %s" % (info.getLogin(), info.title, info.description)
+                    infoList.append(entry)
+            
+                return infoList
+            else:
+                counter = len(principals)
+                return ["""%s principals form LDAP server successfully synchronized!
+                        """ % counter
+                       ]
+        else:
+            return None
+
+    sync = ViewPageTemplateFile('sync.pt')


Property changes on: ldapauth/trunk/browser/sync.py
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Zope3-Checkins mailing list