[ckan-changes] commit/ckan: thejimmyg: Start of template refactors, checking in to share with Adria

Bitbucket commits-noreply at bitbucket.org
Tue Jul 19 15:31:29 UTC 2011


1 new changeset in ckan:

http://bitbucket.org/okfn/ckan/changeset/f5e5c854bfc1/
changeset:   f5e5c854bfc1
branch:      feature-1094-authz
user:        thejimmyg
date:        2011-07-19 17:30:42
summary:     Start of template refactors, checking in to share with Adria
affected #:  7 files (694 bytes)

--- a/ckan/lib/base.py	Fri Jun 24 15:22:03 2011 +0100
+++ b/ckan/lib/base.py	Tue Jul 19 16:30:42 2011 +0100
@@ -46,11 +46,29 @@
                   headers=headers, 
                   comment=comment)
 
+from ckan.logic import check_access
+
+
 def render(template_name, extra_vars=None, cache_key=None, cache_type=None, 
            cache_expire=None, method='xhtml', loader_class=MarkupTemplate):
     
+    if not extra_vars:
+        extra_vars = {}
+    if not extra_vars.has_key('context'):
+        extra_vars['context'] = {
+            'model': model, 
+            'session': model.Session,
+            'user': c.user or c.author,
+            'extras_as_string': True,
+            'schema': self._form_to_db_schema(),
+        }
+    if not extra_vars.has_key('check_access'):
+        def template_check_access(action, data_dict=None):
+            return check_access(extra_vars['context'], action, data_dict=data_dict)
+        extra_vars['check_access'] = template_check_access
+
     def render_template():
-        globs = extra_vars or {}
+        globs = extra_vars
         globs.update(pylons_globals())
         globs['actions'] = model.Action
         template = globs['app_globals'].genshi_loader.load(template_name,


--- a/ckan/templates/authorization_group/layout.html	Fri Jun 24 15:22:03 2011 +0100
+++ b/ckan/templates/authorization_group/layout.html	Tue Jul 19 16:30:42 2011 +0100
@@ -9,10 +9,10 @@
   <py:match path="minornavigation" py:if="c.authorization_group"><ul class="tabbed"><li>${h.subnav_link(c, h.icon('authorization_group') + _('View'), controller='authorization_group', action='read', id=c.authorization_group.name)}</li>
-    <li py:if="h.am_authorized(c, actions.EDIT, c.authorization_group)">
+    <li py:if="check_access('authorization_group_edit', {'id': c.authorization_group.id})">
       ${h.subnav_link(c, h.icon('authorization_group_edit') + _('Edit'), controller='authorization_group', action='edit', id=c.authorization_group.name)}
     </li>
-    <li py:if="h.am_authorized(c, actions.EDIT_PERMISSIONS, c.authorization_group)">
+    <li py:if="check_access('authorization_group_authz', {'id': c.authorization_group.authz})">
       ${h.subnav_link(c, h.icon('lock') + _('Authorization'), controller='authorization_group', action='authz', id=c.authorization_group.name)}
     </li></ul>


--- a/ckan/templates/group/layout.html	Fri Jun 24 15:22:03 2011 +0100
+++ b/ckan/templates/group/layout.html	Tue Jul 19 16:30:42 2011 +0100
@@ -24,11 +24,11 @@
   <py:match path="minornavigation" py:if="c.group"><ul class="tabbed"><li>${h.subnav_link(c, h.icon('group') + _('View'), controller='group', action='read', id=c.group.name)}</li>
-    <li py:if="h.am_authorized(c, actions.EDIT, c.group)">
+    <li py:if="check_access('group_edit', {'id': c.group.id})">
       ${h.subnav_link(c, h.icon('group_edit') + _('Edit'), controller='group', action='edit', id=c.group.name)}
     </li><li>${h.subnav_link(c, h.icon('page_white_stack') + _('History'), controller='group', action='history', id=c.group.name)}</li>
-    <li py:if="h.am_authorized(c, actions.EDIT_PERMISSIONS, c.group)">
+    <li py:if="check_access('group_authz', {'id': c.group.id})">
       ${h.subnav_link(c, h.icon('lock') + _('Authorization'), controller='group', action='authz', id=c.group.name)}
     </li></ul>


--- a/ckan/templates/package/layout.html	Fri Jun 24 15:22:03 2011 +0100
+++ b/ckan/templates/package/layout.html	Tue Jul 19 16:30:42 2011 +0100
@@ -9,11 +9,11 @@
     <py:if test="c.pkg"><ul class="tabbed"><li>${h.subnav_link(c, h.icon('package') + _('View'), controller='package', action='read', id=c.pkg.name)}</li>
-      <li py:if="h.am_authorized(c, actions.EDIT, c.pkg)">
+      <li py:if="check_access('package_edit', {'id': c.pkg.id})">
           ${h.subnav_link(c, h.icon('package_edit') + _('Edit'), controller='package', action='edit', id=c.pkg.name)}
       </li><li>${h.subnav_link(c, h.icon('page_white_stack') + _('History'), controller='package', action='history', id=c.pkg.name)}</li>
-      <li py:if="h.am_authorized(c, actions.EDIT_PERMISSIONS, c.pkg)">
+      <li py:if="check_access('package_authz', {'id': c.pkg.id})">
         ${h.subnav_link(c, h.icon('lock') + _('Authorization'), controller='package', action='authz', id=c.pkg.name)}
       </li></ul>


--- a/ckan/templates/package/read.html	Fri Jun 24 15:22:03 2011 +0100
+++ b/ckan/templates/package/read.html	Tue Jul 19 16:30:42 2011 +0100
@@ -17,7 +17,7 @@
     <li class="widget-container widget_text"><h3>Tags</h3>
         ${tag_list(c.pkg_dict.get('tags', ''))}
-        <p class="widget_action" py:if="h.am_authorized(c, actions.EDIT, c.pkg)">
+        <p class="widget_action" py:if="check_access('package_edit', {'id': c.pkg.id})">
             ${h.subnav_link(c, 'Add a new Tag', controller='package', action='edit', id=c.pkg.name)}
         </p></li>
@@ -34,7 +34,7 @@
         <py:if test="not c.pkg.groups">
              Groups are collections of packages maintained by users of ${g.site_title}. This package has not been added to any groups yet.
         </py:if>
-        <p class="widget_action" py:if="h.am_authorized(c, actions.EDIT, c.pkg)">
+        <p class="widget_action" py:if="check_access('pacakge_edit', {'id': c.pkg.id})">
             ${h.subnav_link(c, 'Add to a Group', controller='package', action='edit', id=c.pkg.name)}        
         </p></li>


--- a/ckan/templates/package/read_core.html	Fri Jun 24 15:22:03 2011 +0100
+++ b/ckan/templates/package/read_core.html	Tue Jul 19 16:30:42 2011 +0100
@@ -103,7 +103,7 @@
           <td class="package-details">${value}</td></tr></tbody>
-          <caption py:if="h.am_authorized(c, actions.EDIT, c.pkg)">
+          <caption py:if="check_access('package_edit', {'id': c.pkg.id})">
               Something missing? ${h.subnav_link(c, 'Please help improve this page by adding more information', controller='package', action='edit', id=c.pkg.name)}.
           </caption></table>
@@ -146,7 +146,7 @@
     </div><ul>
-      <py:if test="h.am_authorized(c, actions.CHANGE_STATE, c.pkg)">
+      <py:if test="c.user.sysadmin"><li><strong>State:</strong> ${c.pkg.state}</li></py:if></ul>


--- a/ckan/templates/package/search.html	Fri Jun 24 15:22:03 2011 +0100
+++ b/ckan/templates/package/search.html	Tue Jul 19 16:30:42 2011 +0100
@@ -10,7 +10,7 @@
 
   <py:match path="primarysidebar">
     
-    <li class="widget-container widget_text" py:if="h.am_authorized(c, actions.PACKAGE_CREATE)">
+    <li class="widget-container widget_text" py:if="check_access('package_create')"><h4>Add a package</h4><p>
             Do you know of a dataset that should be added to ${g.site_title}?

Repository URL: https://bitbucket.org/okfn/ckan/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list