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:
parent
b8b690feb9
commit
2a828e2798
102 changed files with 461 additions and 429 deletions
|
@ -33,7 +33,7 @@ func UserAssignmentWeb() func(ctx *Context) {
|
|||
// UserIDAssignmentAPI returns a middleware to handle context-user assignment for api routes
|
||||
func UserIDAssignmentAPI() func(ctx *APIContext) {
|
||||
return func(ctx *APIContext) {
|
||||
userID := ctx.PathParamInt64(":user-id")
|
||||
userID := ctx.PathParamInt64("user-id")
|
||||
|
||||
if ctx.IsSigned && ctx.Doer.ID == userID {
|
||||
ctx.ContextUser = ctx.Doer
|
||||
|
@ -59,7 +59,7 @@ func UserAssignmentAPI() func(ctx *APIContext) {
|
|||
}
|
||||
|
||||
func userAssignment(ctx *Base, doer *user_model.User, errCb func(int, string, any)) (contextUser *user_model.User) {
|
||||
username := ctx.PathParam(":username")
|
||||
username := ctx.PathParam("username")
|
||||
|
||||
if doer != nil && doer.LowerName == strings.ToLower(username) {
|
||||
contextUser = doer
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue