fix: never set Poster or Assignee to nil

When a user is not found for whatever reason, it must be mapped to the
GhostUser.

Fixes: https://codeberg.org/forgejo/forgejo/issues/4718
This commit is contained in:
Earl Warren 2024-07-29 11:56:50 +02:00
parent 5bbc9ef97c
commit e6786db393
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
6 changed files with 188 additions and 24 deletions

View file

@ -939,6 +939,20 @@ func GetUserByIDs(ctx context.Context, ids []int64) ([]*User, error) {
return users, err
}
func IsValidUserID(id int64) bool {
return id > 0 || id == GhostUserID || id == ActionsUserID
}
func GetUserFromMap(id int64, idMap map[int64]*User) (int64, *User) {
if user, ok := idMap[id]; ok {
return id, user
}
if id == ActionsUserID {
return ActionsUserID, NewActionsUser()
}
return GhostUserID, NewGhostUser()
}
// 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 {