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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. GhostUserID = -1
  33. ActionsUserID = -2
  34. ActionsUserName = "gitea-actions"
  35. ActionsFullName = "Gitea Actions"
  36. ActionsEmail = "teabot@gitea.io"
  37. )
  38. // NewActionsUser creates and returns a fake user for running the actions.
  39. func NewActionsUser() *User {
  40. return &User{
  41. ID: ActionsUserID,
  42. Name: ActionsUserName,
  43. LowerName: ActionsUserName,
  44. IsActive: true,
  45. FullName: ActionsFullName,
  46. Email: ActionsEmail,
  47. KeepEmailPrivate: true,
  48. LoginName: ActionsUserName,
  49. Type: UserTypeIndividual,
  50. AllowCreateOrganization: true,
  51. Visibility: structs.VisibleTypePublic,
  52. }
  53. }
  54. func (u *User) IsActions() bool {
  55. return u != nil && u.ID == ActionsUserID
  56. }