From a2a5ef8d0e93b52c7f681e09bae3407aed1a7c86 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 3 May 2026 00:32:36 +0800 Subject: [PATCH] Fix update branch protection order (#37508) Regression of changed behavior or Golang JSON v2 package Fix #37506 --- routers/web/repo/setting/protected_branch.go | 13 +++++++++---- routers/web/web.go | 2 +- services/forms/repo_form.go | 4 ---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/routers/web/repo/setting/protected_branch.go b/routers/web/repo/setting/protected_branch.go index 4374e95340a..a5a25e6c4e0 100644 --- a/routers/web/repo/setting/protected_branch.go +++ b/routers/web/repo/setting/protected_branch.go @@ -20,6 +20,7 @@ import ( "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/glob" + "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/templates" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/routers/web/repo" @@ -312,10 +313,14 @@ func DeleteProtectedBranchRulePost(ctx *context.Context) { } func UpdateBranchProtectionPriories(ctx *context.Context) { - form := web.GetForm(ctx).(*forms.ProtectBranchPriorityForm) - repo := ctx.Repo.Repository - - if err := git_model.UpdateProtectBranchPriorities(ctx, repo, form.IDs); err != nil { + var form struct { + IDs []int64 `json:"ids"` + } + if err := json.NewDecoder(ctx.Req.Body).Decode(&form); err != nil { + ctx.JSONError("invalid argument") + return + } + if err := git_model.UpdateProtectBranchPriorities(ctx, ctx.Repo.Repository, form.IDs); err != nil { ctx.ServerError("UpdateProtectBranchPriorities", err) return } diff --git a/routers/web/web.go b/routers/web/web.go index c6dece7b569..ecd75250d24 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1175,7 +1175,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) { m.Combo("/edit").Get(repo_setting.SettingsProtectedBranch). Post(web.Bind(forms.ProtectBranchForm{}), context.RepoMustNotBeArchived(), repo_setting.SettingsProtectedBranchPost) m.Post("/{id}/delete", repo_setting.DeleteProtectedBranchRulePost) - m.Post("/priority", web.Bind(forms.ProtectBranchPriorityForm{}), context.RepoMustNotBeArchived(), repo_setting.UpdateBranchProtectionPriories) + m.Post("/priority", context.RepoMustNotBeArchived(), repo_setting.UpdateBranchProtectionPriories) }) m.Group("/tags", func() { diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index 3135026e36c..d8e019f8609 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -202,10 +202,6 @@ func (f *ProtectBranchForm) Validate(req *http.Request, errs binding.Errors) bin return middleware.Validate(errs, ctx.Data, f, ctx.Locale) } -type ProtectBranchPriorityForm struct { - IDs []int64 -} - // WebhookForm form for changing web hook type WebhookForm struct { Name string `binding:"MaxSize(255)"`