1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

More db.DefaultContext refactor (#27265) (#27347)

Backport #27265 by @JakobDev

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.

Co-authored-by: JakobDev <jakobdev@gmx.de>
This commit is contained in:
Giteabot
2023-09-29 21:35:01 +08:00
committed by GitHub
parent 84ee02faa7
commit f13a294b47
66 changed files with 455 additions and 456 deletions

View File

@@ -42,7 +42,7 @@ func NodeInfo(ctx *context.APIContext) {
usersActiveHalfyear := int(user_model.CountUsers(ctx, &user_model.CountUserFilter{LastLoginSince: &timeHaveYearAgo}))
allIssues, _ := issues_model.CountIssues(ctx, &issues_model.IssuesOptions{})
allComments, _ := issues_model.CountComments(&issues_model.FindCommentsOptions{})
allComments, _ := issues_model.CountComments(ctx, &issues_model.FindCommentsOptions{})
nodeInfoUsage = structs.NodeInfoUsage{
Users: structs.NodeInfoUsageUsers{

View File

@@ -127,7 +127,7 @@ func ListRepoNotifications(ctx *context.APIContext) {
ctx.SetTotalCountHeader(totalCount)
ctx.JSON(http.StatusOK, convert.ToNotifications(nl))
ctx.JSON(http.StatusOK, convert.ToNotifications(ctx, nl))
}
// ReadRepoNotifications mark notification threads as read on a specific repo
@@ -222,7 +222,7 @@ func ReadRepoNotifications(ctx *context.APIContext) {
return
}
_ = notif.LoadAttributes(ctx)
changed = append(changed, convert.ToNotificationThread(notif))
changed = append(changed, convert.ToNotificationThread(ctx, notif))
}
ctx.JSON(http.StatusResetContent, changed)
}

View File

@@ -46,7 +46,7 @@ func GetThread(ctx *context.APIContext) {
return
}
ctx.JSON(http.StatusOK, convert.ToNotificationThread(n))
ctx.JSON(http.StatusOK, convert.ToNotificationThread(ctx, n))
}
// ReadThread mark notification as read by ID
@@ -97,7 +97,7 @@ func ReadThread(ctx *context.APIContext) {
ctx.InternalServerError(err)
return
}
ctx.JSON(http.StatusResetContent, convert.ToNotificationThread(notif))
ctx.JSON(http.StatusResetContent, convert.ToNotificationThread(ctx, notif))
}
func getThread(ctx *context.APIContext) *activities_model.Notification {

View File

@@ -86,7 +86,7 @@ func ListNotifications(ctx *context.APIContext) {
}
ctx.SetTotalCountHeader(totalCount)
ctx.JSON(http.StatusOK, convert.ToNotifications(nl))
ctx.JSON(http.StatusOK, convert.ToNotifications(ctx, nl))
}
// ReadNotifications mark notification threads as read, unread, or pinned
@@ -167,7 +167,7 @@ func ReadNotifications(ctx *context.APIContext) {
return
}
_ = notif.LoadAttributes(ctx)
changed = append(changed, convert.ToNotificationThread(notif))
changed = append(changed, convert.ToNotificationThread(ctx, notif))
}
ctx.JSON(http.StatusResetContent, changed)

View File

@@ -53,7 +53,7 @@ func ListCollaborators(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
count, err := repo_model.CountCollaborators(ctx.Repo.Repository.ID)
count, err := repo_model.CountCollaborators(ctx, ctx.Repo.Repository.ID)
if err != nil {
ctx.InternalServerError(err)
return

View File

@@ -803,7 +803,7 @@ func EditIssue(ctx *context.APIContext) {
deadlineUnix = timeutil.TimeStamp(deadline.Unix())
}
if err := issues_model.UpdateIssueDeadline(issue, deadlineUnix, ctx.Doer); err != nil {
if err := issues_model.UpdateIssueDeadline(ctx, issue, deadlineUnix, ctx.Doer); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateIssueDeadline", err)
return
}
@@ -852,7 +852,7 @@ func EditIssue(ctx *context.APIContext) {
}
issue.IsClosed = api.StateClosed == api.StateType(*form.State)
}
statusChangeComment, titleChanged, err := issues_model.UpdateIssueByAPI(issue, ctx.Doer)
statusChangeComment, titleChanged, err := issues_model.UpdateIssueByAPI(ctx, issue, ctx.Doer)
if err != nil {
if issues_model.IsErrDependenciesLeft(err) {
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
@@ -990,7 +990,7 @@ func UpdateIssueDeadline(ctx *context.APIContext) {
deadlineUnix = timeutil.TimeStamp(deadline.Unix())
}
if err := issues_model.UpdateIssueDeadline(issue, deadlineUnix, ctx.Doer); err != nil {
if err := issues_model.UpdateIssueDeadline(ctx, issue, deadlineUnix, ctx.Doer); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateIssueDeadline", err)
return
}

View File

@@ -86,7 +86,7 @@ func ListIssueComments(ctx *context.APIContext) {
return
}
totalCount, err := issues_model.CountComments(opts)
totalCount, err := issues_model.CountComments(ctx, opts)
if err != nil {
ctx.InternalServerError(err)
return
@@ -285,7 +285,7 @@ func ListRepoIssueComments(ctx *context.APIContext) {
return
}
totalCount, err := issues_model.CountComments(opts)
totalCount, err := issues_model.CountComments(ctx, opts)
if err != nil {
ctx.InternalServerError(err)
return

View File

@@ -522,7 +522,7 @@ func EditPullRequest(ctx *context.APIContext) {
deadlineUnix = timeutil.TimeStamp(deadline.Unix())
}
if err := issues_model.UpdateIssueDeadline(issue, deadlineUnix, ctx.Doer); err != nil {
if err := issues_model.UpdateIssueDeadline(ctx, issue, deadlineUnix, ctx.Doer); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateIssueDeadline", err)
return
}
@@ -589,7 +589,7 @@ func EditPullRequest(ctx *context.APIContext) {
}
issue.IsClosed = api.StateClosed == api.StateType(*form.State)
}
statusChangeComment, titleChanged, err := issues_model.UpdateIssueByAPI(issue, ctx.Doer)
statusChangeComment, titleChanged, err := issues_model.UpdateIssueByAPI(ctx, issue, ctx.Doer)
if err != nil {
if issues_model.IsErrDependenciesLeft(err) {
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this pull request because it still has open dependencies")

View File

@@ -260,7 +260,7 @@ func DeletePullReview(ctx *context.APIContext) {
return
}
if err := issues_model.DeleteReview(review); err != nil {
if err := issues_model.DeleteReview(ctx, review); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteReview", fmt.Errorf("can not delete ReviewID: %d", review.ID))
return
}
@@ -713,7 +713,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
}
if comment != nil && isAdd {
if err = comment.LoadReview(); err != nil {
if err = comment.LoadReview(ctx); err != nil {
ctx.ServerError("ReviewRequest", err)
return
}
@@ -757,7 +757,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
}
if comment != nil && isAdd {
if err = comment.LoadReview(); err != nil {
if err = comment.LoadReview(ctx); err != nil {
ctx.ServerError("ReviewRequest", err)
return
}