mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-23 08:47:42 -05:00
e54348f67c
Refs: https://codeberg.org/forgejo/forgejo/issues/1403 (cherry picked from commit87bd40411e
) Conflicts: routers/api/v1/user/user.go https://codeberg.org/forgejo/forgejo/pulls/1469 (cherry picked from commit74f70ca873
) (cherry picked from commit673a75bb43
) (cherry picked from commitfcd4535ac6
) (cherry picked from commit56b229f22e
) (cherry picked from commit45b922ae76
) (cherry picked from commit03805f3bf4
) (cherry picked from commit16c67f70d5
) (cherry picked from commit1b862a14ad
) (cherry picked from commit4a5cdcf649
)
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
|
|
}
|