Skip to content

Commit

Permalink
Merge pull request #861 from ChildMindInstitute/release-20231116.2
Browse files Browse the repository at this point in the history
Release 20231116.2
  • Loading branch information
vshvechko authored Nov 23, 2023
2 parents 26c37da + 0d4d82d commit cc6bcdd
Show file tree
Hide file tree
Showing 36 changed files with 2,022 additions and 1,309 deletions.
27 changes: 14 additions & 13 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "pypi"
aioredis = "~=2.0.1"
alembic = "~=1.8.1"
asyncpg = "~=0.27.0"
asynctest = "*"
asynctest = "==0.13.0"
boto3 = "==1.26.10"
fastapi = "==0.87.0"
# The latest version of the fastapi is not taken because of the issue
Expand All @@ -24,17 +24,19 @@ pydantic = {extras = ["email"], version = "~=1.10.2"}
python-jose = {version = "~=3.3.0", extras = ["cryptography"]}
python-multipart = "~=0.0.5"
sentry-sdk = "~=1.6"
sqlalchemy = {extras = ["asyncio"], version = "~=1.4.46"}
sqlalchemy = {extras = ["asyncio"], version = "==1.4.49"}
uvicorn = {extras = ["standard"], version = "==0.19"}
aiohttp = "*"
firebase-admin = "*"
aio-pika = "*"
pyld = "*"
azure-storage-blob = "*"
taskiq-fastapi = "*"
taskiq-redis = "*"
taskiq-aio-pika = "*"
taskiq = {extras = ["reload"], version = "==0.9.1"}
aiohttp = "==3.8.5"
firebase-admin = "==6.2.0"
aio-pika = "==9.3.0"
pyld = "==2.0.3"
azure-storage-blob = "==12.18.2"
taskiq-fastapi = "==0.3.0"
taskiq-redis = "==0.5.0"
taskiq-aio-pika = "==0.4.0"
sqlalchemy-utils = "==0.41.1"
typer = {extras = ["all"], version = "==0.9.0"}

[dev-packages]
black = "~=22.6"
Expand Down Expand Up @@ -78,9 +80,8 @@ pycryptodomex = "==3.9.7"
psycopg2-binary = "==2.9.6"
cachetools = "==5.3.0"
pyld = "==2.0.3"
types-requests = "*"
taskiq = {extras = ["reload"], version = "*"}
types-pytz = "*"
types-requests = "==2.31.0.10"
types-pytz = "==2023.3.1.1"

[requires]
python_version = "3.10"
2,202 changes: 1,140 additions & 1,062 deletions Pipfile.lock

Large diffs are not rendered by default.

74 changes: 15 additions & 59 deletions src/apps/answers/crud/answers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
Version,
)
from apps.answers.errors import AnswerNotFoundError
from apps.applets.db.schemas import AppletHistorySchema, AppletSchema
from apps.applets.db.schemas import AppletHistorySchema
from apps.shared.filtering import Comparisons, FilterField, Filtering
from apps.shared.paging import paging
from infrastructure.database.crud import BaseCRUD
Expand Down Expand Up @@ -342,64 +342,6 @@ async def get_by_applet_activity_created_at(
db_result = await self._execute(query)
return db_result.scalars().all()

async def get_activity_flow_by_answer_id(
self, answer_id: uuid.UUID
) -> bool:
query: Query = select(AnswerItemSchema, ActivityFlowHistoriesSchema)
query = query.join(
AnswerSchema, AnswerSchema.id == AnswerItemSchema.answer_id
)
query = query.join(
ActivityFlowHistoriesSchema,
ActivityFlowHistoriesSchema.id_version
== AnswerSchema.flow_history_id,
isouter=True,
)
query = query.where(AnswerItemSchema.is_assessment == False) # noqa
query = query.where(AnswerSchema.id == answer_id)

db_result = await self._execute(query)
(
_,
flow_history_schema,
) = (
db_result.first()
) # type: AnswerItemSchema, ActivityFlowHistoriesSchema
if not flow_history_schema:
return False
return flow_history_schema.is_single_report

async def get_applet_info_by_answer_id(
self, answer: AnswerSchema
) -> tuple[AppletHistorySchema, ActivityHistorySchema]:
query: Query = select(
AppletSchema,
ActivityHistorySchema,
)
query = query.join(
AppletHistorySchema,
AppletHistorySchema.id == AppletSchema.id,
isouter=True,
)
query = query.join(
ActivityHistorySchema,
and_(
ActivityHistorySchema.applet_id
== AppletHistorySchema.id_version,
ActivityHistorySchema.id_version == answer.activity_history_id,
),
isouter=True,
)
query = query.where(
and_(
AppletSchema.id == answer.applet_id,
AppletHistorySchema.version == answer.version,
)
)
db_result = await self._execute(query)
res = db_result.first()
return res

async def get_activities_which_has_answer(
self, activity_hist_ids: list[str], respondent_id: uuid.UUID | None
) -> list[str]:
Expand Down Expand Up @@ -557,6 +499,20 @@ async def update_encrypted_fields(

await self._execute(query)

async def is_single_report_flow(self, answer_flow_id: str | None) -> bool:
query: Query = select(ActivityFlowHistoriesSchema)
query = query.where(
ActivityFlowHistoriesSchema.id_version == answer_flow_id
)
db_result = await self._execute(query)
db_result = db_result.first()
flow_history_schema = (
db_result[0] if db_result else None
) # type: ActivityFlowHistoriesSchema | None
if not flow_history_schema:
return False
return flow_history_schema.is_single_report

async def get_last_activity(
self, respondent_ids: list[uuid.UUID], applet_id: uuid.UUID | None
) -> dict[uuid.UUID, datetime.datetime]:
Expand Down
29 changes: 15 additions & 14 deletions src/apps/answers/fixtures/arbitrary_server_answers.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@
"user_id": "6cde911e-8a57-47c0-b6b2-685b3664f418",
"workspace_name": "eRPtCowGI0bcq4BEzB3lGA==",
"is_modified": false,
"database_uri": "postgresql+asyncpg://postgres:postgres@localhost:5432/test_arbitrary",
"storage_type": "key",
"storage_access_key": "key",
"storage_secret_key": "DefaultEndpointsProtocol=https;AccountName=youraccountname;AccountKey=youraccountkey;EndpointSuffix=core.windows.net",
"storage_region": "region",
"storage_url": "url",
"database_uri": "ehwQOnQu9X8higAEDMzDhH9HB5a0jO4FsgU/awOCwMgFccefd2//Ek6e0bKAwvauf6pwAS+PWDChFns1WIyL/z4oH52gEIKpYsBjUmznqYc=",
"storage_type": "gEkn6yn8U2jb0U+Ln1KSAw==",
"storage_access_key": "gEkn6yn8U2jb0U+Ln1KSAw==",
"storage_secret_key": "ww3Y0xCDnjCMQk2Kbmzoh0PGFmo4B1FGaaO7w7h0cUDoLgzFgpIJyoko/xTilJzIMINMa1j4V722KLW1NugxGkjqb+f9bWXJ2ytObwgbw8z6RbqZsJNOp6GFzT+az9Wpq7IW82Lyjok7ctS7R63oGTdDXbOpKzIJtu0/YAGCaNE=",
"storage_region": "5yruV8O3eukVP4fK/A5M6g==",
"storage_url": "KJ3yVM/QBmlmDQXx3CuuTw==",
"use_arbitrary": true
},
"note": {
Expand Down Expand Up @@ -142,7 +142,8 @@
"meta": {
"nickname": "f0dd4996-e0eb-461f-b2f8-ba873a674781",
"secretUserId": "f0dd4996-e0eb-461f-b2f8-ba873a674781"
}
},
"nickname": "hFywashKw+KlcDPazIy5QHz4AdkTOYkD28Q8+dpeDDA="
}
},
{
Expand Down Expand Up @@ -180,7 +181,8 @@
"meta": {
"nickname": "f0dd4996-e0eb-461f-b2f8-ba873a674781",
"secretUserId": "f0dd4996-e0eb-461f-b2f8-ba873a674781"
}
},
"nickname": "hFywashKw+KlcDPazIy5QHz4AdkTOYkD28Q8+dpeDDA="
}
},
{
Expand All @@ -200,15 +202,16 @@
"theme_id": null,
"version": "1.1.0",
"user_id": "6cde911e-8a57-47c0-b6b2-685b3664f418",
"report_server_ip": "",
"report_public_key": "",
"report_recipients": [],
"report_server_ip": "https://report-server.l.trackmage.com",
"report_public_key": "-----BEGIN PUBLIC KEY-----\nMIIIIjANBgkqhkiG9w0BAQEFAAOCCA8AMIIICgKCCAEA0Ooez1FjFM1kW8YG9k81\nLCZBEVg7fK6qAv6PN/VC5xfdafQfi704Yvv2FaLQ1blH531eb89QjjWksmUxTCrL\nRKy3QQAerQp7kegdWHo3q0co6WFFjIRtt7MFxGIT5y4ZBeT0Jm6fHy8SXJCheRwB\ni0BqBRt3k5pvlYHV4u3tnUen4Neyn8r5NgYMQc77ZDD6wcIw0L7XnPbNB7WHP5w9\n0VfnnUqqeGLoiy2mTx/3kv7EKalUBBUSCY5qcbsmNr0x91/hSsnSeICREuKcpW1c\nbAsarFSyiRLkZEBh4FrdKfp9+ZLUqrejWltSdlkqY9ih8DtiaXEvJLjQp6V2aYrQ\nMZBYZdrg8c5/UI3yhSioB0TYxkI9lgGyTSrhqRjRtzQ+MEJ7cV0BWqji5BOO3OJ9\nrGC2Mb+3T6EzhNB6HqdRDfThJqDeThPtT/zEu5OU0UuW9NiEqP4twz2IEYVOCo/B\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Kh1gmk/IjTesPjtt0jiv\nKgowXEvK5IkXkSFbGtbmGvbQn5CwtNyMkv/TPhUmiVu8LRdwfO0Rr7JbaTLvymIQ\nma6ZATMyhNcnkCNgqJqAj85IT78hqqKGYQ7nGyPw2H7utErWFcSwLUwBAok/qOeb\nW2EFUykoTbF2EHjXjAO5b60CAwEAAQ==\n-----END PUBLIC KEY-----",
"report_recipients": ["[email protected]"],
"report_include_user_id": false,
"report_include_case_id": false,
"report_email_body": "",
"id_version": "92917a56-d586-4613-b7aa-991f2c4b15b8_1.1.0",
"id": "92917a56-d586-4613-b7aa-991f2c4b15b8",
"display_name": "Applet0"
"display_name": "Applet0",
"stream_enabled": false
},
"private_key": ""
},
Expand Down Expand Up @@ -652,5 +655,3 @@
}

]


3 changes: 2 additions & 1 deletion src/apps/answers/fixtures/duplicate_activity_in_flow.json
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@
"meta": {
"nickname": "f0dd4996-e0eb-461f-b2f8-ba873a674781",
"secretUserId": "f0dd4996-e0eb-461f-b2f8-ba873a674781"
}
},
"nickname": "hFywashKw+KlcDPazIy5QHz4AdkTOYkD28Q8+dpeDDA="
}
}
]
Loading

0 comments on commit cc6bcdd

Please sign in to comment.