mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Replace -1 with GhostUserID (#27703)
This commit is contained in:
@@ -58,8 +58,7 @@ func GenerateRandomAvatar(ctx context.Context, u *User) error {
|
||||
|
||||
// AvatarLinkWithSize returns a link to the user's avatar with size. size <= 0 means default size
|
||||
func (u *User) AvatarLinkWithSize(ctx context.Context, size int) string {
|
||||
if u.ID == -1 {
|
||||
// ghost user
|
||||
if u.IsGhost() {
|
||||
return avatars.DefaultAvatarLink()
|
||||
}
|
||||
|
||||
|
@@ -933,7 +933,7 @@ func GetUserByIDs(ctx context.Context, ids []int64) ([]*User, error) {
|
||||
// GetPossibleUserByID returns the user if id > 0 or return system usrs if id < 0
|
||||
func GetPossibleUserByID(ctx context.Context, id int64) (*User, error) {
|
||||
switch id {
|
||||
case -1:
|
||||
case GhostUserID:
|
||||
return NewGhostUser(), nil
|
||||
case ActionsUserID:
|
||||
return NewActionsUser(), nil
|
||||
@@ -949,7 +949,7 @@ func GetPossibleUserByIDs(ctx context.Context, ids []int64) ([]*User, error) {
|
||||
uniqueIDs := container.SetOf(ids...)
|
||||
users := make([]*User, 0, len(ids))
|
||||
_ = uniqueIDs.Remove(0)
|
||||
if uniqueIDs.Remove(-1) {
|
||||
if uniqueIDs.Remove(GhostUserID) {
|
||||
users = append(users, NewGhostUser())
|
||||
}
|
||||
if uniqueIDs.Remove(ActionsUserID) {
|
||||
|
@@ -9,12 +9,18 @@ import (
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
)
|
||||
|
||||
const (
|
||||
GhostUserID = -1
|
||||
GhostUserName = "Ghost"
|
||||
GhostUserLowerName = "ghost"
|
||||
)
|
||||
|
||||
// NewGhostUser creates and returns a fake user for someone has deleted their account.
|
||||
func NewGhostUser() *User {
|
||||
return &User{
|
||||
ID: -1,
|
||||
Name: "Ghost",
|
||||
LowerName: "ghost",
|
||||
ID: GhostUserID,
|
||||
Name: GhostUserName,
|
||||
LowerName: GhostUserLowerName,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,13 +29,13 @@ func (u *User) IsGhost() bool {
|
||||
if u == nil {
|
||||
return false
|
||||
}
|
||||
return u.ID == -1 && u.Name == "Ghost"
|
||||
return u.ID == GhostUserID && u.Name == GhostUserName
|
||||
}
|
||||
|
||||
// NewReplaceUser creates and returns a fake user for external user
|
||||
func NewReplaceUser(name string) *User {
|
||||
return &User{
|
||||
ID: -1,
|
||||
ID: 0,
|
||||
Name: name,
|
||||
LowerName: strings.ToLower(name),
|
||||
}
|
||||
|
Reference in New Issue
Block a user