diff options
author | JakobDev <jakobdev@gmx.de> | 2023-09-25 15:17:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-25 13:17:37 +0000 |
commit | 7047df36d4c39fefa6464b713c66302aa0038123 (patch) | |
tree | a5c471a3e8abf5cabac8de42c0fd8a814df7abf1 /routers/api/v1 | |
parent | 93bd4351bfb4a2f5f37ecb80d50496d044240e00 (diff) | |
download | gitea-7047df36d4c39fefa6464b713c66302aa0038123.tar.gz gitea-7047df36d4c39fefa6464b713c66302aa0038123.zip |
Another round of `db.DefaultContext` refactor (#27103)
Part of #27065
---------
Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
Diffstat (limited to 'routers/api/v1')
-rw-r--r-- | routers/api/v1/admin/user.go | 2 | ||||
-rw-r--r-- | routers/api/v1/api.go | 4 | ||||
-rw-r--r-- | routers/api/v1/org/team.go | 6 | ||||
-rw-r--r-- | routers/api/v1/packages/package.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/issue_reaction.go | 12 | ||||
-rw-r--r-- | routers/api/v1/repo/key.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/pull_review.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/release.go | 10 | ||||
-rw-r--r-- | routers/api/v1/repo/release_tags.go | 4 | ||||
-rw-r--r-- | routers/api/v1/repo/repo.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/tag.go | 2 | ||||
-rw-r--r-- | routers/api/v1/user/gpg_key.go | 12 | ||||
-rw-r--r-- | routers/api/v1/user/helper.go | 2 | ||||
-rw-r--r-- | routers/api/v1/user/key.go | 2 | ||||
-rw-r--r-- | routers/api/v1/user/user.go | 2 |
15 files changed, 33 insertions, 33 deletions
diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go index 66946e5797..610eba1749 100644 --- a/routers/api/v1/admin/user.go +++ b/routers/api/v1/admin/user.go @@ -402,7 +402,7 @@ func DeleteUserPublicKey(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - if err := asymkey_service.DeletePublicKey(ctx.ContextUser, ctx.ParamsInt64(":id")); err != nil { + if err := asymkey_service.DeletePublicKey(ctx, ctx.ContextUser, ctx.ParamsInt64(":id")); err != nil { if asymkey_model.IsErrKeyNotExist(err) { ctx.NotFound() } else if asymkey_model.IsErrKeyAccessDenied(err) { diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index dc1f914922..441801885f 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -148,7 +148,7 @@ func repoAssignment() func(ctx *context.APIContext) { owner, err = user_model.GetUserByName(ctx, userName) if err != nil { if user_model.IsErrUserNotExist(err) { - if redirectUserID, err := user_model.LookupUserRedirect(userName); err == nil { + if redirectUserID, err := user_model.LookupUserRedirect(ctx, userName); err == nil { context.RedirectToUser(ctx.Base, userName, redirectUserID) } else if user_model.IsErrUserRedirectNotExist(err) { ctx.NotFound("GetUserByName", err) @@ -564,7 +564,7 @@ func orgAssignment(args ...bool) func(ctx *context.APIContext) { ctx.Org.Organization, err = organization.GetOrgByName(ctx, ctx.Params(":org")) if err != nil { if organization.IsErrOrgNotExist(err) { - redirectUserID, err := user_model.LookupUserRedirect(ctx.Params(":org")) + redirectUserID, err := user_model.LookupUserRedirect(ctx, ctx.Params(":org")) if err == nil { context.RedirectToUser(ctx.Base, ctx.Params(":org"), redirectUserID) } else if user_model.IsErrUserRedirectNotExist(err) { diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index 83cbfe68d0..9b68253623 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -53,7 +53,7 @@ func ListTeams(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - teams, count, err := organization.SearchTeam(&organization.SearchTeamOptions{ + teams, count, err := organization.SearchTeam(ctx, &organization.SearchTeamOptions{ ListOptions: utils.GetListOptions(ctx), OrgID: ctx.Org.Organization.ID, }) @@ -92,7 +92,7 @@ func ListUserTeams(ctx *context.APIContext) { // "200": // "$ref": "#/responses/TeamList" - teams, count, err := organization.SearchTeam(&organization.SearchTeamOptions{ + teams, count, err := organization.SearchTeam(ctx, &organization.SearchTeamOptions{ ListOptions: utils.GetListOptions(ctx), UserID: ctx.Doer.ID, }) @@ -810,7 +810,7 @@ func SearchTeam(ctx *context.APIContext) { opts.UserID = ctx.Doer.ID } - teams, maxResults, err := organization.SearchTeam(opts) + teams, maxResults, err := organization.SearchTeam(ctx, opts) if err != nil { log.Error("SearchTeam failed: %v", err) ctx.JSON(http.StatusInternalServerError, map[string]any{ diff --git a/routers/api/v1/packages/package.go b/routers/api/v1/packages/package.go index 53724179a2..a79ba315be 100644 --- a/routers/api/v1/packages/package.go +++ b/routers/api/v1/packages/package.go @@ -164,7 +164,7 @@ func DeletePackage(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - err := packages_service.RemovePackageVersion(ctx.Doer, ctx.Package.Descriptor.Version) + err := packages_service.RemovePackageVersion(ctx, ctx.Doer, ctx.Package.Descriptor.Version) if err != nil { ctx.Error(http.StatusInternalServerError, "RemovePackageVersion", err) return diff --git a/routers/api/v1/repo/issue_reaction.go b/routers/api/v1/repo/issue_reaction.go index 5210d4cced..29c99184e7 100644 --- a/routers/api/v1/repo/issue_reaction.go +++ b/routers/api/v1/repo/issue_reaction.go @@ -68,7 +68,7 @@ func GetIssueCommentReactions(ctx *context.APIContext) { return } - reactions, _, err := issues_model.FindCommentReactions(comment.IssueID, comment.ID) + reactions, _, err := issues_model.FindCommentReactions(ctx, comment.IssueID, comment.ID) if err != nil { ctx.Error(http.StatusInternalServerError, "FindCommentReactions", err) return @@ -202,7 +202,7 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp if isCreateType { // PostIssueCommentReaction part - reaction, err := issues_model.CreateCommentReaction(ctx.Doer.ID, comment.Issue.ID, comment.ID, form.Reaction) + reaction, err := issues_model.CreateCommentReaction(ctx, ctx.Doer.ID, comment.Issue.ID, comment.ID, form.Reaction) if err != nil { if issues_model.IsErrForbiddenIssueReaction(err) { ctx.Error(http.StatusForbidden, err.Error(), err) @@ -225,7 +225,7 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp }) } else { // DeleteIssueCommentReaction part - err = issues_model.DeleteCommentReaction(ctx.Doer.ID, comment.Issue.ID, comment.ID, form.Reaction) + err = issues_model.DeleteCommentReaction(ctx, ctx.Doer.ID, comment.Issue.ID, comment.ID, form.Reaction) if err != nil { ctx.Error(http.StatusInternalServerError, "DeleteCommentReaction", err) return @@ -292,7 +292,7 @@ func GetIssueReactions(ctx *context.APIContext) { return } - reactions, count, err := issues_model.FindIssueReactions(issue.ID, utils.GetListOptions(ctx)) + reactions, count, err := issues_model.FindIssueReactions(ctx, issue.ID, utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "FindIssueReactions", err) return @@ -418,7 +418,7 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i if isCreateType { // PostIssueReaction part - reaction, err := issues_model.CreateIssueReaction(ctx.Doer.ID, issue.ID, form.Reaction) + reaction, err := issues_model.CreateIssueReaction(ctx, ctx.Doer.ID, issue.ID, form.Reaction) if err != nil { if issues_model.IsErrForbiddenIssueReaction(err) { ctx.Error(http.StatusForbidden, err.Error(), err) @@ -441,7 +441,7 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i }) } else { // DeleteIssueReaction part - err = issues_model.DeleteIssueReaction(ctx.Doer.ID, issue.ID, form.Reaction) + err = issues_model.DeleteIssueReaction(ctx, ctx.Doer.ID, issue.ID, form.Reaction) if err != nil { ctx.Error(http.StatusInternalServerError, "DeleteIssueReaction", err) return diff --git a/routers/api/v1/repo/key.go b/routers/api/v1/repo/key.go index b7d820d1d8..7d97f5f5e2 100644 --- a/routers/api/v1/repo/key.go +++ b/routers/api/v1/repo/key.go @@ -279,7 +279,7 @@ func DeleteDeploykey(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - if err := asymkey_service.DeleteDeployKey(ctx.Doer, ctx.ParamsInt64(":id")); err != nil { + if err := asymkey_service.DeleteDeployKey(ctx, ctx.Doer, ctx.ParamsInt64(":id")); err != nil { if asymkey_model.IsErrKeyAccessDenied(err) { ctx.Error(http.StatusForbidden, "", "You do not have access to this key") } else { diff --git a/routers/api/v1/repo/pull_review.go b/routers/api/v1/repo/pull_review.go index 82cbb3e763..43379821c9 100644 --- a/routers/api/v1/repo/pull_review.go +++ b/routers/api/v1/repo/pull_review.go @@ -92,7 +92,7 @@ func ListPullReviews(ctx *context.APIContext) { return } - count, err := issues_model.CountReviews(opts) + count, err := issues_model.CountReviews(ctx, opts) if err != nil { ctx.InternalServerError(err) return diff --git a/routers/api/v1/repo/release.go b/routers/api/v1/repo/release.go index be9c0cd00a..61e5bdd679 100644 --- a/routers/api/v1/repo/release.go +++ b/routers/api/v1/repo/release.go @@ -90,7 +90,7 @@ func GetLatestRelease(ctx *context.APIContext) { // "$ref": "#/responses/Release" // "404": // "$ref": "#/responses/notFound" - release, err := repo_model.GetLatestReleaseByRepoID(ctx.Repo.Repository.ID) + release, err := repo_model.GetLatestReleaseByRepoID(ctx, ctx.Repo.Repository.ID) if err != nil && !repo_model.IsErrReleaseNotExist(err) { ctx.Error(http.StatusInternalServerError, "GetLatestRelease", err) return @@ -179,7 +179,7 @@ func ListReleases(ctx *context.APIContext) { rels[i] = convert.ToAPIRelease(ctx, ctx.Repo.Repository, release) } - filteredCount, err := repo_model.CountReleasesByRepoID(ctx.Repo.Repository.ID, opts) + filteredCount, err := repo_model.CountReleasesByRepoID(ctx, ctx.Repo.Repository.ID, opts) if err != nil { ctx.InternalServerError(err) return @@ -222,7 +222,7 @@ func CreateRelease(ctx *context.APIContext) { // "409": // "$ref": "#/responses/error" form := web.GetForm(ctx).(*api.CreateReleaseOption) - rel, err := repo_model.GetRelease(ctx.Repo.Repository.ID, form.TagName) + rel, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, form.TagName) if err != nil { if !repo_model.IsErrReleaseNotExist(err) { ctx.Error(http.StatusInternalServerError, "GetRelease", err) @@ -269,7 +269,7 @@ func CreateRelease(ctx *context.APIContext) { rel.Publisher = ctx.Doer rel.Target = form.Target - if err = release_service.UpdateRelease(ctx.Doer, ctx.Repo.GitRepo, rel, nil, nil, nil); err != nil { + if err = release_service.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, nil, nil, nil); err != nil { ctx.Error(http.StatusInternalServerError, "UpdateRelease", err) return } @@ -344,7 +344,7 @@ func EditRelease(ctx *context.APIContext) { if form.IsPrerelease != nil { rel.IsPrerelease = *form.IsPrerelease } - if err := release_service.UpdateRelease(ctx.Doer, ctx.Repo.GitRepo, rel, nil, nil, nil); err != nil { + if err := release_service.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, nil, nil, nil); err != nil { ctx.Error(http.StatusInternalServerError, "UpdateRelease", err) return } diff --git a/routers/api/v1/repo/release_tags.go b/routers/api/v1/repo/release_tags.go index a03edfafcf..926a713c94 100644 --- a/routers/api/v1/repo/release_tags.go +++ b/routers/api/v1/repo/release_tags.go @@ -44,7 +44,7 @@ func GetReleaseByTag(ctx *context.APIContext) { tag := ctx.Params(":tag") - release, err := repo_model.GetRelease(ctx.Repo.Repository.ID, tag) + release, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, tag) if err != nil { if repo_model.IsErrReleaseNotExist(err) { ctx.NotFound() @@ -97,7 +97,7 @@ func DeleteReleaseByTag(ctx *context.APIContext) { tag := ctx.Params(":tag") - release, err := repo_model.GetRelease(ctx.Repo.Repository.ID, tag) + release, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, tag) if err != nil { if repo_model.IsErrReleaseNotExist(err) { ctx.NotFound() diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index 5f25fdce14..9769668f47 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -1114,7 +1114,7 @@ func Delete(ctx *context.APIContext) { owner := ctx.Repo.Owner repo := ctx.Repo.Repository - canDelete, err := repo_module.CanUserDelete(repo, ctx.Doer) + canDelete, err := repo_module.CanUserDelete(ctx, repo, ctx.Doer) if err != nil { ctx.Error(http.StatusInternalServerError, "CanUserDelete", err) return diff --git a/routers/api/v1/repo/tag.go b/routers/api/v1/repo/tag.go index cd29937cb8..dbc8df0ef8 100644 --- a/routers/api/v1/repo/tag.go +++ b/routers/api/v1/repo/tag.go @@ -257,7 +257,7 @@ func DeleteTag(ctx *context.APIContext) { // "$ref": "#/responses/repoArchivedError" tagName := ctx.Params("*") - tag, err := repo_model.GetRelease(ctx.Repo.Repository.ID, tagName) + tag, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, tagName) if err != nil { if repo_model.IsErrReleaseNotExist(err) { ctx.NotFound() diff --git a/routers/api/v1/user/gpg_key.go b/routers/api/v1/user/gpg_key.go index 4aebbaf314..8578e09054 100644 --- a/routers/api/v1/user/gpg_key.go +++ b/routers/api/v1/user/gpg_key.go @@ -29,7 +29,7 @@ func listGPGKeys(ctx *context.APIContext, uid int64, listOptions db.ListOptions) apiKeys[i] = convert.ToGPGKey(keys[i]) } - total, err := asymkey_model.CountUserGPGKeys(uid) + total, err := asymkey_model.CountUserGPGKeys(ctx, uid) if err != nil { ctx.InternalServerError(err) return @@ -112,7 +112,7 @@ func GetGPGKey(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - key, err := asymkey_model.GetGPGKeyByID(ctx.ParamsInt64(":id")) + key, err := asymkey_model.GetGPGKeyByID(ctx, ctx.ParamsInt64(":id")) if err != nil { if asymkey_model.IsErrGPGKeyNotExist(err) { ctx.NotFound() @@ -129,9 +129,9 @@ func CreateUserGPGKey(ctx *context.APIContext, form api.CreateGPGKeyOption, uid token := asymkey_model.VerificationToken(ctx.Doer, 1) lastToken := asymkey_model.VerificationToken(ctx.Doer, 0) - keys, err := asymkey_model.AddGPGKey(uid, form.ArmoredKey, token, form.Signature) + keys, err := asymkey_model.AddGPGKey(ctx, uid, form.ArmoredKey, token, form.Signature) if err != nil && asymkey_model.IsErrGPGInvalidTokenSignature(err) { - keys, err = asymkey_model.AddGPGKey(uid, form.ArmoredKey, lastToken, form.Signature) + keys, err = asymkey_model.AddGPGKey(ctx, uid, form.ArmoredKey, lastToken, form.Signature) } if err != nil { HandleAddGPGKeyError(ctx, err, token) @@ -198,7 +198,7 @@ func VerifyUserGPGKey(ctx *context.APIContext) { ctx.Error(http.StatusInternalServerError, "VerifyUserGPGKey", err) } - key, err := asymkey_model.GetGPGKeysByKeyID(form.KeyID) + key, err := asymkey_model.GetGPGKeysByKeyID(ctx, form.KeyID) if err != nil { if asymkey_model.IsErrGPGKeyNotExist(err) { ctx.NotFound() @@ -259,7 +259,7 @@ func DeleteGPGKey(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - if err := asymkey_model.DeleteGPGKey(ctx.Doer, ctx.ParamsInt64(":id")); err != nil { + if err := asymkey_model.DeleteGPGKey(ctx, ctx.Doer, ctx.ParamsInt64(":id")); err != nil { if asymkey_model.IsErrGPGKeyAccessDenied(err) { ctx.Error(http.StatusForbidden, "", "You do not have access to this key") } else { diff --git a/routers/api/v1/user/helper.go b/routers/api/v1/user/helper.go index 4b642910b1..392b266ebd 100644 --- a/routers/api/v1/user/helper.go +++ b/routers/api/v1/user/helper.go @@ -16,7 +16,7 @@ func GetUserByParamsName(ctx *context.APIContext, name string) *user_model.User user, err := user_model.GetUserByName(ctx, username) if err != nil { if user_model.IsErrUserNotExist(err) { - if redirectUserID, err2 := user_model.LookupUserRedirect(username); err2 == nil { + if redirectUserID, err2 := user_model.LookupUserRedirect(ctx, username); err2 == nil { context.RedirectToUser(ctx.Base, username, redirectUserID) } else { ctx.NotFound("GetUserByName", err) diff --git a/routers/api/v1/user/key.go b/routers/api/v1/user/key.go index 21cc560847..7fc10e82f2 100644 --- a/routers/api/v1/user/key.go +++ b/routers/api/v1/user/key.go @@ -277,7 +277,7 @@ func DeletePublicKey(ctx *context.APIContext) { return } - if err := asymkey_service.DeletePublicKey(ctx.Doer, id); err != nil { + if err := asymkey_service.DeletePublicKey(ctx, ctx.Doer, id); err != nil { if asymkey_model.IsErrKeyAccessDenied(err) { ctx.Error(http.StatusForbidden, "", "You do not have access to this key") } else { diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go index 251e7a6013..6359138369 100644 --- a/routers/api/v1/user/user.go +++ b/routers/api/v1/user/user.go @@ -138,7 +138,7 @@ func GetUserHeatmapData(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - heatmap, err := activities_model.GetUserHeatmapDataByUser(ctx.ContextUser, ctx.Doer) + heatmap, err := activities_model.GetUserHeatmapDataByUser(ctx, ctx.ContextUser, ctx.Doer) if err != nil { ctx.Error(http.StatusInternalServerError, "GetUserHeatmapDataByUser", err) return |