forked from NYANDEV/forgejo
4a5cdcf649
Refs: https://codeberg.org/forgejo/forgejo/issues/1403 (cherry picked from commit 87bd40411e3af7eefce55e2a05475a8b366caa6f) Conflicts: routers/api/v1/user/user.go https://codeberg.org/forgejo/forgejo/pulls/1469 (cherry picked from commit 74f70ca873fa516e19eeb379dccd0f1fc8fba73b) (cherry picked from commit 673a75bb43fb2808e49df9cd1dc51c075ed1463c) (cherry picked from commit fcd4535ac66609d6e76079af4f97300d31554bee) (cherry picked from commit 56b229f22e55f6e2f6cca8e596cc6d749026eceb) (cherry picked from commit 45b922ae76ef27c368afdb2fe2003f27f65cb470) (cherry picked from commit 03805f3bf45a5617bb92ee2d473605e74a405abb) (cherry picked from commit 16c67f70d54f78613ca8c894613154079e8f0761) (cherry picked from commit 1b862a14adfd0673c65b44485d5a705e0905a60c)
66 lines
1.5 KiB
Go
66 lines
1.5 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package user
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"code.gitea.io/gitea/modules/structs"
|
|
)
|
|
|
|
const GhostUserID = -1
|
|
|
|
// NewGhostUser creates and returns a fake user for someone has deleted their account.
|
|
func NewGhostUser() *User {
|
|
return &User{
|
|
ID: GhostUserID,
|
|
Name: "Ghost",
|
|
LowerName: "ghost",
|
|
}
|
|
}
|
|
|
|
// IsGhost check if user is fake user for a deleted account
|
|
func (u *User) IsGhost() bool {
|
|
if u == nil {
|
|
return false
|
|
}
|
|
return u.ID == -1 && u.Name == "Ghost"
|
|
}
|
|
|
|
// NewReplaceUser creates and returns a fake user for external user
|
|
func NewReplaceUser(name string) *User {
|
|
return &User{
|
|
ID: -1,
|
|
Name: name,
|
|
LowerName: strings.ToLower(name),
|
|
}
|
|
}
|
|
|
|
const (
|
|
ActionsUserID = -2
|
|
ActionsUserName = "gitea-actions"
|
|
ActionsFullName = "Gitea Actions"
|
|
ActionsEmail = "teabot@gitea.io"
|
|
)
|
|
|
|
// NewActionsUser creates and returns a fake user for running the actions.
|
|
func NewActionsUser() *User {
|
|
return &User{
|
|
ID: ActionsUserID,
|
|
Name: ActionsUserName,
|
|
LowerName: ActionsUserName,
|
|
IsActive: true,
|
|
FullName: ActionsFullName,
|
|
Email: ActionsEmail,
|
|
KeepEmailPrivate: true,
|
|
LoginName: ActionsUserName,
|
|
Type: UserTypeIndividual,
|
|
AllowCreateOrganization: true,
|
|
Visibility: structs.VisibleTypePublic,
|
|
}
|
|
}
|
|
|
|
func (u *User) IsActions() bool {
|
|
return u != nil && u.ID == ActionsUserID
|
|
}
|