[Zope3-checkins] SVN: Zope3/branches/3.3/ - Added more elegant solution to inform developers (and other people *sigh*)

Christian Theune ct at gocept.com
Thu Aug 17 09:34:18 EDT 2006


Log message for revision 69598:
   - Added more elegant solution to inform developers (and other people *sigh*)
     about API doc beeing disabled because of disabled developer mode.
  
     (This still belongs to issue 507)
  

Changed:
  A   Zope3/branches/3.3/ftesting-base.zcml
  A   Zope3/branches/3.3/ftesting-nodevmode.zcml
  U   Zope3/branches/3.3/ftesting.zcml
  A   Zope3/branches/3.3/src/zope/app/apidoc/browser/disabled.pt
  A   Zope3/branches/3.3/src/zope/app/apidoc/browser/disabled.zcml
  U   Zope3/branches/3.3/src/zope/app/apidoc/browser/ftests.py
  A   Zope3/branches/3.3/src/zope/app/apidoc/browser/nodevmode.txt
  U   Zope3/branches/3.3/src/zope/app/apidoc/configure.zcml
  A   Zope3/branches/3.3/src/zope/app/apidoc/disabled.py
  A   Zope3/branches/3.3/src/zope/app/apidoc/disabled.zcml
  A   Zope3/branches/3.3/src/zope/app/apidoc/enabled.zcml
  U   Zope3/branches/3.3/src/zope/app/onlinehelp/help/welcome.stx
  U   Zope3/branches/3.3/src/zope/app/server/main.py
  U   Zope3/branches/3.3/src/zope/app/twisted/main.py
  U   Zope3/branches/3.3/src/zope/app/wsgi/__init__.py

-=-
Added: Zope3/branches/3.3/ftesting-base.zcml
===================================================================
--- Zope3/branches/3.3/ftesting-base.zcml	2006-08-17 13:08:41 UTC (rev 69597)
+++ Zope3/branches/3.3/ftesting-base.zcml	2006-08-17 13:34:17 UTC (rev 69598)
@@ -0,0 +1,59 @@
+<configure
+   xmlns="http://namespaces.zope.org/zope"
+   xmlns:meta="http://namespaces.zope.org/meta"
+   i18n_domain="zope"
+   >
+
+  <!-- This file is the equivalent of site.zcml and it is -->
+  <!-- used for functional testing setup -->
+
+  <include package="zope.app" />
+  <include package="zope.app" file="ftesting.zcml" />
+
+  <include files="zopeskel/etc/package-includes/*-meta.zcml" />
+  <include files="zopeskel/etc/package-includes/*-configure.zcml" />
+  <include files="zopeskel/etc/package-includes/*-ftesting.zcml" />
+
+  <include file="securitypolicy.zcml" />
+  <include file="securitypolicy-ftesting.zcml" />
+
+  <!-- Principals -->
+
+  <unauthenticatedPrincipal
+      id="zope.anybody"
+      title="Unauthenticated User" />
+
+  <unauthenticatedGroup
+    id="zope.Anybody"
+    title="Unauthenticated Users"
+    />
+
+  <authenticatedGroup
+    id="zope.Authenticated"
+    title="Authenticated Users"
+    />
+
+  <everybodyGroup
+    id="zope.Everybody"
+    title="All Users"
+    />
+
+  <!-- Principal that tests generally run as -->
+  <principal
+      id="zope.mgr"
+      title="Manager"
+      login="mgr"
+      password="mgrpw" />
+
+  <!-- Bootstrap principal used to make local grant to the principal above -->
+  <principal
+      id="zope.globalmgr"
+      title="Manager"
+      login="globalmgr"
+      password="globalmgrpw" />
+
+  <grant role="zope.Manager" principal="zope.globalmgr" />
+
+  <includeOverrides file="overrides_ftesting.zcml" />
+
+</configure>


Property changes on: Zope3/branches/3.3/ftesting-base.zcml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: Zope3/branches/3.3/ftesting-nodevmode.zcml
===================================================================
--- Zope3/branches/3.3/ftesting-nodevmode.zcml	2006-08-17 13:08:41 UTC (rev 69597)
+++ Zope3/branches/3.3/ftesting-nodevmode.zcml	2006-08-17 13:34:17 UTC (rev 69598)
@@ -0,0 +1,12 @@
+<configure
+   xmlns="http://namespaces.zope.org/zope"
+   xmlns:meta="http://namespaces.zope.org/meta"
+   i18n_domain="zope"
+   >
+
+  <!-- Turn off the devmode -->
+  <meta:provides feature="nodevmode" />
+
+  <include file="ftesting-base.zcml" />
+
+</configure>


Property changes on: Zope3/branches/3.3/ftesting-nodevmode.zcml
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: Zope3/branches/3.3/ftesting.zcml
===================================================================
--- Zope3/branches/3.3/ftesting.zcml	2006-08-17 13:08:41 UTC (rev 69597)
+++ Zope3/branches/3.3/ftesting.zcml	2006-08-17 13:34:17 UTC (rev 69598)
@@ -7,56 +7,6 @@
   <!-- Turn on the devmode -->
   <meta:provides feature="devmode" />
 
-  <!-- This file is the equivalent of site.zcml and it is -->
-  <!-- used for functional testing setup -->
+  <include file="ftesting-base.zcml" />
 
-  <include package="zope.app" />
-  <include package="zope.app" file="ftesting.zcml" />
-
-  <include files="zopeskel/etc/package-includes/*-meta.zcml" />
-  <include files="zopeskel/etc/package-includes/*-configure.zcml" />
-  <include files="zopeskel/etc/package-includes/*-ftesting.zcml" />
-
-  <include file="securitypolicy.zcml" />
-  <include file="securitypolicy-ftesting.zcml" />
-
-  <!-- Principals -->
-
-  <unauthenticatedPrincipal
-      id="zope.anybody"
-      title="Unauthenticated User" />
-
-  <unauthenticatedGroup
-    id="zope.Anybody"
-    title="Unauthenticated Users"
-    />
-
-  <authenticatedGroup
-    id="zope.Authenticated"
-    title="Authenticated Users"
-    />
-
-  <everybodyGroup
-    id="zope.Everybody"
-    title="All Users"
-    />
-
-  <!-- Principal that tests generally run as -->
-  <principal
-      id="zope.mgr"
-      title="Manager"
-      login="mgr"
-      password="mgrpw" />
-
-  <!-- Bootstrap principal used to make local grant to the principal above -->
-  <principal
-      id="zope.globalmgr"
-      title="Manager"
-      login="globalmgr"
-      password="globalmgrpw" />
-
-  <grant role="zope.Manager" principal="zope.globalmgr" />
-
-  <includeOverrides file="overrides_ftesting.zcml" />
-
 </configure>

Added: Zope3/branches/3.3/src/zope/app/apidoc/browser/disabled.pt
===================================================================
--- Zope3/branches/3.3/src/zope/app/apidoc/browser/disabled.pt	2006-08-17 13:08:41 UTC (rev 69597)
+++ Zope3/branches/3.3/src/zope/app/apidoc/browser/disabled.pt	2006-08-17 13:34:17 UTC (rev 69598)
@@ -0,0 +1,11 @@
+<html>
+  <body>
+    <h1>API documentation is disabled</h1>
+
+    <p>The API documentation is only available in developer mode. To enable
+      developer mode, modify your zope.conf and restart the application
+      server.
+    </p>
+
+  </body>
+</html>


Property changes on: Zope3/branches/3.3/src/zope/app/apidoc/browser/disabled.pt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: Zope3/branches/3.3/src/zope/app/apidoc/browser/disabled.zcml
===================================================================
--- Zope3/branches/3.3/src/zope/app/apidoc/browser/disabled.zcml	2006-08-17 13:08:41 UTC (rev 69597)
+++ Zope3/branches/3.3/src/zope/app/apidoc/browser/disabled.zcml	2006-08-17 13:34:17 UTC (rev 69598)
@@ -0,0 +1,14 @@
+<configure
+  xmlns="http://namespaces.zope.org/browser"
+  xmlns:zope="http://namespaces.zope.org/zope"
+  i18n_domain="zope">
+
+  <page
+      for="..disabled.APIDocStub"
+      name="index.html"
+      permission="zope.View"
+      template="disabled.pt"
+      />
+
+</configure>
+


Property changes on: Zope3/branches/3.3/src/zope/app/apidoc/browser/disabled.zcml
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: Zope3/branches/3.3/src/zope/app/apidoc/browser/ftests.py
===================================================================
--- Zope3/branches/3.3/src/zope/app/apidoc/browser/ftests.py	2006-08-17 13:08:41 UTC (rev 69597)
+++ Zope3/branches/3.3/src/zope/app/apidoc/browser/ftests.py	2006-08-17 13:34:17 UTC (rev 69598)
@@ -16,10 +16,13 @@
 $Id$
 """
 import unittest
+
+import zope.app.testing.functional
 from zope.testing import doctest
 from zope.app.testing.functional import BrowserTestCase
 from zope.app.testing.functional import FunctionalDocFileSuite
 
+
 class APIDocTests(BrowserTestCase):
     """Just a couple of tests ensuring that the templates render."""
 
@@ -32,7 +35,6 @@
         self.checkForBrokenLinks(body, '/++apidoc++/menu.html',
                                  basic='mgr:mgrpw')
 
-
     def testIndexView(self):
         response = self.publish('/++apidoc++/index.html',
                                 basic='mgr:mgrpw')
@@ -62,13 +64,26 @@
                                  basic='mgr:mgrpw')
 
 
+NoDevModeLayer = zope.app.testing.functional.ZCMLLayer(
+    "ftesting-nodevmode.zcml",
+    __name__, 
+    "NoDevModeLayer")
+
+
 def test_suite():
-    return unittest.TestSuite((
-        unittest.makeSuite(APIDocTests),
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(APIDocTests))
+    suite.addTest(
         FunctionalDocFileSuite(
             "README.txt",
             optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE),
-        ))
+        )
 
+    nodevmode = FunctionalDocFileSuite("nodevmode.txt")
+    nodevmode.layer = NoDevModeLayer
+    suite.addTest(nodevmode)
+    return suite
+
+
 if __name__ == '__main__':
     unittest.main(defaultTest='test_suite')

Added: Zope3/branches/3.3/src/zope/app/apidoc/browser/nodevmode.txt
===================================================================
--- Zope3/branches/3.3/src/zope/app/apidoc/browser/nodevmode.txt	2006-08-17 13:08:41 UTC (rev 69597)
+++ Zope3/branches/3.3/src/zope/app/apidoc/browser/nodevmode.txt	2006-08-17 13:34:17 UTC (rev 69598)
@@ -0,0 +1,18 @@
+API doc when developer mode is disabled
+=======================================
+
+The API docs should not be exposed to anybody as they allow introspection of
+code and files on the file system that should not be exposed through the web.
+
+In this test case, the developer mode was disabled, so we will only see a page
+informing the user that the API docs are disabled. We do this as we changed
+the default during the release of Zope 3.3 and many developers will still
+assume that their instances are running in developer mode, while they aren't.
+
+  >>> from zope.testbrowser.testing import Browser
+  >>> browser = Browser()
+  >>> browser.handleErrors = False
+  >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+  >>> browser.open("http://localhost/++apidoc++")
+  >>> browser.contents      # doctest: +ELLIPSIS
+  '...API documentation is disabled...'


Property changes on: Zope3/branches/3.3/src/zope/app/apidoc/browser/nodevmode.txt
___________________________________________________________________
Name: svn:keywords
   + Id Rev Date
Name: svn:eol-style
   + native

Modified: Zope3/branches/3.3/src/zope/app/apidoc/configure.zcml
===================================================================
--- Zope3/branches/3.3/src/zope/app/apidoc/configure.zcml	2006-08-17 13:08:41 UTC (rev 69597)
+++ Zope3/branches/3.3/src/zope/app/apidoc/configure.zcml	2006-08-17 13:34:17 UTC (rev 69598)
@@ -2,86 +2,16 @@
   xmlns="http://namespaces.zope.org/zope"
   xmlns:apidoc="http://namespaces.zope.org/apidoc"
   xmlns:zcml="http://namespaces.zope.org/zcml"
-  zcml:condition="have devmode"
   i18n_domain="zope">
 
-  <permission
-      id="zope.app.apidoc.UseAPIDoc"
-      title="[zope.app.apidoc.UseAPIDoc] Access Online API documentation"
-      />
+  <include
+    zcml:condition="have devmode"
+    file="enabled.zcml"
+    />
 
-  <class class=".apidoc.APIDocumentation">
-    <require
-        interface="zope.app.container.interfaces.IReadContainer"
-        permission="zope.ManageApplication"
-        />
-  </class>
+  <include
+    zcml:condition="have nodevmode"
+    file="disabled.zcml"
+    />
 
-  <view
-      name="apidoc" type="*"
-      provides="zope.traversing.interfaces.ITraversable" for="*"
-      factory=".apidoc.apidocNamespace"
-      />
-  <adapter
-      name="apidoc"
-      provides="zope.traversing.interfaces.ITraversable" for="*"
-      factory=".apidoc.apidocNamespace"
-      />
-
-  <!-- Register Public API Dcoumentation -->
-
-  <apidoc:bookchapter
-      id="inspect"
-      title="Inspection API"
-      />
-  <apidoc:bookchapter
-      id="interface"
-      title="Interfaces"
-      doc_path="interface.txt"
-      parent="inspect"
-      />
-  <apidoc:bookchapter
-      id="component"
-      title="Components"
-      doc_path="component.txt"
-      parent="inspect"
-      />
-  <apidoc:bookchapter
-      id="presentation"
-      title="Presentation"
-      doc_path="presentation.txt"
-      parent="inspect"
-      />
-  <apidoc:bookchapter
-      id="misc"
-      title="Miscellaneous"
-      doc_path="utilities.txt"
-      parent="inspect"
-      />
-  <apidoc:bookchapter
-      id="classregistry"
-      title="Class Registry"
-      doc_path="classregistry.txt"
-      parent="inspect"
-      />
-
-  <include package=".browser" />
-
-  <preferenceGroup
-      id="apidoc"
-      title="API Doc Tool"
-      description="
-         These are all the preferences related to viewing the API
-         documentation."
-      category="True"
-      />
-
-  <!-- API Documentation Modules -->
-  <include package=".bookmodule" />
-  <include package=".codemodule" />
-  <include package=".ifacemodule" />
-  <include package=".typemodule" />
-  <include package=".utilitymodule" />
-  <include package=".zcmlmodule" />
-
 </configure>

Added: Zope3/branches/3.3/src/zope/app/apidoc/disabled.py
===================================================================
--- Zope3/branches/3.3/src/zope/app/apidoc/disabled.py	2006-08-17 13:08:41 UTC (rev 69597)
+++ Zope3/branches/3.3/src/zope/app/apidoc/disabled.py	2006-08-17 13:34:17 UTC (rev 69598)
@@ -0,0 +1,41 @@
+##############################################################################
+#
+# Copyright (c) 2004 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.
+#
+##############################################################################
+"""Zope 3 API Documentation
+
+$Id$
+"""
+__docformat__ = 'restructuredtext'
+
+import zope.component
+from zope.interface import implements
+from zope.publisher.browser import applySkin
+from zope.location import locate
+from zope.location.interfaces import ILocation
+
+from zope.app.apidoc.interfaces import IDocumentationModule
+from zope.app.apidoc.utilities import ReadContainerBase
+
+class APIDocStub(object):
+    """A stub to use as display context when APIDoc is disabled.
+    """
+
+class apidocNamespace(object):
+    """Used to traverse to an API Documentation."""
+
+    def __init__(self, ob, request=None):
+        self.request = request
+        self.context = ob
+
+    def traverse(self, name, ignore):
+        return APIDocStub()


Property changes on: Zope3/branches/3.3/src/zope/app/apidoc/disabled.py
___________________________________________________________________
Name: svn:keywords
   + Id Rev Date
Name: svn:eol-style
   + native

Added: Zope3/branches/3.3/src/zope/app/apidoc/disabled.zcml
===================================================================
--- Zope3/branches/3.3/src/zope/app/apidoc/disabled.zcml	2006-08-17 13:08:41 UTC (rev 69597)
+++ Zope3/branches/3.3/src/zope/app/apidoc/disabled.zcml	2006-08-17 13:34:17 UTC (rev 69598)
@@ -0,0 +1,20 @@
+<configure
+  xmlns="http://namespaces.zope.org/zope"
+  xmlns:apidoc="http://namespaces.zope.org/apidoc"
+  xmlns:zcml="http://namespaces.zope.org/zcml"
+  i18n_domain="zope">
+
+  <view
+      name="apidoc" type="*"
+      provides="zope.traversing.interfaces.ITraversable" for="*"
+      factory=".disabled.apidocNamespace"
+      />
+  <adapter
+      name="apidoc"
+      provides="zope.traversing.interfaces.ITraversable" for="*"
+      factory=".disabled.apidocNamespace"
+      />
+
+  <include package=".browser" file="disabled.zcml" />
+
+</configure>


Property changes on: Zope3/branches/3.3/src/zope/app/apidoc/disabled.zcml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: Zope3/branches/3.3/src/zope/app/apidoc/enabled.zcml
===================================================================
--- Zope3/branches/3.3/src/zope/app/apidoc/enabled.zcml	2006-08-17 13:08:41 UTC (rev 69597)
+++ Zope3/branches/3.3/src/zope/app/apidoc/enabled.zcml	2006-08-17 13:34:17 UTC (rev 69598)
@@ -0,0 +1,86 @@
+<configure
+  xmlns="http://namespaces.zope.org/zope"
+  xmlns:apidoc="http://namespaces.zope.org/apidoc"
+  xmlns:zcml="http://namespaces.zope.org/zcml"
+  i18n_domain="zope">
+
+  <permission
+      id="zope.app.apidoc.UseAPIDoc"
+      title="[zope.app.apidoc.UseAPIDoc] Access Online API documentation"
+      />
+
+  <class class=".apidoc.APIDocumentation">
+    <require
+        interface="zope.app.container.interfaces.IReadContainer"
+        permission="zope.ManageApplication"
+        />
+  </class>
+
+  <view
+      name="apidoc" type="*"
+      provides="zope.traversing.interfaces.ITraversable" for="*"
+      factory=".apidoc.apidocNamespace"
+      />
+  <adapter
+      name="apidoc"
+      provides="zope.traversing.interfaces.ITraversable" for="*"
+      factory=".apidoc.apidocNamespace"
+      />
+
+  <!-- Register Public API Dcoumentation -->
+
+  <apidoc:bookchapter
+      id="inspect"
+      title="Inspection API"
+      />
+  <apidoc:bookchapter
+      id="interface"
+      title="Interfaces"
+      doc_path="interface.txt"
+      parent="inspect"
+      />
+  <apidoc:bookchapter
+      id="component"
+      title="Components"
+      doc_path="component.txt"
+      parent="inspect"
+      />
+  <apidoc:bookchapter
+      id="presentation"
+      title="Presentation"
+      doc_path="presentation.txt"
+      parent="inspect"
+      />
+  <apidoc:bookchapter
+      id="misc"
+      title="Miscellaneous"
+      doc_path="utilities.txt"
+      parent="inspect"
+      />
+  <apidoc:bookchapter
+      id="classregistry"
+      title="Class Registry"
+      doc_path="classregistry.txt"
+      parent="inspect"
+      />
+
+  <include package=".browser" />
+
+  <preferenceGroup
+      id="apidoc"
+      title="API Doc Tool"
+      description="
+         These are all the preferences related to viewing the API
+         documentation."
+      category="True"
+      />
+
+  <!-- API Documentation Modules -->
+  <include package=".bookmodule" />
+  <include package=".codemodule" />
+  <include package=".ifacemodule" />
+  <include package=".typemodule" />
+  <include package=".utilitymodule" />
+  <include package=".zcmlmodule" />
+
+</configure>


Property changes on: Zope3/branches/3.3/src/zope/app/apidoc/enabled.zcml
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: Zope3/branches/3.3/src/zope/app/onlinehelp/help/welcome.stx
===================================================================
--- Zope3/branches/3.3/src/zope/app/onlinehelp/help/welcome.stx	2006-08-17 13:08:41 UTC (rev 69597)
+++ Zope3/branches/3.3/src/zope/app/onlinehelp/help/welcome.stx	2006-08-17 13:34:17 UTC (rev 69598)
@@ -4,7 +4,7 @@
 
         Other Help / Documentation
 
-              - <a href="/++apidoc++" target="_blank">API Docs</a> (To view this, set _devmode on_ in etc/zope.conf)
+              - <a href="/++apidoc++" target="_blank">API Docs</a>
 
               - <a href="http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/FrontPage" target="_blank">Documentation Wiki</a>
 

Modified: Zope3/branches/3.3/src/zope/app/server/main.py
===================================================================
--- Zope3/branches/3.3/src/zope/app/server/main.py	2006-08-17 13:08:41 UTC (rev 69597)
+++ Zope3/branches/3.3/src/zope/app/server/main.py	2006-08-17 13:34:17 UTC (rev 69598)
@@ -105,6 +105,8 @@
         logging.warning("Developer mode is enabled: this is a security risk "
             "and should NOT be enabled on production servers. Developer mode "
             "can be turned off in etc/zope.conf")
+    else:
+        features += ('nodevmode',)
 
     zope.app.appsetup.config(options.site_definition, features=features)
 

Modified: Zope3/branches/3.3/src/zope/app/twisted/main.py
===================================================================
--- Zope3/branches/3.3/src/zope/app/twisted/main.py	2006-08-17 13:08:41 UTC (rev 69597)
+++ Zope3/branches/3.3/src/zope/app/twisted/main.py	2006-08-17 13:34:17 UTC (rev 69598)
@@ -136,6 +136,8 @@
         logging.warning("Developer mode is enabled: this is a security risk "
             "and should NOT be enabled on production servers. Developer mode "
             "can be turned off in etc/zope.conf")
+    else:
+        features += ('nodevmode',)
 
     zope.app.appsetup.config(options.site_definition, features=features)
 

Modified: Zope3/branches/3.3/src/zope/app/wsgi/__init__.py
===================================================================
--- Zope3/branches/3.3/src/zope/app/wsgi/__init__.py	2006-08-17 13:08:41 UTC (rev 69597)
+++ Zope3/branches/3.3/src/zope/app/wsgi/__init__.py	2006-08-17 13:34:17 UTC (rev 69598)
@@ -123,6 +123,8 @@
         logging.warning("Developer mode is enabled: this is a security risk "
             "and should NOT be enabled on production servers. Developer mode "
             "can be turned off in etc/zope.conf")
+    else:
+        features += ('nodevmode',)
 
     # Configure the application
     appsetup.config(options.site_definition, features=features)



More information about the Zope3-Checkins mailing list