mirror of
https://github.com/valitydev/redash.git
synced 2024-11-07 01:25:16 +00:00
Fix: event reporting breaks when using ApiUser.
This commit is contained in:
parent
0ec8c3e0b9
commit
c3299ff0e6
@ -62,7 +62,7 @@ def hmac_load_user_from_request(request):
|
||||
calculated_signature = sign(query.api_key, request.path, expires)
|
||||
|
||||
if query.api_key and signature == calculated_signature:
|
||||
return models.ApiUser(query.api_key, query.org, query.groups.keys())
|
||||
return models.ApiUser(query.api_key, query.org, query.groups.keys(), name="ApiKey: Query {}".format(query.id))
|
||||
|
||||
return None
|
||||
|
||||
@ -84,7 +84,7 @@ def get_user_from_api_key(api_key, query_id):
|
||||
if query_id:
|
||||
query = models.Query.get_by_id_and_org(query_id, current_org.id)
|
||||
if query and query.api_key == api_key:
|
||||
user = models.ApiUser(api_key, query.org, query.groups.keys())
|
||||
user = models.ApiUser(api_key, query.org, query.groups.keys(), name="ApiKey: Query {}".format(query.id))
|
||||
|
||||
return user
|
||||
|
||||
|
@ -35,7 +35,7 @@ class BaseResource(Resource):
|
||||
def record_event(self, options):
|
||||
if isinstance(self.current_user, ApiUser):
|
||||
options.update({
|
||||
'api_key': self.current_user.id,
|
||||
'api_key': self.current_user.name,
|
||||
'org_id': self.current_org.id
|
||||
})
|
||||
else:
|
||||
|
@ -114,7 +114,7 @@ class QueryResultResource(BaseResource):
|
||||
'org_id': self.current_org.id,
|
||||
'action': 'api_get',
|
||||
'timestamp': int(time.time()),
|
||||
'api_key': self.current_user.id,
|
||||
'api_key': self.current_user.name,
|
||||
'file_type': filetype,
|
||||
'user_agent': request.user_agent.string,
|
||||
'ip': request.remote_addr
|
||||
|
@ -145,19 +145,20 @@ class AnonymousUser(AnonymousUserMixin, PermissionsCheckMixin):
|
||||
|
||||
|
||||
class ApiUser(UserMixin, PermissionsCheckMixin):
|
||||
def __init__(self, api_key, org, groups):
|
||||
def __init__(self, api_key, org, groups, name=None):
|
||||
self.object = None
|
||||
if isinstance(api_key, basestring):
|
||||
self.id = api_key
|
||||
self.name = name
|
||||
else:
|
||||
self.id = api_key.api_key
|
||||
self.name = "ApiKey: {}".format(api_key.id)
|
||||
self.object = api_key.object
|
||||
# self.name =
|
||||
self.groups = groups
|
||||
self.org = org
|
||||
|
||||
def __repr__(self):
|
||||
return u"<ApiUser: {}>".format(self.id)
|
||||
return u"<{}>".format(self.name)
|
||||
|
||||
@property
|
||||
def permissions(self):
|
||||
@ -315,7 +316,7 @@ class User(ModelTimestampsMixin, BaseModel, BelongsToOrgMixin, UserMixin, Permis
|
||||
@classmethod
|
||||
def all(cls, org):
|
||||
return cls.select().where(cls.org == org)
|
||||
|
||||
|
||||
@classmethod
|
||||
def find_by_email(cls, email):
|
||||
return cls.select().where(cls.email == email)
|
||||
|
Loading…
Reference in New Issue
Block a user