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.

processorhelper.go 960B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2022 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package markup
  4. import (
  5. "context"
  6. "code.gitea.io/gitea/models/user"
  7. gitea_context "code.gitea.io/gitea/modules/context"
  8. "code.gitea.io/gitea/modules/markup"
  9. )
  10. func ProcessorHelper() *markup.ProcessorHelper {
  11. return &markup.ProcessorHelper{
  12. ElementDir: "auto", // set dir="auto" for necessary (eg: <p>, <h?>, etc) tags
  13. IsUsernameMentionable: func(ctx context.Context, username string) bool {
  14. mentionedUser, err := user.GetUserByName(ctx, username)
  15. if err != nil {
  16. return false
  17. }
  18. giteaCtx, ok := ctx.(*gitea_context.Context)
  19. if !ok {
  20. // when using general context, use user's visibility to check
  21. return mentionedUser.Visibility.IsPublic()
  22. }
  23. // when using gitea context (web context), use user's visibility and user's permission to check
  24. return user.IsUserVisibleToViewer(giteaCtx, mentionedUser, giteaCtx.Doer)
  25. },
  26. }
  27. }