aboutsummaryrefslogtreecommitdiff
path: root/models/org_team.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2017-02-24 13:19:42 -0500
committerUnknwon <u@gogs.io>2017-02-24 13:19:42 -0500
commit0696d430c9baa409297dc06ffa0ab84c0ea44a29 (patch)
tree7fac3c1319c28af84a9a534dbe86f9fed920b441 /models/org_team.go
parent68b231bd89ab4bf2061a4f83dba67e3e901f2e45 (diff)
protect_branch: only list teams have write access
List teams without write access to the repository cause confusion to make users think members of team could push to the branch.
Diffstat (limited to 'models/org_team.go')
-rw-r--r--models/org_team.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/models/org_team.go b/models/org_team.go
index 9d2835cb..d4a6b1e3 100644
--- a/models/org_team.go
+++ b/models/org_team.go
@@ -615,18 +615,18 @@ func RemoveTeamMember(orgID, teamID, uid int64) error {
// TeamRepo represents an team-repository relation.
type TeamRepo struct {
- ID int64 `xorm:"pk autoincr"`
+ ID int64
OrgID int64 `xorm:"INDEX"`
TeamID int64 `xorm:"UNIQUE(s)"`
RepoID int64 `xorm:"UNIQUE(s)"`
}
func hasTeamRepo(e Engine, orgID, teamID, repoID int64) bool {
- has, _ := e.Where("org_id=?", orgID).And("team_id=?", teamID).And("repo_id=?", repoID).Get(new(TeamRepo))
+ has, _ := e.Where("org_id = ?", orgID).And("team_id = ?", teamID).And("repo_id = ?", repoID).Get(new(TeamRepo))
return has
}
-// HasTeamRepo returns true if given repository belongs to team.
+// HasTeamRepo returns true if given team has access to the repository of the organization.
func HasTeamRepo(orgID, teamID, repoID int64) bool {
return hasTeamRepo(x, orgID, teamID, repoID)
}
@@ -657,3 +657,13 @@ func removeTeamRepo(e Engine, teamID, repoID int64) error {
func RemoveTeamRepo(teamID, repoID int64) error {
return removeTeamRepo(x, teamID, repoID)
}
+
+// GetTeamsHaveAccessToRepo returns all teams in an organization that have given access level to the repository.
+func GetTeamsHaveAccessToRepo(orgID, repoID int64, mode AccessMode) ([]*Team, error) {
+ teams := make([]*Team, 0, 5)
+ return teams, x.Where("team.authorize >= ?", mode).
+ Join("INNER", "team_repo", "team_repo.team_id = team.id").
+ And("team_repo.org_id = ?", orgID).
+ And("team_repo.repo_id = ?", repoID).
+ Find(&teams)
+}