Skip to content

Commit

Permalink
Replace id by team_id to get id of user teams (#5711)
Browse files Browse the repository at this point in the history
TeamsAllAPI was not working because user.teams returns the TeamMembers table and there is no column named id. During the loop on user.teams, id is replaced by team_id.
  • Loading branch information
Aadesh-Baral authored Apr 17, 2023
1 parent 026c4ff commit 2cab77b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/api/teams/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def get(self):
teams = TeamService.get_all_teams(search_dto)
return teams.to_primitive(), 200
except Exception as e:
error_msg = f"User GET - unhandled error: {str(e)}"
error_msg = f"Teams GET - unhandled error: {str(e)}"
current_app.logger.critical(error_msg)
return {"Error": error_msg, "SubCode": "InternalServerError"}, 500

Expand Down
5 changes: 3 additions & 2 deletions backend/services/team_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,13 @@ def get_all_teams(search_dto: TeamSearchDTO) -> TeamsListDTO:
if orgs_query:
query = query.union(orgs_query)

# Only show public teams or teams that the user is a member of
# Only show public teams and teams that the user is a member of
if not is_admin:
query = query.filter(
or_(
Team.visibility == TeamVisibility.PUBLIC.value,
Team.id.in_([team.id for team in user.teams]),
# Since user.teams returns TeamMembers, we need to get the team_id
Team.id.in_([team.team_id for team in user.teams]),
)
)
teams_list_dto = TeamsListDTO()
Expand Down

0 comments on commit 2cab77b

Please sign in to comment.