mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Move almost all functions' parameter db.Engine to context.Context (#19748)
* Move almost all functions' parameter db.Engine to context.Context * remove some unnecessary wrap functions
This commit is contained in:
@@ -30,7 +30,7 @@ func AvatarByUserName(ctx *context.Context) {
|
||||
var user *user_model.User
|
||||
if strings.ToLower(userName) != "ghost" {
|
||||
var err error
|
||||
if user, err = user_model.GetUserByName(userName); err != nil {
|
||||
if user, err = user_model.GetUserByName(ctx, userName); err != nil {
|
||||
ctx.ServerError("Invalid user: "+userName, err)
|
||||
return
|
||||
}
|
||||
|
@@ -615,7 +615,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
|
||||
|
||||
ctx.Data["Issues"] = issues
|
||||
|
||||
approvalCounts, err := models.IssueList(issues).GetApprovalCounts()
|
||||
approvalCounts, err := models.IssueList(issues).GetApprovalCounts(ctx)
|
||||
if err != nil {
|
||||
ctx.ServerError("ApprovalCounts", err)
|
||||
return
|
||||
|
@@ -34,7 +34,7 @@ func GetNotificationCount(c *context.Context) {
|
||||
}
|
||||
|
||||
c.Data["NotificationUnreadCount"] = func() int64 {
|
||||
count, err := models.GetNotificationCount(c.Doer, models.NotificationStatusUnread)
|
||||
count, err := models.GetNotificationCount(c, c.Doer, models.NotificationStatusUnread)
|
||||
if err != nil {
|
||||
c.ServerError("GetNotificationCount", err)
|
||||
return -1
|
||||
@@ -79,7 +79,7 @@ func getNotifications(c *context.Context) {
|
||||
status = models.NotificationStatusUnread
|
||||
}
|
||||
|
||||
total, err := models.GetNotificationCount(c.Doer, status)
|
||||
total, err := models.GetNotificationCount(c, c.Doer, status)
|
||||
if err != nil {
|
||||
c.ServerError("ErrGetNotificationCount", err)
|
||||
return
|
||||
@@ -93,7 +93,7 @@ func getNotifications(c *context.Context) {
|
||||
}
|
||||
|
||||
statuses := []models.NotificationStatus{status, models.NotificationStatusPinned}
|
||||
notifications, err := models.NotificationsForUser(c.Doer, statuses, page, perPage)
|
||||
notifications, err := models.NotificationsForUser(c, c.Doer, statuses, page, perPage)
|
||||
if err != nil {
|
||||
c.ServerError("ErrNotificationsForUser", err)
|
||||
return
|
||||
@@ -195,5 +195,5 @@ func NotificationPurgePost(c *context.Context) {
|
||||
|
||||
// NewAvailable returns the notification counts
|
||||
func NewAvailable(ctx *context.Context) {
|
||||
ctx.JSON(http.StatusOK, structs.NotificationCount{New: models.CountUnread(ctx.Doer)})
|
||||
ctx.JSON(http.StatusOK, structs.NotificationCount{New: models.CountUnread(ctx, ctx.Doer.ID)})
|
||||
}
|
||||
|
@@ -42,7 +42,7 @@ func Profile(ctx *context.Context) {
|
||||
}
|
||||
|
||||
// check view permissions
|
||||
if !user_model.IsUserVisibleToViewer(ctx.ContextUser, ctx.Doer) {
|
||||
if !user_model.IsUserVisibleToViewer(ctx, ctx.ContextUser, ctx.Doer) {
|
||||
ctx.NotFound("user", fmt.Errorf(ctx.ContextUser.Name))
|
||||
return
|
||||
}
|
||||
@@ -217,7 +217,7 @@ func Profile(ctx *context.Context) {
|
||||
|
||||
total = int(count)
|
||||
case "projects":
|
||||
ctx.Data["OpenProjects"], _, err = project_model.GetProjects(project_model.SearchOptions{
|
||||
ctx.Data["OpenProjects"], _, err = project_model.GetProjects(ctx, project_model.SearchOptions{
|
||||
Page: -1,
|
||||
IsClosed: util.OptionalBoolFalse,
|
||||
Type: project_model.TypeIndividual,
|
||||
|
@@ -181,7 +181,7 @@ func EmailPost(ctx *context.Context) {
|
||||
Email: form.Email,
|
||||
IsActivated: !setting.Service.RegisterEmailConfirm,
|
||||
}
|
||||
if err := user_model.AddEmailAddress(email); err != nil {
|
||||
if err := user_model.AddEmailAddress(ctx, email); err != nil {
|
||||
if user_model.IsErrEmailAlreadyUsed(err) {
|
||||
loadAccountData(ctx)
|
||||
|
||||
|
@@ -32,7 +32,7 @@ func AdoptOrDeleteRepository(ctx *context.Context) {
|
||||
root := user_model.UserPath(ctxUser.LowerName)
|
||||
|
||||
// check not a repo
|
||||
has, err := repo_model.IsRepositoryExist(ctxUser, dir)
|
||||
has, err := repo_model.IsRepositoryExist(ctx, ctxUser, dir)
|
||||
if err != nil {
|
||||
ctx.ServerError("IsRepositoryExist", err)
|
||||
return
|
||||
|
@@ -93,12 +93,12 @@ func loadApplicationsData(ctx *context.Context) {
|
||||
ctx.Data["Tokens"] = tokens
|
||||
ctx.Data["EnableOAuth2"] = setting.OAuth2.Enable
|
||||
if setting.OAuth2.Enable {
|
||||
ctx.Data["Applications"], err = auth.GetOAuth2ApplicationsByUserID(ctx.Doer.ID)
|
||||
ctx.Data["Applications"], err = auth.GetOAuth2ApplicationsByUserID(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetOAuth2ApplicationsByUserID", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Grants"], err = auth.GetOAuth2GrantsByUserID(ctx.Doer.ID)
|
||||
ctx.Data["Grants"], err = auth.GetOAuth2GrantsByUserID(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetOAuth2GrantsByUserID", err)
|
||||
return
|
||||
|
@@ -34,7 +34,7 @@ func OAuthApplicationsPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
// TODO validate redirect URI
|
||||
app, err := auth.CreateOAuth2Application(auth.CreateOAuth2ApplicationOptions{
|
||||
app, err := auth.CreateOAuth2Application(ctx, auth.CreateOAuth2ApplicationOptions{
|
||||
Name: form.Name,
|
||||
RedirectURIs: []string{form.RedirectURI},
|
||||
UserID: ctx.Doer.ID,
|
||||
@@ -85,7 +85,7 @@ func OAuthApplicationsRegenerateSecret(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsApplications"] = true
|
||||
|
||||
app, err := auth.GetOAuth2ApplicationByID(ctx.ParamsInt64("id"))
|
||||
app, err := auth.GetOAuth2ApplicationByID(ctx, ctx.ParamsInt64("id"))
|
||||
if err != nil {
|
||||
if auth.IsErrOAuthApplicationNotFound(err) {
|
||||
ctx.NotFound("Application not found", err)
|
||||
@@ -110,7 +110,7 @@ func OAuthApplicationsRegenerateSecret(ctx *context.Context) {
|
||||
|
||||
// OAuth2ApplicationShow displays the given application
|
||||
func OAuth2ApplicationShow(ctx *context.Context) {
|
||||
app, err := auth.GetOAuth2ApplicationByID(ctx.ParamsInt64("id"))
|
||||
app, err := auth.GetOAuth2ApplicationByID(ctx, ctx.ParamsInt64("id"))
|
||||
if err != nil {
|
||||
if auth.IsErrOAuthApplicationNotFound(err) {
|
||||
ctx.NotFound("Application not found", err)
|
||||
@@ -147,7 +147,7 @@ func RevokeOAuth2Grant(ctx *context.Context) {
|
||||
ctx.ServerError("RevokeOAuth2Grant", fmt.Errorf("user id or grant id is zero"))
|
||||
return
|
||||
}
|
||||
if err := auth.RevokeOAuth2Grant(ctx.FormInt64("id"), ctx.Doer.ID); err != nil {
|
||||
if err := auth.RevokeOAuth2Grant(ctx, ctx.FormInt64("id"), ctx.Doer.ID); err != nil {
|
||||
ctx.ServerError("RevokeOAuth2Grant", err)
|
||||
return
|
||||
}
|
||||
|
@@ -180,7 +180,7 @@ func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser *
|
||||
} else if ctxUser.UseCustomAvatar && ctxUser.Avatar == "" {
|
||||
// No avatar is uploaded but setting has been changed to enable,
|
||||
// generate a random one when needed.
|
||||
if err := user_model.GenerateRandomAvatar(ctxUser); err != nil {
|
||||
if err := user_model.GenerateRandomAvatar(ctx, ctxUser); err != nil {
|
||||
log.Error("GenerateRandomAvatar[%d]: %v", ctxUser.ID, err)
|
||||
}
|
||||
}
|
||||
|
@@ -90,7 +90,7 @@ func settingsOpenIDVerify(ctx *context.Context) {
|
||||
log.Trace("Verified ID: " + id)
|
||||
|
||||
oid := &user_model.UserOpenID{UID: ctx.Doer.ID, URI: id}
|
||||
if err = user_model.AddUserOpenID(oid); err != nil {
|
||||
if err = user_model.AddUserOpenID(ctx, oid); err != nil {
|
||||
if user_model.IsErrOpenIDAlreadyUsed(err) {
|
||||
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", id), tplSettingsSecurity, &forms.AddOpenIDForm{Openid: id})
|
||||
return
|
||||
|
Reference in New Issue
Block a user