Create stub User object for API to use permissions model

This commit is contained in:
Arik Fraimovich 2014-04-06 20:05:43 +03:00
parent 5de1795380
commit 0167bebf04
2 changed files with 10 additions and 0 deletions

View File

@ -40,6 +40,7 @@ class HMACAuthentication(object):
calculated_signature = sign(query.api_key, request.path, expires)
if query.api_key and signature == calculated_signature:
login_user(models.ApiUser(query.api_key), remember=False)
return True
return False

View File

@ -22,6 +22,15 @@ class AnonymousUser(AnonymousUserMixin):
return []
class ApiUser(UserMixin):
def __init__(self, api_key):
self.id = api_key
@property
def permissions(self):
return ['view_query']
class User(BaseModel, UserMixin):
DEFAULT_PERMISSIONS = ['create_dashboard', 'create_query', 'edit_dashboard', 'edit_query',
'view_query', 'view_source', 'execute_query']