get user perms or create them on login

This commit is contained in:
dandds 2018-07-18 10:44:42 -04:00
parent ac150d1af3
commit 0c0aa44468
2 changed files with 56 additions and 42 deletions

View File

@ -24,9 +24,16 @@ class BaseHandler(tornado.web.RequestHandler):
@tornado.gen.coroutine @tornado.gen.coroutine
def _get_user_permissions(self, user_id): def _get_user_permissions(self, user_id):
response = yield self.authz_client.post( response = yield self.authz_client.get(
"/users", json={"id": user_id, "atat_role": "ccpo"} "/users/{}".format(user_id), raise_error=False
) )
if response.code == 404:
response = yield self.authz_client.post(
"/users", json={"id": user_id, "atat_role": "developer"}
)
return response.json
else:
return response.json return response.json
def get_current_user(self): def get_current_user(self):

View File

@ -5,6 +5,7 @@ from atst.api_client import ApiClient
class MockApiClient(ApiClient): class MockApiClient(ApiClient):
def __init__(self, service): def __init__(self, service):
self.service = service self.service = service
@ -43,6 +44,7 @@ class MockApiClient(ApiClient):
class MockRequestsClient(MockApiClient): class MockRequestsClient(MockApiClient):
@tornado.gen.coroutine @tornado.gen.coroutine
def get(self, path, **kwargs): def get(self, path, **kwargs):
json = { json = {
@ -64,9 +66,7 @@ class MockRequestsClient(MockApiClient):
class MockAuthzClient(MockApiClient): class MockAuthzClient(MockApiClient):
@tornado.gen.coroutine _json = {
def post(self, path, **kwargs):
json = {
"atat_permissions": [ "atat_permissions": [
"view_original_jedi_request", "view_original_jedi_request",
"review_and_approve_jedi_workspace_request", "review_and_approve_jedi_workspace_request",
@ -104,4 +104,11 @@ class MockAuthzClient(MockApiClient):
"username": None, "username": None,
"workspace_roles": [], "workspace_roles": [],
} }
return self._get_response("POST", path, 200, json=json)
@tornado.gen.coroutine
def post(self, path, **kwargs):
return self._get_response("POST", path, 200, json=self._json)
@tornado.gen.coroutine
def get(self, path, **kwargs):
return self._get_response("POST", path, 200, json=self._json)