From 654d9d42515e032a2f09a2797499dace7266fc35 Mon Sep 17 00:00:00 2001 From: prabinoid <38830224+prabinoid@users.noreply.github.com> Date: Thu, 14 Nov 2024 14:21:27 +0545 Subject: [PATCH] fix: Join team by request --- backend/api/teams/actions.py | 9 +++++---- backend/services/messaging/message_service.py | 5 ----- backend/services/team_service.py | 11 ++++++----- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/backend/api/teams/actions.py b/backend/api/teams/actions.py index 7ddf9ac2c9..2913a507c5 100644 --- a/backend/api/teams/actions.py +++ b/backend/api/teams/actions.py @@ -62,10 +62,11 @@ async def post( description: Internal Server Error """ try: - await TeamService.request_to_join_team(team_id, user.id, db) - return JSONResponse( - content={"Success": "Join request successful"}, status_code=200 - ) + async with db.transaction(): + await TeamService.request_to_join_team(team_id, user.id, db) + return JSONResponse( + content={"Success": "Join request successful"}, status_code=200 + ) except TeamServiceError as e: return JSONResponse( content={"Error": str(e), "SubCode": "InvalidRequest"}, status_code=400 diff --git a/backend/services/messaging/message_service.py b/backend/services/messaging/message_service.py index 19aaf4a5cd..b7ddb12a9a 100644 --- a/backend/services/messaging/message_service.py +++ b/backend/services/messaging/message_service.py @@ -270,13 +270,10 @@ async def send_message_after_comment( """Will send a canned message to anyone @'d in a comment""" # Fetch the user who made the comment comment_from_user = await UserService.get_user_by_id(comment_from, db) - print(comment, "The comment....") # Parse the comment for mentions usernames = await MessageService._parse_message_for_username( comment, project_id, task_id, db ) - print(usernames, "The list of usernamess....") - if comment_from_user.username in usernames: usernames.remove(comment_from_user.username) @@ -330,7 +327,6 @@ async def send_message_after_comment( for username in usernames: try: user = await UserService.get_user_by_username(username, db) - print(user, "The userrrr...") except NotFound: continue @@ -1011,7 +1007,6 @@ async def get_message_as_dto(message_id: int, user_id: int, db: Database): message_dict = dict(message) message_dict["message_type"] = MessageType(message_dict["message_type"]).name - print(message_dict, "blaaaaaa...") return message_dict @staticmethod diff --git a/backend/services/team_service.py b/backend/services/team_service.py index 99e71f61c4..cfd01ece95 100644 --- a/backend/services/team_service.py +++ b/backend/services/team_service.py @@ -84,15 +84,16 @@ async def request_to_join_team(team_id: int, user_id: int, db: Database): if team.join_method == TeamJoinMethod.ANY.value: active = True await TeamService.add_team_member(team_id, user_id, role, active, db) - # Notify team managers about a join request in BY_REQUEST team. if team.join_method == TeamJoinMethod.BY_REQUEST.value: team_managers = await Team.get_team_managers(db, team.id) for manager in team_managers: - # Only send notifications to team managers who have join request notification enabled. if manager.join_request_notifications: - MessageService.send_request_to_join_team( - user.id, user.username, manager.user_id, team.name, team_id, db + manager_obj = await UserService.get_user_by_username( + manager.username, db + ) + await MessageService.send_request_to_join_team( + user.id, user.username, manager_obj.id, team.name, team_id, db ) @staticmethod @@ -547,7 +548,7 @@ async def get_team_by_id(team_id: int, db: Database): """ # Raw SQL query to select the team by ID query = """ - SELECT id, name, organisation_id + SELECT id, name, organisation_id, join_method, description, visibility FROM teams WHERE id = :team_id """