Permalink
Browse files

add "user" attribute to the request. add request_cache decorator to g…

…et_user.
  • Loading branch information...
1 parent 084de37 commit b5cf7c980675565b3de9e9c0276bc109e38ecc39 @disko disko committed May 24, 2012
Showing with 16 additions and 2 deletions.
  1. +13 −0 kotti/__init__.py
  2. +1 −0 kotti/security.py
  3. +2 −2 kotti/views/cache.py
View
@@ -34,12 +34,15 @@ def authtkt_factory(**settings):
return AuthTktAuthenticationPolicy(
secret=settings['kotti.secret2'], callback=list_groups_callback)
+
def acl_factory(**settings):
return ACLAuthorizationPolicy()
+
def beaker_session_factory(**settings):
return session_factory_from_settings(settings)
+
def none_factory(**kwargs): # pragma: no cover
return None
@@ -80,9 +83,11 @@ def none_factory(**kwargs): # pragma: no cover
'kotti.caching_policy_chooser',
])
+
def get_version():
return pkg_resources.require("Kotti")[0].version
+
@request_cache(lambda: None)
def get_settings():
from kotti.resources import Settings
@@ -95,6 +100,7 @@ def get_settings():
else:
return get_current_registry().settings
+
def _resolve_dotted(d, keys=conf_dotted):
for key in keys:
value = d[key]
@@ -105,13 +111,15 @@ def _resolve_dotted(d, keys=conf_dotted):
new_value.append(DottedNameResolver(None).resolve(dottedname))
d[key] = new_value
+
def main(global_config, **settings):
""" This function is a 'paste.app_factory' and returns a WSGI
application.
"""
config = base_configure(global_config, **settings)
return config.make_wsgi_app()
+
def base_configure(global_config, **settings):
"""Resolve dotted names in settings, include plug-ins and create a
Configurator.
@@ -166,8 +174,13 @@ def base_configure(global_config, **settings):
engine = engine_from_config(settings, 'sqlalchemy.')
config._set_root_factory(appmaker(engine))
+ # add the authenticated user to the request object
+ from kotti.security import get_user
+ config.set_request_property(get_user, name="user", reify=True)
+
return config
+
def includeme(config):
import kotti.views.util
View
@@ -30,6 +30,7 @@ def get_principals():
return get_settings()['kotti.principals_factory'][0]()
+@request_cache(lambda request: None)
def get_user(request):
userid = authenticated_userid(request)
return get_principals().get(userid)
View
@@ -4,9 +4,9 @@
from pyramid.events import subscriber
from pyramid.events import NewResponse
from pyramid.response import FileResponse
-from pyramid.security import authenticated_userid
from kotti import get_settings
+from kotti.security import get_user
CACHE_POLICY_HEADER = 'x-caching-policy'
@@ -79,7 +79,7 @@ def default_caching_policy_chooser(context, request, response):
return None
elif isinstance(response, FileResponse):
return 'Cache Resource'
- elif authenticated_userid(request) is not None:
+ elif get_user(request) is not None:
return 'No Cache'
elif response.headers['content-type'].startswith('text/html'):
return 'Cache HTML'

0 comments on commit b5cf7c9

Please sign in to comment.