diff options
author | zeripath <art27@cantab.net> | 2022-12-04 17:48:18 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-04 17:48:18 +0000 |
commit | ea86c2b56afeca6450a3e1081c0fd417a09e5434 (patch) | |
tree | 2feef409919b7864dda32a17f9cb5360edab5c75 /models | |
parent | 84d2a820e59f0d96d818d40205d705deab2af576 (diff) | |
download | gitea-ea86c2b56afeca6450a3e1081c0fd417a09e5434.tar.gz gitea-ea86c2b56afeca6450a3e1081c0fd417a09e5434.zip |
Use GhostUser if needed for TrackedTimes (#22021)
When getting tracked times out of the db and loading their attributes
handle not exist errors in a nicer way. (Also prevent an NPE.)
Fix #22006
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'models')
-rw-r--r-- | models/issues/tracked_time.go | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/models/issues/tracked_time.go b/models/issues/tracked_time.go index 2de63a3a45..554b01bd40 100644 --- a/models/issues/tracked_time.go +++ b/models/issues/tracked_time.go @@ -5,6 +5,7 @@ package issues import ( "context" + "errors" "time" "code.gitea.io/gitea/models/db" @@ -46,33 +47,41 @@ 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.GetUserByID(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. |