Skip to content

Commit

Permalink
M2-5116 Create patch to migrate alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
vshvechko committed Feb 6, 2024
1 parent d6730af commit a255fc0
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/apps/alerts/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Alert(InternalModel):
image: str
workspace: str
respondent_id: uuid.UUID
subject_id: uuid.UUID | None


class AlertPublic(PublicModel):
Expand All @@ -51,6 +52,7 @@ class AlertPublic(PublicModel):
image: str
workspace: str
respondent_id: uuid.UUID
subject_id: uuid.UUID | None

@validator("encryption", pre=True)
def convert_response_values_keys(cls, response_values):
Expand All @@ -62,7 +64,7 @@ def convert_response_values_keys(cls, response_values):
class AlertMessage(InternalModel):
id: uuid.UUID
respondent_id: uuid.UUID
subject_id: uuid.UUID
subject_id: uuid.UUID | None
applet_id: uuid.UUID
version: str
message: str
Expand All @@ -87,6 +89,7 @@ class AlertHandlerResult(InternalModel):
image: str
workspace: str
respondent_id: str
subject_id: str | None


class AlertResponseMulti(ResponseMulti[AlertPublic]):
Expand Down
1 change: 1 addition & 0 deletions src/apps/alerts/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ async def get_all_alerts(self, filters: QueryParams) -> list[Alert]:
image=applet_history.image,
workspace=workspace.workspace_name,
respondent_id=alert.respondent_id,
subject_id=alert.subject_id,
)
)
return alerts
Expand Down
1 change: 1 addition & 0 deletions src/apps/alerts/ws_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ async def _handle_websocket(websocket, user_id, session):
image=applet_history.image,
workspace=workspace.workspace_name,
respondent_id=str(alert_message.respondent_id),
subject_id=str(alert_message.subject_id),
)
await websocket.send_json(applet_alert.dict())
except ConnectionClosed:
Expand Down
15 changes: 10 additions & 5 deletions src/apps/shared/commands/patch_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,27 @@
PatchRegister.register(
file_path="m2_4608_create_subjects.sql",
task_id="M2-4608",
description="Create subject record for each respondent",
description="[Subject] Create subject record for each respondent",
)
PatchRegister.register(
file_path="m2_4611_add_answer_subjects.py",
task_id="M2-4611",
description="Add subject ids for answers in internal DB and arbitrary DBs",
description="[Subject] Add subject ids for answers in internal and arbitrary DBs",
)
PatchRegister.register(
file_path="m2_4613_create_invitation_subjects.py",
task_id="M2-4613",
description="Create subjects for pending invitations",
description="[Subject] Create subjects for pending invitations",
)
PatchRegister.register(
file_path="m2_5018_migrate_reviewer_respondents_list.py",
task_id="M2-5018",
description="Replace reviewer respondent list with subject list",
description="[Subject] Replace reviewer respondent list with subject list",
)
PatchRegister.register(
file_path="m2_5116_add_alert_subjects.sql",
task_id="M2-5116",
description="[Subject] Populate alerts with subject ids",
)


Expand Down Expand Up @@ -92,7 +97,7 @@ def wrap_error_msg(msg):

@app.command(short_help="Show list of registered patches.")
@coro
async def show():
async def list():
data = PatchRegister.get_all()
if not data:
print("[bold green]Patches not registered[/bold green]")
Expand Down
10 changes: 10 additions & 0 deletions src/apps/shared/commands/patches/m2_5116_add_alert_subjects.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
update alerts
set subject_id = (
select id
from subjects
where
applet_id = alerts.applet_id
and user_id = alerts.respondent_id
)
where
respondent_id is not null
2 changes: 1 addition & 1 deletion src/apps/subjects/crud/subject.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ async def upsert(self, schema: Subject) -> Subject:
schema.id = model_id
return schema

async def reduce_applet_subject_ids(self, applet_id, subject_ids: list[uuid.UUID | str]) -> list[uuid.UUID]:
async def reduce_applet_subject_ids(self, applet_id, subject_ids: list[uuid.UUID] | list[str]) -> list[uuid.UUID]:
query = select(SubjectSchema.id).where(
SubjectSchema.id.in_(subject_ids),
SubjectSchema.applet_id == applet_id,
Expand Down
1 change: 0 additions & 1 deletion src/apps/workspaces/service/check_access.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import uuid

from apps.shared.exception import AccessDeniedError
from apps.subjects.services import SubjectsService
from apps.workspaces.crud.applet_access import AppletAccessCRUD
from apps.workspaces.domain.constants import Role
from apps.workspaces.errors import (
Expand Down

0 comments on commit a255fc0

Please sign in to comment.