Skip to content

Commit 0ebb645

Browse files
fix: move post-fetch processing inside try in applet_answers_export
1 parent ff2378c commit 0ebb645

2 files changed

Lines changed: 18 additions & 26 deletions

File tree

src/apps/answers/api.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,15 @@ async def applet_answers_export(
10061006
data: AnswerExport = await AnswerService(session, user.id, answer_session).get_export_data(
10071007
applet_id, query_params, activities_last_version
10081008
)
1009+
total_answers = data.total_answers
1010+
for answer in data.answers:
1011+
if answer.is_manager:
1012+
answer.respondent_secret_id = f"[admin account] ({answer.respondent_secret_id})"
1013+
1014+
if activities_last_version:
1015+
applet = await AppletService(session, user.id).get(applet_id)
1016+
activities = await ActivityHistoryService(session, applet.id, applet.version).get_full()
1017+
data.activities = activities
10091018
except BaseError as e:
10101019
await log(
10111020
AuditEvent(
@@ -1016,15 +1025,6 @@ async def applet_answers_export(
10161025
)
10171026
)
10181027
raise
1019-
total_answers = data.total_answers
1020-
for answer in data.answers:
1021-
if answer.is_manager:
1022-
answer.respondent_secret_id = f"[admin account] ({answer.respondent_secret_id})"
1023-
1024-
if activities_last_version:
1025-
applet = await AppletService(session, user.id).get(applet_id)
1026-
activities = await ActivityHistoryService(session, applet.id, applet.version).get_full()
1027-
data.activities = activities
10281028
await log(
10291029
AuditEvent(
10301030
user_id=user.id,

src/apps/workspaces/api.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
PublicWorkspaceRespondent,
3535
WorkspaceAppletPublic,
3636
WorkspacePrioritizedRole,
37+
WorkspaceRespondent,
3738
WorkspaceSearchAppletPublic,
3839
)
3940
from apps.workspaces.filters import WorkspaceUsersQueryParams
@@ -242,7 +243,7 @@ async def workspace_respondents_list(
242243
session=Depends(get_session),
243244
answer_session=Depends(get_answer_session_by_owner_id),
244245
) -> ResponseMultiOrdering[PublicWorkspaceRespondent]:
245-
respondents = []
246+
respondents: list[WorkspaceRespondent] = []
246247
try:
247248
service = WorkspaceService(session, user.id)
248249
await service.exists_by_owner_id(owner_id)
@@ -256,18 +257,15 @@ async def workspace_respondents_list(
256257
respondents = await InvitationsService(session, user).fill_pending_invitations_respondents(respondents)
257258

258259
applet_ids = [
259-
detail.applet_id for respondent in respondents if respondent.details for detail in respondent.details
260+
r_detail.applet_id for respondent in respondents if respondent.details for r_detail in respondent.details
260261
]
261262

262263
accesses = await AppletAccessService(session).get_applet_accesses(applet_ids=applet_ids, user_id=user.id)
263264
is_super_reviewer = any(access.role in Role.super_reviewers() for access in accesses)
264265
reviewer_access = next((access for access in accesses if access.role == Role.REVIEWER), None)
265266
except BaseError as e:
266267
subject_ids = [
267-
detail.subject_id
268-
for respondent in respondents
269-
if respondent.details
270-
for detail in respondent.details
268+
r_detail.subject_id for respondent in respondents if respondent.details for r_detail in respondent.details
271269
]
272270
await log(
273271
AuditEvent(
@@ -282,8 +280,8 @@ async def workspace_respondents_list(
282280
subjects_by_applet: dict[uuid.UUID, list[uuid.UUID]] = {}
283281
for respondent in respondents:
284282
if respondent.details:
285-
for detail in respondent.details:
286-
subjects_by_applet.setdefault(detail.applet_id, []).append(detail.subject_id)
283+
for r_detail in respondent.details:
284+
subjects_by_applet.setdefault(r_detail.applet_id, []).append(r_detail.subject_id)
287285

288286
for applet_id in set(applet_ids):
289287
await log(
@@ -322,7 +320,7 @@ async def workspace_applet_respondents_list(
322320
session=Depends(get_session),
323321
answer_session=Depends(get_answer_session_by_owner_id),
324322
) -> ResponseMultiOrdering[PublicWorkspaceRespondent]:
325-
respondents = []
323+
respondents: list[WorkspaceRespondent] = []
326324
try:
327325
service = WorkspaceService(session, user.id)
328326
await service.exists_by_owner_id(owner_id)
@@ -342,10 +340,7 @@ async def workspace_applet_respondents_list(
342340
reviewer_access = next((access for access in accesses if access.role == Role.REVIEWER), None)
343341
except BaseError as e:
344342
subject_ids = [
345-
detail.subject_id
346-
for respondent in respondents
347-
if respondent.details
348-
for detail in respondent.details
343+
r_detail.subject_id for respondent in respondents if respondent.details for r_detail in respondent.details
349344
]
350345
await log(
351346
AuditEvent(
@@ -359,10 +354,7 @@ async def workspace_applet_respondents_list(
359354
raise
360355

361356
subject_ids = [
362-
detail.subject_id
363-
for respondent in respondents
364-
if respondent.details
365-
for detail in respondent.details
357+
r_detail.subject_id for respondent in respondents if respondent.details for r_detail in respondent.details
366358
]
367359

368360
await log(

0 commit comments

Comments
 (0)