]> source.dussan.org Git - gitea.git/commitdiff
fix bug when users have serval teams with different units on different repositories...
authorLunny Xiao <xiaolunwen@gmail.com>
Fri, 9 Nov 2018 06:16:52 +0000 (14:16 +0800)
committerLauris BH <lauris@nix.lv>
Fri, 9 Nov 2018 06:16:52 +0000 (08:16 +0200)
models/org_team.go
models/repo.go

index 505f11d39df5e70ae66f917a6148ff591205d111..ad11431a4954ed0526840b950ab340059186437d 100644 (file)
@@ -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)
index 3e18776046062d3df9597694b4845cc267e91018..b7be50e9d17a5895cb5919c60d3e5b50b46967ea 100644 (file)
@@ -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
        }