mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
@@ -31,7 +31,7 @@ func apiError(ctx *context.Context, status int, obj any) {
|
||||
}
|
||||
|
||||
func GetRepositoryKey(ctx *context.Context) {
|
||||
_, pub, err := alpine_service.GetOrCreateKeyPair(ctx.Package.Owner.ID)
|
||||
_, pub, err := alpine_service.GetOrCreateKeyPair(ctx, ctx.Package.Owner.ID)
|
||||
if err != nil {
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
return
|
||||
|
@@ -4,6 +4,7 @@
|
||||
package chef
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto"
|
||||
"crypto/rsa"
|
||||
"crypto/sha1"
|
||||
@@ -63,7 +64,7 @@ func (a *Auth) Verify(req *http.Request, w http.ResponseWriter, store auth.DataS
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
pub, err := getUserPublicKey(u)
|
||||
pub, err := getUserPublicKey(req.Context(), u)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -93,8 +94,8 @@ func getUserFromRequest(req *http.Request) (*user_model.User, error) {
|
||||
return user_model.GetUserByName(req.Context(), username)
|
||||
}
|
||||
|
||||
func getUserPublicKey(u *user_model.User) (crypto.PublicKey, error) {
|
||||
pubKey, err := user_model.GetSetting(u.ID, chef_module.SettingPublicPem)
|
||||
func getUserPublicKey(ctx context.Context, u *user_model.User) (crypto.PublicKey, error) {
|
||||
pubKey, err := user_model.GetSetting(ctx, u.ID, chef_module.SettingPublicPem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@ func apiError(ctx *context.Context, status int, obj any) {
|
||||
}
|
||||
|
||||
func GetRepositoryKey(ctx *context.Context) {
|
||||
_, pub, err := debian_service.GetOrCreateKeyPair(ctx.Package.Owner.ID)
|
||||
_, pub, err := debian_service.GetOrCreateKeyPair(ctx, ctx.Package.Owner.ID)
|
||||
if err != nil {
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
return
|
||||
|
@@ -23,7 +23,7 @@ func (a *Auth) Name() string {
|
||||
|
||||
// https://docs.microsoft.com/en-us/nuget/api/package-publish-resource#request-parameters
|
||||
func (a *Auth) Verify(req *http.Request, w http.ResponseWriter, store auth.DataStore, sess auth.SessionStore) (*user_model.User, error) {
|
||||
token, err := auth_model.GetAccessTokenBySHA(req.Header.Get("X-NuGet-ApiKey"))
|
||||
token, err := auth_model.GetAccessTokenBySHA(req.Context(), req.Header.Get("X-NuGet-ApiKey"))
|
||||
if err != nil {
|
||||
if !(auth_model.IsErrAccessTokenNotExist(err) || auth_model.IsErrAccessTokenEmpty(err)) {
|
||||
log.Error("GetAccessTokenBySHA: %v", err)
|
||||
@@ -39,7 +39,7 @@ func (a *Auth) Verify(req *http.Request, w http.ResponseWriter, store auth.DataS
|
||||
}
|
||||
|
||||
token.UpdatedUnix = timeutil.TimeStampNow()
|
||||
if err := auth_model.UpdateAccessToken(token); err != nil {
|
||||
if err := auth_model.UpdateAccessToken(req.Context(), token); err != nil {
|
||||
log.Error("UpdateAccessToken: %v", err)
|
||||
}
|
||||
|
||||
|
@@ -45,7 +45,7 @@ gpgkey=`+url+`/repository.key`)
|
||||
|
||||
// Gets or creates the PGP public key used to sign repository metadata files
|
||||
func GetRepositoryKey(ctx *context.Context) {
|
||||
_, pub, err := rpm_service.GetOrCreateKeyPair(ctx.Package.Owner.ID)
|
||||
_, pub, err := rpm_service.GetOrCreateKeyPair(ctx, ctx.Package.Owner.ID)
|
||||
if err != nil {
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
return
|
||||
|
@@ -66,7 +66,7 @@ func Person(ctx *context.APIContext) {
|
||||
person.PublicKey.ID = ap.IRI(link + "#main-key")
|
||||
person.PublicKey.Owner = ap.IRI(link)
|
||||
|
||||
publicKeyPem, err := activitypub.GetPublicKey(ctx.ContextUser)
|
||||
publicKeyPem, err := activitypub.GetPublicKey(ctx, ctx.ContextUser)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetPublicKey", err)
|
||||
return
|
||||
|
@@ -776,7 +776,7 @@ func verifyAuthWithOptions(options *common.VerifyOptions) func(ctx *context.APIC
|
||||
if skip, ok := ctx.Data["SkipLocalTwoFA"]; ok && skip.(bool) {
|
||||
return // Skip 2FA
|
||||
}
|
||||
twofa, err := auth_model.GetTwoFactorByUID(ctx.Doer.ID)
|
||||
twofa, err := auth_model.GetTwoFactorByUID(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
if auth_model.IsErrTwoFactorNotEnrolled(err) {
|
||||
return // No 2FA enrollment for this user
|
||||
|
@@ -693,7 +693,7 @@ func AddTeamRepository(ctx *context.APIContext) {
|
||||
ctx.Error(http.StatusForbidden, "", "Must have admin-level access to the repository")
|
||||
return
|
||||
}
|
||||
if err := org_service.TeamAddRepository(ctx.Org.Team, repo); err != nil {
|
||||
if err := org_service.TeamAddRepository(ctx, ctx.Org.Team, repo); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "TeamAddRepository", err)
|
||||
return
|
||||
}
|
||||
|
@@ -189,7 +189,7 @@ func CreateIssueAttachment(ctx *context.APIContext) {
|
||||
|
||||
issue.Attachments = append(issue.Attachments, attachment)
|
||||
|
||||
if err := issue_service.ChangeContent(issue, ctx.Doer, issue.Content); err != nil {
|
||||
if err := issue_service.ChangeContent(ctx, issue, ctx.Doer, issue.Content); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "ChangeContent", err)
|
||||
return
|
||||
}
|
||||
@@ -298,7 +298,7 @@ func DeleteIssueAttachment(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := repo_model.DeleteAttachment(attachment, true); err != nil {
|
||||
if err := repo_model.DeleteAttachment(ctx, attachment, true); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "DeleteAttachment", err)
|
||||
return
|
||||
}
|
||||
|
@@ -303,7 +303,7 @@ func DeleteIssueCommentAttachment(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := repo_model.DeleteAttachment(attach, true); err != nil {
|
||||
if err := repo_model.DeleteAttachment(ctx, attach, true); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "DeleteAttachment", err)
|
||||
return
|
||||
}
|
||||
|
@@ -97,7 +97,7 @@ func ListPullRequests(ctx *context.APIContext) {
|
||||
|
||||
listOptions := utils.GetListOptions(ctx)
|
||||
|
||||
prs, maxResults, err := issues_model.PullRequests(ctx.Repo.Repository.ID, &issues_model.PullRequestsOptions{
|
||||
prs, maxResults, err := issues_model.PullRequests(ctx, ctx.Repo.Repository.ID, &issues_model.PullRequestsOptions{
|
||||
ListOptions: listOptions,
|
||||
State: ctx.FormTrim("state"),
|
||||
SortType: ctx.FormTrim("sort"),
|
||||
|
@@ -345,7 +345,7 @@ func DeleteReleaseAttachment(ctx *context.APIContext) {
|
||||
}
|
||||
// FIXME Should prove the existence of the given repo, but results in unnecessary database requests
|
||||
|
||||
if err := repo_model.DeleteAttachment(attach, true); err != nil {
|
||||
if err := repo_model.DeleteAttachment(ctx, attach, true); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "DeleteAttachment", err)
|
||||
return
|
||||
}
|
||||
|
@@ -45,7 +45,7 @@ func ListStargazers(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
stargazers, err := repo_model.GetStargazers(ctx.Repo.Repository, utils.GetListOptions(ctx))
|
||||
stargazers, err := repo_model.GetStargazers(ctx, ctx.Repo.Repository, utils.GetListOptions(ctx))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetStargazers", err)
|
||||
return
|
||||
|
@@ -45,7 +45,7 @@ func ListSubscribers(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
subscribers, err := repo_model.GetRepoWatchers(ctx.Repo.Repository.ID, utils.GetListOptions(ctx))
|
||||
subscribers, err := repo_model.GetRepoWatchers(ctx, ctx.Repo.Repository.ID, utils.GetListOptions(ctx))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetRepoWatchers", err)
|
||||
return
|
||||
|
@@ -99,7 +99,7 @@ func IsTeam(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if repo_service.HasRepository(team, ctx.Repo.Repository.ID) {
|
||||
if repo_service.HasRepository(ctx, team, ctx.Repo.Repository.ID) {
|
||||
apiTeam, err := convert.ToTeam(ctx, team)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
@@ -198,14 +198,14 @@ func changeRepoTeam(ctx *context.APIContext, add bool) {
|
||||
return
|
||||
}
|
||||
|
||||
repoHasTeam := repo_service.HasRepository(team, ctx.Repo.Repository.ID)
|
||||
repoHasTeam := repo_service.HasRepository(ctx, team, ctx.Repo.Repository.ID)
|
||||
var err error
|
||||
if add {
|
||||
if repoHasTeam {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "alreadyAdded", fmt.Errorf("team '%s' is already added to repo", team.Name))
|
||||
return
|
||||
}
|
||||
err = org_service.TeamAddRepository(team, ctx.Repo.Repository)
|
||||
err = org_service.TeamAddRepository(ctx, team, ctx.Repo.Repository)
|
||||
} else {
|
||||
if !repoHasTeam {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "notAdded", fmt.Errorf("team '%s' was not added to repo", team.Name))
|
||||
|
@@ -46,12 +46,12 @@ func ListAccessTokens(ctx *context.APIContext) {
|
||||
|
||||
opts := auth_model.ListAccessTokensOptions{UserID: ctx.Doer.ID, ListOptions: utils.GetListOptions(ctx)}
|
||||
|
||||
count, err := auth_model.CountAccessTokens(opts)
|
||||
count, err := auth_model.CountAccessTokens(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
tokens, err := auth_model.ListAccessTokens(opts)
|
||||
tokens, err := auth_model.ListAccessTokens(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
@@ -103,7 +103,7 @@ func CreateAccessToken(ctx *context.APIContext) {
|
||||
Name: form.Name,
|
||||
}
|
||||
|
||||
exist, err := auth_model.AccessTokenByNameExists(t)
|
||||
exist, err := auth_model.AccessTokenByNameExists(ctx, t)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
@@ -120,7 +120,7 @@ func CreateAccessToken(ctx *context.APIContext) {
|
||||
}
|
||||
t.Scope = scope
|
||||
|
||||
if err := auth_model.NewAccessToken(t); err != nil {
|
||||
if err := auth_model.NewAccessToken(ctx, t); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "NewAccessToken", err)
|
||||
return
|
||||
}
|
||||
@@ -162,7 +162,7 @@ func DeleteAccessToken(ctx *context.APIContext) {
|
||||
tokenID, _ := strconv.ParseInt(token, 0, 64)
|
||||
|
||||
if tokenID == 0 {
|
||||
tokens, err := auth_model.ListAccessTokens(auth_model.ListAccessTokensOptions{
|
||||
tokens, err := auth_model.ListAccessTokens(ctx, auth_model.ListAccessTokensOptions{
|
||||
Name: token,
|
||||
UserID: ctx.Doer.ID,
|
||||
})
|
||||
@@ -187,7 +187,7 @@ func DeleteAccessToken(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := auth_model.DeleteAccessTokenByID(tokenID, ctx.Doer.ID); err != nil {
|
||||
if err := auth_model.DeleteAccessTokenByID(ctx, tokenID, ctx.Doer.ID); err != nil {
|
||||
if auth_model.IsErrAccessTokenNotExist(err) {
|
||||
ctx.NotFound()
|
||||
} else {
|
||||
|
@@ -155,7 +155,7 @@ func Star(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
err := repo_model.StarRepo(ctx.Doer.ID, ctx.Repo.Repository.ID, true)
|
||||
err := repo_model.StarRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, true)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
|
||||
return
|
||||
@@ -185,7 +185,7 @@ func Unstar(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
err := repo_model.StarRepo(ctx.Doer.ID, ctx.Repo.Repository.ID, false)
|
||||
err := repo_model.StarRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, false)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
|
||||
return
|
||||
|
@@ -124,7 +124,7 @@ func IsWatching(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// description: User is not watching this repo or repo do not exist
|
||||
|
||||
if repo_model.IsWatching(ctx.Doer.ID, ctx.Repo.Repository.ID) {
|
||||
if repo_model.IsWatching(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID) {
|
||||
ctx.JSON(http.StatusOK, api.WatchInfo{
|
||||
Subscribed: true,
|
||||
Ignored: false,
|
||||
|
@@ -238,7 +238,7 @@ func prepareUserInfo(ctx *context.Context) *user_model.User {
|
||||
}
|
||||
ctx.Data["Sources"] = sources
|
||||
|
||||
hasTOTP, err := auth.HasTwoFactorByUID(u.ID)
|
||||
hasTOTP, err := auth.HasTwoFactorByUID(ctx, u.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("auth.HasTwoFactorByUID", err)
|
||||
return nil
|
||||
@@ -410,12 +410,12 @@ func EditUserPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if form.Reset2FA {
|
||||
tf, err := auth.GetTwoFactorByUID(u.ID)
|
||||
tf, err := auth.GetTwoFactorByUID(ctx, u.ID)
|
||||
if err != nil && !auth.IsErrTwoFactorNotEnrolled(err) {
|
||||
ctx.ServerError("auth.GetTwoFactorByUID", err)
|
||||
return
|
||||
} else if tf != nil {
|
||||
if err := auth.DeleteTwoFactorByID(tf.ID, u.ID); err != nil {
|
||||
if err := auth.DeleteTwoFactorByID(ctx, tf.ID, u.ID); err != nil {
|
||||
ctx.ServerError("auth.DeleteTwoFactorByID", err)
|
||||
return
|
||||
}
|
||||
|
@@ -53,7 +53,7 @@ func TwoFactorPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
id := idSess.(int64)
|
||||
twofa, err := auth.GetTwoFactorByUID(id)
|
||||
twofa, err := auth.GetTwoFactorByUID(ctx, id)
|
||||
if err != nil {
|
||||
ctx.ServerError("UserSignIn", err)
|
||||
return
|
||||
@@ -83,7 +83,7 @@ func TwoFactorPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
twofa.LastUsedPasscode = form.Passcode
|
||||
if err = auth.UpdateTwoFactor(twofa); err != nil {
|
||||
if err = auth.UpdateTwoFactor(ctx, twofa); err != nil {
|
||||
ctx.ServerError("UserSignIn", err)
|
||||
return
|
||||
}
|
||||
@@ -126,7 +126,7 @@ func TwoFactorScratchPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
id := idSess.(int64)
|
||||
twofa, err := auth.GetTwoFactorByUID(id)
|
||||
twofa, err := auth.GetTwoFactorByUID(ctx, id)
|
||||
if err != nil {
|
||||
ctx.ServerError("UserSignIn", err)
|
||||
return
|
||||
@@ -140,7 +140,7 @@ func TwoFactorScratchPost(ctx *context.Context) {
|
||||
ctx.ServerError("UserSignIn", err)
|
||||
return
|
||||
}
|
||||
if err = auth.UpdateTwoFactor(twofa); err != nil {
|
||||
if err = auth.UpdateTwoFactor(ctx, twofa); err != nil {
|
||||
ctx.ServerError("UserSignIn", err)
|
||||
return
|
||||
}
|
||||
|
@@ -236,7 +236,7 @@ func SignInPost(ctx *context.Context) {
|
||||
|
||||
// If this user is enrolled in 2FA TOTP, we can't sign the user in just yet.
|
||||
// Instead, redirect them to the 2FA authentication page.
|
||||
hasTOTPtwofa, err := auth.HasTwoFactorByUID(u.ID)
|
||||
hasTOTPtwofa, err := auth.HasTwoFactorByUID(ctx, u.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("UserSignIn", err)
|
||||
return
|
||||
|
@@ -157,7 +157,7 @@ func linkAccount(ctx *context.Context, u *user_model.User, gothUser goth.User, r
|
||||
// If this user is enrolled in 2FA, we can't sign the user in just yet.
|
||||
// Instead, redirect them to the 2FA authentication page.
|
||||
// We deliberately ignore the skip local 2fa setting here because we are linking to a previous user here
|
||||
_, err := auth.GetTwoFactorByUID(u.ID)
|
||||
_, err := auth.GetTwoFactorByUID(ctx, u.ID)
|
||||
if err != nil {
|
||||
if !auth.IsErrTwoFactorNotEnrolled(err) {
|
||||
ctx.ServerError("UserLinkAccount", err)
|
||||
|
@@ -1097,7 +1097,7 @@ func handleOAuth2SignIn(ctx *context.Context, source *auth.Source, u *user_model
|
||||
|
||||
needs2FA := false
|
||||
if !source.Cfg.(*oauth2.Source).SkipLocalTwoFA {
|
||||
_, err := auth.GetTwoFactorByUID(u.ID)
|
||||
_, err := auth.GetTwoFactorByUID(ctx, u.ID)
|
||||
if err != nil && !auth.IsErrTwoFactorNotEnrolled(err) {
|
||||
ctx.ServerError("UserSignIn", err)
|
||||
return
|
||||
|
@@ -120,7 +120,7 @@ func commonResetPassword(ctx *context.Context) (*user_model.User, *auth.TwoFacto
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
twofa, err := auth.GetTwoFactorByUID(u.ID)
|
||||
twofa, err := auth.GetTwoFactorByUID(ctx, u.ID)
|
||||
if err != nil {
|
||||
if !auth.IsErrTwoFactorNotEnrolled(err) {
|
||||
ctx.Error(http.StatusInternalServerError, "CommonResetPassword", err.Error())
|
||||
@@ -217,7 +217,7 @@ func ResetPasswdPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
twofa.LastUsedPasscode = passcode
|
||||
if err = auth.UpdateTwoFactor(twofa); err != nil {
|
||||
if err = auth.UpdateTwoFactor(ctx, twofa); err != nil {
|
||||
ctx.ServerError("ResetPasswdPost: UpdateTwoFactor", err)
|
||||
return
|
||||
}
|
||||
@@ -249,7 +249,7 @@ func ResetPasswdPost(ctx *context.Context) {
|
||||
ctx.ServerError("UserSignIn", err)
|
||||
return
|
||||
}
|
||||
if err = auth.UpdateTwoFactor(twofa); err != nil {
|
||||
if err = auth.UpdateTwoFactor(ctx, twofa); err != nil {
|
||||
ctx.ServerError("UserSignIn", err)
|
||||
return
|
||||
}
|
||||
|
@@ -247,7 +247,7 @@ func TeamsRepoAction(ctx *context.Context) {
|
||||
ctx.ServerError("GetRepositoryByName", err)
|
||||
return
|
||||
}
|
||||
err = org_service.TeamAddRepository(ctx.Org.Team, repo)
|
||||
err = org_service.TeamAddRepository(ctx, ctx.Org.Team, repo)
|
||||
case "remove":
|
||||
err = repo_service.RemoveRepositoryFromTeam(ctx, ctx.Org.Team, ctx.FormInt64("repoid"))
|
||||
case "addall":
|
||||
|
@@ -77,7 +77,7 @@ func DeleteAttachment(ctx *context.Context) {
|
||||
ctx.Error(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
err = repo_model.DeleteAttachment(attach, true)
|
||||
err = repo_model.DeleteAttachment(ctx, attach, true)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, fmt.Sprintf("DeleteAttachment: %v", err))
|
||||
return
|
||||
@@ -122,7 +122,7 @@ func ServeAttachment(ctx *context.Context, uuid string) {
|
||||
}
|
||||
}
|
||||
|
||||
if err := attach.IncreaseDownloadCount(); err != nil {
|
||||
if err := attach.IncreaseDownloadCount(ctx); err != nil {
|
||||
ctx.ServerError("IncreaseDownloadCount", err)
|
||||
return
|
||||
}
|
||||
|
@@ -812,7 +812,7 @@ func UploadFileToServer(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
upload, err := repo_model.NewUpload(name, buf, file)
|
||||
upload, err := repo_model.NewUpload(ctx, name, buf, file)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, fmt.Sprintf("NewUpload: %v", err))
|
||||
return
|
||||
@@ -832,7 +832,7 @@ func RemoveUploadFileFromServer(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := repo_model.DeleteUploadByUUID(form.File); err != nil {
|
||||
if err := repo_model.DeleteUploadByUUID(ctx, form.File); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, fmt.Sprintf("DeleteUploadByUUID: %v", err))
|
||||
return
|
||||
}
|
||||
|
@@ -158,7 +158,7 @@ func httpBase(ctx *context.Context) *serviceHandler {
|
||||
}
|
||||
|
||||
if ctx.IsBasicAuth && ctx.Data["IsApiToken"] != true && ctx.Data["IsActionsToken"] != true {
|
||||
_, err = auth_model.GetTwoFactorByUID(ctx.Doer.ID)
|
||||
_, err = auth_model.GetTwoFactorByUID(ctx, ctx.Doer.ID)
|
||||
if err == nil {
|
||||
// TODO: This response should be changed to "invalid credentials" for security reasons once the expectation behind it (creating an app token to authenticate) is properly documented
|
||||
ctx.PlainText(http.StatusUnauthorized, "Users with two-factor authentication enabled cannot perform HTTP/HTTPS operations via plain username and password. Please create and use a personal access token on the user settings page")
|
||||
|
@@ -1975,7 +1975,7 @@ func ViewIssue(ctx *context.Context) {
|
||||
|
||||
var hiddenCommentTypes *big.Int
|
||||
if ctx.IsSigned {
|
||||
val, err := user_model.GetUserSetting(ctx.Doer.ID, user_model.SettingsKeyHiddenCommentTypes)
|
||||
val, err := user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyHiddenCommentTypes)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserSetting", err)
|
||||
return
|
||||
@@ -2205,7 +2205,7 @@ func UpdateIssueContent(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := issue_service.ChangeContent(issue, ctx.Doer, ctx.Req.FormValue("content")); err != nil {
|
||||
if err := issue_service.ChangeContent(ctx, issue, ctx.Doer, ctx.Req.FormValue("content")); err != nil {
|
||||
ctx.ServerError("ChangeContent", err)
|
||||
return
|
||||
}
|
||||
@@ -3451,7 +3451,7 @@ func updateAttachments(ctx *context.Context, item any, files []string) error {
|
||||
if util.SliceContainsString(files, attachments[i].UUID) {
|
||||
continue
|
||||
}
|
||||
if err := repo_model.DeleteAttachment(attachments[i], true); err != nil {
|
||||
if err := repo_model.DeleteAttachment(ctx, attachments[i], true); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@@ -72,12 +72,12 @@ func SetWhitespaceBehavior(ctx *context.Context) {
|
||||
whitespaceBehavior = defaultWhitespaceBehavior
|
||||
}
|
||||
if ctx.IsSigned {
|
||||
userWhitespaceBehavior, err := user_model.GetUserSetting(ctx.Doer.ID, user_model.SettingsKeyDiffWhitespaceBehavior, defaultWhitespaceBehavior)
|
||||
userWhitespaceBehavior, err := user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyDiffWhitespaceBehavior, defaultWhitespaceBehavior)
|
||||
if err == nil {
|
||||
if whitespaceBehavior == "" {
|
||||
whitespaceBehavior = userWhitespaceBehavior
|
||||
} else if whitespaceBehavior != userWhitespaceBehavior {
|
||||
_ = user_model.SetUserSetting(ctx.Doer.ID, user_model.SettingsKeyDiffWhitespaceBehavior, whitespaceBehavior)
|
||||
_ = user_model.SetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyDiffWhitespaceBehavior, whitespaceBehavior)
|
||||
}
|
||||
} // else: we can ignore the error safely
|
||||
}
|
||||
@@ -98,7 +98,7 @@ func SetShowOutdatedComments(ctx *context.Context) {
|
||||
if showOutdatedCommentsValue != "true" && showOutdatedCommentsValue != "false" {
|
||||
// invalid or no value for this form string -> use default or stored user setting
|
||||
if ctx.IsSigned {
|
||||
showOutdatedCommentsValue, _ = user_model.GetUserSetting(ctx.Doer.ID, user_model.SettingsKeyShowOutdatedComments, "false")
|
||||
showOutdatedCommentsValue, _ = user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyShowOutdatedComments, "false")
|
||||
} else {
|
||||
// not logged in user -> use the default value
|
||||
showOutdatedCommentsValue = "false"
|
||||
@@ -106,7 +106,7 @@ func SetShowOutdatedComments(ctx *context.Context) {
|
||||
} else {
|
||||
// valid value -> update user setting if user is logged in
|
||||
if ctx.IsSigned {
|
||||
_ = user_model.SetUserSetting(ctx.Doer.ID, user_model.SettingsKeyShowOutdatedComments, showOutdatedCommentsValue)
|
||||
_ = user_model.SetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyShowOutdatedComments, showOutdatedCommentsValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -308,9 +308,9 @@ func Action(ctx *context.Context) {
|
||||
case "unwatch":
|
||||
err = repo_model.WatchRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, false)
|
||||
case "star":
|
||||
err = repo_model.StarRepo(ctx.Doer.ID, ctx.Repo.Repository.ID, true)
|
||||
err = repo_model.StarRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, true)
|
||||
case "unstar":
|
||||
err = repo_model.StarRepo(ctx.Doer.ID, ctx.Repo.Repository.ID, false)
|
||||
err = repo_model.StarRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, false)
|
||||
case "accept_transfer":
|
||||
err = acceptOrRejectRepoTransfer(ctx, true)
|
||||
case "reject_transfer":
|
||||
|
@@ -173,7 +173,7 @@ func AddTeamPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = org_service.TeamAddRepository(team, ctx.Repo.Repository); err != nil {
|
||||
if err = org_service.TeamAddRepository(ctx, team, ctx.Repo.Repository); err != nil {
|
||||
ctx.ServerError("TeamAddRepository", err)
|
||||
return
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/organization"
|
||||
"code.gitea.io/gitea/models/perm"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
@@ -248,7 +249,7 @@ func TestAddTeamPost(t *testing.T) {
|
||||
|
||||
AddTeamPost(ctx)
|
||||
|
||||
assert.True(t, repo_service.HasRepository(team, re.ID))
|
||||
assert.True(t, repo_service.HasRepository(db.DefaultContext, team, re.ID))
|
||||
assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
|
||||
assert.Empty(t, ctx.Flash.ErrorMsg)
|
||||
}
|
||||
@@ -288,7 +289,7 @@ func TestAddTeamPost_NotAllowed(t *testing.T) {
|
||||
|
||||
AddTeamPost(ctx)
|
||||
|
||||
assert.False(t, repo_service.HasRepository(team, re.ID))
|
||||
assert.False(t, repo_service.HasRepository(db.DefaultContext, team, re.ID))
|
||||
assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
|
||||
assert.NotEmpty(t, ctx.Flash.ErrorMsg)
|
||||
}
|
||||
@@ -329,7 +330,7 @@ func TestAddTeamPost_AddTeamTwice(t *testing.T) {
|
||||
AddTeamPost(ctx)
|
||||
|
||||
AddTeamPost(ctx)
|
||||
assert.True(t, repo_service.HasRepository(team, re.ID))
|
||||
assert.True(t, repo_service.HasRepository(db.DefaultContext, team, re.ID))
|
||||
assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
|
||||
assert.NotEmpty(t, ctx.Flash.ErrorMsg)
|
||||
}
|
||||
@@ -402,5 +403,5 @@ func TestDeleteTeam(t *testing.T) {
|
||||
|
||||
DeleteTeam(ctx)
|
||||
|
||||
assert.False(t, repo_service.HasRepository(team, re.ID))
|
||||
assert.False(t, repo_service.HasRepository(db.DefaultContext, team, re.ID))
|
||||
}
|
||||
|
@@ -1065,7 +1065,7 @@ func Watchers(ctx *context.Context) {
|
||||
ctx.Data["PageIsWatchers"] = true
|
||||
|
||||
RenderUserCards(ctx, ctx.Repo.Repository.NumWatches, func(opts db.ListOptions) ([]*user_model.User, error) {
|
||||
return repo_model.GetRepoWatchers(ctx.Repo.Repository.ID, opts)
|
||||
return repo_model.GetRepoWatchers(ctx, ctx.Repo.Repository.ID, opts)
|
||||
}, tplWatchers)
|
||||
}
|
||||
|
||||
@@ -1075,7 +1075,7 @@ func Stars(ctx *context.Context) {
|
||||
ctx.Data["CardsTitle"] = ctx.Tr("repo.stargazers")
|
||||
ctx.Data["PageIsStargazers"] = true
|
||||
RenderUserCards(ctx, ctx.Repo.Repository.NumStars, func(opts db.ListOptions) ([]*user_model.User, error) {
|
||||
return repo_model.GetStargazers(ctx.Repo.Repository, opts)
|
||||
return repo_model.GetStargazers(ctx, ctx.Repo.Repository, opts)
|
||||
}, tplWatchers)
|
||||
}
|
||||
|
||||
|
@@ -34,7 +34,7 @@ func PrepareContextForProfileBigAvatar(ctx *context.Context) {
|
||||
ctx.Data["ShowUserEmail"] = setting.UI.ShowUserEmail && ctx.ContextUser.Email != "" && ctx.IsSigned && !ctx.ContextUser.KeepEmailPrivate
|
||||
|
||||
// Show OpenID URIs
|
||||
openIDs, err := user_model.GetUserOpenIDs(ctx.ContextUser.ID)
|
||||
openIDs, err := user_model.GetUserOpenIDs(ctx, ctx.ContextUser.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserOpenIDs", err)
|
||||
return
|
||||
|
@@ -53,7 +53,7 @@ func ApplicationsPost(ctx *context.Context) {
|
||||
Scope: scope,
|
||||
}
|
||||
|
||||
exist, err := auth_model.AccessTokenByNameExists(t)
|
||||
exist, err := auth_model.AccessTokenByNameExists(ctx, t)
|
||||
if err != nil {
|
||||
ctx.ServerError("AccessTokenByNameExists", err)
|
||||
return
|
||||
@@ -64,7 +64,7 @@ func ApplicationsPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := auth_model.NewAccessToken(t); err != nil {
|
||||
if err := auth_model.NewAccessToken(ctx, t); err != nil {
|
||||
ctx.ServerError("NewAccessToken", err)
|
||||
return
|
||||
}
|
||||
@@ -77,7 +77,7 @@ func ApplicationsPost(ctx *context.Context) {
|
||||
|
||||
// DeleteApplication response for delete user access token
|
||||
func DeleteApplication(ctx *context.Context) {
|
||||
if err := auth_model.DeleteAccessTokenByID(ctx.FormInt64("id"), ctx.Doer.ID); err != nil {
|
||||
if err := auth_model.DeleteAccessTokenByID(ctx, ctx.FormInt64("id"), ctx.Doer.ID); err != nil {
|
||||
ctx.Flash.Error("DeleteAccessTokenByID: " + err.Error())
|
||||
} else {
|
||||
ctx.Flash.Success(ctx.Tr("settings.delete_token_success"))
|
||||
@@ -88,7 +88,7 @@ func DeleteApplication(ctx *context.Context) {
|
||||
|
||||
func loadApplicationsData(ctx *context.Context) {
|
||||
ctx.Data["AccessTokenScopePublicOnly"] = auth_model.AccessTokenScopePublicOnly
|
||||
tokens, err := auth_model.ListAccessTokens(auth_model.ListAccessTokensOptions{UserID: ctx.Doer.ID})
|
||||
tokens, err := auth_model.ListAccessTokens(ctx, auth_model.ListAccessTokensOptions{UserID: ctx.Doer.ID})
|
||||
if err != nil {
|
||||
ctx.ServerError("ListAccessTokens", err)
|
||||
return
|
||||
|
@@ -107,7 +107,7 @@ func RegenerateChefKeyPair(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := user_model.SetUserSetting(ctx.Doer.ID, chef_module.SettingPublicPem, pub); err != nil {
|
||||
if err := user_model.SetUserSetting(ctx, ctx.Doer.ID, chef_module.SettingPublicPem, pub); err != nil {
|
||||
ctx.ServerError("SetUserSetting", err)
|
||||
return
|
||||
}
|
||||
|
@@ -348,7 +348,7 @@ func Appearance(ctx *context.Context) {
|
||||
ctx.Data["PageIsSettingsAppearance"] = true
|
||||
|
||||
var hiddenCommentTypes *big.Int
|
||||
val, err := user_model.GetUserSetting(ctx.Doer.ID, user_model.SettingsKeyHiddenCommentTypes)
|
||||
val, err := user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyHiddenCommentTypes)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserSetting", err)
|
||||
return
|
||||
@@ -420,7 +420,7 @@ func UpdateUserLang(ctx *context.Context) {
|
||||
|
||||
// UpdateUserHiddenComments update a user's shown comment types
|
||||
func UpdateUserHiddenComments(ctx *context.Context) {
|
||||
err := user_model.SetUserSetting(ctx.Doer.ID, user_model.SettingsKeyHiddenCommentTypes, forms.UserHiddenCommentTypesFromRequest(ctx).String())
|
||||
err := user_model.SetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyHiddenCommentTypes, forms.UserHiddenCommentTypesFromRequest(ctx).String())
|
||||
if err != nil {
|
||||
ctx.ServerError("SetUserSetting", err)
|
||||
return
|
||||
|
@@ -28,7 +28,7 @@ func RegenerateScratchTwoFactor(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsSecurity"] = true
|
||||
|
||||
t, err := auth.GetTwoFactorByUID(ctx.Doer.ID)
|
||||
t, err := auth.GetTwoFactorByUID(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
if auth.IsErrTwoFactorNotEnrolled(err) {
|
||||
ctx.Flash.Error(ctx.Tr("settings.twofa_not_enrolled"))
|
||||
@@ -44,7 +44,7 @@ func RegenerateScratchTwoFactor(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = auth.UpdateTwoFactor(t); err != nil {
|
||||
if err = auth.UpdateTwoFactor(ctx, t); err != nil {
|
||||
ctx.ServerError("SettingsTwoFactor: Failed to UpdateTwoFactor", err)
|
||||
return
|
||||
}
|
||||
@@ -58,7 +58,7 @@ func DisableTwoFactor(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsSecurity"] = true
|
||||
|
||||
t, err := auth.GetTwoFactorByUID(ctx.Doer.ID)
|
||||
t, err := auth.GetTwoFactorByUID(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
if auth.IsErrTwoFactorNotEnrolled(err) {
|
||||
ctx.Flash.Error(ctx.Tr("settings.twofa_not_enrolled"))
|
||||
@@ -68,7 +68,7 @@ func DisableTwoFactor(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = auth.DeleteTwoFactorByID(t.ID, ctx.Doer.ID); err != nil {
|
||||
if err = auth.DeleteTwoFactorByID(ctx, t.ID, ctx.Doer.ID); err != nil {
|
||||
if auth.IsErrTwoFactorNotEnrolled(err) {
|
||||
// There is a potential DB race here - we must have been disabled by another request in the intervening period
|
||||
ctx.Flash.Success(ctx.Tr("settings.twofa_disabled"))
|
||||
@@ -145,7 +145,7 @@ func EnrollTwoFactor(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsSecurity"] = true
|
||||
|
||||
t, err := auth.GetTwoFactorByUID(ctx.Doer.ID)
|
||||
t, err := auth.GetTwoFactorByUID(ctx, ctx.Doer.ID)
|
||||
if t != nil {
|
||||
// already enrolled - we should redirect back!
|
||||
log.Warn("Trying to re-enroll %-v in twofa when already enrolled", ctx.Doer)
|
||||
@@ -171,7 +171,7 @@ func EnrollTwoFactorPost(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsSecurity"] = true
|
||||
|
||||
t, err := auth.GetTwoFactorByUID(ctx.Doer.ID)
|
||||
t, err := auth.GetTwoFactorByUID(ctx, ctx.Doer.ID)
|
||||
if t != nil {
|
||||
// already enrolled
|
||||
ctx.Flash.Error(ctx.Tr("settings.twofa_is_enrolled"))
|
||||
@@ -237,7 +237,7 @@ func EnrollTwoFactorPost(ctx *context.Context) {
|
||||
log.Error("Unable to save changes to the session: %v", err)
|
||||
}
|
||||
|
||||
if err = auth.NewTwoFactor(t); err != nil {
|
||||
if err = auth.NewTwoFactor(ctx, t); err != nil {
|
||||
// FIXME: We need to handle a unique constraint fail here it's entirely possible that another request has beaten us.
|
||||
// If there is a unique constraint fail we should just tolerate the error
|
||||
ctx.ServerError("SettingsTwoFactor: Failed to save two factor", err)
|
||||
|
@@ -44,7 +44,7 @@ func OpenIDPost(ctx *context.Context) {
|
||||
form.Openid = id
|
||||
log.Trace("Normalized id: " + id)
|
||||
|
||||
oids, err := user_model.GetUserOpenIDs(ctx.Doer.ID)
|
||||
oids, err := user_model.GetUserOpenIDs(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserOpenIDs", err)
|
||||
return
|
||||
@@ -105,7 +105,7 @@ func settingsOpenIDVerify(ctx *context.Context) {
|
||||
|
||||
// DeleteOpenID response for delete user's openid
|
||||
func DeleteOpenID(ctx *context.Context) {
|
||||
if err := user_model.DeleteUserOpenID(&user_model.UserOpenID{ID: ctx.FormInt64("id"), UID: ctx.Doer.ID}); err != nil {
|
||||
if err := user_model.DeleteUserOpenID(ctx, &user_model.UserOpenID{ID: ctx.FormInt64("id"), UID: ctx.Doer.ID}); err != nil {
|
||||
ctx.ServerError("DeleteUserOpenID", err)
|
||||
return
|
||||
}
|
||||
@@ -117,7 +117,7 @@ func DeleteOpenID(ctx *context.Context) {
|
||||
|
||||
// ToggleOpenIDVisibility response for toggle visibility of user's openid
|
||||
func ToggleOpenIDVisibility(ctx *context.Context) {
|
||||
if err := user_model.ToggleUserOpenIDVisibility(ctx.FormInt64("id")); err != nil {
|
||||
if err := user_model.ToggleUserOpenIDVisibility(ctx, ctx.FormInt64("id")); err != nil {
|
||||
ctx.ServerError("ToggleUserOpenIDVisibility", err)
|
||||
return
|
||||
}
|
||||
|
@@ -52,7 +52,7 @@ func DeleteAccountLink(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func loadSecurityData(ctx *context.Context) {
|
||||
enrolled, err := auth_model.HasTwoFactorByUID(ctx.Doer.ID)
|
||||
enrolled, err := auth_model.HasTwoFactorByUID(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("SettingsTwoFactor", err)
|
||||
return
|
||||
@@ -66,7 +66,7 @@ func loadSecurityData(ctx *context.Context) {
|
||||
}
|
||||
ctx.Data["WebAuthnCredentials"] = credentials
|
||||
|
||||
tokens, err := auth_model.ListAccessTokens(auth_model.ListAccessTokensOptions{UserID: ctx.Doer.ID})
|
||||
tokens, err := auth_model.ListAccessTokens(ctx, auth_model.ListAccessTokensOptions{UserID: ctx.Doer.ID})
|
||||
if err != nil {
|
||||
ctx.ServerError("ListAccessTokens", err)
|
||||
return
|
||||
@@ -113,7 +113,7 @@ func loadSecurityData(ctx *context.Context) {
|
||||
ctx.Data["OrderedOAuth2Names"] = orderedOAuth2Names
|
||||
ctx.Data["OAuth2Providers"] = oauth2Providers
|
||||
|
||||
openid, err := user_model.GetUserOpenIDs(ctx.Doer.ID)
|
||||
openid, err := user_model.GetUserOpenIDs(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserOpenIDs", err)
|
||||
return
|
||||
|
Reference in New Issue
Block a user