Skip to content

Commit

Permalink
Merge pull request #1657 from ChildMindInstitute/release/1.9.0
Browse files Browse the repository at this point in the history
Release/1.9.0 [main]
  • Loading branch information
ChaconC authored Nov 14, 2024
2 parents a348544 + 00a7c97 commit 7eba132
Show file tree
Hide file tree
Showing 26 changed files with 1,112 additions and 826 deletions.
28 changes: 14 additions & 14 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ name = "pypi"
[packages]
aio-pika = "==9.4.3"
aiofiles = "==24.1.0"
aiohttp = "==3.10.9"
aiohttp = "==3.10.10"
alembic = "==1.13.3"
asyncpg = "==0.29.0"
azure-storage-blob = "==12.22.0"
asyncpg = "==0.30.0"
azure-storage-blob = "==12.23.1"
bcrypt = "==4.2.0"
boto3 = "==1.26.10"
fastapi = "==0.110.3"
boto3 = "==1.35.47"
fastapi = "==0.115.3"
# The latest version of the fastapi is not taken because of the issue
# starlette version for those deps ==0.21.0
# with fastapi-mail that requires 0.21 < starlette < 0.22
Expand Down Expand Up @@ -45,7 +45,7 @@ pyOpenSSL = "==24.2.1"
pydantic = { extras = ["email"], version = "==1.10.18" }
pymongo = "*"
python-multipart = "==0.0.12"
redis = "==5.1.0"
redis = "==5.1.1"
sentry-sdk = "~=2.13"
sqlalchemy = { extras = ["asyncio"], version = "==1.4.53" }
sqlalchemy-utils = "==0.41.2"
Expand All @@ -54,14 +54,14 @@ taskiq-aio-pika = "==0.4.1"
taskiq-fastapi = "==0.3.2"
taskiq-redis = "==1.0.2"
typer = "==0.12.5"
uvicorn = { extras = ["standard"], version = "==0.30.6" }
uvicorn = { extras = ["standard"], version = "==0.32.0" }
pyjwt = "==2.9.0"

[dev-packages]
ipdb = "==0.13.13"
pudb = "==2024.1.2"
pre-commit = "==3.8.0"
ruff = "==0.6.8"
pudb = "==2024.1.3"
pre-commit = "==4.0.1"
ruff = "==0.7.0"
allure-pytest = "==2.13.5"
pydantic-factories = "==1.17.3"
pytest = "==8.3.3"
Expand All @@ -72,11 +72,11 @@ pytest-lazy-fixtures = "==1.1.1"
pytest-mock = "==3.14.0"
nest-asyncio = "==1.6.0"
gevent = "==24.2.1"
mypy = "==1.11.2"
types-python-dateutil = "==2.9.0.20240906"
mypy = "==1.13.0"
types-python-dateutil = "==2.9.0.20241003"
typing-extensions = "==4.12.2"
types-requests = "==2.32.0.20240914"
types-pytz = "==2024.2.0.20240913"
types-requests = "==2.32.0.20241016"
types-pytz = "==2024.2.0.20241003"
types-aiofiles = "==24.1.0.20240626"
types-cachetools = "==5.5.0.20240820"
greenlet = "==3.1.0"
Expand Down
1,539 changes: 763 additions & 776 deletions Pipfile.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ env = [
"DATABASE__USER=postgres",
"DATABASE__DB=test",
"ARBITRARY_DB=test_arbitrary",
"TASK_ANSWER_ENCRYPTION__BATCH_LIMIT=1"
"TASK_ANSWER_ENCRYPTION__BATCH_LIMIT=1",
"CDN__LEGACY_REGION=us-east-1",
"CDN__LEGACY_BUCKET=testing"
]

[tool.coverage.run]
Expand Down
2 changes: 1 addition & 1 deletion src/apps/activities/api/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async def applet_activities(
activities_future,
)
applet_detail = AppletSingleLanguageDetailMobilePublic.from_orm(applet)
respondent_meta = {"nickname": subject.nickname if subject else None, "tag": subject.tag if subject else None}
respondent_meta = SubjectsService.to_respondent_meta(subject)

if filters.has_submitted or filters.has_score:
activities = await __filter_activities(
Expand Down
1 change: 1 addition & 0 deletions src/apps/activities/domain/custom_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ def validate_phrasal_templates(values: dict):
ResponseType.DATE,
ResponseType.SLIDERROWS,
ResponseType.SINGLESELECTROWS,
ResponseType.PARAGRAPHTEXT,
ResponseType.MULTISELECTROWS,
]:
raise IncorrectPhrasalTemplateItemTypeError()
Expand Down
1 change: 1 addition & 0 deletions src/apps/activities/services/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ async def get_by_applet_id_for_duplicate(self, applet_id: uuid.UUID) -> list[Act
subscale_setting=schema.subscale_setting,
performance_task_type=schema.performance_task_type,
is_performance_task=schema.is_performance_task,
auto_assign=schema.auto_assign,
)
activity_map[activity.id] = activity
activities.append(activity)
Expand Down
18 changes: 18 additions & 0 deletions src/apps/activities/tests/fixtures/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,21 @@ def phrasal_template_with_slider_rows_create(
)

return [slider_rows_item_create, phrasal_item]


@pytest.fixture
def phrasal_template_with_paragraph_create(
phrasal_template_config: PhrasalTemplateConfig,
phrasal_template_with_paragraph_response_values: PhrasalTemplateValues,
base_item_data: BaseItemData,
paragraph_text_item_create,
):
phrasal_item = ActivityItemCreate(
**base_item_data.dict(exclude={"name"}),
name="phrasal_template_paragraph_test",
response_type=ResponseType.PHRASAL_TEMPLATE,
config=phrasal_template_config,
response_values=phrasal_template_with_paragraph_response_values,
)

return [paragraph_text_item_create, phrasal_item]
31 changes: 31 additions & 0 deletions src/apps/activities/tests/fixtures/response_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
MultiSelectionRowsValues,
MultiSelectionValues,
NumberSelectionValues,
ParagraphTextValues,
PhrasalTemplateDisplayMode,
PhrasalTemplateField,
PhrasalTemplatePhrase,
Expand Down Expand Up @@ -53,6 +54,13 @@ def single_select_response_values() -> SingleSelectionValues:
)


@pytest.fixture
def paragraph_response_values() -> ParagraphTextValues:
return ParagraphTextValues(
type=ResponseType.PARAGRAPHTEXT,
)


@pytest.fixture
def multi_select_response_values(
single_select_response_values: SingleSelectionValues,
Expand Down Expand Up @@ -202,6 +210,18 @@ def phrasal_template_with_slider_rows_response_fields(slider_rows_item_create) -
]


@pytest.fixture()
def phrasal_template_wiht_paragraph_response_fields(paragraph_text_item_create) -> List[PhrasalTemplateField]:
return [
_PhrasalTemplateSentenceField(text="test sentence"),
_PhrasalTemplateItemResponseField(
item_name=paragraph_text_item_create.name, display_mode=PhrasalTemplateDisplayMode.SENTENCE, item_index=0
),
_PhrasalTemplateLineBreakField(),
_PhrasalTemplateSentenceField(text="test sentence 2"),
]


@pytest.fixture
def phrasal_template_with_slider_rows_response_values(
phrasal_template_with_slider_rows_response_fields,
Expand All @@ -211,3 +231,14 @@ def phrasal_template_with_slider_rows_response_values(
card_title="test card title",
type=ResponseType.PHRASAL_TEMPLATE,
)


@pytest.fixture
def phrasal_template_with_paragraph_response_values(
phrasal_template_wiht_paragraph_response_fields,
) -> PhrasalTemplateValues:
return PhrasalTemplateValues(
phrases=[PhrasalTemplatePhrase(image=None, fields=phrasal_template_wiht_paragraph_response_fields)],
card_title="test paragraph card title",
type=ResponseType.PHRASAL_TEMPLATE,
)
3 changes: 2 additions & 1 deletion src/apps/activities/tests/test_activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ async def test_activities_applet(
assert result["appletDetail"]["activityFlows"] == []

assert result["respondentMeta"] == {
"nickname": f"{tom.first_name} {tom.last_name}",
"subjectId": str(tom_applet_one_subject.id),
"nickname": tom_applet_one_subject.nickname,
"tag": tom_applet_one_subject.tag,
}

Expand Down
4 changes: 2 additions & 2 deletions src/apps/activity_assignments/tests/test_assignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,13 +819,13 @@ async def test_assignment_list_by_applet_with_delete_subject(
assert response.json()["result"]["appletId"] == str(applet_one_with_flow.id)
assignments = response.json()["result"]["assignments"]
assert len(assignments) == 2
assignment = assignments[0]
assignment = [a for a in assignments if a["activityId"] is not None][0]
assert assignment["activityId"] == str(applet_one_with_flow.activities[0].id)
assert assignment["respondentSubjectId"] == str(tom_applet_one_subject.id)
assert assignment["targetSubjectId"] == str(tom_applet_one_subject.id)
assert assignment["activityFlowId"] is None
assert assignment["id"] == assignment_activity["id"]
assignment = assignments[1]
assignment = [a for a in assignments if a["activityFlowId"] is not None][0]
assert assignment["activityId"] is None
assert assignment["respondentSubjectId"] == str(tom_applet_one_subject.id)
assert assignment["targetSubjectId"] == str(lucy_applet_one_subject.id)
Expand Down
1 change: 1 addition & 0 deletions src/apps/activity_flows/service/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ async def get_by_applet_id_duplicate(self, applet_id: uuid.UUID) -> list[FlowDup
hide_badge=schema.hide_badge,
order=schema.order,
is_hidden=schema.is_hidden,
auto_assign=schema.auto_assign,
)
flow_map[flow.id] = flow
flows.append(flow)
Expand Down
2 changes: 1 addition & 1 deletion src/apps/answers/crud/answers.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ async def get_completed_answers_data_list(

return result_list

async def get_latest_applet_version(self, applet_id: uuid.UUID) -> str:
async def get_latest_applet_version(self, applet_id: uuid.UUID) -> str | None:
query: Query = select(AnswerSchema.applet_history_id)
query = query.where(AnswerSchema.applet_id == applet_id)
query = query.order_by(AnswerSchema.version.desc())
Expand Down
2 changes: 2 additions & 0 deletions src/apps/answers/domain/answers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from apps.shared.domain.custom_validations import datetime_from_ms
from apps.shared.domain.types import _BaseModel
from apps.shared.locale import I18N
from apps.subjects.domain import SubjectReadResponse


class ClientMeta(InternalModel):
Expand Down Expand Up @@ -244,6 +245,7 @@ class ActivityAnswer(PublicModel):
migrated_data: dict | None = None
end_datetime: datetime.datetime
created_at: datetime.datetime
source_subject: SubjectReadResponse | None

@validator("activity_id", always=True)
def extract_activity_id(cls, value, values):
Expand Down
44 changes: 43 additions & 1 deletion src/apps/answers/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
from apps.subjects.constants import Relation
from apps.subjects.crud import SubjectsCrud
from apps.subjects.db.schemas import SubjectSchema
from apps.subjects.domain import SubjectReadResponse
from apps.users import User, UserSchema, UsersCRUD
from apps.workspaces.crud.applet_access import AppletAccessCRUD
from apps.workspaces.crud.user_applet_access import UserAppletAccessCRUD
Expand Down Expand Up @@ -627,6 +628,25 @@ async def get_activity_answer(
raise AnswerNotFoundError()

answer = answers[0]
source_subject = None

if answer.source_subject_id:
source_subject_schema = await SubjectsCrud(self.session).get_by_id(answer.source_subject_id)
source_subject = (
SubjectReadResponse(
id=source_subject_schema.id,
first_name=source_subject_schema.first_name,
last_name=source_subject_schema.last_name,
nickname=source_subject_schema.nickname,
secret_user_id=source_subject_schema.secret_user_id,
tag=source_subject_schema.tag,
applet_id=source_subject_schema.applet_id,
user_id=source_subject_schema.user_id,
)
if source_subject_schema
else None
)

answer_result = ActivityAnswer(
**answer.dict(exclude={"migrated_data"}),
**answer.answer_item.dict(
Expand All @@ -640,6 +660,7 @@ async def get_activity_answer(
"end_datetime",
}
),
source_subject=source_subject,
)

activities = await ActivityHistoriesCRUD(self.session).load_full([answer.activity_history_id])
Expand Down Expand Up @@ -744,8 +765,12 @@ async def get_flow_submission(

answer_result: list[ActivityAnswer] = []

source_subject_id_answer_index_map: dict[uuid.UUID, list[int]] = defaultdict(list)

is_flow_completed = False
for answer in answers:
for i, answer in enumerate(answers):
if answer.source_subject_id:
source_subject_id_answer_index_map[answer.source_subject_id].append(i)
if answer.flow_history_id and answer.is_flow_completed:
is_completed = True
answer_result.append(
Expand Down Expand Up @@ -777,6 +802,23 @@ async def get_flow_submission(
flows = await FlowsHistoryCRUD(self.session).load_full([flow_history_id])
assert flows

source_subject_ids = list(source_subject_id_answer_index_map.keys())
source_subjects = await SubjectsCrud(self.session).get_by_ids(source_subject_ids)
for source_subject_schema in source_subjects:
answer_indexes = source_subject_id_answer_index_map[source_subject_schema.id]
source_subject = SubjectReadResponse(
id=source_subject_schema.id,
first_name=source_subject_schema.first_name,
last_name=source_subject_schema.last_name,
nickname=source_subject_schema.nickname,
secret_user_id=source_subject_schema.secret_user_id,
tag=source_subject_schema.tag,
applet_id=source_subject_schema.applet_id,
user_id=source_subject_schema.user_id,
)
for answer_index in answer_indexes:
answer_result[answer_index].source_subject = source_subject

submission = FlowSubmissionDetails(
submission=FlowSubmission(
submit_id=submit_id,
Expand Down
Loading

0 comments on commit 7eba132

Please sign in to comment.