diff options
author | JakobDev <jakobdev@gmx.de> | 2023-10-11 06:24:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-11 04:24:07 +0000 |
commit | ebe803e514acb4eedc884226be2489ee6b4acd28 (patch) | |
tree | 3f4d38f8267142dcd0e8df7d76cd4fe04c47b85e /routers | |
parent | 50166d1f7c6df41c79561b094e29c9698c0000d5 (diff) | |
download | gitea-ebe803e514acb4eedc884226be2489ee6b4acd28.tar.gz gitea-ebe803e514acb4eedc884226be2489ee6b4acd28.zip |
Penultimate round of `db.DefaultContext` refactor (#27414)
Part of #27065
---------
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'routers')
46 files changed, 116 insertions, 114 deletions
diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go index 610eba1749..09d7c1a940 100644 --- a/routers/api/v1/admin/user.go +++ b/routers/api/v1/admin/user.go @@ -36,7 +36,7 @@ func parseAuthSource(ctx *context.APIContext, u *user_model.User, sourceID int64 return } - source, err := auth.GetSourceByID(sourceID) + source, err := auth.GetSourceByID(ctx, sourceID) if err != nil { if auth.IsErrSourceNotExist(err) { ctx.Error(http.StatusUnprocessableEntity, "", err) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 441801885f..8abe51ea4f 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -70,6 +70,7 @@ import ( actions_model "code.gitea.io/gitea/models/actions" auth_model "code.gitea.io/gitea/models/auth" + "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/organization" "code.gitea.io/gitea/models/perm" access_model "code.gitea.io/gitea/models/perm/access" @@ -165,7 +166,7 @@ func repoAssignment() func(ctx *context.APIContext) { ctx.ContextUser = owner // Get repository. - repo, err := repo_model.GetRepositoryByName(owner.ID, repoName) + repo, err := repo_model.GetRepositoryByName(ctx, owner.ID, repoName) if err != nil { if repo_model.IsErrRepoNotExist(err) { redirectRepoID, err := repo_model.LookupRedirect(owner.ID, repoName) @@ -716,7 +717,7 @@ func buildAuthGroup() *auth.Group { group.Add(&auth.ReverseProxy{}) } - if setting.IsWindows && auth_model.IsSSPIEnabled() { + if setting.IsWindows && auth_model.IsSSPIEnabled(db.DefaultContext) { group.Add(&auth.SSPI{}) // it MUST be the last, see the comment of SSPI } diff --git a/routers/api/v1/org/avatar.go b/routers/api/v1/org/avatar.go index a7b5008525..7b621a50c3 100644 --- a/routers/api/v1/org/avatar.go +++ b/routers/api/v1/org/avatar.go @@ -43,7 +43,7 @@ func UpdateAvatar(ctx *context.APIContext) { return } - err = user_service.UploadAvatar(ctx.Org.Organization.AsUser(), content) + err = user_service.UploadAvatar(ctx, ctx.Org.Organization.AsUser(), content) if err != nil { ctx.Error(http.StatusInternalServerError, "UploadAvatar", err) } @@ -69,7 +69,7 @@ func DeleteAvatar(ctx *context.APIContext) { // "$ref": "#/responses/empty" // "404": // "$ref": "#/responses/notFound" - err := user_service.DeleteAvatar(ctx.Org.Organization.AsUser()) + err := user_service.DeleteAvatar(ctx, ctx.Org.Organization.AsUser()) if err != nil { ctx.Error(http.StatusInternalServerError, "DeleteAvatar", err) } diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index 9b68253623..f129c66230 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -638,7 +638,7 @@ func GetTeamRepo(ctx *context.APIContext) { // getRepositoryByParams get repository by a team's organization ID and repo name func getRepositoryByParams(ctx *context.APIContext) *repo_model.Repository { - repo, err := repo_model.GetRepositoryByName(ctx.Org.Team.OrgID, ctx.Params(":reponame")) + repo, err := repo_model.GetRepositoryByName(ctx, ctx.Org.Team.OrgID, ctx.Params(":reponame")) if err != nil { if repo_model.IsErrRepoNotExist(err) { ctx.NotFound() diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 58689b72a6..74e6361f6c 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -188,7 +188,7 @@ func SearchIssues(ctx *context.APIContext) { allPublic = true opts.AllPublic = false // set it false to avoid returning too many repos, we could filter by indexer } - repoIDs, _, err = repo_model.SearchRepositoryIDs(opts) + repoIDs, _, err = repo_model.SearchRepositoryIDs(ctx, opts) if err != nil { ctx.Error(http.StatusInternalServerError, "SearchRepositoryIDs", err) return @@ -837,7 +837,7 @@ func EditIssue(ctx *context.APIContext) { issue.MilestoneID != *form.Milestone { oldMilestoneID := issue.MilestoneID issue.MilestoneID = *form.Milestone - if err = issue_service.ChangeMilestoneAssign(issue, ctx.Doer, oldMilestoneID); err != nil { + if err = issue_service.ChangeMilestoneAssign(ctx, issue, ctx.Doer, oldMilestoneID); err != nil { ctx.Error(http.StatusInternalServerError, "ChangeMilestoneAssign", err) return } diff --git a/routers/api/v1/repo/issue_dependency.go b/routers/api/v1/repo/issue_dependency.go index 9571532800..0e3bcd93ef 100644 --- a/routers/api/v1/repo/issue_dependency.go +++ b/routers/api/v1/repo/issue_dependency.go @@ -576,7 +576,7 @@ func createIssueDependency(ctx *context.APIContext, target, dependency *issues_m return } - err := issues_model.CreateIssueDependency(ctx.Doer, target, dependency) + err := issues_model.CreateIssueDependency(ctx, ctx.Doer, target, dependency) if err != nil { ctx.Error(http.StatusInternalServerError, "CreateIssueDependency", err) return @@ -602,7 +602,7 @@ func removeIssueDependency(ctx *context.APIContext, target, dependency *issues_m return } - err := issues_model.RemoveIssueDependency(ctx.Doer, target, dependency, issues_model.DependencyTypeBlockedBy) + err := issues_model.RemoveIssueDependency(ctx, ctx.Doer, target, dependency, issues_model.DependencyTypeBlockedBy) if err != nil { ctx.Error(http.StatusInternalServerError, "CreateIssueDependency", err) return diff --git a/routers/api/v1/repo/key.go b/routers/api/v1/repo/key.go index 7d97f5f5e2..e2b7b49438 100644 --- a/routers/api/v1/repo/key.go +++ b/routers/api/v1/repo/key.go @@ -105,7 +105,7 @@ func ListDeployKeys(ctx *context.APIContext) { apiLink := composeDeployKeysAPILink(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) apiKeys := make([]*api.DeployKey, len(keys)) for i := range keys { - if err := keys[i].GetContent(); err != nil { + if err := keys[i].GetContent(ctx); err != nil { ctx.Error(http.StatusInternalServerError, "GetContent", err) return } @@ -159,7 +159,7 @@ func GetDeployKey(ctx *context.APIContext) { return } - if err = key.GetContent(); err != nil { + if err = key.GetContent(ctx); err != nil { ctx.Error(http.StatusInternalServerError, "GetContent", err) return } diff --git a/routers/api/v1/repo/milestone.go b/routers/api/v1/repo/milestone.go index 1a86444660..da470dfa74 100644 --- a/routers/api/v1/repo/milestone.go +++ b/routers/api/v1/repo/milestone.go @@ -58,7 +58,7 @@ func ListMilestones(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - milestones, total, err := issues_model.GetMilestones(issues_model.GetMilestonesOption{ + milestones, total, err := issues_model.GetMilestones(ctx, issues_model.GetMilestonesOption{ ListOptions: utils.GetListOptions(ctx), RepoID: ctx.Repo.Repository.ID, State: api.StateType(ctx.FormString("state")), diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 6fcc5267cf..df9e7217bb 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -555,7 +555,7 @@ func EditPullRequest(ctx *context.APIContext) { issue.MilestoneID != form.Milestone { oldMilestoneID := issue.MilestoneID issue.MilestoneID = form.Milestone - if err = issue_service.ChangeMilestoneAssign(issue, ctx.Doer, oldMilestoneID); err != nil { + if err = issue_service.ChangeMilestoneAssign(ctx, issue, ctx.Doer, oldMilestoneID); err != nil { ctx.Error(http.StatusInternalServerError, "ChangeMilestoneAssign", err) return } @@ -578,7 +578,7 @@ func EditPullRequest(ctx *context.APIContext) { labels = append(labels, orgLabels...) } - if err = issues_model.ReplaceIssueLabels(issue, labels, ctx.Doer); err != nil { + if err = issues_model.ReplaceIssueLabels(ctx, issue, labels, ctx.Doer); err != nil { ctx.Error(http.StatusInternalServerError, "ReplaceLabelsError", err) return } diff --git a/routers/api/v1/user/avatar.go b/routers/api/v1/user/avatar.go index 84fa129b13..1c1bb6181a 100644 --- a/routers/api/v1/user/avatar.go +++ b/routers/api/v1/user/avatar.go @@ -36,7 +36,7 @@ func UpdateAvatar(ctx *context.APIContext) { return } - err = user_service.UploadAvatar(ctx.Doer, content) + err = user_service.UploadAvatar(ctx, ctx.Doer, content) if err != nil { ctx.Error(http.StatusInternalServerError, "UploadAvatar", err) } @@ -54,7 +54,7 @@ func DeleteAvatar(ctx *context.APIContext) { // responses: // "204": // "$ref": "#/responses/empty" - err := user_service.DeleteAvatar(ctx.Doer) + err := user_service.DeleteAvatar(ctx, ctx.Doer) if err != nil { ctx.Error(http.StatusInternalServerError, "DeleteAvatar", err) } diff --git a/routers/api/v1/user/key.go b/routers/api/v1/user/key.go index 7fc10e82f2..fd891699ce 100644 --- a/routers/api/v1/user/key.go +++ b/routers/api/v1/user/key.go @@ -59,14 +59,14 @@ func listPublicKeys(ctx *context.APIContext, user *user_model.User) { // Querying not just listing if username != "" { // Restrict to provided uid - keys, err = asymkey_model.SearchPublicKey(user.ID, fingerprint) + keys, err = asymkey_model.SearchPublicKey(ctx, user.ID, fingerprint) } else { // Unrestricted - keys, err = asymkey_model.SearchPublicKey(0, fingerprint) + keys, err = asymkey_model.SearchPublicKey(ctx, 0, fingerprint) } count = len(keys) } else { - total, err2 := asymkey_model.CountPublicKeys(user.ID) + total, err2 := asymkey_model.CountPublicKeys(ctx, user.ID) if err2 != nil { ctx.InternalServerError(err) return @@ -74,7 +74,7 @@ func listPublicKeys(ctx *context.APIContext, user *user_model.User) { count = int(total) // Use ListPublicKeys - keys, err = asymkey_model.ListPublicKeys(user.ID, utils.GetListOptions(ctx)) + keys, err = asymkey_model.ListPublicKeys(ctx, user.ID, utils.GetListOptions(ctx)) } if err != nil { @@ -176,7 +176,7 @@ func GetPublicKey(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - key, err := asymkey_model.GetPublicKeyByID(ctx.ParamsInt64(":id")) + key, err := asymkey_model.GetPublicKeyByID(ctx, ctx.ParamsInt64(":id")) if err != nil { if asymkey_model.IsErrKeyNotExist(err) { ctx.NotFound() @@ -202,7 +202,7 @@ func CreateUserPublicKey(ctx *context.APIContext, form api.CreateKeyOption, uid return } - key, err := asymkey_model.AddPublicKey(uid, form.Title, content, 0) + key, err := asymkey_model.AddPublicKey(ctx, uid, form.Title, content, 0) if err != nil { repo.HandleAddKeyError(ctx, err) return @@ -262,7 +262,7 @@ func DeletePublicKey(ctx *context.APIContext) { // "$ref": "#/responses/notFound" id := ctx.ParamsInt64(":id") - externallyManaged, err := asymkey_model.PublicKeyIsExternallyManaged(id) + externallyManaged, err := asymkey_model.PublicKeyIsExternallyManaged(ctx, id) if err != nil { if asymkey_model.IsErrKeyNotExist(err) { ctx.NotFound() diff --git a/routers/common/markup.go b/routers/common/markup.go index 5f412014d7..aaedc13de9 100644 --- a/routers/common/markup.go +++ b/routers/common/markup.go @@ -65,9 +65,9 @@ func RenderMarkup(ctx *context.Base, repo *context.Repository, mode, text, urlPr meta := map[string]string{} if repo != nil && repo.Repository != nil { if mode == "comment" { - meta = repo.Repository.ComposeMetas() + meta = repo.Repository.ComposeMetas(ctx) } else { - meta = repo.Repository.ComposeDocumentMetas() + meta = repo.Repository.ComposeDocumentMetas(ctx) } } if mode != "comment" { diff --git a/routers/init.go b/routers/init.go index 3cd63eb9ae..0da510cc59 100644 --- a/routers/init.go +++ b/routers/init.go @@ -121,7 +121,7 @@ func InitWebInstalled(ctx context.Context) { mustInit(cache.NewContext) mustInit(feed_service.Init) mustInit(uinotification.Init) - mustInit(archiver.Init) + mustInitCtx(ctx, archiver.Init) highlight.NewContext() external.RegisterRenderers() diff --git a/routers/private/actions.go b/routers/private/actions.go index 74515256da..025a6a2c39 100644 --- a/routers/private/actions.go +++ b/routers/private/actions.go @@ -83,7 +83,7 @@ func parseScope(ctx *context.PrivateContext, scope string) (ownerID, repoID int6 return ownerID, repoID, nil } - r, err := repo_model.GetRepositoryByName(u.ID, repoName) + r, err := repo_model.GetRepositoryByName(ctx, u.ID, repoName) if err != nil { return ownerID, repoID, err } diff --git a/routers/private/hook_post_receive.go b/routers/private/hook_post_receive.go index 0c9a2a10fa..d5a46e4e7f 100644 --- a/routers/private/hook_post_receive.go +++ b/routers/private/hook_post_receive.go @@ -150,7 +150,7 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) { } results = append(results, private.HookPostReceiveBranchResult{ - Message: setting.Git.PullRequestPushMessage && repo.AllowsPulls(), + Message: setting.Git.PullRequestPushMessage && repo.AllowsPulls(ctx), Create: false, Branch: "", URL: fmt.Sprintf("%s/pulls/%d", repo.HTMLURL(), pr.Index), @@ -179,12 +179,12 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) { }) return } - if repo.BaseRepo.AllowsPulls() { + if repo.BaseRepo.AllowsPulls(ctx) { baseRepo = repo.BaseRepo } } - if !baseRepo.AllowsPulls() { + if !baseRepo.AllowsPulls(ctx) { // We can stop there's no need to go any further ctx.JSON(http.StatusOK, private.HookPostReceiveResult{ RepoWasEmpty: wasEmpty, @@ -217,14 +217,14 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) { branch = fmt.Sprintf("%s:%s", repo.OwnerName, branch) } results = append(results, private.HookPostReceiveBranchResult{ - Message: setting.Git.PullRequestPushMessage && baseRepo.AllowsPulls(), + Message: setting.Git.PullRequestPushMessage && baseRepo.AllowsPulls(ctx), Create: true, Branch: branch, URL: fmt.Sprintf("%s/compare/%s...%s", baseRepo.HTMLURL(), util.PathEscapeSegments(baseRepo.DefaultBranch), util.PathEscapeSegments(branch)), }) } else { results = append(results, private.HookPostReceiveBranchResult{ - Message: setting.Git.PullRequestPushMessage && baseRepo.AllowsPulls(), + Message: setting.Git.PullRequestPushMessage && baseRepo.AllowsPulls(ctx), Create: false, Branch: branch, URL: fmt.Sprintf("%s/pulls/%d", baseRepo.HTMLURL(), pr.Index), diff --git a/routers/private/key.go b/routers/private/key.go index a13b4c12ae..176e5ffcc8 100644 --- a/routers/private/key.go +++ b/routers/private/key.go @@ -16,7 +16,7 @@ import ( func UpdatePublicKeyInRepo(ctx *context.PrivateContext) { keyID := ctx.ParamsInt64(":id") repoID := ctx.ParamsInt64(":repoid") - if err := asymkey_model.UpdatePublicKeyUpdated(keyID); err != nil { + if err := asymkey_model.UpdatePublicKeyUpdated(ctx, keyID); err != nil { ctx.JSON(http.StatusInternalServerError, private.Response{ Err: err.Error(), }) diff --git a/routers/private/serv.go b/routers/private/serv.go index b1efc58800..00731947a5 100644 --- a/routers/private/serv.go +++ b/routers/private/serv.go @@ -33,7 +33,7 @@ func ServNoCommand(ctx *context.PrivateContext) { } results := private.KeyAndOwner{} - key, err := asymkey_model.GetPublicKeyByID(keyID) + key, err := asymkey_model.GetPublicKeyByID(ctx, keyID) if err != nil { if asymkey_model.IsErrKeyNotExist(err) { ctx.JSON(http.StatusUnauthorized, private.Response{ @@ -132,7 +132,7 @@ func ServCommand(ctx *context.PrivateContext) { // Now get the Repository and set the results section repoExist := true - repo, err := repo_model.GetRepositoryByName(owner.ID, results.RepoName) + repo, err := repo_model.GetRepositoryByName(ctx, owner.ID, results.RepoName) if err != nil { if repo_model.IsErrRepoNotExist(err) { repoExist = false @@ -184,7 +184,7 @@ func ServCommand(ctx *context.PrivateContext) { } // Get the Public Key represented by the keyID - key, err := asymkey_model.GetPublicKeyByID(keyID) + key, err := asymkey_model.GetPublicKeyByID(ctx, keyID) if err != nil { if asymkey_model.IsErrKeyNotExist(err) { ctx.JSON(http.StatusNotFound, private.Response{ diff --git a/routers/web/admin/auths.go b/routers/web/admin/auths.go index b743d1b0a5..22de15036c 100644 --- a/routers/web/admin/auths.go +++ b/routers/web/admin/auths.go @@ -48,13 +48,13 @@ func Authentications(ctx *context.Context) { ctx.Data["PageIsAdminAuthentications"] = true var err error - ctx.Data["Sources"], err = auth.Sources() + ctx.Data["Sources"], err = auth.Sources(ctx) if err != nil { ctx.ServerError("auth.Sources", err) return } - ctx.Data["Total"] = auth.CountSources() + ctx.Data["Total"] = auth.CountSources(ctx) ctx.HTML(http.StatusOK, tplAuths) } @@ -284,7 +284,7 @@ func NewAuthSourcePost(ctx *context.Context) { ctx.RenderWithErr(err.Error(), tplAuthNew, form) return } - existing, err := auth.SourcesByType(auth.SSPI) + existing, err := auth.SourcesByType(ctx, auth.SSPI) if err != nil || len(existing) > 0 { ctx.Data["Err_Type"] = true ctx.RenderWithErr(ctx.Tr("admin.auths.login_source_of_type_exist"), tplAuthNew, form) @@ -301,7 +301,7 @@ func NewAuthSourcePost(ctx *context.Context) { return } - if err := auth.CreateSource(&auth.Source{ + if err := auth.CreateSource(ctx, &auth.Source{ Type: auth.Type(form.Type), Name: form.Name, IsActive: form.IsActive, @@ -337,7 +337,7 @@ func EditAuthSource(ctx *context.Context) { oauth2providers := oauth2.GetOAuth2Providers() ctx.Data["OAuth2Providers"] = oauth2providers - source, err := auth.GetSourceByID(ctx.ParamsInt64(":authid")) + source, err := auth.GetSourceByID(ctx, ctx.ParamsInt64(":authid")) if err != nil { ctx.ServerError("auth.GetSourceByID", err) return @@ -371,7 +371,7 @@ func EditAuthSourcePost(ctx *context.Context) { oauth2providers := oauth2.GetOAuth2Providers() ctx.Data["OAuth2Providers"] = oauth2providers - source, err := auth.GetSourceByID(ctx.ParamsInt64(":authid")) + source, err := auth.GetSourceByID(ctx, ctx.ParamsInt64(":authid")) if err != nil { ctx.ServerError("auth.GetSourceByID", err) return @@ -421,7 +421,7 @@ func EditAuthSourcePost(ctx *context.Context) { source.IsActive = form.IsActive source.IsSyncEnabled = form.IsSyncEnabled source.Cfg = config - if err := auth.UpdateSource(source); err != nil { + if err := auth.UpdateSource(ctx, source); err != nil { if auth.IsErrSourceAlreadyExist(err) { ctx.Data["Err_Name"] = true ctx.RenderWithErr(ctx.Tr("admin.auths.login_source_exist", err.(auth.ErrSourceAlreadyExist).Name), tplAuthEdit, form) @@ -442,7 +442,7 @@ func EditAuthSourcePost(ctx *context.Context) { // DeleteAuthSource response for deleting an auth source func DeleteAuthSource(ctx *context.Context) { - source, err := auth.GetSourceByID(ctx.ParamsInt64(":authid")) + source, err := auth.GetSourceByID(ctx, ctx.ParamsInt64(":authid")) if err != nil { ctx.ServerError("auth.GetSourceByID", err) return diff --git a/routers/web/admin/users.go b/routers/web/admin/users.go index 18d7313e72..91a578fb55 100644 --- a/routers/web/admin/users.go +++ b/routers/web/admin/users.go @@ -90,7 +90,7 @@ func NewUser(ctx *context.Context) { ctx.Data["login_type"] = "0-0" - sources, err := auth.Sources() + sources, err := auth.Sources(ctx) if err != nil { ctx.ServerError("auth.Sources", err) return @@ -109,7 +109,7 @@ func NewUserPost(ctx *context.Context) { ctx.Data["DefaultUserVisibilityMode"] = setting.Service.DefaultUserVisibilityMode ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice() - sources, err := auth.Sources() + sources, err := auth.Sources(ctx) if err != nil { ctx.ServerError("auth.Sources", err) return @@ -221,7 +221,7 @@ func prepareUserInfo(ctx *context.Context) *user_model.User { ctx.Data["User"] = u if u.LoginSource > 0 { - ctx.Data["LoginSource"], err = auth.GetSourceByID(u.LoginSource) + ctx.Data["LoginSource"], err = auth.GetSourceByID(ctx, u.LoginSource) if err != nil { ctx.ServerError("auth.GetSourceByID", err) return nil @@ -230,7 +230,7 @@ func prepareUserInfo(ctx *context.Context) *user_model.User { ctx.Data["LoginSource"] = &auth.Source{} } - sources, err := auth.Sources() + sources, err := auth.Sources(ctx) if err != nil { ctx.ServerError("auth.Sources", err) return nil @@ -532,7 +532,7 @@ func DeleteAvatar(ctx *context.Context) { return } - if err := user_service.DeleteAvatar(u); err != nil { + if err := user_service.DeleteAvatar(ctx, u); err != nil { ctx.Flash.Error(err.Error()) } diff --git a/routers/web/auth/auth.go b/routers/web/auth/auth.go index 8017602d99..df835a2fa1 100644 --- a/routers/web/auth/auth.go +++ b/routers/web/auth/auth.go @@ -157,7 +157,7 @@ func SignIn(ctx *context.Context) { ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login" ctx.Data["PageIsSignIn"] = true ctx.Data["PageIsLogin"] = true - ctx.Data["EnableSSPI"] = auth.IsSSPIEnabled() + ctx.Data["EnableSSPI"] = auth.IsSSPIEnabled(ctx) if setting.Service.EnableCaptcha && setting.Service.RequireCaptchaForLogin { context.SetCaptchaData(ctx) @@ -181,7 +181,7 @@ func SignInPost(ctx *context.Context) { ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login" ctx.Data["PageIsSignIn"] = true ctx.Data["PageIsLogin"] = true - ctx.Data["EnableSSPI"] = auth.IsSSPIEnabled() + ctx.Data["EnableSSPI"] = auth.IsSSPIEnabled(ctx) if ctx.HasError() { ctx.HTML(http.StatusOK, tplSignIn) diff --git a/routers/web/auth/linkaccount.go b/routers/web/auth/linkaccount.go index 42d846180d..1e70d85cee 100644 --- a/routers/web/auth/linkaccount.go +++ b/routers/web/auth/linkaccount.go @@ -152,7 +152,7 @@ func LinkAccountPostSignIn(ctx *context.Context) { } func linkAccount(ctx *context.Context, u *user_model.User, gothUser goth.User, remember bool) { - updateAvatarIfNeed(gothUser.AvatarURL, u) + updateAvatarIfNeed(ctx, gothUser.AvatarURL, u) // If this user is enrolled in 2FA, we can't sign the user in just yet. // Instead, redirect them to the 2FA authentication page. diff --git a/routers/web/auth/oauth.go b/routers/web/auth/oauth.go index ce58cbdef9..64106e1ab6 100644 --- a/routers/web/auth/oauth.go +++ b/routers/web/auth/oauth.go @@ -1074,7 +1074,7 @@ func showLinkingLogin(ctx *context.Context, gothUser goth.User) { ctx.Redirect(setting.AppSubURL + "/user/link_account") } -func updateAvatarIfNeed(url string, u *user_model.User) { +func updateAvatarIfNeed(ctx *context.Context, url string, u *user_model.User) { if setting.OAuth2Client.UpdateAvatar && len(url) > 0 { resp, err := http.Get(url) if err == nil { @@ -1086,14 +1086,14 @@ func updateAvatarIfNeed(url string, u *user_model.User) { if err == nil && resp.StatusCode == http.StatusOK { data, err := io.ReadAll(io.LimitReader(resp.Body, setting.Avatar.MaxFileSize+1)) if err == nil && int64(len(data)) <= setting.Avatar.MaxFileSize { - _ = user_service.UploadAvatar(u, data) + _ = user_service.UploadAvatar(ctx, u, data) } } } } func handleOAuth2SignIn(ctx *context.Context, source *auth.Source, u *user_model.User, gothUser goth.User) { - updateAvatarIfNeed(gothUser.AvatarURL, u) + updateAvatarIfNeed(ctx, gothUser.AvatarURL, u) needs2FA := false if !source.Cfg.(*oauth2.Source).SkipLocalTwoFA { diff --git a/routers/web/explore/code.go b/routers/web/explore/code.go index 94d83818fc..d81884ec62 100644 --- a/routers/web/explore/code.go +++ b/routers/web/explore/code.go @@ -102,7 +102,7 @@ func Code(ctx *context.Context) { } } - repoMaps, err := repo_model.GetRepositoriesMapByIDs(loadRepoIDs) + repoMaps, err := repo_model.GetRepositoriesMapByIDs(ctx, loadRepoIDs) if err != nil { ctx.ServerError("GetRepositoriesMapByIDs", err) return diff --git a/routers/web/feed/convert.go b/routers/web/feed/convert.go index 04078955bb..4d4918a8fd 100644 --- a/routers/web/feed/convert.go +++ b/routers/web/feed/convert.go @@ -290,7 +290,7 @@ func releasesToFeedItems(ctx *context.Context, releases []*repo_model.Release, i content, err = markdown.RenderString(&markup.RenderContext{ Ctx: ctx, URLPrefix: rel.Repo.Link(), - Metas: rel.Repo.ComposeMetas(), + Metas: rel.Repo.ComposeMetas(ctx), }, rel.Note) if err != nil { diff --git a/routers/web/org/projects.go b/routers/web/org/projects.go index 19d3682f51..439fdf644b 100644 --- a/routers/web/org/projects.go +++ b/routers/web/org/projects.go @@ -468,7 +468,7 @@ func UpdateIssueProject(ctx *context.Context) { } } - if err := issues_model.ChangeProjectAssign(issue, ctx.Doer, projectID); err != nil { + if err := issues_model.ChangeProjectAssign(ctx, issue, ctx.Doer, projectID); err != nil { ctx.ServerError("ChangeProjectAssign", err) return } diff --git a/routers/web/org/setting.go b/routers/web/org/setting.go index 0f082a70df..a8e1bc1c83 100644 --- a/routers/web/org/setting.go +++ b/routers/web/org/setting.go @@ -160,7 +160,7 @@ func SettingsAvatar(ctx *context.Context) { // SettingsDeleteAvatar response for delete avatar on settings page func SettingsDeleteAvatar(ctx *context.Context) { - if err := user_service.DeleteAvatar(ctx.Org.Organization.AsUser()); err != nil { + if err := user_service.DeleteAvatar(ctx, ctx.Org.Organization.AsUser()); err != nil { ctx.Flash.Error(err.Error()) } diff --git a/routers/web/org/teams.go b/routers/web/org/teams.go index 98014d99a6..183b7dd266 100644 --- a/routers/web/org/teams.go +++ b/routers/web/org/teams.go @@ -237,7 +237,7 @@ func TeamsRepoAction(ctx *context.Context) { case "add": repoName := path.Base(ctx.FormString("repo_name")) var repo *repo_model.Repository - repo, err = repo_model.GetRepositoryByName(ctx.Org.Organization.ID, repoName) + repo, err = repo_model.GetRepositoryByName(ctx, ctx.Org.Organization.ID, repoName) if err != nil { if repo_model.IsErrRepoNotExist(err) { ctx.Flash.Error(ctx.Tr("org.teams.add_nonexistent_repo")) diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go index e0e27fd482..bc72d5f2ec 100644 --- a/routers/web/repo/branch.go +++ b/routers/web/repo/branch.go @@ -37,7 +37,7 @@ const ( func Branches(ctx *context.Context) { ctx.Data["Title"] = "Branches" ctx.Data["IsRepoToolbarBranches"] = true - ctx.Data["AllowsPulls"] = ctx.Repo.Repository.AllowsPulls() + ctx.Data["AllowsPulls"] = ctx.Repo.Repository.AllowsPulls(ctx) ctx.Data["IsWriter"] = ctx.Repo.CanWrite(unit.TypeCode) ctx.Data["IsMirror"] = ctx.Repo.Repository.IsMirror ctx.Data["CanPull"] = ctx.Repo.CanWrite(unit.TypeCode) || diff --git a/routers/web/repo/http.go b/routers/web/repo/http.go index 1fd784a40a..9e11d7a8c0 100644 --- a/routers/web/repo/http.go +++ b/routers/web/repo/http.go @@ -105,7 +105,7 @@ func httpBase(ctx *context.Context) *serviceHandler { } repoExist := true - repo, err := repo_model.GetRepositoryByName(owner.ID, reponame) + repo, err := repo_model.GetRepositoryByName(ctx, owner.ID, reponame) if err != nil { if repo_model.IsErrRepoNotExist(err) { if redirectRepoID, err := repo_model.LookupRedirect(owner.ID, reponame); err == nil { diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 5bee8c76a9..bb5f6e7ef5 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -495,7 +495,7 @@ func Issues(ctx *context.Context) { func renderMilestones(ctx *context.Context) { // Get milestones - milestones, _, err := issues_model.GetMilestones(issues_model.GetMilestonesOption{ + milestones, _, err := issues_model.GetMilestones(ctx, issues_model.GetMilestonesOption{ RepoID: ctx.Repo.Repository.ID, State: api.StateAll, }) @@ -519,7 +519,7 @@ func renderMilestones(ctx *context.Context) { // RetrieveRepoMilestonesAndAssignees find all the milestones and assignees of a repository func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *repo_model.Repository) { var err error - ctx.Data["OpenMilestones"], _, err = issues_model.GetMilestones(issues_model.GetMilestonesOption{ + ctx.Data["OpenMilestones"], _, err = issues_model.GetMilestones(ctx, issues_model.GetMilestonesOption{ RepoID: repo.ID, State: api.StateOpen, }) @@ -527,7 +527,7 @@ func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *repo_model.R ctx.ServerError("GetMilestones", err) return } - ctx.Data["ClosedMilestones"], _, err = issues_model.GetMilestones(issues_model.GetMilestonesOption{ + ctx.Data["ClosedMilestones"], _, err = issues_model.GetMilestones(ctx, issues_model.GetMilestonesOption{ RepoID: repo.ID, State: api.StateClosed, }) @@ -1229,7 +1229,7 @@ func NewIssuePost(ctx *context.Context) { ctx.Error(http.StatusBadRequest, "user hasn't permissions to read projects") return } - if err := issues_model.ChangeProjectAssign(issue, ctx.Doer, projectID); err != nil { + if err := issues_model.ChangeProjectAssign(ctx, issue, ctx.Doer, projectID); err != nil { ctx.ServerError("ChangeProjectAssign", err) return } @@ -1332,7 +1332,7 @@ func ViewIssue(ctx *context.Context) { extIssueUnit, err := ctx.Repo.Repository.GetUnit(ctx, unit.TypeExternalTracker) if err == nil && extIssueUnit != nil { if extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == markup.IssueNameStyleNumeric || extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == "" { - metas := ctx.Repo.Repository.ComposeMetas() + metas := ctx.Repo.Repository.ComposeMetas(ctx) metas["index"] = ctx.Params(":index") res, err := vars.Expand(extIssueUnit.ExternalTrackerConfig().ExternalTrackerFormat, metas) if err != nil { @@ -1425,7 +1425,7 @@ func ViewIssue(ctx *context.Context) { issue.RenderedContent, err = markdown.RenderString(&markup.RenderContext{ URLPrefix: ctx.Repo.RepoLink, - Metas: ctx.Repo.Repository.ComposeMetas(), + Metas: ctx.Repo.Repository.ComposeMetas(ctx), GitRepo: ctx.Repo.GitRepo, Ctx: ctx, }, issue.Content) @@ -1588,7 +1588,7 @@ func ViewIssue(ctx *context.Context) { comment.RenderedContent, err = markdown.RenderString(&markup.RenderContext{ URLPrefix: ctx.Repo.RepoLink, - Metas: ctx.Repo.Repository.ComposeMetas(), + Metas: ctx.Repo.Repository.ComposeMetas(ctx), GitRepo: ctx.Repo.GitRepo, Ctx: ctx, }, comment.Content) @@ -1665,7 +1665,7 @@ func ViewIssue(ctx *context.Context) { } else if comment.Type.HasContentSupport() { comment.RenderedContent, err = markdown.RenderString(&markup.RenderContext{ URLPrefix: ctx.Repo.RepoLink, - Metas: ctx.Repo.Repository.ComposeMetas(), + Metas: ctx.Repo.Repository.ComposeMetas(ctx), GitRepo: ctx.Repo.GitRepo, Ctx: ctx, }, comment.Content) @@ -1909,7 +1909,7 @@ func ViewIssue(ctx *context.Context) { if pull.HasMerged || issue.IsClosed || !ctx.IsSigned { return false } - if pull.CanAutoMerge() || pull.IsWorkInProgress() || pull.IsChecking() { + if pull.CanAutoMerge() || pull.IsWorkInProgress(ctx) || pull.IsChecking() { return false } if (ctx.Doer.IsAdmin || ctx.Repo.IsAdmin()) && prConfig.AllowManualMerge { @@ -2223,7 +2223,7 @@ func UpdateIssueContent(ctx *context.Context) { content, err := markdown.RenderString(&markup.RenderContext{ URLPrefix: ctx.FormString("context"), // FIXME: <- IS THIS SAFE ? - Metas: ctx.Repo.Repository.ComposeMetas(), + Metas: ctx.Repo.Repository.ComposeMetas(ctx), GitRepo: ctx.Repo.GitRepo, Ctx: ctx, }, issue.Content) @@ -2286,7 +2286,7 @@ func UpdateIssueMilestone(ctx *context.Context) { continue } issue.MilestoneID = milestoneID - if err := issue_service.ChangeMilestoneAssign(issue, ctx.Doer, oldMilestoneID); err != nil { + if err := issue_service.ChangeMilestoneAssign(ctx, issue, ctx.Doer, oldMilestoneID); err != nil { ctx.ServerError("ChangeMilestoneAssign", err) return } @@ -2536,7 +2536,7 @@ func SearchIssues(ctx *context.Context) { allPublic = true opts.AllPublic = false // set it false to avoid returning too many repos, we could filter by indexer } - repoIDs, _, err = repo_model.SearchRepositoryIDs(opts) + repoIDs, _, err = repo_model.SearchRepositoryIDs(ctx, opts) if err != nil { ctx.Error(http.StatusInternalServerError, "SearchRepositoryIDs", err.Error()) return @@ -3127,7 +3127,7 @@ func UpdateCommentContent(ctx *context.Context) { content, err := markdown.RenderString(&markup.RenderContext{ URLPrefix: ctx.FormString("context"), // FIXME: <- IS THIS SAFE ? - Metas: ctx.Repo.Repository.ComposeMetas(), + Metas: ctx.Repo.Repository.ComposeMetas(ctx), GitRepo: ctx.Repo.GitRepo, Ctx: ctx, }, comment.Content) diff --git a/routers/web/repo/issue_dependency.go b/routers/web/repo/issue_dependency.go index 5b9c570b74..716a02ab6c 100644 --- a/routers/web/repo/issue_dependency.go +++ b/routers/web/repo/issue_dependency.go @@ -72,7 +72,7 @@ func AddDependency(ctx *context.Context) { return } - err = issues_model.CreateIssueDependency(ctx.Doer, issue, dep) + err = issues_model.CreateIssueDependency(ctx, ctx.Doer, issue, dep) if err != nil { if issues_model.IsErrDependencyExists(err) { ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_exists")) @@ -131,7 +131,7 @@ func RemoveDependency(ctx *context.Context) { return } - if err = issues_model.RemoveIssueDependency(ctx.Doer, issue, dep, depType); err != nil { + if err = issues_model.RemoveIssueDependency(ctx, ctx.Doer, issue, dep, depType); err != nil { if issues_model.IsErrDependencyNotExists(err) { ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_not_exist")) return diff --git a/routers/web/repo/issue_lock.go b/routers/web/repo/issue_lock.go index 93f5a588d9..f83109d9b3 100644 --- a/routers/web/repo/issue_lock.go +++ b/routers/web/repo/issue_lock.go @@ -29,7 +29,7 @@ func LockIssue(ctx *context.Context) { return } - if err := issues_model.LockIssue(&issues_model.IssueLockOptions{ + if err := issues_model.LockIssue(ctx, &issues_model.IssueLockOptions{ Doer: ctx.Doer, Issue: issue, Reason: form.Reason, @@ -53,7 +53,7 @@ func UnlockIssue(ctx *context.Context) { return } - if err := issues_model.UnlockIssue(&issues_model.IssueLockOptions{ + if err := issues_model.UnlockIssue(ctx, &issues_model.IssueLockOptions{ Doer: ctx.Doer, Issue: issue, }); err != nil { diff --git a/routers/web/repo/milestone.go b/routers/web/repo/milestone.go index df52ca3528..32cbc29c67 100644 --- a/routers/web/repo/milestone.go +++ b/routers/web/repo/milestone.go @@ -50,7 +50,7 @@ func Milestones(ctx *context.Context) { state = structs.StateClosed } - miles, total, err := issues_model.GetMilestones(issues_model.GetMilestonesOption{ + miles, total, err := issues_model.GetMilestones(ctx, issues_model.GetMilestonesOption{ ListOptions: db.ListOptions{ Page: page, PageSize: setting.UI.IssuePagingNum, @@ -82,7 +82,7 @@ func Milestones(ctx *context.Context) { for _, m := range miles { m.RenderedContent, err = markdown.RenderString(&markup.RenderContext{ URLPrefix: ctx.Repo.RepoLink, - Metas: ctx.Repo.Repository.ComposeMetas(), + Metas: ctx.Repo.Repository.ComposeMetas(ctx), GitRepo: ctx.Repo.GitRepo, Ctx: ctx, }, m.Content) @@ -275,7 +275,7 @@ func MilestoneIssuesAndPulls(ctx *context.Context) { milestone.RenderedContent, err = markdown.RenderString(&markup.RenderContext{ URLPrefix: ctx.Repo.RepoLink, - Metas: ctx.Repo.Repository.ComposeMetas(), + Metas: ctx.Repo.Repository.ComposeMetas(ctx), GitRepo: ctx.Repo.GitRepo, Ctx: ctx, }, milestone.Content) diff --git a/routers/web/repo/projects.go b/routers/web/repo/projects.go index 33bc79d96d..ada398fdc8 100644 --- a/routers/web/repo/projects.go +++ b/routers/web/repo/projects.go @@ -87,7 +87,7 @@ func Projects(ctx *context.Context) { for i := range projects { projects[i].RenderedContent, err = markdown.RenderString(&markup.RenderContext{ URLPrefix: ctx.Repo.RepoLink, - Metas: ctx.Repo.Repository.ComposeMetas(), + Metas: ctx.Repo.Repository.ComposeMetas(ctx), GitRepo: ctx.Repo.GitRepo, Ctx: ctx, }, projects[i].Description) @@ -353,7 +353,7 @@ func ViewProject(ctx *context.Context) { project.RenderedContent, err = markdown.RenderString(&markup.RenderContext{ URLPrefix: ctx.Repo.RepoLink, - Metas: ctx.Repo.Repository.ComposeMetas(), + Metas: ctx.Repo.Repository.ComposeMetas(ctx), GitRepo: ctx.Repo.GitRepo, Ctx: ctx, }, project.Description) @@ -391,7 +391,7 @@ func UpdateIssueProject(ctx *context.Context) { } } - if err := issues_model.ChangeProjectAssign(issue, ctx.Doer, projectID); err != nil { + if err := issues_model.ChangeProjectAssign(ctx, issue, ctx.Doer, projectID); err != nil { ctx.ServerError("ChangeProjectAssign", err) return } diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 639c0c74d0..c8a0a04fe5 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -371,8 +371,8 @@ func setMergeTarget(ctx *context.Context, pull *issues_model.PullRequest) { ctx.Data["HeadTarget"] = pull.MustHeadUserName(ctx) + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch } ctx.Data["BaseTarget"] = pull.BaseBranch - ctx.Data["HeadBranchLink"] = pull.GetHeadBranchLink() - ctx.Data["BaseBranchLink"] = pull.GetBaseBranchLink() + ctx.Data["HeadBranchLink"] = pull.GetHeadBranchLink(ctx) + ctx.Data["BaseBranchLink"] = pull.GetBaseBranchLink(ctx) } // GetPullDiffStats get Pull Requests diff stats @@ -696,7 +696,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C ctx.Data["IsNothingToCompare"] = true } - if pull.IsWorkInProgress() { + if pull.IsWorkInProgress(ctx) { ctx.Data["IsPullWorkInProgress"] = true ctx.Data["WorkInProgressPrefix"] = pull.GetWorkInProgressPrefix(ctx) } diff --git a/routers/web/repo/release.go b/routers/web/repo/release.go index 61f1973125..5cbd6b3d51 100644 --- a/routers/web/repo/release.go +++ b/routers/web/repo/release.go @@ -136,7 +136,7 @@ func Releases(ctx *context.Context) { r.Note, err = markdown.RenderString(&markup.RenderContext{ URLPrefix: ctx.Repo.RepoLink, - Metas: ctx.Repo.Repository.ComposeMetas(), + Metas: ctx.Repo.Repository.ComposeMetas(ctx), GitRepo: ctx.Repo.GitRepo, Ctx: ctx, }, r.Note) @@ -285,7 +285,7 @@ func SingleRelease(ctx *context.Context) { } release.Note, err = markdown.RenderString(&markup.RenderContext{ URLPrefix: ctx.Repo.RepoLink, - Metas: ctx.Repo.Repository.ComposeMetas(), + Metas: ctx.Repo.Repository.ComposeMetas(ctx), GitRepo: ctx.Repo.GitRepo, Ctx: ctx, }, release.Note) diff --git a/routers/web/repo/render.go b/routers/web/repo/render.go index f07b4e8c11..33476c1d2c 100644 --- a/routers/web/repo/render.go +++ b/routers/web/repo/render.go @@ -67,7 +67,7 @@ func RenderFile(ctx *context.Context) { Ctx: ctx, RelativePath: ctx.Repo.TreePath, URLPrefix: path.Dir(treeLink), - Metas: ctx.Repo.Repository.ComposeDocumentMetas(), + Metas: ctx.Repo.Repository.ComposeDocumentMetas(ctx), GitRepo: ctx.Repo.GitRepo, InStandalonePage: true, }, rd, ctx.Resp) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 6571790627..4dfa01d8e2 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -312,7 +312,7 @@ func renderReadmeFile(ctx *context.Context, subfolder string, readmeFile *git.Tr Ctx: ctx, RelativePath: path.Join(ctx.Repo.TreePath, readmeFile.Name()), // ctx.Repo.TreePath is the directory not the Readme so we must append the Readme filename (and path). URLPrefix: path.Join(readmeTreelink, subfolder), - Metas: ctx.Repo.Repository.ComposeDocumentMetas(), + Metas: ctx.Repo.Repository.ComposeDocumentMetas(ctx), GitRepo: ctx.Repo.GitRepo, }, rd) if err != nil { @@ -469,7 +469,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st if !detected { markupType = "" } - metas := ctx.Repo.Repository.ComposeDocumentMetas() + metas := ctx.Repo.Repository.ComposeDocumentMetas(ctx) metas["BranchNameSubURL"] = ctx.Repo.BranchNameSubURL() ctx.Data["EscapeStatus"], ctx.Data["FileContent"], err = markupRender(ctx, &markup.RenderContext{ Ctx: ctx, @@ -582,7 +582,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st Ctx: ctx, RelativePath: ctx.Repo.TreePath, URLPrefix: path.Dir(treeLink), - Metas: ctx.Repo.Repository.ComposeDocumentMetas(), + Metas: ctx.Repo.Repository.ComposeDocumentMetas(ctx), GitRepo: ctx.Repo.GitRepo, }, rd) if err != nil { @@ -879,7 +879,7 @@ func renderDirectoryFiles(ctx *context.Context, timeout time.Duration) git.Entri } func renderLanguageStats(ctx *context.Context) { - langs, err := repo_model.GetTopLanguageStats(ctx.Repo.Repository, 5) + langs, err := repo_model.GetTopLanguageStats(ctx, ctx.Repo.Repository, 5) if err != nil { ctx.ServerError("Repo.GetTopLanguageStats", err) return diff --git a/routers/web/repo/wiki.go b/routers/web/repo/wiki.go index c9cec0313d..8ea18a186c 100644 --- a/routers/web/repo/wiki.go +++ b/routers/web/repo/wiki.go @@ -240,7 +240,7 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) { rctx := &markup.RenderContext{ Ctx: ctx, URLPrefix: ctx.Repo.RepoLink, - Metas: ctx.Repo.Repository.ComposeDocumentMetas(), + Metas: ctx.Repo.Repository.ComposeDocumentMetas(ctx), IsWiki: true, } buf := &strings.Builder{} diff --git a/routers/web/shared/user/header.go b/routers/web/shared/user/header.go index 355f2ddeff..6d1901dd2b 100644 --- a/routers/web/shared/user/header.go +++ b/routers/web/shared/user/header.go @@ -85,7 +85,7 @@ func PrepareContextForProfileBigAvatar(ctx *context.Context) { } func FindUserProfileReadme(ctx *context.Context) (profileGitRepo *git.Repository, profileReadmeBlob *git.Blob, profileClose func()) { - profileDbRepo, err := repo_model.GetRepositoryByName(ctx.ContextUser.ID, ".profile") + profileDbRepo, err := repo_model.GetRepositoryByName(ctx, ctx.ContextUser.ID, ".profile") if err == nil && !profileDbRepo.IsEmpty && !profileDbRepo.IsPrivate { if profileGitRepo, err = git.OpenRepository(ctx, profileDbRepo.RepoPath()); err != nil { log.Error("FindUserProfileReadme failed to OpenRepository: %v", err) diff --git a/routers/web/user/code.go b/routers/web/user/code.go index 42d7284189..ee514a7cfe 100644 --- a/routers/web/user/code.go +++ b/routers/web/user/code.go @@ -100,7 +100,7 @@ func CodeSearch(ctx *context.Context) { } } - repoMaps, err := repo_model.GetRepositoriesMapByIDs(loadRepoIDs) + repoMaps, err := repo_model.GetRepositoriesMapByIDs(ctx, loadRepoIDs) if err != nil { ctx.ServerError("GetRepositoriesMapByIDs", err) return diff --git a/routers/web/user/home.go b/routers/web/user/home.go index 76b9262ead..9364ce80dc 100644 --- a/routers/web/user/home.go +++ b/routers/web/user/home.go @@ -247,7 +247,7 @@ func Milestones(ctx *context.Context) { milestones[i].RenderedContent, err = markdown.RenderString(&markup.RenderContext{ URLPrefix: milestones[i].Repo.Link(), - Metas: milestones[i].Repo.ComposeMetas(), + Metas: milestones[i].Repo.ComposeMetas(ctx), Ctx: ctx, }, milestones[i].Content) if err != nil { @@ -463,7 +463,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) { } accessibleRepos := container.Set[int64]{} { - ids, _, err := repo_model.SearchRepositoryIDs(repoOpts) + ids, _, err := repo_model.SearchRepositoryIDs(ctx, repoOpts) if err != nil { ctx.ServerError("SearchRepositoryIDs", err) return @@ -576,7 +576,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) { } // showReposMap maps repository IDs to their Repository pointers. - showReposMap, err := loadRepoByIDs(ctxUser, issueCountByRepo, unitType) + showReposMap, err := loadRepoByIDs(ctx, ctxUser, issueCountByRepo, unitType) if err != nil { if repo_model.IsErrRepoNotExist(err) { ctx.NotFound("GetRepositoryByID", err) @@ -734,7 +734,7 @@ func getRepoIDs(reposQuery string) []int64 { return repoIDs } -func loadRepoByIDs(ctxUser *user_model.User, issueCountByRepo map[int64]int64, unitType unit.Type) (map[int64]*repo_model.Repository, error) { +func loadRepoByIDs(ctx *context.Context, ctxUser *user_model.User, issueCountByRepo map[int64]int64, unitType unit.Type) (map[int64]*repo_model.Repository, error) { totalRes := make(map[int64]*repo_model.Repository, len(issueCountByRepo)) repoIDs := make([]int64, 0, 500) for id := range issueCountByRepo { @@ -743,14 +743,14 @@ func loadRepoByIDs(ctxUser *user_model.User, issueCountByRepo map[int64]int64, u } repoIDs = append(repoIDs, id) if len(repoIDs) == 500 { - if err := repo_model.FindReposMapByIDs(repoIDs, totalRes); err != nil { + if err := repo_model.FindReposMapByIDs(ctx, repoIDs, totalRes); err != nil { return nil, err } repoIDs = repoIDs[:0] } } if len(repoIDs) > 0 { - if err := repo_model.FindReposMapByIDs(repoIDs, totalRes); err != nil { + if err := repo_model.FindReposMapByIDs(ctx, repoIDs, totalRes); err != nil { return nil, err } } @@ -759,7 +759,7 @@ func loadRepoByIDs(ctxUser *user_model.User, issueCountByRepo map[int64]int64, u // ShowSSHKeys output all the ssh keys of user by uid func ShowSSHKeys(ctx *context.Context) { - keys, err := asymkey_model.ListPublicKeys(ctx.ContextUser.ID, db.ListOptions{}) + keys, err := asymkey_model.ListPublicKeys(ctx, ctx.ContextUser.ID, db.ListOptions{}) if err != nil { ctx.ServerError("ListPublicKeys", err) return diff --git a/routers/web/user/setting/keys.go b/routers/web/user/setting/keys.go index 160c5ee0c0..227c1d3a75 100644 --- a/routers/web/user/setting/keys.go +++ b/routers/web/user/setting/keys.go @@ -168,7 +168,7 @@ func KeysPost(ctx *context.Context) { return } - if _, err = asymkey_model.AddPublicKey(ctx.Doer.ID, form.Title, content, 0); err != nil { + if _, err = asymkey_model.AddPublicKey(ctx, ctx.Doer.ID, form.Title, content, 0); err != nil { ctx.Data["HasSSHError"] = true switch { case asymkey_model.IsErrKeyAlreadyExist(err): @@ -231,7 +231,7 @@ func DeleteKey(ctx *context.Context) { } case "ssh": keyID := ctx.FormInt64("id") - external, err := asymkey_model.PublicKeyIsExternallyManaged(keyID) + external, err := asymkey_model.PublicKeyIsExternallyManaged(ctx, keyID) if err != nil { ctx.ServerError("sshKeysExternalManaged", err) return @@ -260,14 +260,14 @@ func DeleteKey(ctx *context.Context) { } func loadKeysData(ctx *context.Context) { - keys, err := asymkey_model.ListPublicKeys(ctx.Doer.ID, db.ListOptions{}) + keys, err := asymkey_model.ListPublicKeys(ctx, ctx.Doer.ID, db.ListOptions{}) if err != nil { ctx.ServerError("ListPublicKeys", err) return } ctx.Data["Keys"] = keys - externalKeys, err := asymkey_model.PublicKeysAreExternallyManaged(keys) + externalKeys, err := asymkey_model.PublicKeysAreExternallyManaged(ctx, keys) if err != nil { ctx.ServerError("ListPublicKeys", err) return diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index 72e60bda58..c97e66574e 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -157,7 +157,7 @@ func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser * if !(st.IsImage() && !st.IsSvgImage()) { return errors.New(ctx.Tr("settings.uploaded_avatar_not_a_image")) } - if err = user_service.UploadAvatar(ctxUser, data); err != nil { + if err = user_service.UploadAvatar(ctx, ctxUser, data); err != nil { return fmt.Errorf("UploadAvatar: %w", err) } } else if ctxUser.UseCustomAvatar && ctxUser.Avatar == "" { @@ -189,7 +189,7 @@ func AvatarPost(ctx *context.Context) { // DeleteAvatar render delete avatar page func DeleteAvatar(ctx *context.Context) { - if err := user_service.DeleteAvatar(ctx.Doer); err != nil { + if err := user_service.DeleteAvatar(ctx, ctx.Doer); err != nil { ctx.Flash.Error(err.Error()) } diff --git a/routers/web/user/setting/security/security.go b/routers/web/user/setting/security/security.go index 5a17c161fe..833940d928 100644 --- a/routers/web/user/setting/security/security.go +++ b/routers/web/user/setting/security/security.go @@ -82,7 +82,7 @@ func loadSecurityData(ctx *context.Context) { // map the provider display name with the AuthSource sources := make(map[*auth_model.Source]string) for _, externalAccount := range accountLinks { - if authSource, err := auth_model.GetSourceByID(externalAccount.LoginSourceID); err == nil { + if authSource, err := auth_model.GetSourceByID(ctx, externalAccount.LoginSourceID); err == nil { var providerDisplayName string type DisplayNamed interface { diff --git a/routers/web/web.go b/routers/web/web.go index 2154838726..d2179a0008 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -9,6 +9,7 @@ import ( "strings" auth_model "code.gitea.io/gitea/models/auth" + "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/perm" "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/context" @@ -94,7 +95,7 @@ func buildAuthGroup() *auth_service.Group { group.Add(&auth_service.ReverseProxy{}) } - if setting.IsWindows && auth_model.IsSSPIEnabled() { + if setting.IsWindows && auth_model.IsSSPIEnabled(db.DefaultContext) { group.Add(&auth_service.SSPI{}) // it MUST be the last, see the comment of SSPI } |