Commits

Olemis Lang committed d298c48

BH Multiproduct #492 : Suggested replacement for req.product_perm

Comments (0)

Files changed (3)

 t492/t492_r1462792_neighborhood_web_chrome.diff
 t492/t492_r1465566_null_neighborhood.diff
 t492/t492_r1465566_neighborhood_perm.diff
+t492/t492_r1465566_req_product_perm_v2.diff

t492/t492_r1465566_neighborhood_perm.diff

 
 diff -r f4c58d044848 bloodhound_multiproduct/multiproduct/api.py
 --- a/bloodhound_multiproduct/multiproduct/api.py	Mon Apr 08 21:21:41 2013 -0500
-+++ b/bloodhound_multiproduct/multiproduct/api.py	Tue Apr 09 01:39:56 2013 -0500
++++ b/bloodhound_multiproduct/multiproduct/api.py	Tue Apr 09 02:28:57 2013 -0500
 @@ -515,12 +515,12 @@
          elif neighborhood._realm == 'product':
              prefix = neighborhood._id
      def manager_exists(self, neighborhood):
 diff -r f4c58d044848 bloodhound_multiproduct/tests/perm.py
 --- a/bloodhound_multiproduct/tests/perm.py	Mon Apr 08 21:21:41 2013 -0500
-+++ b/bloodhound_multiproduct/tests/perm.py	Tue Apr 09 01:39:56 2013 -0500
++++ b/bloodhound_multiproduct/tests/perm.py	Tue Apr 09 02:28:57 2013 -0500
 @@ -23,11 +23,13 @@
  
  from trac.admin.api import AdminCommandError
      suite.addTest(unittest.makeSuite(SudoTestCase, 'test'))
 diff -r f4c58d044848 trac/trac/perm.py
 --- a/trac/trac/perm.py	Mon Apr 08 21:21:41 2013 -0500
-+++ b/trac/trac/perm.py	Tue Apr 09 01:39:56 2013 -0500
++++ b/trac/trac/perm.py	Tue Apr 09 02:28:57 2013 -0500
 @@ -26,7 +26,8 @@
  from trac.cache import cached
  from trac.config import ExtensionOption, OrderedExtensionsOption
          for policy in self.policies:
              decision = policy.check_permission(action, username, resource,
                                                 perm)
-@@ -521,6 +534,9 @@
+@@ -521,6 +534,10 @@
  
      def __init__(self, env, username=None, resource=None, cache=None,
                   groups=None):
 +        if resource and resource.neighborhood is not None:
 +            env = manager_for_neighborhood(env, resource.neighborhood)
 +            resource = Neighborhood(None, None).child(resource)
++            cache = None
          self.env = env
          self.username = username or 'anonymous'
          self._resource = resource
-@@ -563,11 +579,17 @@
+@@ -563,11 +580,17 @@
              if resource == cache_resource:
                  return cache_decision
          perm = self
  
 diff -r f4c58d044848 trac/trac/resource.py
 --- a/trac/trac/resource.py	Mon Apr 08 21:21:41 2013 -0500
-+++ b/trac/trac/resource.py	Tue Apr 09 01:39:56 2013 -0500
++++ b/trac/trac/resource.py	Tue Apr 09 02:28:57 2013 -0500
 @@ -540,28 +540,6 @@
                                     (neighborhood,))
          return c.load_manager(neighborhood)

t492/t492_r1465566_req_product_perm_v2.diff

+# HG changeset patch
+# Parent 260e0b6d66651215e377aef1863af61f27d6817e
+BH Multiproduct #492 : Implement req.product_perm in terms of Neighborhoods
+
+diff -r 260e0b6d6665 bloodhound_dashboard/bhdashboard/widgets/product.py
+--- a/bloodhound_dashboard/bhdashboard/widgets/product.py	Tue Apr 09 01:39:56 2013 -0500
++++ b/bloodhound_dashboard/bhdashboard/widgets/product.py	Tue Apr 09 02:28:17 2013 -0500
+@@ -26,6 +26,7 @@
+ 
+ import itertools
+ 
++from trac.resource import Neighborhood
+ from trac.util.translation import _
+ from trac.ticket.model import Milestone, Component, Version
+ from trac.ticket.query import Query
+@@ -117,7 +118,7 @@
+ 
+         if not isinstance(req.perm.env, ProductEnvironment):
+             for p in Product.select(self.env):
+-                if 'PRODUCT_VIEW' in req.product_perm(p.prefix):
++                if 'PRODUCT_VIEW' in req.perm(Neighborhood('product', p.prefix)):
+                     for resource in (
+                         { 'type': Milestone, 'name': 'milestone', 'hrefurl': True },
+                         { 'type': Component, 'name': 'component' },
+diff -r 260e0b6d6665 bloodhound_multiproduct/multiproduct/hooks.py
+--- a/bloodhound_multiproduct/multiproduct/hooks.py	Tue Apr 09 01:39:56 2013 -0500
++++ b/bloodhound_multiproduct/multiproduct/hooks.py	Tue Apr 09 02:28:17 2013 -0500
+@@ -85,17 +85,6 @@
+             self.href = ProductizedHref(self.href, env.href.base)
+             self.abs_href = ProductizedHref(self.abs_href, env.abs_href.base)
+ 
+-    def product_perm(self, product, resource=None):
+-        """Helper for per product permissions"""
+-        from multiproduct.env import Environment, ProductEnvironment
+-        if isinstance(self.perm.env, Environment):
+-            return PermissionCache(ProductEnvironment(self.perm.env, product),
+-                                   username=self.authname, resource=resource)
+-        elif isinstance(self.perm.env, ProductEnvironment):
+-            return PermissionCache(ProductEnvironment(self.perm.env.parent, product),
+-                                   username=self.authname, resource=resource)
+-        else:
+-            raise TracError("Internal error, product permissions evaluated on invalid environment.")
+ 
+ class ProductRequestFactory(RequestFactoryBase):
+     def create_request(self, env, environ, start_response):
+diff -r 260e0b6d6665 bloodhound_multiproduct/multiproduct/web_ui.py
+--- a/bloodhound_multiproduct/multiproduct/web_ui.py	Tue Apr 09 01:39:56 2013 -0500
++++ b/bloodhound_multiproduct/multiproduct/web_ui.py	Tue Apr 09 02:28:17 2013 -0500
+@@ -26,7 +26,7 @@
+ from genshi.core import Attrs, QName
+ 
+ from trac.core import Component, implements, TracError
+-from trac.resource import Resource, ResourceNotFound
++from trac.resource import Neighborhood, Resource, ResourceNotFound
+ from trac.util.translation import _
+ from trac.web.api import IRequestFilter, IRequestHandler, Request, HTTPNotFound
+ from trac.web.chrome import (add_link, add_notice, add_warning, prevnext_nav,
+@@ -174,7 +174,8 @@
+         action = req.args.get('action', 'view')
+         
+         products = [p for p in Product.select(self.env)
+-                    if 'PRODUCT_VIEW' in req.product_perm(p.prefix)]
++                    if 'PRODUCT_VIEW' in req.perm(Neighborhood('product',
++                                                               p.prefix))]
+         
+         if pid is not None:
+             add_link(req, 'up', req.href.products(), _('Products'))
+diff -r 260e0b6d6665 bloodhound_theme/bhtheme/theme.py
+--- a/bloodhound_theme/bhtheme/theme.py	Tue Apr 09 01:39:56 2013 -0500
++++ b/bloodhound_theme/bhtheme/theme.py	Tue Apr 09 02:28:17 2013 -0500
+@@ -27,7 +27,7 @@
+ from trac.core import *
+ from trac.config import ListOption
+ from trac.mimeview.api import get_mimetype
+-from trac.resource import Resource
++from trac.resource import Neighborhood, Resource
+ from trac.ticket.api import TicketSystem
+ from trac.ticket.model import Ticket, Milestone
+ from trac.ticket.notification import TicketNotifyEmail
+@@ -354,7 +354,8 @@
+             href_fcn = req.href.products
+         product_list = []
+         for product in Product.select(self.env):
+-            if 'PRODUCT_VIEW' in req.product_perm(product.prefix, product.resource):
++            if 'PRODUCT_VIEW' in req.perm(Neighborhood('product', prefix),
++                                          product.resource):
+                 product_list.append((product.prefix, product.name,
+                     href_fcn(product.prefix)))
+         return product_list