mirror of https://sc.cryxtal.org/crystal/forgejo
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
952 B
34 lines
952 B
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package markup
|
|
|
|
import (
|
|
"context"
|
|
|
|
"code.gitea.io/gitea/models/user"
|
|
gitea_context "code.gitea.io/gitea/modules/context"
|
|
"code.gitea.io/gitea/modules/markup"
|
|
)
|
|
|
|
func ProcessorHelper() *markup.ProcessorHelper {
|
|
return &markup.ProcessorHelper{
|
|
IsUsernameMentionable: func(ctx context.Context, username string) bool {
|
|
mentionedUser, err := user.GetUserByName(ctx, username)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
giteaCtx, ok := ctx.(*gitea_context.Context)
|
|
if !ok {
|
|
// 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)
|
|
},
|
|
}
|
|
}
|