mirror of
https://github.com/go-gitea/gitea
synced 2025-02-25 14:24:18 +00:00
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
35 lines
1016 B
Go
35 lines
1016 B
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package markup
|
|
|
|
import (
|
|
"context"
|
|
|
|
"code.gitea.io/gitea/models/user"
|
|
"code.gitea.io/gitea/modules/markup"
|
|
gitea_context "code.gitea.io/gitea/services/context"
|
|
)
|
|
|
|
func FormalRenderHelperFuncs() *markup.RenderHelperFuncs {
|
|
return &markup.RenderHelperFuncs{
|
|
RenderRepoFileCodePreview: renderRepoFileCodePreview,
|
|
RenderRepoIssueIconTitle: renderRepoIssueIconTitle,
|
|
IsUsernameMentionable: func(ctx context.Context, username string) bool {
|
|
mentionedUser, err := user.GetUserByName(ctx, username)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
giteaCtx := gitea_context.GetWebContext(ctx)
|
|
if giteaCtx == nil {
|
|
// when using general context, use user's visibility to check
|
|
return mentionedUser.Visibility.IsPublic()
|
|
}
|
|
|
|
// when using gitea context (web context), use user's visibility and user's permission to check
|
|
return user.IsUserVisibleToViewer(giteaCtx, mentionedUser, giteaCtx.Doer)
|
|
},
|
|
}
|
|
}
|