fix bug when users have serval teams with different units on different repositories (#5307)

This commit is contained in:
Lunny Xiao 2018-11-09 14:16:52 +08:00 committed by Lauris BH
parent 599adde1bc
commit c5d098c32e
2 changed files with 11 additions and 1 deletions

View file

@ -525,6 +525,16 @@ func getUserTeams(e Engine, orgID, userID int64) (teams []*Team, err error) {
Find(&teams) 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. // GetUserTeams returns all teams that user belongs to in given organization.
func GetUserTeams(orgID, userID int64) ([]*Team, error) { func GetUserTeams(orgID, userID int64) ([]*Team, error) {
return getUserTeams(x, orgID, userID) return getUserTeams(x, orgID, userID)

View file

@ -364,7 +364,7 @@ func (repo *Repository) getUnitsByUserID(e Engine, userID int64, isAdmin bool) (
return nil return nil
} }
teams, err := getUserTeams(e, repo.OwnerID, userID) teams, err := getUserRepoTeams(e, repo.OwnerID, userID, repo.ID)
if err != nil { if err != nil {
return err return err
} }