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