diff options
author | Unknwon <u@gogs.io> | 2017-02-23 18:25:12 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2017-02-23 18:25:12 -0500 |
commit | 6072e9a52cf01723aea2b9a5ca7dfe22b101fbfc (patch) | |
tree | 17fe0e830584dfef2ff855bc75992df727997c08 /routers | |
parent | b78e03934d057bdb4c628fefb364dda6eb1f260a (diff) |
repo: add protect branch whitelist (#4177)
Add options to add users and teams to whitelist of a protected
branch. This is only available for organizational repositories.
Diffstat (limited to 'routers')
-rw-r--r-- | routers/repo/setting.go | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 769794f9..eb8048c5 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -415,7 +415,6 @@ func SettingsProtectedBranch(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.settings.protected_branches") + " - " + branch ctx.Data["PageIsSettingsBranches"] = true - ctx.Data["IsOrgRepo"] = ctx.Repo.Owner.IsOrganization() protectBranch, err := models.GetProtectBranchOfRepoByName(ctx.Repo.Repository.ID, branch) if err != nil { @@ -430,6 +429,23 @@ func SettingsProtectedBranch(ctx *context.Context) { } } + if ctx.Repo.Owner.IsOrganization() { + users, err := ctx.Repo.Repository.GetWriters() + if err != nil { + ctx.Handle(500, "Repo.Repository.GetPushers", err) + return + } + ctx.Data["Users"] = users + ctx.Data["whitelist_users"] = protectBranch.WhitelistUserIDs + + if err = ctx.Repo.Owner.GetTeams(); err != nil { + ctx.Handle(500, "Repo.Owner.GetTeams", err) + return + } + ctx.Data["Teams"] = ctx.Repo.Owner.Teams + ctx.Data["whitelist_teams"] = protectBranch.WhitelistTeamIDs + } + ctx.Data["Branch"] = protectBranch ctx.HTML(200, SETTINGS_PROTECTED_BRANCH) } @@ -457,8 +473,14 @@ func SettingsProtectedBranchPost(ctx *context.Context, form auth.ProtectBranchFo protectBranch.Protected = form.Protected protectBranch.RequirePullRequest = form.RequirePullRequest - if err = models.UpdateProtectBranch(protectBranch); err != nil { - ctx.Handle(500, "UpdateProtectBranch", err) + protectBranch.EnableWhitelist = form.EnableWhitelist + if ctx.Repo.Owner.IsOrganization() { + err = models.UpdateOrgProtectBranch(ctx.Repo.Repository, protectBranch, form.WhitelistUsers, form.WhitelistTeams) + } else { + err = models.UpdateProtectBranch(protectBranch) + } + if err != nil { + ctx.Handle(500, "UpdateOrgProtectBranch/UpdateProtectBranch", err) return } |