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.
This commit is contained in:
bayangan1991 2018-03-08 23:11:34 +11:00 committed by jc
parent 679147cd5d
commit 51e087fd87

View File

@ -642,8 +642,14 @@ func viewIssue(c *context.Context, isPullList bool) {
if issue.IsPull && issue.PullRequest.HasMerged { if issue.IsPull && issue.PullRequest.HasMerged {
pull := issue.PullRequest 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.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 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"]) c.Data["DeleteBranchLink"] = fmt.Sprintf("%s?commit=%s&redirect_to=%s", deleteBranchUrl, pull.MergedCommitID, c.Data["Link"])