2022-10-22 22:45:52 +05:30
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2022-10-22 22:45:52 +05:30
|
|
|
|
|
|
|
package markup
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models/user"
|
2022-10-23 14:43:52 +05:30
|
|
|
gitea_context "code.gitea.io/gitea/modules/context"
|
2022-10-22 22:45:52 +05:30
|
|
|
"code.gitea.io/gitea/modules/markup"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ProcessorHelper() *markup.ProcessorHelper {
|
|
|
|
return &markup.ProcessorHelper{
|
|
|
|
IsUsernameMentionable: func(ctx context.Context, username string) bool {
|
2022-10-23 14:43:52 +05:30
|
|
|
mentionedUser, err := user.GetUserByName(ctx, username)
|
2022-10-22 22:45:52 +05:30
|
|
|
if err != nil {
|
2022-10-23 14:43:52 +05:30
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
giteaCtx, ok := ctx.(*gitea_context.Context)
|
|
|
|
if !ok {
|
|
|
|
// when using general context, use user's visibility to check
|
|
|
|
return mentionedUser.Visibility.IsPublic()
|
2022-10-22 22:45:52 +05:30
|
|
|
}
|
2022-10-23 14:43:52 +05:30
|
|
|
|
|
|
|
// when using gitea context (web context), use user's visibility and user's permission to check
|
|
|
|
return user.IsUserVisibleToViewer(giteaCtx, mentionedUser, giteaCtx.Doer)
|
2022-10-22 22:45:52 +05:30
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|