mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 14:09:20 -04:00
Add load org before request to allow current_org to be accessible from request context
This commit is contained in:
@@ -142,6 +142,7 @@ def init_app(application):
|
||||
application.after_request(useful_headers_after_request)
|
||||
application.after_request(save_service_after_request)
|
||||
application.before_request(load_service_before_request)
|
||||
application.before_request(load_organisation_before_request)
|
||||
application.before_request(request_helper.check_proxy_header_before_request)
|
||||
|
||||
@application.before_request
|
||||
@@ -405,6 +406,29 @@ def load_service_before_request():
|
||||
raise
|
||||
|
||||
|
||||
def load_organisation_before_request():
|
||||
if '/static/' in request.url:
|
||||
_request_ctx_stack.top.organisation = None
|
||||
return
|
||||
if _request_ctx_stack.top is not None:
|
||||
_request_ctx_stack.top.organisation = None
|
||||
|
||||
if request.view_args:
|
||||
org_id = request.view_args.get('org_id', session.get('org_id'))
|
||||
else:
|
||||
org_id = session.get('org_id')
|
||||
|
||||
if org_id:
|
||||
try:
|
||||
_request_ctx_stack.top.organisation = organisations_client.get_organisation(org_id)
|
||||
except HTTPError as exc:
|
||||
# if org id isn't real, then 404 rather than 500ing later because we expect org to be set
|
||||
if exc.status_code == 404:
|
||||
abort(404)
|
||||
else:
|
||||
raise
|
||||
|
||||
|
||||
def save_service_after_request(response):
|
||||
# Only save the current session if the request is 200
|
||||
service_id = request.view_args.get('service_id', None) if request.view_args else None
|
||||
|
||||
Reference in New Issue
Block a user