mirror of
https://github.com/go-gitea/gitea
synced 2025-07-23 02:38:35 +00:00
Clarify path param naming (#32969)
In history (from some legacy frameworks), both `:name` and `name` are supported as path path name, `:name` is an alias to `name`. To make code consistent, now we should only use `name` but not `:name`. Also added panic check in related functions to make sure the name won't be abused in case some downstreams still use them.
This commit is contained in:
@@ -30,7 +30,7 @@ func GitHooksEdit(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("repo.settings.githooks")
|
||||
ctx.Data["PageIsSettingsGitHooks"] = true
|
||||
|
||||
name := ctx.PathParam(":name")
|
||||
name := ctx.PathParam("name")
|
||||
hook, err := ctx.Repo.GitRepo.GetHook(name)
|
||||
if err != nil {
|
||||
if err == git.ErrNotValidHook {
|
||||
@@ -46,7 +46,7 @@ func GitHooksEdit(ctx *context.Context) {
|
||||
|
||||
// GitHooksEditPost response for editing a git hook of a repository
|
||||
func GitHooksEditPost(ctx *context.Context) {
|
||||
name := ctx.PathParam(":name")
|
||||
name := ctx.PathParam("name")
|
||||
hook, err := ctx.Repo.GitRepo.GetHook(name)
|
||||
if err != nil {
|
||||
if err == git.ErrNotValidHook {
|
||||
|
@@ -170,7 +170,7 @@ func setTagsContext(ctx *context.Context) error {
|
||||
func selectProtectedTagByContext(ctx *context.Context) *git_model.ProtectedTag {
|
||||
id := ctx.FormInt64("id")
|
||||
if id == 0 {
|
||||
id = ctx.PathParamInt64(":id")
|
||||
id = ctx.PathParamInt64("id")
|
||||
}
|
||||
|
||||
tag, err := git_model.GetProtectedTagByID(ctx, id)
|
||||
|
@@ -147,7 +147,7 @@ func RunnersEdit(ctx *context.Context) {
|
||||
}
|
||||
|
||||
actions_shared.RunnerDetails(ctx, page,
|
||||
ctx.PathParamInt64(":runnerid"), rCtx.OwnerID, rCtx.RepoID,
|
||||
ctx.PathParamInt64("runnerid"), rCtx.OwnerID, rCtx.RepoID,
|
||||
)
|
||||
ctx.HTML(http.StatusOK, rCtx.RunnerEditTemplate)
|
||||
}
|
||||
@@ -158,9 +158,9 @@ func RunnersEditPost(ctx *context.Context) {
|
||||
ctx.ServerError("getRunnersCtx", err)
|
||||
return
|
||||
}
|
||||
actions_shared.RunnerDetailsEditPost(ctx, ctx.PathParamInt64(":runnerid"),
|
||||
actions_shared.RunnerDetailsEditPost(ctx, ctx.PathParamInt64("runnerid"),
|
||||
rCtx.OwnerID, rCtx.RepoID,
|
||||
rCtx.RedirectLink+url.PathEscape(ctx.PathParam(":runnerid")))
|
||||
rCtx.RedirectLink+url.PathEscape(ctx.PathParam("runnerid")))
|
||||
}
|
||||
|
||||
func ResetRunnerRegistrationToken(ctx *context.Context) {
|
||||
@@ -179,7 +179,7 @@ func RunnerDeletePost(ctx *context.Context) {
|
||||
ctx.ServerError("getRunnersCtx", err)
|
||||
return
|
||||
}
|
||||
actions_shared.RunnerDeletePost(ctx, ctx.PathParamInt64(":runnerid"), rCtx.RedirectLink, rCtx.RedirectLink+url.PathEscape(ctx.PathParam(":runnerid")))
|
||||
actions_shared.RunnerDeletePost(ctx, ctx.PathParamInt64("runnerid"), rCtx.RedirectLink, rCtx.RedirectLink+url.PathEscape(ctx.PathParam("runnerid")))
|
||||
}
|
||||
|
||||
func RedirectToDefaultSetting(ctx *context.Context) {
|
||||
|
@@ -99,9 +99,9 @@ func getOwnerRepoCtx(ctx *context.Context) (*ownerRepoCtx, error) {
|
||||
if ctx.Data["PageIsAdmin"] == true {
|
||||
return &ownerRepoCtx{
|
||||
IsAdmin: true,
|
||||
IsSystemWebhook: ctx.PathParam(":configType") == "system-hooks",
|
||||
IsSystemWebhook: ctx.PathParam("configType") == "system-hooks",
|
||||
Link: path.Join(setting.AppSubURL, "/-/admin/hooks"),
|
||||
LinkNew: path.Join(setting.AppSubURL, "/-/admin/", ctx.PathParam(":configType")),
|
||||
LinkNew: path.Join(setting.AppSubURL, "/-/admin/", ctx.PathParam("configType")),
|
||||
NewTemplate: tplAdminHookNew,
|
||||
}, nil
|
||||
}
|
||||
@@ -110,7 +110,7 @@ func getOwnerRepoCtx(ctx *context.Context) (*ownerRepoCtx, error) {
|
||||
}
|
||||
|
||||
func checkHookType(ctx *context.Context) string {
|
||||
hookType := strings.ToLower(ctx.PathParam(":type"))
|
||||
hookType := strings.ToLower(ctx.PathParam("type"))
|
||||
if !util.SliceContainsString(setting.Webhook.Types, hookType, true) {
|
||||
ctx.NotFound("checkHookType", nil)
|
||||
return ""
|
||||
@@ -592,11 +592,11 @@ func checkWebhook(ctx *context.Context) (*ownerRepoCtx, *webhook.Webhook) {
|
||||
|
||||
var w *webhook.Webhook
|
||||
if orCtx.RepoID > 0 {
|
||||
w, err = webhook.GetWebhookByRepoID(ctx, orCtx.RepoID, ctx.PathParamInt64(":id"))
|
||||
w, err = webhook.GetWebhookByRepoID(ctx, orCtx.RepoID, ctx.PathParamInt64("id"))
|
||||
} else if orCtx.OwnerID > 0 {
|
||||
w, err = webhook.GetWebhookByOwnerID(ctx, orCtx.OwnerID, ctx.PathParamInt64(":id"))
|
||||
w, err = webhook.GetWebhookByOwnerID(ctx, orCtx.OwnerID, ctx.PathParamInt64("id"))
|
||||
} else if orCtx.IsAdmin {
|
||||
w, err = webhook.GetSystemOrDefaultWebhook(ctx, ctx.PathParamInt64(":id"))
|
||||
w, err = webhook.GetSystemOrDefaultWebhook(ctx, ctx.PathParamInt64("id"))
|
||||
}
|
||||
if err != nil || w == nil {
|
||||
if webhook.IsErrWebhookNotExist(err) {
|
||||
@@ -645,7 +645,7 @@ func WebHooksEdit(ctx *context.Context) {
|
||||
|
||||
// TestWebhook test if web hook is work fine
|
||||
func TestWebhook(ctx *context.Context) {
|
||||
hookID := ctx.PathParamInt64(":id")
|
||||
hookID := ctx.PathParamInt64("id")
|
||||
w, err := webhook.GetWebhookByRepoID(ctx, ctx.Repo.Repository.ID, hookID)
|
||||
if err != nil {
|
||||
ctx.Flash.Error("GetWebhookByRepoID: " + err.Error())
|
||||
@@ -706,7 +706,7 @@ func TestWebhook(ctx *context.Context) {
|
||||
|
||||
// ReplayWebhook replays a webhook
|
||||
func ReplayWebhook(ctx *context.Context) {
|
||||
hookTaskUUID := ctx.PathParam(":uuid")
|
||||
hookTaskUUID := ctx.PathParam("uuid")
|
||||
|
||||
orCtx, w := checkWebhook(ctx)
|
||||
if ctx.Written() {
|
||||
|
Reference in New Issue
Block a user