mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 00:20:25 +08: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:
		@@ -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{
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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 {
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -805,7 +805,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
 | 
			
		||||
		}
 | 
			
		||||
@@ -854,7 +854,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")
 | 
			
		||||
@@ -992,7 +992,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
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -524,7 +524,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
 | 
			
		||||
		}
 | 
			
		||||
@@ -591,7 +591,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")
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
				}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user