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>
This commit is contained in:
Lunny Xiao 2022-12-03 10:48:26 +08:00 committed by GitHub
parent 8698458f48
commit 0a7d3ff786
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
145 changed files with 360 additions and 369 deletions

View file

@ -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
}

View file

@ -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)

View file

@ -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
}

View file

@ -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
}