diff options
author | bayangan1991 <ryan.bayangan@gmail.com> | 2018-03-08 23:11:34 +1100 |
---|---|---|
committer | jc <u@gogs.io> | 2018-03-08 07:11:34 -0500 |
commit | 51e087fd8731137c969f616bc90f383a2c2bff27 (patch) | |
tree | c8019a214d0c5708070f16ecef2a273f4c4e217c | |
parent | 679147cd5d9d3184e32849512a8c2cd616074244 (diff) |
repo: disallow web ui to delete protected branch after PR merged (#4803)
* Disallow web ui to delete protected branch
* Fix for branches not yet protected
Had to change how error was handled. If a branch had not yet been protected the error would be generated.
Reworked to start as false and then use the protected if it was found.
-rw-r--r-- | routes/repo/issue.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/routes/repo/issue.go b/routes/repo/issue.go index 8920bc32..29fab3af 100644 --- a/routes/repo/issue.go +++ b/routes/repo/issue.go @@ -642,8 +642,14 @@ func viewIssue(c *context.Context, isPullList bool) { if issue.IsPull && issue.PullRequest.HasMerged { pull := issue.PullRequest + branchProtected := false + protectBranch, err := models.GetProtectBranchOfRepoByName(pull.BaseRepoID, pull.HeadBranch) + if err == nil { + branchProtected = protectBranch.Protected + } c.Data["IsPullBranchDeletable"] = pull.BaseRepoID == pull.HeadRepoID && - c.Repo.IsWriter() && c.Repo.GitRepo.IsBranchExist(pull.HeadBranch) + c.Repo.IsWriter() && c.Repo.GitRepo.IsBranchExist(pull.HeadBranch) && + !branchProtected deleteBranchUrl := c.Repo.RepoLink + "/branches/delete/" + pull.HeadBranch c.Data["DeleteBranchLink"] = fmt.Sprintf("%s?commit=%s&redirect_to=%s", deleteBranchUrl, pull.MergedCommitID, c.Data["Link"]) |