<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: zope code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Mon, 18 Aug 2008 07:16:13 GMT</pubDate>
    <description>DZone Snippets: zope code</description>
    <item>
      <title>Check that a user has permission on all parents in Zope</title>
      <link>http://snippets.dzone.com/posts/show/484</link>
      <description>If you need to be sure that a user can view an object, you need to check the View permission not only on the object but also all of its parents.  To do this, I slightly modified the script at http://zopelabs.com/cookbook/1018022911 so that it uses the context object and specified the View permission.&lt;br /&gt;&lt;br /&gt;Create a Python script in your acquisition path (I used portal_skins/custom) named can_view and paste in this code:&lt;br /&gt;&lt;code&gt;permission = "View"&lt;br /&gt;try:&lt;br /&gt;  object=context&lt;br /&gt;  if not object.acquiredRolesAreUsedBy( permission ):&lt;br /&gt;    for p in object.rolesOfPermission( permission ):&lt;br /&gt;      if p['selected']:&lt;br /&gt;        if p['name'] in user.getRoles():&lt;br /&gt;          return 1&lt;br /&gt;  else:&lt;br /&gt;   return 1&lt;br /&gt;except:&lt;br /&gt;    pass&lt;br /&gt;return 0&lt;br /&gt;&lt;/code&gt;Then you can check the permission in TAL like this:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;div tal:condition="some_object/can_view"&gt;&lt;br /&gt;  ...&lt;br /&gt;&lt;/div&gt;</description>
      <pubDate>Tue, 19 Jul 2005 22:41:19 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/484</guid>
      <author>georgehotelling (George Hotelling)</author>
    </item>
  </channel>
</rss>
