Skip to content

Commit

Permalink
OS-8014. Changed user_id param to email in list invites
Browse files Browse the repository at this point in the history
  • Loading branch information
nk-hystax authored Dec 2, 2024
1 parent 978747d commit a03b421
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions optscale_client/rest_api_client/client_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,10 @@ def invite_url(id=None):
def invite_create(self, params):
return self.post(self.invite_url(), params)

def invite_list(self, organization_id=None, user_id=None):
def invite_list(self, organization_id=None, email=None):
params = {
"organization_id": organization_id,
"user_id": user_id
"email": email
}
return self.get(self.invite_url() + self.query_url(**params))

Expand Down
7 changes: 3 additions & 4 deletions rest_api/rest_api_server/controllers/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,11 @@ def delete_invite(self, invite):
invite_assignment.deleted_at = opttime.utcnow_timestamp()
super().delete(invite.id)

def list(self, organization_id=None, user_id=None):
def list(self, organization_id=None, email=None):
query = self.session.query(self.model_type).filter(
self.model_type.deleted_at == 0)
if user_id:
user_info = self.get_user_info(user_id)
query = query.filter(self.model_type.email == user_info['email'])
if email:
query = query.filter(self.model_type.email == email)
if organization_id:
pool_query = self.session.query(Pool.id).filter(
Pool.deleted_at == 0,
Expand Down
13 changes: 8 additions & 5 deletions rest_api/rest_api_server/handlers/v2/invites.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ async def get(self):
"""
---
description: |
Get list of invites for current user by token
Get list of invites. If used with token returns invites for current
user.
Required permission: TOKEN or CLUSTER_SECRET
tags: [invites]
summary: List of invites
Expand All @@ -229,10 +230,10 @@ async def get(self):
description: Organization id to filter
required: false
type: string
- name: user_id
- name: email
in: query
type: string
description: User id to filter (only with CLUSTER_SECRET)
description: invite target email (only with CLUSTER_SECRET)
required: false
responses:
200:
Expand Down Expand Up @@ -291,11 +292,13 @@ async def get(self):
- secret: []
"""
if self.check_cluster_secret(raises=False):
user_id = self.get_arg('user_id', str, None)
email = self.get_arg('email', str, None)
else:
user_id = await self.check_self_auth()
user_info = await self.get_user_info(user_id)
email = user_info['email']
organization_id = self.get_arg('organization_id', str, None)
res = await run_task(self.controller.list, organization_id, user_id)
res = await run_task(self.controller.list, organization_id, email)
invites = {'invites': [invite.to_dict() for invite in res]}
self.write(json.dumps(invites, cls=ModelEncoder))

Expand Down
4 changes: 2 additions & 2 deletions rest_api/rest_api_server/tests/unittests/test_invite_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,13 @@ def test_list_by_secret(self):
self.assertEqual(code, 200)
self.assertEqual(len(response['invites']), 2)

def test_list_user_id(self):
def test_list_by_email(self):
patch('rest_api.rest_api_server.handlers.v1.base.BaseAuthHandler.'
'check_cluster_secret', return_value=True).start()
code, response = self.client.invite_create(self.correct_body)
self.assertEqual(code, 201)
self.mock_user_info(self.email_1)
code, response = self.client.invite_list(user_id=self.user_id)
code, response = self.client.invite_list(email=self.email_1)
self.assertEqual(code, 200)
invites = response['invites']
self.assertEqual(len(invites), 1)
Expand Down

0 comments on commit a03b421

Please sign in to comment.