Fix track_and_log for grant-ed users

This commit is contained in:
Joseph Schorr 2015-11-19 17:40:33 -05:00
parent d8f395447e
commit b49435bfee

View file

@ -4,7 +4,8 @@ import random
from app import analytics, app, userevents
from data import model
from flask import request
from auth.auth_context import get_authenticated_user, get_validated_token, get_validated_oauth_token
from auth.auth_context import (get_authenticated_user, get_validated_token,
get_validated_oauth_token, get_grant_user_context)
logger = logging.getLogger(__name__)
@ -22,6 +23,11 @@ def track_and_log(event_name, repo, analytics_name=None, analytics_sample=1, **k
authenticated_oauth_token = get_validated_oauth_token()
authenticated_user = get_authenticated_user()
authenticated_token = get_validated_token() if not authenticated_user else None
granted_username = get_grant_user_context()
# TODO: Fix this to support OAuth tokens as well.
if granted_username is not None:
authenticated_user = model.user.get_user(granted_username)
logger.debug('Logging the %s to Mixpanel and the log system', event_name)
if authenticated_oauth_token: