From bee7306152cda7320b1f394c60e6db1e08212c82 Mon Sep 17 00:00:00 2001 From: Carlos Chacon Date: Wed, 12 Jun 2024 10:30:02 -0600 Subject: [PATCH] feat(mi): add owner_id to applets response (M2-6948) (#1402) * feat: add owner_id to applets response * add owner_id to applet_retrieve_by_key * update related tests --- src/apps/applets/api/applets.py | 2 ++ src/apps/applets/domain/applet.py | 1 + src/apps/applets/domain/base.py | 1 + src/apps/applets/service/applet.py | 7 +++++++ src/apps/applets/tests/test_applet.py | 2 ++ 5 files changed, 13 insertions(+) diff --git a/src/apps/applets/api/applets.py b/src/apps/applets/api/applets.py index 4106b544561..4a0625d4410 100644 --- a/src/apps/applets/api/applets.py +++ b/src/apps/applets/api/applets.py @@ -97,6 +97,8 @@ async def applet_retrieve( applet_future = service.get_single_language_by_id(applet_id, language) subject_future = SubjectsService(session, user.id).get_by_user_and_applet(user.id, applet_id) applet, subject = await asyncio.gather(applet_future, subject_future) + applet_owner = await UserAppletAccessCRUD(session).get_applet_owner(applet_id) + applet.owner_id = applet_owner.owner_id return AppletRetrieveResponse( result=AppletSingleLanguageDetailPublic.from_orm(applet), respondent_meta={"nickname": subject.nickname if subject else None, "tag": subject.tag if subject else None}, diff --git a/src/apps/applets/domain/applet.py b/src/apps/applets/domain/applet.py index af40f6c0ccc..c82a98c4176 100644 --- a/src/apps/applets/domain/applet.py +++ b/src/apps/applets/domain/applet.py @@ -90,6 +90,7 @@ class AppletSingleLanguageDetailForPublic(AppletBaseInfo, PublicModel): activity_flows: list[FlowSingleLanguageDetailPublic] = Field(default_factory=list) theme: PublicTheme encryption: Encryption | None + owner_id: uuid.UUID | None class AppletSingleLanguageInfo(AppletFetchBase, InternalModel): diff --git a/src/apps/applets/domain/base.py b/src/apps/applets/domain/base.py index f712c0d7263..47e06342e6a 100644 --- a/src/apps/applets/domain/base.py +++ b/src/apps/applets/domain/base.py @@ -69,3 +69,4 @@ class AppletFetchBase(AppletReportConfigurationBase, AppletBaseInfo): created_at: datetime.datetime | None updated_at: datetime.datetime | None is_published: bool = False + owner_id: uuid.UUID | None diff --git a/src/apps/applets/service/applet.py b/src/apps/applets/service/applet.py index 0056ccee6fc..65d18ed0493 100644 --- a/src/apps/applets/service/applet.py +++ b/src/apps/applets/service/applet.py @@ -406,6 +406,7 @@ async def get_list_by_single_language( for schema in schemas: theme = theme_map.get(schema.theme_id) + applet_owner = await UserAppletAccessCRUD(self.session).get_applet_owner(schema.id) applets.append( AppletSingleLanguageInfo( id=schema.id, @@ -429,6 +430,7 @@ async def get_list_by_single_language( stream_enabled=schema.stream_enabled, stream_ip_address=schema.stream_ip_address, stream_port=schema.stream_port, + owner_id=applet_owner.owner_id, ) ) return applets @@ -485,6 +487,7 @@ async def get_single_language_by_key(self, key: uuid.UUID, language: str) -> App schema = await AppletsCRUD(self.session).get_by_link(key) if not schema: raise AppletNotFoundError(key="key", value=str(key)) + applet_owner = await UserAppletAccessCRUD(self.session).get_applet_owner(schema.id) theme = None if schema.theme_id: theme = await ThemeService(self.session, self.user_id).get_by_id(schema.theme_id) @@ -509,6 +512,7 @@ async def get_single_language_by_key(self, key: uuid.UUID, language: str) -> App updated_at=schema.updated_at, retention_period=schema.retention_period, retention_type=schema.retention_type, + owner_id=applet_owner.owner_id, ) applet.activities = await ActivityService(self.session, self.user_id).get_single_language_by_applet_id( @@ -677,6 +681,9 @@ async def get_full_applet(self, applet_id: uuid.UUID) -> AppletFull: applet = AppletFull.from_orm(schema) applet.activities = await ActivityService(self.session, self.user_id).get_full_activities(applet_id) applet.activity_flows = await FlowService(self.session).get_full_flows(applet_id) + applet_owner = await UserAppletAccessCRUD(self.session).get_applet_owner(applet_id) + applet.owner_id = applet_owner.owner_id + return applet async def publish(self, applet_id: uuid.UUID): diff --git a/src/apps/applets/tests/test_applet.py b/src/apps/applets/tests/test_applet.py index e9f2b9d33f0..3a566e41967 100644 --- a/src/apps/applets/tests/test_applet.py +++ b/src/apps/applets/tests/test_applet.py @@ -345,6 +345,7 @@ async def test_applet_detail(self, client: TestClient, tom: User, applet_one_wit assert response.status_code == http.HTTPStatus.OK result = response.json()["result"] assert result["displayName"] == applet_one_with_flow.display_name + assert result["ownerId"] == str(tom.id) assert len(result["activities"]) == 1 assert len(result["activityFlows"]) == 1 assert response.json()["respondentMeta"]["nickname"] == tom.get_full_name() @@ -354,6 +355,7 @@ async def test_public_applet_detail(self, client: TestClient, applet_one_with_pu assert response.status_code == http.HTTPStatus.OK result = response.json()["result"] assert result["displayName"] == applet_one_with_public_link.display_name + assert result["ownerId"] == "7484f34a-3acc-4ee6-8a94-fd7299502fa1" assert len(result["activities"]) == 1 async def test_create_applet__initial_version_is_created_in_applet_history(