Skip to content

Commit fdcbca3

Browse files
committed
OpenConceptLab/ocl_online#31 | Added superuser token to report analytics API
1 parent 018f251 commit fdcbca3

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

core/middlewares/middlewares.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,15 @@ class AnalyticsMiddleware(BaseMiddleware):
169169
def __call__(self, request):
170170
start = time.monotonic()
171171
response = self.get_response(request)
172-
if request.path.rstrip("/") not in ['', '/swagger', '/redoc', '/version', '/toggles']:
172+
path = request.path
173+
174+
ignore_any_under_paths = ['/users/login/', '/users/logout/', '/users/signup/']
175+
ignore_paths = [
176+
'', '/swagger', '/redoc', '/version', '/toggles', '/users/oidc/code-exchange', '/favicon.ico',
177+
'/users/api-token', '/users/password/reset', '/user',
178+
*[p.rstrip('/') for p in ignore_any_under_paths]
179+
]
180+
if path.rstrip("/") not in ignore_paths and not any(path.startswith(p) for p in ignore_any_under_paths):
173181
duration_ms = int((time.monotonic() - start) * 1000)
174182
AnalyticsEventEmitter(request, response, duration_ms).emit()
175183
return response

core/services/analytics_event_emitter.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ def _build_payload(self):
9393

9494
def _send(self, payload):
9595
try:
96-
requests.post(self.ANALYTICS_ENDPOINT, json=payload, timeout=self.TIMEOUT_SECONDS)
96+
requests.post(
97+
self.ANALYTICS_ENDPOINT,
98+
json=payload,
99+
timeout=self.TIMEOUT_SECONDS,
100+
headers={'Authorization': f'Token {settings.API_SUPERUSER_TOKEN}'}
101+
)
97102
except Exception as exc:
98103
logger.debug("Analytics emit failed: %s", exc)
99104

0 commit comments

Comments
 (0)