From 3daa58e9d6f1b861f17b80d7ec27a36a42f3ed5f Mon Sep 17 00:00:00 2001 From: prabinoid <38830224+prabinoid@users.noreply.github.com> Date: Mon, 18 Nov 2024 16:38:20 +0545 Subject: [PATCH] fix: clear priority areas, send message after validation, project comment. --- backend/models/dtos/message_dto.py | 2 +- backend/models/postgis/project.py | 3 +-- backend/services/messaging/message_service.py | 2 +- backend/services/project_service.py | 2 +- backend/services/team_service.py | 11 ++++++++++- backend/services/validator_service.py | 2 +- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/backend/models/dtos/message_dto.py b/backend/models/dtos/message_dto.py index e4525d6a77..4a57557202 100644 --- a/backend/models/dtos/message_dto.py +++ b/backend/models/dtos/message_dto.py @@ -67,7 +67,7 @@ class ListChatMessageDTO(BaseModel): id: Optional[int] = Field(None, alias="id") message: str = Field(required=True) - picture_url: str = Field(default=None, alias="pictureUrl") + picture_url: Optional[str] = Field(None, alias="pictureUrl") timestamp: datetime username: str diff --git a/backend/models/postgis/project.py b/backend/models/postgis/project.py index 4ec7ec7e61..7553543133 100644 --- a/backend/models/postgis/project.py +++ b/backend/models/postgis/project.py @@ -655,9 +655,8 @@ async def update(self, project_dto: ProjectDTO, db: Database): await ProjectInfo.update_from_dto(ProjectInfo(**project_info), dto, db) # Always clear Priority Area prior to updating - + await Project.clear_existing_priority_areas(db, self.id) if project_dto.priority_areas: - await Project.clear_existing_priority_areas(db, self.id) for priority_area in project_dto.priority_areas: pa = await PriorityArea.from_dict(priority_area, db) # Link project and priority area in the database diff --git a/backend/services/messaging/message_service.py b/backend/services/messaging/message_service.py index b7ddb12a9a..8e22eafded 100644 --- a/backend/services/messaging/message_service.py +++ b/backend/services/messaging/message_service.py @@ -85,7 +85,7 @@ async def send_message_after_validation( """ project_name = await db.fetch_val( project_name_query, - values={"project_id": project_id, "locale": project["default_locale"]}, + values={"project_id": project_id, "locale": project.default_locale}, ) user = await UserService.get_user_by_id(mapped_by, db) text_template = get_txt_template( diff --git a/backend/services/project_service.py b/backend/services/project_service.py index 3e9f32519d..dc75524016 100644 --- a/backend/services/project_service.py +++ b/backend/services/project_service.py @@ -227,7 +227,7 @@ async def get_project_dto_for_mapper( if project.status == ProjectStatus.DRAFT.value: if not is_manager_permission: is_allowed_user = False - raise HTTPException(status_code=400, detail="Unable to fetch project.") + raise ProjectServiceError("ProjectNotFetched- Unable to fetch project") # Private Projects - allowed_users, admins, org admins & # assigned teams (mappers, validators, project managers), authors permitted diff --git a/backend/services/team_service.py b/backend/services/team_service.py index b4801fa4c9..6e8fbac864 100644 --- a/backend/services/team_service.py +++ b/backend/services/team_service.py @@ -790,10 +790,17 @@ async def send_message_to_all_team_members( team_name: str, message_dto: MessageDTO, user_id: int, - db: Database, + db: Database = None, ): + if db is None: + print("inside....") + db = await acquire_connection() + print("Sending message to the team...") + print(db) team_members = await TeamService._get_active_team_members(team_id, db) user = await UserService.get_user_by_id(user_id, db) + print("Fetched User....") + sender = user.username message_dto.message = ( "A message from {}, manager of {} team:

{}".format( @@ -804,6 +811,8 @@ async def send_message_to_all_team_members( ) messages = [] for team_member in team_members: + print("Looping teams.......") + if team_member.user_id != user_id: message = Message.from_dto(team_member.user_id, message_dto) message.message_type = MessageType.TEAM_BROADCAST.value diff --git a/backend/services/validator_service.py b/backend/services/validator_service.py index 6d337d5809..c9abbf3ba5 100644 --- a/backend/services/validator_service.py +++ b/backend/services/validator_service.py @@ -103,7 +103,7 @@ async def lock_tasks_for_validation( "ProjectNotPublished- Validation not allowed because: Project not published" ) elif error_reason == ValidatingNotAllowed.USER_ALREADY_HAS_TASK_LOCKED: - user_tasks = Task.get_locked_tasks_for_user(validation_dto.user_id) + user_tasks = Task.get_locked_tasks_for_user(validation_dto.user_id, db) if set(user_tasks.locked_tasks) != set(validation_dto.task_ids): raise ValidatorServiceError( "UserAlreadyHasTaskLocked- User already has a task locked"