diff options
author | David Svantesson <davidsvantesson@gmail.com> | 2020-02-13 00:19:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-12 23:19:35 +0000 |
commit | 9ff4e1d2d9636ea8aa328427f1d31c962221263e (patch) | |
tree | b0df096e3885a6f05c26959f784cca0ce6a9763c /models/org_team.go | |
parent | 908f8952be3ba7a4e4c32b0fd0dab5eb08ca8dd4 (diff) | |
download | gitea-9ff4e1d2d9636ea8aa328427f1d31c962221263e.tar.gz gitea-9ff4e1d2d9636ea8aa328427f1d31c962221263e.zip |
Add API branch protection endpoint (#9311)
* add API branch protection endpoint
* lint
* Change to use team names instead of ids.
* Status codes.
* fix
* Fix
* Add new branch protection options (BlockOnRejectedReviews, DismissStaleApprovals, RequireSignedCommits)
* Do xorm query directly
* fix xorm GetUserNamesByIDs
* Add some tests
* Improved GetTeamNamesByID
* http status created for CreateBranchProtection
* Correct status code in integration test
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'models/org_team.go')
-rw-r--r-- | models/org_team.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/models/org_team.go b/models/org_team.go index 214790703c..f8013d12c6 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -553,6 +553,23 @@ func GetTeam(orgID int64, name string) (*Team, error) { return getTeam(x, orgID, name) } +// GetTeamIDsByNames returns a slice of team ids corresponds to names. +func GetTeamIDsByNames(orgID int64, names []string, ignoreNonExistent bool) ([]int64, error) { + ids := make([]int64, 0, len(names)) + for _, name := range names { + u, err := GetTeam(orgID, name) + if err != nil { + if ignoreNonExistent { + continue + } else { + return nil, err + } + } + ids = append(ids, u.ID) + } + return ids, nil +} + // getOwnerTeam returns team by given team name and organization. func getOwnerTeam(e Engine, orgID int64) (*Team, error) { return getTeam(e, orgID, ownerTeamName) @@ -574,6 +591,22 @@ func GetTeamByID(teamID int64) (*Team, error) { return getTeamByID(x, teamID) } +// GetTeamNamesByID returns team's lower name from a list of team ids. +func GetTeamNamesByID(teamIDs []int64) ([]string, error) { + if len(teamIDs) == 0 { + return []string{}, nil + } + + var teamNames []string + err := x.Table("team"). + Select("lower_name"). + In("id", teamIDs). + Asc("name"). + Find(&teamNames) + + return teamNames, err +} + // UpdateTeam updates information of team. func UpdateTeam(t *Team, authChanged bool, includeAllChanged bool) (err error) { if len(t.Name) == 0 { |