From c5d098c32e85d2ac42d318de5a37b7bfe34dc8cc Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 9 Nov 2018 14:16:52 +0800 Subject: [PATCH] fix bug when users have serval teams with different units on different repositories (#5307) --- models/org_team.go | 10 ++++++++++ models/repo.go | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/models/org_team.go b/models/org_team.go index 505f11d39..ad11431a4 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -525,6 +525,16 @@ func getUserTeams(e Engine, orgID, userID int64) (teams []*Team, err error) { Find(&teams) } +func getUserRepoTeams(e Engine, orgID, userID, repoID int64) (teams []*Team, err error) { + return teams, e. + Join("INNER", "team_user", "team_user.team_id = team.id"). + Join("INNER", "team_repo", "team_repo.team_id = team.id"). + Where("team.org_id = ?", orgID). + And("team_user.uid=?", userID). + And("team_repo.repo_id=?", repoID). + Find(&teams) +} + // GetUserTeams returns all teams that user belongs to in given organization. func GetUserTeams(orgID, userID int64) ([]*Team, error) { return getUserTeams(x, orgID, userID) diff --git a/models/repo.go b/models/repo.go index 3e1877604..b7be50e9d 100644 --- a/models/repo.go +++ b/models/repo.go @@ -364,7 +364,7 @@ func (repo *Repository) getUnitsByUserID(e Engine, userID int64, isAdmin bool) ( return nil } - teams, err := getUserTeams(e, repo.OwnerID, userID) + teams, err := getUserRepoTeams(e, repo.OwnerID, userID, repo.ID) if err != nil { return err }