diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-12-03 10:48:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-03 10:48:26 +0800 |
commit | 0a7d3ff786508284224ada17956a65bb759d9265 (patch) | |
tree | 4860fca95c1432ab59c6723ee2b053b1c7d6779d /routers/api/v1/user | |
parent | 8698458f48eafeab21014db544aa7160368856e1 (diff) | |
download | gitea-0a7d3ff786508284224ada17956a65bb759d9265.tar.gz gitea-0a7d3ff786508284224ada17956a65bb759d9265.zip |
refactor some functions to support ctx as first parameter (#21878)
Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'routers/api/v1/user')
-rw-r--r-- | routers/api/v1/user/key.go | 3 | ||||
-rw-r--r-- | routers/api/v1/user/repo.go | 4 | ||||
-rw-r--r-- | routers/api/v1/user/star.go | 2 | ||||
-rw-r--r-- | routers/api/v1/user/watch.go | 2 |
4 files changed, 6 insertions, 5 deletions
diff --git a/routers/api/v1/user/key.go b/routers/api/v1/user/key.go index d00eec85e4..25bda0444a 100644 --- a/routers/api/v1/user/key.go +++ b/routers/api/v1/user/key.go @@ -7,6 +7,7 @@ import ( "net/http" asymkey_model "code.gitea.io/gitea/models/asymkey" + "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/perm" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" @@ -29,7 +30,7 @@ func appendPrivateInformation(apiKey *api.PublicKey, key *asymkey_model.PublicKe if defaultUser.ID == key.OwnerID { apiKey.Owner = convert.ToUser(defaultUser, defaultUser) } else { - user, err := user_model.GetUserByID(key.OwnerID) + user, err := user_model.GetUserByID(db.DefaultContext, key.OwnerID) if err != nil { return apiKey, err } diff --git a/routers/api/v1/user/repo.go b/routers/api/v1/user/repo.go index 2af70f9ad3..e79a9d8f8b 100644 --- a/routers/api/v1/user/repo.go +++ b/routers/api/v1/user/repo.go @@ -44,7 +44,7 @@ func listUserRepos(ctx *context.APIContext, u *user_model.User, private bool) { return } if ctx.IsSigned && ctx.Doer.IsAdmin || access >= perm.AccessModeRead { - apiRepos = append(apiRepos, convert.ToRepo(repos[i], access)) + apiRepos = append(apiRepos, convert.ToRepo(ctx, repos[i], access)) } } @@ -127,7 +127,7 @@ func ListMyRepos(ctx *context.APIContext) { if err != nil { ctx.Error(http.StatusInternalServerError, "AccessLevel", err) } - results[i] = convert.ToRepo(repo, accessMode) + results[i] = convert.ToRepo(ctx, repo, accessMode) } ctx.SetLinkHeader(int(count), opts.ListOptions.PageSize) diff --git a/routers/api/v1/user/star.go b/routers/api/v1/user/star.go index 2ef5806974..0475489640 100644 --- a/routers/api/v1/user/star.go +++ b/routers/api/v1/user/star.go @@ -32,7 +32,7 @@ func getStarredRepos(ctx std_context.Context, user *user_model.User, private boo if err != nil { return nil, err } - repos[i] = convert.ToRepo(starred, access) + repos[i] = convert.ToRepo(ctx, starred, access) } return repos, nil } diff --git a/routers/api/v1/user/watch.go b/routers/api/v1/user/watch.go index 43c097444e..707e5da090 100644 --- a/routers/api/v1/user/watch.go +++ b/routers/api/v1/user/watch.go @@ -30,7 +30,7 @@ func getWatchedRepos(ctx std_context.Context, user *user_model.User, private boo if err != nil { return nil, 0, err } - repos[i] = convert.ToRepo(watched, access) + repos[i] = convert.ToRepo(ctx, watched, access) } return repos, total, nil } |