Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GhostUser if needed for TrackedTimes (#22021) #22029

Merged
merged 2 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions models/issues/tracked_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package issues

import (
"context"
"errors"
"time"

"code.gitea.io/gitea/models/db"
Expand Down Expand Up @@ -47,33 +48,42 @@ func (t *TrackedTime) LoadAttributes() (err error) {
}

func (t *TrackedTime) loadAttributes(ctx context.Context) (err error) {
// Load the issue
if t.Issue == nil {
t.Issue, err = GetIssueByID(ctx, t.IssueID)
if err != nil {
return

if err != nil && !errors.Is(err, util.ErrNotExist) {
return err
}
}
// Now load the repo for the issue (which we may have just loaded)
if t.Issue != nil {
err = t.Issue.LoadRepo(ctx)
if err != nil {
return
if err != nil && !errors.Is(err, util.ErrNotExist) {
return err
}
}
// Load the user
if t.User == nil {
t.User, err = user_model.GetUserByIDCtx(ctx, t.UserID)
if err != nil {
return
if !errors.Is(err, util.ErrNotExist) {
return err
}
t.User = user_model.NewGhostUser()
}
}
return err
return nil
}

// LoadAttributes load Issue, User
func (tl TrackedTimeList) LoadAttributes() (err error) {
func (tl TrackedTimeList) LoadAttributes() error {
for _, t := range tl {
if err = t.LoadAttributes(); err != nil {
if err := t.LoadAttributes(); err != nil {
return err
}
}
return err
return nil
}

// FindTrackedTimesOptions represent the filters for tracked times. If an ID is 0 it will be ignored.
Expand Down
11 changes: 5 additions & 6 deletions modules/convert/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,11 @@ func ToAPIIssueList(il issues_model.IssueList) []*api.Issue {
// ToTrackedTime converts TrackedTime to API format
func ToTrackedTime(t *issues_model.TrackedTime) (apiT *api.TrackedTime) {
apiT = &api.TrackedTime{
ID: t.ID,
IssueID: t.IssueID,
UserID: t.UserID,
UserName: t.User.Name,
Time: t.Time,
Created: t.Created,
ID: t.ID,
IssueID: t.IssueID,
UserID: t.UserID,
Time: t.Time,
Created: t.Created,
}
if t.Issue != nil {
apiT.Issue = ToAPIIssue(t.Issue)
Expand Down