diff --git a/src/apps/answers/crud/answers.py b/src/apps/answers/crud/answers.py index fb5ef8c3a9c..dcf4e20f48b 100644 --- a/src/apps/answers/crud/answers.py +++ b/src/apps/answers/crud/answers.py @@ -325,7 +325,6 @@ async def get_applet_answers( AnswerItemSchema.respondent_id, self._exclude_assessment_val(AnswerSchema.target_subject_id).label("target_subject_id"), self._exclude_assessment_val(AnswerSchema.source_subject_id).label("source_subject_id"), - self._exclude_assessment_val(AnswerSchema.input_subject_id).label("input_subject_id"), self._exclude_assessment_val(AnswerSchema.relation).label("relation"), AnswerItemSchema.answer, AnswerItemSchema.events, diff --git a/src/apps/answers/domain/answers.py b/src/apps/answers/domain/answers.py index c3a18bfb169..374cd14e63c 100644 --- a/src/apps/answers/domain/answers.py +++ b/src/apps/answers/domain/answers.py @@ -526,19 +526,12 @@ class UserAnswerDataBase(BaseModel): submit_id: uuid.UUID version: str respondent_id: uuid.UUID | str | None = None - respondent_secret_id: str | None = None - source_subject_id: uuid.UUID | str | None = None - source_secret_id: uuid.UUID | str | None = None - source_user_nickname: str | None = None - source_user_tag: str | None = None target_subject_id: uuid.UUID | str | None = None target_secret_id: uuid.UUID | str | None = None - target_user_nickname: str | None = None - target_user_tag: str | None = None - input_subject_id: uuid.UUID | str | None = None - input_secret_id: uuid.UUID | str | None = None - input_user_nickname: str | None = None + source_subject_id: uuid.UUID | str | None = None + source_secret_id: uuid.UUID | str | None = None relation: str | None = None + respondent_secret_id: str | None = None legacy_profile_id: str | None = None user_public_key: str | None answer: str | None = None diff --git a/src/apps/answers/service.py b/src/apps/answers/service.py index 06002d9a7fe..c3334da241f 100644 --- a/src/apps/answers/service.py +++ b/src/apps/answers/service.py @@ -1212,16 +1212,15 @@ async def get_export_data( # noqa: C901 applet_assessment_ids = set() activity_hist_ids = set() flow_hist_ids = set() - - # collect ids to resolve data for answer in answers: - respondent_ids.add(answer.respondent_id) # type: ignore[arg-type] # noqa: E501 - if answer.source_subject_id: - subject_ids.add(answer.source_subject_id) # type: ignore[arg-type] # noqa: E501 + # collect id to resolve data + if answer.reviewed_answer_id: + # collect reviewer ids to fetch the data + respondent_ids.add(answer.respondent_id) # type: ignore[arg-type] # noqa: E501 if answer.target_subject_id: subject_ids.add(answer.target_subject_id) # type: ignore[arg-type] # noqa: E501 - if answer.input_subject_id: - subject_ids.add(answer.input_subject_id) # type: ignore[arg-type] # noqa: E501 + if answer.source_subject_id: + subject_ids.add(answer.source_subject_id) # type: ignore[arg-type] # noqa: E501 if answer.reviewed_answer_id: applet_assessment_ids.add(answer.applet_history_id) if answer.flow_history_id: @@ -1232,53 +1231,35 @@ async def get_export_data( # noqa: C901 flows_coro = FlowsHistoryCRUD(self.session).get_by_id_versions(list(flow_hist_ids)) user_map_coro = AppletAccessCRUD(self.session).get_respondent_export_data(applet_id, list(respondent_ids)) subject_map_coro = AppletAccessCRUD(self.session).get_subject_export_data(applet_id, list(subject_ids)) - current_user_subject_coro = SubjectsCrud(self.session).get_user_subject(self.user_id, applet_id) # type: ignore[arg-type] coros_result = await asyncio.gather( flows_coro, user_map_coro, subject_map_coro, - current_user_subject_coro, return_exceptions=True, ) for res in coros_result: if isinstance(res, BaseException): raise res - flows, user_map, subject_map, current_user = coros_result + flows, user_map, subject_map = coros_result flow_map = {flow.id_version: flow for flow in flows} # type: ignore for answer in answers: - respondent = user_map[answer.respondent_id] # type: ignore - answer.respondent_secret_id = current_user.secret_user_id # type: ignore + # respondent data + if answer.reviewed_answer_id: + # assessment + respondent = user_map[answer.respondent_id] # type: ignore + else: + respondent = subject_map[answer.target_subject_id] # type: ignore + answer.respondent_secret_id = respondent.secret_id answer.source_secret_id = ( subject_map.get(answer.source_subject_id).secret_id if answer.source_subject_id else None # type: ignore ) - answer.source_user_nickname = ( - subject_map.get(answer.source_subject_id).nickname if answer.source_subject_id else None # type: ignore - ) - answer.source_user_tag = ( - subject_map.get(answer.source_subject_id).tag if answer.source_subject_id else None # type: ignore - ) - answer.target_secret_id = ( subject_map.get(answer.target_subject_id).secret_id if answer.target_subject_id else None # type: ignore ) - answer.target_user_nickname = ( - subject_map.get(answer.target_subject_id).nickname if answer.target_subject_id else None # type: ignore - ) - answer.target_user_tag = ( - subject_map.get(answer.target_subject_id).tag if answer.target_subject_id else None # type: ignore - ) - - answer.input_secret_id = ( - subject_map.get(answer.input_subject_id).secret_id if answer.input_subject_id else None # type: ignore - ) - answer.input_user_nickname = ( - subject_map.get(answer.input_subject_id).nickname if answer.input_subject_id else None # type: ignore - ) - answer.respondent_email = respondent.email answer.is_manager = respondent.is_manager answer.legacy_profile_id = respondent.legacy_profile_id diff --git a/src/apps/answers/tests/test_answers.py b/src/apps/answers/tests/test_answers.py index 58ce8b0c571..2958929f790 100644 --- a/src/apps/answers/tests/test_answers.py +++ b/src/apps/answers/tests/test_answers.py @@ -1840,11 +1840,9 @@ async def test_answers_export( "flowName", "id", "itemIds", "migratedData", "respondentId", "respondentSecretId", "reviewedAnswerId", "userPublicKey", "version", "submitId", "scheduledDatetime", "startDatetime", - "endDatetime", "legacyProfileId", "migratedDate", "relation", - "sourceSubjectId", "sourceSecretId", "sourceUserNickname", "sourceUserTag", - "targetSubjectId", "targetSecretId", "targetUserNickname", "targetUserTag", - "inputSubjectId", "inputSecretId", "inputUserNickname", - "client", "tzOffset", "scheduledEventId", "reviewedFlowSubmitId" + "endDatetime", "legacyProfileId", "migratedDate", + "relation", "sourceSubjectId", "sourceSecretId", "targetSubjectId", + "targetSecretId", "client", "tzOffset", "scheduledEventId", "reviewedFlowSubmitId" } # Comment for now, wtf is it # assert int(answer['startDatetime'] * 1000) == answer_item_create.start_time @@ -1876,8 +1874,7 @@ async def test_get_applet_answers_without_assessment( assert len(data["answers"]) == 1 assert resp_data["count"] == 1 assert data["answers"][0]["respondentId"] == str(tom.id) - respondent_secret_id = data["answers"][0]["respondentSecretId"].split(" ")[-1].strip("()") - assert respondent_secret_id == answer_shell_account_target["respondent_secret_user_id"] + assert data["answers"][0]["respondentSecretId"] == answer_shell_account_target["target_secret_user_id"] @pytest.mark.parametrize( "user_fixture, exp_cnt", diff --git a/src/apps/answers/tests/test_answers_arbitrary.py b/src/apps/answers/tests/test_answers_arbitrary.py index 623aa6b4e7e..e305266cb93 100644 --- a/src/apps/answers/tests/test_answers_arbitrary.py +++ b/src/apps/answers/tests/test_answers_arbitrary.py @@ -619,11 +619,9 @@ async def test_answers_export( "flowName", "id", "itemIds", "migratedData", "respondentId", "respondentSecretId", "reviewedAnswerId", "userPublicKey", "version", "submitId", "scheduledDatetime", "startDatetime", - "endDatetime", "legacyProfileId", "migratedDate", "relation", - "sourceSubjectId", "sourceSecretId", "sourceUserNickname", "sourceUserTag", - "targetSubjectId", "targetSecretId", "targetUserNickname", "targetUserTag", - "inputSubjectId", "inputSecretId", "inputUserNickname", - "client", "tzOffset", "scheduledEventId", "reviewedFlowSubmitId" + "endDatetime", "legacyProfileId", "migratedDate", + "relation", "sourceSubjectId", "sourceSecretId", "targetSubjectId", + "targetSecretId", "client", "tzOffset", "scheduledEventId", "reviewedFlowSubmitId" } assert set(assessment.keys()) == expected_keys diff --git a/src/apps/workspaces/crud/applet_access.py b/src/apps/workspaces/crud/applet_access.py index 7521b18969b..5f88ad1e3fb 100644 --- a/src/apps/workspaces/crud/applet_access.py +++ b/src/apps/workspaces/crud/applet_access.py @@ -278,8 +278,6 @@ async def get_subject_export_data( SubjectSchema.id, SubjectSchema.user_id, SubjectSchema.email, - SubjectSchema.nickname, - SubjectSchema.tag, SubjectSchema.secret_user_id.label("secret_id"), UserAppletAccessSchema.legacy_profile_id, has_manager_role.label("is_manager"), diff --git a/src/apps/workspaces/domain/user_applet_access.py b/src/apps/workspaces/domain/user_applet_access.py index 702b03be499..7d2d8b6efaa 100644 --- a/src/apps/workspaces/domain/user_applet_access.py +++ b/src/apps/workspaces/domain/user_applet_access.py @@ -137,8 +137,6 @@ class RespondentExportData(InternalModel): class SubjectExportData(RespondentExportData): user_id: uuid.UUID | None - nickname: str | None - tag: str | None class RespondentInfoPublic(PublicModel):