Skip to content

Commit

Permalink
fix: Join team by request
Browse files Browse the repository at this point in the history
  • Loading branch information
prabinoid committed Nov 14, 2024
1 parent 4d64e02 commit 654d9d4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
9 changes: 5 additions & 4 deletions backend/api/teams/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions backend/services/messaging/message_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions backend/services/team_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
"""
Expand Down

0 comments on commit 654d9d4

Please sign in to comment.