aboutsummaryrefslogtreecommitdiffstats
path: root/models/org_team.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2017-09-14 16:16:22 +0800
committerGitHub <noreply@github.com>2017-09-14 16:16:22 +0800
commit1739e84ac02c0384c04576a00abab9348293f9c7 (patch)
tree1015e68f36421f274d2e883ff3ddb0cb29b6af71 /models/org_team.go
parentbe3319b3d545289b772d7a92b4b62205863954d9 (diff)
downloadgitea-1739e84ac02c0384c04576a00abab9348293f9c7.tar.gz
gitea-1739e84ac02c0384c04576a00abab9348293f9c7.zip
improve protected branch to add whitelist support (#2451)
* improve protected branch to add whitelist support * fix lint * fix style check * fix tests * fix description on UI and import * fix test * bug fixed * fix tests and languages * move isSliceInt64Eq to util pkg; improve function names & typo
Diffstat (limited to 'models/org_team.go')
-rw-r--r--models/org_team.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/models/org_team.go b/models/org_team.go
index bc0e12b504..acddc70b58 100644
--- a/models/org_team.go
+++ b/models/org_team.go
@@ -35,6 +35,11 @@ func (t *Team) GetUnitTypes() []UnitType {
return t.UnitTypes
}
+// HasWriteAccess returns true if team has at least write level access mode.
+func (t *Team) HasWriteAccess() bool {
+ return t.Authorize >= AccessModeWrite
+}
+
// IsOwnerTeam returns true if team is owner team.
func (t *Team) IsOwnerTeam() bool {
return t.Name == ownerTeamName
@@ -594,6 +599,11 @@ func RemoveTeamMember(team *Team, userID int64) error {
return sess.Commit()
}
+// IsUserInTeams returns if a user in some teams
+func IsUserInTeams(userID int64, teamIDs []int64) (bool, error) {
+ return x.Where("uid=?", userID).In("team_id", teamIDs).Exist(new(TeamUser))
+}
+
// ___________ __________
// \__ ___/___ _____ _____\______ \ ____ ______ ____
// | |_/ __ \\__ \ / \| _// __ \\____ \ / _ \
@@ -639,3 +649,13 @@ func removeTeamRepo(e Engine, teamID, repoID int64) error {
})
return err
}
+
+// GetTeamsWithAccessToRepo returns all teams in an organization that have given access level to the repository.
+func GetTeamsWithAccessToRepo(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)
+}