diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-05-20 22:08:52 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-20 22:08:52 +0800 |
commit | fd7d83ace60258acf7139c4c787aa8af75b7ba8c (patch) | |
tree | 50038348ec10485f72344f3ac80324e04abc1283 /routers/web/user | |
parent | d81e31ad7826a81fc7139f329f250594610a274b (diff) | |
download | gitea-fd7d83ace60258acf7139c4c787aa8af75b7ba8c.tar.gz gitea-fd7d83ace60258acf7139c4c787aa8af75b7ba8c.zip |
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
Diffstat (limited to 'routers/web/user')
-rw-r--r-- | routers/web/user/avatar.go | 2 | ||||
-rw-r--r-- | routers/web/user/home.go | 2 | ||||
-rw-r--r-- | routers/web/user/notification.go | 8 | ||||
-rw-r--r-- | routers/web/user/profile.go | 4 | ||||
-rw-r--r-- | routers/web/user/setting/account.go | 2 | ||||
-rw-r--r-- | routers/web/user/setting/adopt.go | 2 | ||||
-rw-r--r-- | routers/web/user/setting/applications.go | 4 | ||||
-rw-r--r-- | routers/web/user/setting/oauth2.go | 8 | ||||
-rw-r--r-- | routers/web/user/setting/profile.go | 2 | ||||
-rw-r--r-- | routers/web/user/setting/security/openid.go | 2 |
10 files changed, 18 insertions, 18 deletions
diff --git a/routers/web/user/avatar.go b/routers/web/user/avatar.go index c8bca9dc2c..53a603fab0 100644 --- a/routers/web/user/avatar.go +++ b/routers/web/user/avatar.go @@ -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 } diff --git a/routers/web/user/home.go b/routers/web/user/home.go index 37f6b88352..2a802053fb 100644 --- a/routers/web/user/home.go +++ b/routers/web/user/home.go @@ -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 diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index 05421cf555..0b1789dcf8 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -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)}) } diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go index 85870eddf5..8bce5460cc 100644 --- a/routers/web/user/profile.go +++ b/routers/web/user/profile.go @@ -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, diff --git a/routers/web/user/setting/account.go b/routers/web/user/setting/account.go index b2476dff94..92f6c9a183 100644 --- a/routers/web/user/setting/account.go +++ b/routers/web/user/setting/account.go @@ -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) diff --git a/routers/web/user/setting/adopt.go b/routers/web/user/setting/adopt.go index ce2377a997..c7139f8bb1 100644 --- a/routers/web/user/setting/adopt.go +++ b/routers/web/user/setting/adopt.go @@ -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 diff --git a/routers/web/user/setting/applications.go b/routers/web/user/setting/applications.go index b0f599fc45..4ffec47801 100644 --- a/routers/web/user/setting/applications.go +++ b/routers/web/user/setting/applications.go @@ -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 diff --git a/routers/web/user/setting/oauth2.go b/routers/web/user/setting/oauth2.go index 76c50852a0..db76a12f18 100644 --- a/routers/web/user/setting/oauth2.go +++ b/routers/web/user/setting/oauth2.go @@ -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 } diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index 0123b9b523..c2a406b184 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -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) } } diff --git a/routers/web/user/setting/security/openid.go b/routers/web/user/setting/security/openid.go index 2ecc9b0533..a378c8bf64 100644 --- a/routers/web/user/setting/security/openid.go +++ b/routers/web/user/setting/security/openid.go @@ -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 |