From a03b42180c5796367987629b8dd15ebe8385758c Mon Sep 17 00:00:00 2001 From: nk-hystax <128669932+nk-hystax@users.noreply.github.com> Date: Mon, 2 Dec 2024 14:24:54 +0300 Subject: [PATCH] OS-8014. Changed user_id param to email in list invites --- optscale_client/rest_api_client/client_v2.py | 4 ++-- rest_api/rest_api_server/controllers/invite.py | 7 +++---- rest_api/rest_api_server/handlers/v2/invites.py | 13 ++++++++----- .../tests/unittests/test_invite_api.py | 4 ++-- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/optscale_client/rest_api_client/client_v2.py b/optscale_client/rest_api_client/client_v2.py index 9a95c4ec..0f401237 100644 --- a/optscale_client/rest_api_client/client_v2.py +++ b/optscale_client/rest_api_client/client_v2.py @@ -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)) diff --git a/rest_api/rest_api_server/controllers/invite.py b/rest_api/rest_api_server/controllers/invite.py index 5a0117be..29d6d3b5 100644 --- a/rest_api/rest_api_server/controllers/invite.py +++ b/rest_api/rest_api_server/controllers/invite.py @@ -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, diff --git a/rest_api/rest_api_server/handlers/v2/invites.py b/rest_api/rest_api_server/handlers/v2/invites.py index b4192639..a87ece4f 100644 --- a/rest_api/rest_api_server/handlers/v2/invites.py +++ b/rest_api/rest_api_server/handlers/v2/invites.py @@ -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 @@ -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: @@ -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)) diff --git a/rest_api/rest_api_server/tests/unittests/test_invite_api.py b/rest_api/rest_api_server/tests/unittests/test_invite_api.py index 24ad2fbc..551f0554 100644 --- a/rest_api/rest_api_server/tests/unittests/test_invite_api.py +++ b/rest_api/rest_api_server/tests/unittests/test_invite_api.py @@ -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)