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.

user_system.go 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2022 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package user
  4. import (
  5. "strings"
  6. "code.gitea.io/gitea/modules/structs"
  7. )
  8. // NewGhostUser creates and returns a fake user for someone has deleted their account.
  9. func NewGhostUser() *User {
  10. return &User{
  11. ID: -1,
  12. Name: "Ghost",
  13. LowerName: "ghost",
  14. }
  15. }
  16. // IsGhost check if user is fake user for a deleted account
  17. func (u *User) IsGhost() bool {
  18. if u == nil {
  19. return false
  20. }
  21. return u.ID == -1 && u.Name == "Ghost"
  22. }
  23. // NewReplaceUser creates and returns a fake user for external user
  24. func NewReplaceUser(name string) *User {
  25. return &User{
  26. ID: -1,
  27. Name: name,
  28. LowerName: strings.ToLower(name),
  29. }
  30. }
  31. const (
  32. ActionsUserID = -2
  33. ActionsUserName = "gitea-actions"
  34. ActionsFullName = "Gitea Actions"
  35. ActionsEmail = "teabot@gitea.io"
  36. )
  37. // NewActionsUser creates and returns a fake user for running the actions.
  38. func NewActionsUser() *User {
  39. return &User{
  40. ID: ActionsUserID,
  41. Name: ActionsUserName,
  42. LowerName: ActionsUserName,
  43. IsActive: true,
  44. FullName: ActionsFullName,
  45. Email: ActionsEmail,
  46. KeepEmailPrivate: true,
  47. LoginName: ActionsUserName,
  48. Type: UserTypeIndividual,
  49. AllowCreateOrganization: true,
  50. Visibility: structs.VisibleTypePublic,
  51. }
  52. }
  53. func (u *User) IsActions() bool {
  54. return u != nil && u.ID == ActionsUserID
  55. }