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

@ -23,7 +23,7 @@ func (comments CommentList) LoadPosters(ctx context.Context) error {
}
posterIDs := container.FilterSlice(comments, func(c *Comment) (int64, bool) {
return c.PosterID, c.Poster == nil && c.PosterID > 0
return c.PosterID, c.Poster == nil && user_model.IsValidUserID(c.PosterID)
})
posterMaps, err := getPostersByIDs(ctx, posterIDs)
@ -33,7 +33,7 @@ func (comments CommentList) LoadPosters(ctx context.Context) error {
for _, comment := range comments {
if comment.Poster == nil {
comment.Poster = getPoster(comment.PosterID, posterMaps)
comment.PosterID, comment.Poster = user_model.GetUserFromMap(comment.PosterID, posterMaps)
}
}
return nil
@ -165,7 +165,7 @@ func (comments CommentList) loadOldMilestones(ctx context.Context) error {
func (comments CommentList) getAssigneeIDs() []int64 {
return container.FilterSlice(comments, func(comment *Comment) (int64, bool) {
return comment.AssigneeID, comment.AssigneeID > 0
return comment.AssigneeID, user_model.IsValidUserID(comment.AssigneeID)
})
}
@ -206,11 +206,7 @@ func (comments CommentList) loadAssignees(ctx context.Context) error {
}
for _, comment := range comments {
comment.Assignee = assignees[comment.AssigneeID]
if comment.Assignee == nil {
comment.AssigneeID = user_model.GhostUserID
comment.Assignee = user_model.NewGhostUser()
}
comment.AssigneeID, comment.Assignee = user_model.GetUserFromMap(comment.AssigneeID, assignees)
}
return nil
}