Skip to content

Commit

Permalink
feat(mi): add owner_id to applets response (M2-6948) (#1402)
Browse files Browse the repository at this point in the history
* feat: add owner_id to applets response

* add owner_id to applet_retrieve_by_key

* update related tests
  • Loading branch information
ChaconC authored Jun 12, 2024
1 parent 9bc407c commit bee7306
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/apps/applets/api/applets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
1 change: 1 addition & 0 deletions src/apps/applets/domain/applet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions src/apps/applets/domain/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions src/apps/applets/service/applet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions src/apps/applets/tests/test_applet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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(
Expand Down

0 comments on commit bee7306

Please sign in to comment.