feat: move more subscriber logic to wuttaweb
This commit is contained in:
parent
3b92bb3a9e
commit
9d2684046f
|
@ -52,30 +52,17 @@ def new_request(event):
|
|||
"""
|
||||
Event hook called when processing a new request.
|
||||
|
||||
This first invokes the upstream hook:
|
||||
:func:`wuttaweb:wuttaweb.subscribers.new_request()`
|
||||
This first invokes the upstream hooks:
|
||||
|
||||
* :func:`wuttaweb:wuttaweb.subscribers.new_request()`
|
||||
* :func:`wuttaweb:wuttaweb.subscribers.new_request_set_user()`
|
||||
|
||||
It then adds more things to the request object; among them:
|
||||
|
||||
.. attribute:: request.rattail_config
|
||||
|
||||
Reference to the app :term:`config object`. Note that this
|
||||
will be the same as ``request.wutta_config``.
|
||||
|
||||
.. attribute:: request.user
|
||||
|
||||
Reference to the current authenticated user, or ``None``.
|
||||
|
||||
.. attribute:: request.is_admin
|
||||
|
||||
Flag indicating whether current user is a member of the
|
||||
Administrator role.
|
||||
|
||||
.. attribute:: request.is_root
|
||||
|
||||
Flag indicating whether user is currently elevated to root
|
||||
privileges. This is only possible if ``request.is_admin =
|
||||
True``.
|
||||
will be the same as :attr:`wuttaweb:request.wutta_config`.
|
||||
|
||||
.. method:: request.has_perm(name)
|
||||
|
||||
|
@ -94,10 +81,9 @@ def new_request(event):
|
|||
then in the base template all registered components will be
|
||||
properly loaded.
|
||||
"""
|
||||
# log.debug("new request: %s", event)
|
||||
request = event.request
|
||||
|
||||
# invoke upstream logic
|
||||
# invoke main upstream logic
|
||||
# nb. this sets request.wutta_config
|
||||
base.new_request(event)
|
||||
|
||||
|
@ -109,25 +95,20 @@ def new_request(event):
|
|||
rattail_config = config
|
||||
request.rattail_config = rattail_config
|
||||
|
||||
def user(request):
|
||||
user = None
|
||||
uuid = request.authenticated_userid
|
||||
if uuid:
|
||||
app = request.rattail_config.get_app()
|
||||
model = app.model
|
||||
user = Session.get(model.User, uuid)
|
||||
if user:
|
||||
Session().set_continuum_user(user)
|
||||
return user
|
||||
def user_getter(request, db_session=None):
|
||||
user = base.default_user_getter(request, db_session=db_session)
|
||||
if user:
|
||||
# nb. we also assign continuum user to session
|
||||
session = db_session or Session()
|
||||
session.set_continuum_user(user)
|
||||
return user
|
||||
|
||||
request.set_property(user, reify=True)
|
||||
# invoke upstream hook to set user
|
||||
base.new_request_set_user(event, user_getter=user_getter, db_session=Session())
|
||||
|
||||
# assign client IP address to the session, for sake of versioning
|
||||
Session().continuum_remote_addr = request.client_addr
|
||||
|
||||
request.is_admin = auth.user_is_admin(request.user)
|
||||
request.is_root = request.is_admin and request.session.get('is_root', False)
|
||||
|
||||
# TODO: why would this ever be null?
|
||||
if rattail_config:
|
||||
|
||||
|
@ -286,27 +267,10 @@ def context_found(event):
|
|||
|
||||
The following is attached to the request:
|
||||
|
||||
* ``get_referrer()`` function
|
||||
|
||||
* ``get_session_timeout()`` function
|
||||
"""
|
||||
request = event.request
|
||||
|
||||
def get_referrer(default=None, **kwargs):
|
||||
if request.params.get('referrer'):
|
||||
return request.params['referrer']
|
||||
if request.session.get('referrer'):
|
||||
return request.session.pop('referrer')
|
||||
referrer = request.referrer
|
||||
if (not referrer or referrer == request.current_route_url()
|
||||
or not referrer.startswith(request.host_url)):
|
||||
if default:
|
||||
referrer = default
|
||||
else:
|
||||
referrer = request.route_url('home')
|
||||
return referrer
|
||||
request.get_referrer = get_referrer
|
||||
|
||||
def get_session_timeout():
|
||||
"""
|
||||
Returns the timeout in effect for the current session
|
||||
|
|
Loading…
Reference in a new issue