mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
More db.DefaultContext
refactor (#27265)
Part of #27065 This PR touches functions used in templates. As templates are not static typed, errors are harder to find, but I hope I catch it all. I think some tests from other persons do not hurt.
This commit is contained in:
@@ -19,9 +19,9 @@ func ToAPIComment(ctx context.Context, repo *repo_model.Repository, c *issues_mo
|
||||
return &api.Comment{
|
||||
ID: c.ID,
|
||||
Poster: ToUser(ctx, c.Poster, nil),
|
||||
HTMLURL: c.HTMLURL(),
|
||||
IssueURL: c.IssueURL(),
|
||||
PRURL: c.PRURL(),
|
||||
HTMLURL: c.HTMLURL(ctx),
|
||||
IssueURL: c.IssueURL(ctx),
|
||||
PRURL: c.PRURL(ctx),
|
||||
Body: c.Content,
|
||||
Attachments: ToAPIAttachments(repo, c.Attachments),
|
||||
Created: c.CreatedUnix.AsTime(),
|
||||
@@ -37,19 +37,19 @@ func ToTimelineComment(ctx context.Context, repo *repo_model.Repository, c *issu
|
||||
return nil
|
||||
}
|
||||
|
||||
err = c.LoadAssigneeUserAndTeam()
|
||||
err = c.LoadAssigneeUserAndTeam(ctx)
|
||||
if err != nil {
|
||||
log.Error("LoadAssigneeUserAndTeam: %v", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
err = c.LoadResolveDoer()
|
||||
err = c.LoadResolveDoer(ctx)
|
||||
if err != nil {
|
||||
log.Error("LoadResolveDoer: %v", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
err = c.LoadDepIssueDetails()
|
||||
err = c.LoadDepIssueDetails(ctx)
|
||||
if err != nil {
|
||||
log.Error("LoadDepIssueDetails: %v", err)
|
||||
return nil
|
||||
@@ -61,7 +61,7 @@ func ToTimelineComment(ctx context.Context, repo *repo_model.Repository, c *issu
|
||||
return nil
|
||||
}
|
||||
|
||||
err = c.LoadLabel()
|
||||
err = c.LoadLabel(ctx)
|
||||
if err != nil {
|
||||
log.Error("LoadLabel: %v", err)
|
||||
return nil
|
||||
@@ -82,9 +82,9 @@ func ToTimelineComment(ctx context.Context, repo *repo_model.Repository, c *issu
|
||||
ID: c.ID,
|
||||
Type: c.Type.String(),
|
||||
Poster: ToUser(ctx, c.Poster, nil),
|
||||
HTMLURL: c.HTMLURL(),
|
||||
IssueURL: c.IssueURL(),
|
||||
PRURL: c.PRURL(),
|
||||
HTMLURL: c.HTMLURL(ctx),
|
||||
IssueURL: c.IssueURL(ctx),
|
||||
PRURL: c.PRURL(ctx),
|
||||
Body: c.Content,
|
||||
Created: c.CreatedUnix.AsTime(),
|
||||
Updated: c.UpdatedUnix.AsTime(),
|
||||
|
@@ -4,17 +4,17 @@
|
||||
package convert
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
|
||||
activities_model "code.gitea.io/gitea/models/activities"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/perm"
|
||||
access_model "code.gitea.io/gitea/models/perm/access"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
)
|
||||
|
||||
// ToNotificationThread convert a Notification to api.NotificationThread
|
||||
func ToNotificationThread(n *activities_model.Notification) *api.NotificationThread {
|
||||
func ToNotificationThread(ctx context.Context, n *activities_model.Notification) *api.NotificationThread {
|
||||
result := &api.NotificationThread{
|
||||
ID: n.ID,
|
||||
Unread: !(n.Status == activities_model.NotificationStatusRead || n.Status == activities_model.NotificationStatusPinned),
|
||||
@@ -25,7 +25,7 @@ func ToNotificationThread(n *activities_model.Notification) *api.NotificationThr
|
||||
|
||||
// since user only get notifications when he has access to use minimal access mode
|
||||
if n.Repository != nil {
|
||||
result.Repository = ToRepo(db.DefaultContext, n.Repository, access_model.Permission{AccessMode: perm.AccessModeRead})
|
||||
result.Repository = ToRepo(ctx, n.Repository, access_model.Permission{AccessMode: perm.AccessModeRead})
|
||||
|
||||
// This permission is not correct and we should not be reporting it
|
||||
for repository := result.Repository; repository != nil; repository = repository.Parent {
|
||||
@@ -44,8 +44,8 @@ func ToNotificationThread(n *activities_model.Notification) *api.NotificationThr
|
||||
result.Subject.State = n.Issue.State()
|
||||
comment, err := n.Issue.GetLastComment()
|
||||
if err == nil && comment != nil {
|
||||
result.Subject.LatestCommentURL = comment.APIURL()
|
||||
result.Subject.LatestCommentHTMLURL = comment.HTMLURL()
|
||||
result.Subject.LatestCommentURL = comment.APIURL(ctx)
|
||||
result.Subject.LatestCommentHTMLURL = comment.HTMLURL(ctx)
|
||||
}
|
||||
}
|
||||
case activities_model.NotificationSourcePullRequest:
|
||||
@@ -57,8 +57,8 @@ func ToNotificationThread(n *activities_model.Notification) *api.NotificationThr
|
||||
result.Subject.State = n.Issue.State()
|
||||
comment, err := n.Issue.GetLastComment()
|
||||
if err == nil && comment != nil {
|
||||
result.Subject.LatestCommentURL = comment.APIURL()
|
||||
result.Subject.LatestCommentHTMLURL = comment.HTMLURL()
|
||||
result.Subject.LatestCommentURL = comment.APIURL(ctx)
|
||||
result.Subject.LatestCommentHTMLURL = comment.HTMLURL(ctx)
|
||||
}
|
||||
|
||||
pr, _ := n.Issue.GetPullRequest()
|
||||
@@ -88,10 +88,10 @@ func ToNotificationThread(n *activities_model.Notification) *api.NotificationThr
|
||||
}
|
||||
|
||||
// ToNotifications convert list of Notification to api.NotificationThread list
|
||||
func ToNotifications(nl activities_model.NotificationList) []*api.NotificationThread {
|
||||
func ToNotifications(ctx context.Context, nl activities_model.NotificationList) []*api.NotificationThread {
|
||||
result := make([]*api.NotificationThread, 0, len(nl))
|
||||
for _, n := range nl {
|
||||
result = append(result, ToNotificationThread(n))
|
||||
result = append(result, ToNotificationThread(ctx, n))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
@@ -36,10 +36,10 @@ func ToPullReview(ctx context.Context, r *issues_model.Review, doer *user_model.
|
||||
Stale: r.Stale,
|
||||
Official: r.Official,
|
||||
Dismissed: r.Dismissed,
|
||||
CodeCommentsCount: r.GetCodeCommentsCount(),
|
||||
CodeCommentsCount: r.GetCodeCommentsCount(ctx),
|
||||
Submitted: r.CreatedUnix.AsTime(),
|
||||
Updated: r.UpdatedUnix.AsTime(),
|
||||
HTMLURL: r.HTMLURL(),
|
||||
HTMLURL: r.HTMLURL(ctx),
|
||||
HTMLPullURL: r.Issue.HTMLURL(),
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ func ToPullReviewCommentList(ctx context.Context, review *issues_model.Review, d
|
||||
CommitID: comment.CommitSHA,
|
||||
OrigCommitID: comment.OldRef,
|
||||
DiffHunk: patch2diff(comment.Patch),
|
||||
HTMLURL: comment.HTMLURL(),
|
||||
HTMLURL: comment.HTMLURL(ctx),
|
||||
HTMLPullURL: review.Issue.HTMLURL(),
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user