summaryrefslogtreecommitdiffstats
path: root/routers/api
diff options
context:
space:
mode:
authorJakobDev <jakobdev@gmx.de>2023-09-14 19:09:32 +0200
committerGitHub <noreply@github.com>2023-09-14 19:09:32 +0200
commit76659b1114153603050de810006e04a938e9dcb7 (patch)
treeed180213ca459bca51c44dbcc55fd3f9bc2d0460 /routers/api
parentRemove the useless function `GetUserIssueStats` and move relevant tests to `i... (diff)
downloadforgejo-76659b1114153603050de810006e04a938e9dcb7.tar.xz
forgejo-76659b1114153603050de810006e04a938e9dcb7.zip
Reduce usage of `db.DefaultContext` (#27073)
Part of #27065 This reduces the usage of `db.DefaultContext`. I think I've got enough files for the first PR. When this is merged, I will continue working on this. Considering how many files this PR affect, I hope it won't take to long to merge, so I don't end up in the merge conflict hell. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'routers/api')
-rw-r--r--routers/api/v1/admin/email.go2
-rw-r--r--routers/api/v1/admin/org.go2
-rw-r--r--routers/api/v1/admin/user.go4
-rw-r--r--routers/api/v1/misc/nodeinfo.go6
-rw-r--r--routers/api/v1/org/member.go2
-rw-r--r--routers/api/v1/org/org.go2
-rw-r--r--routers/api/v1/org/team.go10
-rw-r--r--routers/api/v1/repo/branch.go8
-rw-r--r--routers/api/v1/repo/fork.go2
-rw-r--r--routers/api/v1/repo/issue_subscription.go2
-rw-r--r--routers/api/v1/repo/pull.go2
-rw-r--r--routers/api/v1/user/email.go6
-rw-r--r--routers/api/v1/user/user.go2
13 files changed, 25 insertions, 25 deletions
diff --git a/routers/api/v1/admin/email.go b/routers/api/v1/admin/email.go
index 8d0491e070..5914215bc2 100644
--- a/routers/api/v1/admin/email.go
+++ b/routers/api/v1/admin/email.go
@@ -37,7 +37,7 @@ func GetAllEmails(ctx *context.APIContext) {
listOptions := utils.GetListOptions(ctx)
- emails, maxResults, err := user_model.SearchEmails(&user_model.SearchEmailOptions{
+ emails, maxResults, err := user_model.SearchEmails(ctx, &user_model.SearchEmailOptions{
Keyword: ctx.Params(":email"),
ListOptions: listOptions,
})
diff --git a/routers/api/v1/admin/org.go b/routers/api/v1/admin/org.go
index 6d50a12674..65620459b7 100644
--- a/routers/api/v1/admin/org.go
+++ b/routers/api/v1/admin/org.go
@@ -101,7 +101,7 @@ func GetAllOrgs(ctx *context.APIContext) {
listOptions := utils.GetListOptions(ctx)
- users, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{
+ users, maxResults, err := user_model.SearchUsers(ctx, &user_model.SearchUserOptions{
Actor: ctx.Doer,
Type: user_model.UserTypeOrganization,
OrderBy: db.SearchOrderByAlphabetically,
diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go
index 4f1e9a3f53..66946e5797 100644
--- a/routers/api/v1/admin/user.go
+++ b/routers/api/v1/admin/user.go
@@ -128,7 +128,7 @@ func CreateUser(ctx *context.APIContext) {
u.UpdatedUnix = u.CreatedUnix
}
- if err := user_model.CreateUser(u, overwriteDefault); err != nil {
+ if err := user_model.CreateUser(ctx, u, overwriteDefault); err != nil {
if user_model.IsErrUserAlreadyExist(err) ||
user_model.IsErrEmailAlreadyUsed(err) ||
db.IsErrNameReserved(err) ||
@@ -450,7 +450,7 @@ func SearchUsers(ctx *context.APIContext) {
listOptions := utils.GetListOptions(ctx)
- users, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{
+ users, maxResults, err := user_model.SearchUsers(ctx, &user_model.SearchUserOptions{
Actor: ctx.Doer,
Type: user_model.UserTypeIndividual,
LoginName: ctx.FormTrim("login_name"),
diff --git a/routers/api/v1/misc/nodeinfo.go b/routers/api/v1/misc/nodeinfo.go
index 319c3483e1..22004a8a88 100644
--- a/routers/api/v1/misc/nodeinfo.go
+++ b/routers/api/v1/misc/nodeinfo.go
@@ -34,12 +34,12 @@ func NodeInfo(ctx *context.APIContext) {
nodeInfoUsage, cached = ctx.Cache.Get(cacheKeyNodeInfoUsage).(structs.NodeInfoUsage)
}
if !cached {
- usersTotal := int(user_model.CountUsers(nil))
+ usersTotal := int(user_model.CountUsers(ctx, nil))
now := time.Now()
timeOneMonthAgo := now.AddDate(0, -1, 0).Unix()
timeHaveYearAgo := now.AddDate(0, -6, 0).Unix()
- usersActiveMonth := int(user_model.CountUsers(&user_model.CountUserFilter{LastLoginSince: &timeOneMonthAgo}))
- usersActiveHalfyear := int(user_model.CountUsers(&user_model.CountUserFilter{LastLoginSince: &timeHaveYearAgo}))
+ usersActiveMonth := int(user_model.CountUsers(ctx, &user_model.CountUserFilter{LastLoginSince: &timeOneMonthAgo}))
+ 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{})
diff --git a/routers/api/v1/org/member.go b/routers/api/v1/org/member.go
index e5ea584d5d..67956e66bd 100644
--- a/routers/api/v1/org/member.go
+++ b/routers/api/v1/org/member.go
@@ -31,7 +31,7 @@ func listMembers(ctx *context.APIContext, publicOnly bool) {
return
}
- members, _, err := organization.FindOrgMembers(opts)
+ members, _, err := organization.FindOrgMembers(ctx, opts)
if err != nil {
ctx.InternalServerError(err)
return
diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go
index 0216b62352..c5f531923b 100644
--- a/routers/api/v1/org/org.go
+++ b/routers/api/v1/org/org.go
@@ -203,7 +203,7 @@ func GetAll(ctx *context.APIContext) {
listOptions := utils.GetListOptions(ctx)
- publicOrgs, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{
+ publicOrgs, maxResults, err := user_model.SearchUsers(ctx, &user_model.SearchUserOptions{
Actor: ctx.Doer,
ListOptions: listOptions,
Type: user_model.UserTypeOrganization,
diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go
index abb5381a70..944fd763ca 100644
--- a/routers/api/v1/org/team.go
+++ b/routers/api/v1/org/team.go
@@ -239,7 +239,7 @@ func CreateTeam(ctx *context.APIContext) {
attachAdminTeamUnits(team)
}
- if err := models.NewTeam(team); err != nil {
+ if err := models.NewTeam(ctx, team); err != nil {
if organization.IsErrTeamAlreadyExist(err) {
ctx.Error(http.StatusUnprocessableEntity, "", err)
} else {
@@ -330,7 +330,7 @@ func EditTeam(ctx *context.APIContext) {
attachAdminTeamUnits(team)
}
- if err := models.UpdateTeam(team, isAuthChanged, isIncludeAllChanged); err != nil {
+ if err := models.UpdateTeam(ctx, team, isAuthChanged, isIncludeAllChanged); err != nil {
ctx.Error(http.StatusInternalServerError, "EditTeam", err)
return
}
@@ -361,7 +361,7 @@ func DeleteTeam(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
- if err := models.DeleteTeam(ctx.Org.Team); err != nil {
+ if err := models.DeleteTeam(ctx, ctx.Org.Team); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteTeam", err)
return
}
@@ -493,7 +493,7 @@ func AddTeamMember(ctx *context.APIContext) {
if ctx.Written() {
return
}
- if err := models.AddTeamMember(ctx.Org.Team, u.ID); err != nil {
+ if err := models.AddTeamMember(ctx, ctx.Org.Team, u.ID); err != nil {
ctx.Error(http.StatusInternalServerError, "AddMember", err)
return
}
@@ -530,7 +530,7 @@ func RemoveTeamMember(ctx *context.APIContext) {
return
}
- if err := models.RemoveTeamMember(ctx.Org.Team, u.ID); err != nil {
+ if err := models.RemoveTeamMember(ctx, ctx.Org.Team, u.ID); err != nil {
ctx.Error(http.StatusInternalServerError, "RemoveTeamMember", err)
return
}
diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go
index cdc176b8e4..c851525c0f 100644
--- a/routers/api/v1/repo/branch.go
+++ b/routers/api/v1/repo/branch.go
@@ -447,7 +447,7 @@ func GetBranchProtection(ctx *context.APIContext) {
return
}
- ctx.JSON(http.StatusOK, convert.ToBranchProtection(bp))
+ ctx.JSON(http.StatusOK, convert.ToBranchProtection(ctx, bp))
}
// ListBranchProtections list branch protections for a repo
@@ -480,7 +480,7 @@ func ListBranchProtections(ctx *context.APIContext) {
}
apiBps := make([]*api.BranchProtection, len(bps))
for i := range bps {
- apiBps[i] = convert.ToBranchProtection(bps[i])
+ apiBps[i] = convert.ToBranchProtection(ctx, bps[i])
}
ctx.JSON(http.StatusOK, apiBps)
@@ -688,7 +688,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
return
}
- ctx.JSON(http.StatusCreated, convert.ToBranchProtection(bp))
+ ctx.JSON(http.StatusCreated, convert.ToBranchProtection(ctx, bp))
}
// EditBranchProtection edits a branch protection for a repo
@@ -960,7 +960,7 @@ func EditBranchProtection(ctx *context.APIContext) {
return
}
- ctx.JSON(http.StatusOK, convert.ToBranchProtection(bp))
+ ctx.JSON(http.StatusOK, convert.ToBranchProtection(ctx, bp))
}
// DeleteBranchProtection deletes a branch protection for a repo
diff --git a/routers/api/v1/repo/fork.go b/routers/api/v1/repo/fork.go
index 7ae4356204..ef152eef85 100644
--- a/routers/api/v1/repo/fork.go
+++ b/routers/api/v1/repo/fork.go
@@ -55,7 +55,7 @@ func ListForks(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
- forks, err := repo_model.GetForks(ctx.Repo.Repository, utils.GetListOptions(ctx))
+ forks, err := repo_model.GetForks(ctx, ctx.Repo.Repository, utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetForks", err)
return
diff --git a/routers/api/v1/repo/issue_subscription.go b/routers/api/v1/repo/issue_subscription.go
index 5a05471264..1fec029465 100644
--- a/routers/api/v1/repo/issue_subscription.go
+++ b/routers/api/v1/repo/issue_subscription.go
@@ -273,7 +273,7 @@ func GetIssueSubscribers(ctx *context.APIContext) {
userIDs = append(userIDs, iw.UserID)
}
- users, err := user_model.GetUsersByIDs(userIDs)
+ users, err := user_model.GetUsersByIDs(ctx, userIDs)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUsersByIDs", err)
return
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index 01ce754c74..0fe657d245 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -985,7 +985,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
}
// Check if current user has fork of repository or in the same repository.
- headRepo := repo_model.GetForkedRepo(headUser.ID, baseRepo.ID)
+ headRepo := repo_model.GetForkedRepo(ctx, headUser.ID, baseRepo.ID)
if headRepo == nil && !isSameRepo {
log.Trace("parseCompareInfo[%d]: does not have fork or in same repository", baseRepo.ID)
ctx.NotFound("GetForkedRepo")
diff --git a/routers/api/v1/user/email.go b/routers/api/v1/user/email.go
index fc74c8d148..68f6c974a5 100644
--- a/routers/api/v1/user/email.go
+++ b/routers/api/v1/user/email.go
@@ -27,7 +27,7 @@ func ListEmails(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/EmailList"
- emails, err := user_model.GetEmailAddresses(ctx.Doer.ID)
+ emails, err := user_model.GetEmailAddresses(ctx, ctx.Doer.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetEmailAddresses", err)
return
@@ -71,7 +71,7 @@ func AddEmail(ctx *context.APIContext) {
}
}
- if err := user_model.AddEmailAddresses(emails); err != nil {
+ if err := user_model.AddEmailAddresses(ctx, emails); err != nil {
if user_model.IsErrEmailAlreadyUsed(err) {
ctx.Error(http.StatusUnprocessableEntity, "", "Email address has been used: "+err.(user_model.ErrEmailAlreadyUsed).Email)
} else if user_model.IsErrEmailCharIsNotSupported(err) || user_model.IsErrEmailInvalid(err) {
@@ -129,7 +129,7 @@ func DeleteEmail(ctx *context.APIContext) {
}
}
- if err := user_model.DeleteEmailAddresses(emails); err != nil {
+ if err := user_model.DeleteEmailAddresses(ctx, emails); err != nil {
if user_model.IsErrEmailAddressNotExist(err) {
ctx.Error(http.StatusNotFound, "DeleteEmailAddresses", err)
return
diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go
index 2a2361be67..251e7a6013 100644
--- a/routers/api/v1/user/user.go
+++ b/routers/api/v1/user/user.go
@@ -54,7 +54,7 @@ func Search(ctx *context.APIContext) {
listOptions := utils.GetListOptions(ctx)
- users, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{
+ users, maxResults, err := user_model.SearchUsers(ctx, &user_model.SearchUserOptions{
Actor: ctx.Doer,
Keyword: ctx.FormTrim("q"),
UID: ctx.FormInt64("uid"),