1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Fix context usage (#33554)

Some old code use direct type-casting to get context, it causes
problems.

This PR fixes all legacy problems and use correct `ctx.Value` to get
low-level contexts.

Fix #33518
This commit is contained in:
wxiaoguang
2025-02-11 16:46:03 +08:00
committed by GitHub
parent e9b98aef44
commit 245ac321c3
11 changed files with 18 additions and 17 deletions

View File

@@ -21,8 +21,8 @@ func FormalRenderHelperFuncs() *markup.RenderHelperFuncs {
return false
}
giteaCtx, ok := ctx.(*gitea_context.Context)
if !ok {
giteaCtx := gitea_context.GetWebContext(ctx)
if giteaCtx == nil {
// when using general context, use user's visibility to check
return mentionedUser.Visibility.IsPublic()
}

View File

@@ -36,8 +36,8 @@ func renderRepoFileCodePreview(ctx context.Context, opts markup.RenderCodePrevie
return "", err
}
webCtx, ok := ctx.Value(gitea_context.WebContextKey).(*gitea_context.Context)
if !ok {
webCtx := gitea_context.GetWebContext(ctx)
if webCtx == nil {
return "", fmt.Errorf("context is not a web context")
}
doer := webCtx.Doer

View File

@@ -18,8 +18,8 @@ import (
)
func renderRepoIssueIconTitle(ctx context.Context, opts markup.RenderIssueIconTitleOptions) (_ template.HTML, err error) {
webCtx, ok := ctx.Value(gitea_context.WebContextKey).(*gitea_context.Context)
if !ok {
webCtx := gitea_context.GetWebContext(ctx)
if webCtx == nil {
return "", fmt.Errorf("context is not a web context")
}