[Checkins] SVN: grok/trunk/src/grok/ Fix https://launchpad.net/grok/+bug/82918:

Philipp von Weitershausen philikon at philikon.de
Wed Feb 7 07:04:49 EST 2007


Log message for revision 72419:
  Fix https://launchpad.net/grok/+bug/82918:
  IPermission mandates unicode objects for permission ids and titles.
  

Changed:
  A   grok/trunk/src/grok/ftests/security/grant.py
  U   grok/trunk/src/grok/meta.py

-=-
Added: grok/trunk/src/grok/ftests/security/grant.py
===================================================================
--- grok/trunk/src/grok/ftests/security/grant.py	2007-02-07 11:48:58 UTC (rev 72418)
+++ grok/trunk/src/grok/ftests/security/grant.py	2007-02-07 12:04:48 UTC (rev 72419)
@@ -0,0 +1,31 @@
+# -*- coding: latin-1 -*-
+"""
+We can define a few permissions with grok.define_permission:
+
+  >>> import grok
+  >>> grok.grok('grok.ftests.security.grant')
+
+and then take a look at them in Zope 3's grant view:
+
+  >>> from zope.testbrowser.testing import Browser
+  >>> browser = Browser()
+  >>> browser.handleErrors = False
+
+  >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+  >>> browser.open("http://localhost/@@grant.html")
+
+  >>> browser.getControl(name='field.principal.MA__.searchstring').value = 'manager'
+  >>> browser.getControl('Search').click()
+  >>> browser.getControl('Apply').click()
+  >>> 'grok.ascii-permission' in browser.contents
+  True
+
+"""
+import grok
+grok.define_permission('grok.ascii-permission')
+
+# TODO Technically, it's absolutely possible to give permissions
+# non-ASCII names. However the way Zope 3's grant view uses widgets to
+# display form controls for each permission is not unicode-safe.
+
+#grok.define_permission(u'grok.ünicöde-permission')


Property changes on: grok/trunk/src/grok/ftests/security/grant.py
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: grok/trunk/src/grok/meta.py
===================================================================
--- grok/trunk/src/grok/meta.py	2007-02-07 11:48:58 UTC (rev 72418)
+++ grok/trunk/src/grok/meta.py	2007-02-07 12:04:48 UTC (rev 72419)
@@ -430,8 +430,14 @@
     def register(self, context, module_info, templates):
         permissions = module_info.getAnnotation('grok.define_permission', [])
         for permission in permissions:
+            # IPermission.title says that permission ids (and titles,
+            # descriptions) *must* be unicode objects.  Good news is
+            # that the directive handler already made sure we either
+            # got pure ASCII or unicode here:
+            permission = unicode(permission)
             # TODO permission title and description
-            component.provideUtility(Permission(permission), name=permission)
+            component.provideUtility(Permission(permission, title=permission),
+                                     name=permission)
 
 
 class AnnotationGrokker(grok.ClassGrokker):



More information about the Checkins mailing list