2016-10-13 17:05:37 +01:00
|
|
|
from flask_login import current_user
|
2016-11-30 17:00:42 +00:00
|
|
|
from flask import has_request_context, request
|
|
|
|
|
from notifications_python_client.base import BaseAPIClient
|
|
|
|
|
from notifications_python_client.version import __version__
|
2016-04-15 11:08:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def _attach_current_user(data):
|
2016-08-11 14:20:43 +01:00
|
|
|
return dict(
|
|
|
|
|
created_by=current_user.id,
|
|
|
|
|
**data
|
|
|
|
|
)
|
2016-11-30 17:00:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class NotifyAdminAPIClient(BaseAPIClient):
|
|
|
|
|
def generate_headers(self, api_token):
|
|
|
|
|
headers = {
|
|
|
|
|
"Content-type": "application/json",
|
|
|
|
|
"Authorization": "Bearer {}".format(api_token),
|
|
|
|
|
"User-agent": "NOTIFY-API-PYTHON-CLIENT/{}".format(__version__)
|
|
|
|
|
}
|
|
|
|
|
return self._add_request_id_header(headers)
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def _add_request_id_header(headers):
|
|
|
|
|
if not has_request_context():
|
|
|
|
|
return headers
|
|
|
|
|
headers['NotifyRequestID'] = request.request_id
|
|
|
|
|
return headers
|