Author: jure
Date: Wed Mar 13 16:03:17 2013
New Revision: 1456015
URL: http://svn.apache.org/r1456015
Log:
Request cross-product permission check method added
Modified:
incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/hooks.py
incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_theme/bhtheme/theme.py
Modified:
incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/hooks.py
URL:
http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/hooks.py?rev=1456015&r1=1456014&r2=1456015&view=diff
==============================================================================
---
incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/hooks.py
(original)
+++
incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/hooks.py
Wed Mar 13 16:03:17 2013
@@ -24,6 +24,8 @@ import re
from trac.hooks import EnvironmentFactoryBase, RequestFactoryBase
from trac.web.main import RequestWithSession
from trac.web.href import Href
+from trac.perm import PermissionCache
+from trac.core import TracError
PRODUCT_RE = re.compile(r'^/products/(?P<pid>[^/]*)(?P<pathinfo>.*)')
@@ -79,6 +81,18 @@ class ProductRequestWithSession(RequestW
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,
ProductEnvironmentFactory
+ if isinstance(self.perm.env, Environment):
+ return PermissionCache(ProductEnvironmentFactory(self.perm.env,
product),
+ username=self.authname, resource=resource)
+ elif isinstance(self.perm.env, ProductEnvironment):
+ return
PermissionCache(ProductEnvironmentFactory(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):
if isinstance(env, multiproduct.env.ProductEnvironment):
Modified:
incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_theme/bhtheme/theme.py
URL:
http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_theme/bhtheme/theme.py?rev=1456015&r1=1456014&r2=1456015&view=diff
==============================================================================
---
incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_theme/bhtheme/theme.py
(original)
+++
incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_theme/bhtheme/theme.py
Wed Mar 13 16:03:17 2013
@@ -349,11 +349,7 @@ class BloodhoundTheme(ThemeBase):
if is_product_scope:
# Per-product permissions only work when checking them against
# the appropriate ProductEnvironment (i.e. not cross-product).
- # Reaquest's permissions are thus copied and associated with
- # another ProductEnvironment for each check.
- perm = copy.copy(req.perm)
- perm.env = ProductEnvironmentFactory(product._env.parent,
product.prefix)
- if 'PRODUCT_VIEW' in perm(product.resource):
+ if 'PRODUCT_VIEW' in req.product_perm(product.prefix,
product.resource):
product_list.append(product)
else:
product_list.append(product)