Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mi): add owner_id to applets response (M2-6948) #1402

Merged
merged 4 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/apps/applets/api/applets.py
ChaconC marked this conversation as resolved.
Show resolved Hide resolved
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
ChaconC marked this conversation as resolved.
Show resolved Hide resolved
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
Loading