Next round of db.DefaultContext refactor (#27089)

Part of #27065
This commit is contained in:
JakobDev 2023-09-16 16:39:12 +02:00 committed by GitHub
parent a1b2a11812
commit f91dbbba98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
90 changed files with 434 additions and 464 deletions

View file

@ -50,7 +50,7 @@ func ListLabels(ctx *context.APIContext) {
return
}
count, err := issues_model.CountLabelsByOrgID(ctx.Org.Organization.ID)
count, err := issues_model.CountLabelsByOrgID(ctx, ctx.Org.Organization.ID)
if err != nil {
ctx.InternalServerError(err)
return
@ -218,7 +218,7 @@ func EditLabel(ctx *context.APIContext) {
l.Description = *form.Description
}
l.SetArchived(form.IsArchived != nil && *form.IsArchived)
if err := issues_model.UpdateLabel(l); err != nil {
if err := issues_model.UpdateLabel(ctx, l); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateLabel", err)
return
}
@ -249,7 +249,7 @@ func DeleteLabel(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
if err := issues_model.DeleteLabel(ctx.Org.Organization.ID, ctx.ParamsInt64(":id")); err != nil {
if err := issues_model.DeleteLabel(ctx, ctx.Org.Organization.ID, ctx.ParamsInt64(":id")); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteLabel", err)
return
}

View file

@ -234,7 +234,7 @@ func DeleteCollaborator(ctx *context.APIContext) {
return
}
if err := repo_service.DeleteCollaboration(ctx.Repo.Repository, collaborator.ID); err != nil {
if err := repo_service.DeleteCollaboration(ctx, ctx.Repo.Repository, collaborator.ID); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteCollaboration", err)
return
}

View file

@ -413,7 +413,7 @@ func ListIssues(ctx *context.APIContext) {
var labelIDs []int64
if splitted := strings.Split(ctx.FormString("labels"), ","); len(splitted) > 0 {
labelIDs, err = issues_model.GetLabelIDsInRepoByNames(ctx.Repo.Repository.ID, splitted)
labelIDs, err = issues_model.GetLabelIDsInRepoByNames(ctx, ctx.Repo.Repository.ID, splitted)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetLabelIDsInRepoByNames", err)
return
@ -425,7 +425,7 @@ func ListIssues(ctx *context.APIContext) {
for i := range part {
// uses names and fall back to ids
// non existent milestones are discarded
mile, err := issues_model.GetMilestoneByRepoIDANDName(ctx.Repo.Repository.ID, part[i])
mile, err := issues_model.GetMilestoneByRepoIDANDName(ctx, ctx.Repo.Repository.ID, part[i])
if err == nil {
mileIDs = append(mileIDs, mile.ID)
continue

View file

@ -107,7 +107,7 @@ func AddIssueLabels(ctx *context.APIContext) {
return
}
if err = issue_service.AddLabels(issue, ctx.Doer, labels); err != nil {
if err = issue_service.AddLabels(ctx, issue, ctx.Doer, labels); err != nil {
ctx.Error(http.StatusInternalServerError, "AddLabels", err)
return
}
@ -186,7 +186,7 @@ func DeleteIssueLabel(ctx *context.APIContext) {
return
}
if err := issue_service.RemoveLabel(issue, ctx.Doer, label); err != nil {
if err := issue_service.RemoveLabel(ctx, issue, ctx.Doer, label); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteIssueLabel", err)
return
}
@ -237,7 +237,7 @@ func ReplaceIssueLabels(ctx *context.APIContext) {
return
}
if err := issue_service.ReplaceLabels(issue, ctx.Doer, labels); err != nil {
if err := issue_service.ReplaceLabels(ctx, issue, ctx.Doer, labels); err != nil {
ctx.Error(http.StatusInternalServerError, "ReplaceLabels", err)
return
}
@ -298,7 +298,7 @@ func ClearIssueLabels(ctx *context.APIContext) {
return
}
if err := issue_service.ClearLabels(issue, ctx.Doer); err != nil {
if err := issue_service.ClearLabels(ctx, issue, ctx.Doer); err != nil {
ctx.Error(http.StatusInternalServerError, "ClearLabels", err)
return
}
@ -317,7 +317,7 @@ func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption)
return nil, nil, err
}
labels, err := issues_model.GetLabelsByIDs(form.Labels, "id", "repo_id", "org_id")
labels, err := issues_model.GetLabelsByIDs(ctx, form.Labels, "id", "repo_id", "org_id")
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetLabelsByIDs", err)
return nil, nil, err

View file

@ -152,7 +152,7 @@ func DeleteIssueStopwatch(ctx *context.APIContext) {
return
}
if err := issues_model.CancelStopwatch(ctx.Doer, issue); err != nil {
if err := issues_model.CancelStopwatch(ctx, ctx.Doer, issue); err != nil {
ctx.Error(http.StatusInternalServerError, "CancelStopwatch", err)
return
}
@ -182,7 +182,7 @@ func prepareIssueStopwatch(ctx *context.APIContext, shouldExist bool) (*issues_m
return nil, errors.New("Cannot use time tracker")
}
if issues_model.StopwatchExists(ctx.Doer.ID, issue.ID) != shouldExist {
if issues_model.StopwatchExists(ctx, ctx.Doer.ID, issue.ID) != shouldExist {
if shouldExist {
ctx.Error(http.StatusConflict, "StopwatchExists", "cannot stop/cancel a non existent stopwatch")
err = errors.New("cannot stop/cancel a non existent stopwatch")
@ -218,13 +218,13 @@ func GetStopwatches(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/StopWatchList"
sws, err := issues_model.GetUserStopwatches(ctx.Doer.ID, utils.GetListOptions(ctx))
sws, err := issues_model.GetUserStopwatches(ctx, ctx.Doer.ID, utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUserStopwatches", err)
return
}
count, err := issues_model.CountUserStopwatches(ctx.Doer.ID)
count, err := issues_model.CountUserStopwatches(ctx, ctx.Doer.ID)
if err != nil {
ctx.InternalServerError(err)
return

View file

@ -132,7 +132,7 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
return
}
current, err := issues_model.CheckIssueWatch(user, issue)
current, err := issues_model.CheckIssueWatch(ctx, user, issue)
if err != nil {
ctx.Error(http.StatusInternalServerError, "CheckIssueWatch", err)
return
@ -145,7 +145,7 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
}
// Update watch state
if err := issues_model.CreateOrUpdateIssueWatch(user.ID, issue.ID, watch); err != nil {
if err := issues_model.CreateOrUpdateIssueWatch(ctx, user.ID, issue.ID, watch); err != nil {
ctx.Error(http.StatusInternalServerError, "CreateOrUpdateIssueWatch", err)
return
}
@ -196,7 +196,7 @@ func CheckIssueSubscription(ctx *context.APIContext) {
return
}
watching, err := issues_model.CheckIssueWatch(ctx.Doer, issue)
watching, err := issues_model.CheckIssueWatch(ctx, ctx.Doer, issue)
if err != nil {
ctx.InternalServerError(err)
return

View file

@ -55,7 +55,7 @@ func ListLabels(ctx *context.APIContext) {
return
}
count, err := issues_model.CountLabelsByRepoID(ctx.Repo.Repository.ID)
count, err := issues_model.CountLabelsByRepoID(ctx, ctx.Repo.Repository.ID)
if err != nil {
ctx.InternalServerError(err)
return
@ -240,7 +240,7 @@ func EditLabel(ctx *context.APIContext) {
l.Description = *form.Description
}
l.SetArchived(form.IsArchived != nil && *form.IsArchived)
if err := issues_model.UpdateLabel(l); err != nil {
if err := issues_model.UpdateLabel(ctx, l); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateLabel", err)
return
}
@ -276,7 +276,7 @@ func DeleteLabel(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
if err := issues_model.DeleteLabel(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")); err != nil {
if err := issues_model.DeleteLabel(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteLabel", err)
return
}

View file

@ -163,7 +163,7 @@ func CreateMilestone(ctx *context.APIContext) {
milestone.ClosedDateUnix = timeutil.TimeStampNow()
}
if err := issues_model.NewMilestone(milestone); err != nil {
if err := issues_model.NewMilestone(ctx, milestone); err != nil {
ctx.Error(http.StatusInternalServerError, "NewMilestone", err)
return
}
@ -225,7 +225,7 @@ func EditMilestone(ctx *context.APIContext) {
milestone.IsClosed = *form.State == string(api.StateClosed)
}
if err := issues_model.UpdateMilestone(milestone, oldIsClosed); err != nil {
if err := issues_model.UpdateMilestone(ctx, milestone, oldIsClosed); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateMilestone", err)
return
}
@ -264,7 +264,7 @@ func DeleteMilestone(ctx *context.APIContext) {
return
}
if err := issues_model.DeleteMilestoneByRepoID(ctx.Repo.Repository.ID, m.ID); err != nil {
if err := issues_model.DeleteMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, m.ID); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteMilestoneByRepoID", err)
return
}
@ -286,7 +286,7 @@ func getMilestoneByIDOrName(ctx *context.APIContext) *issues_model.Milestone {
}
}
milestone, err := issues_model.GetMilestoneByRepoIDANDName(ctx.Repo.Repository.ID, mile)
milestone, err := issues_model.GetMilestoneByRepoIDANDName(ctx, ctx.Repo.Repository.ID, mile)
if err != nil {
if issues_model.IsErrMilestoneNotExist(err) {
ctx.NotFound()

View file

@ -1003,14 +1003,14 @@ func updateRepoArchivedState(ctx *context.APIContext, opts api.EditRepoOption) e
return err
}
if *opts.Archived {
if err := repo_model.SetArchiveRepoState(repo, *opts.Archived); err != nil {
if err := repo_model.SetArchiveRepoState(ctx, repo, *opts.Archived); err != nil {
log.Error("Tried to archive a repo: %s", err)
ctx.Error(http.StatusInternalServerError, "ArchiveRepoState", err)
return err
}
log.Trace("Repository was archived: %s/%s", ctx.Repo.Owner.Name, repo.Name)
} else {
if err := repo_model.SetArchiveRepoState(repo, *opts.Archived); err != nil {
if err := repo_model.SetArchiveRepoState(ctx, repo, *opts.Archived); err != nil {
log.Error("Tried to un-archive a repo: %s", err)
ctx.Error(http.StatusInternalServerError, "ArchiveRepoState", err)
return err

View file

@ -53,7 +53,7 @@ func ListTopics(ctx *context.APIContext) {
RepoID: ctx.Repo.Repository.ID,
}
topics, total, err := repo_model.FindTopics(opts)
topics, total, err := repo_model.FindTopics(ctx, opts)
if err != nil {
ctx.InternalServerError(err)
return
@ -120,7 +120,7 @@ func UpdateTopics(ctx *context.APIContext) {
return
}
err := repo_model.SaveTopics(ctx.Repo.Repository.ID, validTopics...)
err := repo_model.SaveTopics(ctx, ctx.Repo.Repository.ID, validTopics...)
if err != nil {
log.Error("SaveTopics failed: %v", err)
ctx.InternalServerError(err)
@ -172,7 +172,7 @@ func AddTopic(ctx *context.APIContext) {
}
// Prevent adding more topics than allowed to repo
count, err := repo_model.CountTopics(&repo_model.FindTopicOptions{
count, err := repo_model.CountTopics(ctx, &repo_model.FindTopicOptions{
RepoID: ctx.Repo.Repository.ID,
})
if err != nil {
@ -187,7 +187,7 @@ func AddTopic(ctx *context.APIContext) {
return
}
_, err = repo_model.AddTopic(ctx.Repo.Repository.ID, topicName)
_, err = repo_model.AddTopic(ctx, ctx.Repo.Repository.ID, topicName)
if err != nil {
log.Error("AddTopic failed: %v", err)
ctx.InternalServerError(err)
@ -238,7 +238,7 @@ func DeleteTopic(ctx *context.APIContext) {
return
}
topic, err := repo_model.DeleteTopic(ctx.Repo.Repository.ID, topicName)
topic, err := repo_model.DeleteTopic(ctx, ctx.Repo.Repository.ID, topicName)
if err != nil {
log.Error("DeleteTopic failed: %v", err)
ctx.InternalServerError(err)
@ -287,7 +287,7 @@ func TopicSearch(ctx *context.APIContext) {
ListOptions: utils.GetListOptions(ctx),
}
topics, total, err := repo_model.FindTopics(opts)
topics, total, err := repo_model.FindTopics(ctx, opts)
if err != nil {
ctx.InternalServerError(err)
return

View file

@ -221,7 +221,7 @@ func acceptOrRejectRepoTransfer(ctx *context.APIContext, accept bool) error {
return err
}
if !repoTransfer.CanUserAcceptTransfer(ctx.Doer) {
if !repoTransfer.CanUserAcceptTransfer(ctx, ctx.Doer) {
ctx.Error(http.StatusForbidden, "CanUserAcceptTransfer", nil)
return fmt.Errorf("user does not have permissions to do this")
}
@ -230,5 +230,5 @@ func acceptOrRejectRepoTransfer(ctx *context.APIContext, accept bool) error {
return repo_service.TransferOwnership(ctx, repoTransfer.Doer, repoTransfer.Recipient, ctx.Repo.Repository, repoTransfer.Teams)
}
return models.CancelRepositoryTransfer(ctx.Repo.Repository)
return models.CancelRepositoryTransfer(ctx, ctx.Repo.Repository)
}

View file

@ -151,7 +151,7 @@ func ListFollowing(ctx *context.APIContext) {
}
func checkUserFollowing(ctx *context.APIContext, u *user_model.User, followID int64) {
if user_model.IsFollowing(u.ID, followID) {
if user_model.IsFollowing(ctx, u.ID, followID) {
ctx.Status(http.StatusNoContent)
} else {
ctx.NotFound()
@ -224,7 +224,7 @@ func Follow(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
if err := user_model.FollowUser(ctx.Doer.ID, ctx.ContextUser.ID); err != nil {
if err := user_model.FollowUser(ctx, ctx.Doer.ID, ctx.ContextUser.ID); err != nil {
ctx.Error(http.StatusInternalServerError, "FollowUser", err)
return
}
@ -248,7 +248,7 @@ func Unfollow(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
if err := user_model.UnfollowUser(ctx.Doer.ID, ctx.ContextUser.ID); err != nil {
if err := user_model.UnfollowUser(ctx, ctx.Doer.ID, ctx.ContextUser.ID); err != nil {
ctx.Error(http.StatusInternalServerError, "UnfollowUser", err)
return
}

View file

@ -140,7 +140,7 @@ func InitWebInstalled(ctx context.Context) {
mustInitCtx(ctx, models.Init)
mustInitCtx(ctx, authmodel.Init)
mustInit(repo_service.Init)
mustInitCtx(ctx, repo_service.Init)
// Booting long running goroutines.
mustInit(indexer_service.Init)

View file

@ -243,7 +243,7 @@ func prepareUserInfo(ctx *context.Context) *user_model.User {
ctx.ServerError("auth.HasTwoFactorByUID", err)
return nil
}
hasWebAuthn, err := auth.HasWebAuthnRegistrationsByUID(u.ID)
hasWebAuthn, err := auth.HasWebAuthnRegistrationsByUID(ctx, u.ID)
if err != nil {
ctx.ServerError("auth.HasWebAuthnRegistrationsByUID", err)
return nil
@ -421,13 +421,13 @@ func EditUserPost(ctx *context.Context) {
}
}
wn, err := auth.GetWebAuthnCredentialsByUID(u.ID)
wn, err := auth.GetWebAuthnCredentialsByUID(ctx, u.ID)
if err != nil {
ctx.ServerError("auth.GetTwoFactorByUID", err)
return
}
for _, cred := range wn {
if _, err := auth.DeleteCredential(cred.ID, u.ID); err != nil {
if _, err := auth.DeleteCredential(ctx, cred.ID, u.ID); err != nil {
ctx.ServerError("auth.DeleteCredential", err)
return
}

View file

@ -243,7 +243,7 @@ func SignInPost(ctx *context.Context) {
}
// Check if the user has webauthn registration
hasWebAuthnTwofa, err := auth.HasWebAuthnRegistrationsByUID(u.ID)
hasWebAuthnTwofa, err := auth.HasWebAuthnRegistrationsByUID(ctx, u.ID)
if err != nil {
ctx.ServerError("UserSignIn", err)
return

View file

@ -185,7 +185,7 @@ func linkAccount(ctx *context.Context, u *user_model.User, gothUser goth.User, r
}
// If WebAuthn is enrolled -> Redirect to WebAuthn instead
regs, err := auth.GetWebAuthnCredentialsByUID(u.ID)
regs, err := auth.GetWebAuthnCredentialsByUID(ctx, u.ID)
if err == nil && len(regs) > 0 {
ctx.Redirect(setting.AppSubURL + "/user/webauthn")
return

View file

@ -237,7 +237,7 @@ func newAccessTokenResponse(ctx go_context.Context, grant *auth.OAuth2Grant, ser
idToken.EmailVerified = user.IsActive
}
if grant.ScopeContains("groups") {
groups, err := getOAuthGroupsForUser(user)
groups, err := getOAuthGroupsForUser(ctx, user)
if err != nil {
log.Error("Error getting groups: %v", err)
return nil, &AccessTokenError{
@ -291,7 +291,7 @@ func InfoOAuth(ctx *context.Context) {
Picture: ctx.Doer.AvatarLink(ctx),
}
groups, err := getOAuthGroupsForUser(ctx.Doer)
groups, err := getOAuthGroupsForUser(ctx, ctx.Doer)
if err != nil {
ctx.ServerError("Oauth groups for user", err)
return
@ -303,8 +303,8 @@ func InfoOAuth(ctx *context.Context) {
// returns a list of "org" and "org:team" strings,
// that the given user is a part of.
func getOAuthGroupsForUser(user *user_model.User) ([]string, error) {
orgs, err := org_model.GetUserOrgsList(user)
func getOAuthGroupsForUser(ctx go_context.Context, user *user_model.User) ([]string, error) {
orgs, err := org_model.GetUserOrgsList(ctx, user)
if err != nil {
return nil, fmt.Errorf("GetUserOrgList: %w", err)
}
@ -1197,7 +1197,7 @@ func handleOAuth2SignIn(ctx *context.Context, source *auth.Source, u *user_model
}
// If WebAuthn is enrolled -> Redirect to WebAuthn instead
regs, err := auth.GetWebAuthnCredentialsByUID(u.ID)
regs, err := auth.GetWebAuthnCredentialsByUID(ctx, u.ID)
if err == nil && len(regs) > 0 {
ctx.Redirect(setting.AppSubURL + "/user/webauthn")
return

View file

@ -55,7 +55,7 @@ func WebAuthnLoginAssertion(ctx *context.Context) {
return
}
exists, err := auth.ExistsWebAuthnCredentialsForUID(user.ID)
exists, err := auth.ExistsWebAuthnCredentialsForUID(ctx, user.ID)
if err != nil {
ctx.ServerError("UserSignIn", err)
return
@ -127,14 +127,14 @@ func WebAuthnLoginAssertionPost(ctx *context.Context) {
}
// Success! Get the credential and update the sign count with the new value we received.
dbCred, err := auth.GetWebAuthnCredentialByCredID(user.ID, cred.ID)
dbCred, err := auth.GetWebAuthnCredentialByCredID(ctx, user.ID, cred.ID)
if err != nil {
ctx.ServerError("GetWebAuthnCredentialByCredID", err)
return
}
dbCred.SignCount = cred.Authenticator.SignCount
if err := dbCred.UpdateSignCount(); err != nil {
if err := dbCred.UpdateSignCount(ctx); err != nil {
ctx.ServerError("UpdateSignCount", err)
return
}

View file

@ -23,7 +23,7 @@ func TopicSearch(ctx *context.Context) {
},
}
topics, total, err := repo_model.FindTopics(opts)
topics, total, err := repo_model.FindTopics(ctx, opts)
if err != nil {
ctx.Error(http.StatusInternalServerError)
return

View file

@ -131,7 +131,7 @@ func Home(ctx *context.Context) {
var isFollowing bool
if ctx.Doer != nil {
isFollowing = user_model.IsFollowing(ctx.Doer.ID, ctx.ContextUser.ID)
isFollowing = user_model.IsFollowing(ctx, ctx.Doer.ID, ctx.ContextUser.ID)
}
ctx.Data["Repos"] = repos

View file

@ -76,7 +76,7 @@ func UpdateLabel(ctx *context.Context) {
l.Description = form.Description
l.Color = form.Color
l.SetArchived(form.IsArchived)
if err := issues_model.UpdateLabel(l); err != nil {
if err := issues_model.UpdateLabel(ctx, l); err != nil {
ctx.ServerError("UpdateLabel", err)
return
}
@ -85,7 +85,7 @@ func UpdateLabel(ctx *context.Context) {
// DeleteLabel delete a label
func DeleteLabel(ctx *context.Context) {
if err := issues_model.DeleteLabel(ctx.Org.Organization.ID, ctx.FormInt64("id")); err != nil {
if err := issues_model.DeleteLabel(ctx, ctx.Org.Organization.ID, ctx.FormInt64("id")); err != nil {
ctx.Flash.Error("DeleteLabel: " + err.Error())
} else {
ctx.Flash.Success(ctx.Tr("repo.issues.label_deletion_success"))

View file

@ -1412,7 +1412,7 @@ func ViewIssue(ctx *context.Context) {
if ctx.Doer != nil {
iw.UserID = ctx.Doer.ID
iw.IssueID = issue.ID
iw.IsWatching, err = issues_model.CheckIssueWatch(ctx.Doer, issue)
iw.IsWatching, err = issues_model.CheckIssueWatch(ctx, ctx.Doer, issue)
if err != nil {
ctx.ServerError("CheckIssueWatch", err)
return
@ -1530,7 +1530,7 @@ func ViewIssue(ctx *context.Context) {
if ctx.Repo.Repository.IsTimetrackerEnabled(ctx) {
if ctx.IsSigned {
// Deal with the stopwatch
ctx.Data["IsStopwatchRunning"] = issues_model.StopwatchExists(ctx.Doer.ID, issue.ID)
ctx.Data["IsStopwatchRunning"] = issues_model.StopwatchExists(ctx, ctx.Doer.ID, issue.ID)
if !ctx.Data["IsStopwatchRunning"].(bool) {
var exists bool
var swIssue *issues_model.Issue
@ -2708,7 +2708,7 @@ func ListIssues(ctx *context.Context) {
var labelIDs []int64
if splitted := strings.Split(ctx.FormString("labels"), ","); len(splitted) > 0 {
labelIDs, err = issues_model.GetLabelIDsInRepoByNames(ctx.Repo.Repository.ID, splitted)
labelIDs, err = issues_model.GetLabelIDsInRepoByNames(ctx, ctx.Repo.Repository.ID, splitted)
if err != nil {
ctx.Error(http.StatusInternalServerError, err.Error())
return
@ -2720,7 +2720,7 @@ func ListIssues(ctx *context.Context) {
for i := range part {
// uses names and fall back to ids
// non existent milestones are discarded
mile, err := issues_model.GetMilestoneByRepoIDANDName(ctx.Repo.Repository.ID, part[i])
mile, err := issues_model.GetMilestoneByRepoIDANDName(ctx, ctx.Repo.Repository.ID, part[i])
if err == nil {
mileIDs = append(mileIDs, mile.ID)
continue
@ -3037,7 +3037,7 @@ func NewComment(ctx *context.Context) {
return
}
} else {
if err := stopTimerIfAvailable(ctx.Doer, issue); err != nil {
if err := stopTimerIfAvailable(ctx, ctx.Doer, issue); err != nil {
ctx.ServerError("CreateOrStopIssueStopwatch", err)
return
}

View file

@ -145,7 +145,7 @@ func UpdateLabel(ctx *context.Context) {
l.Color = form.Color
l.SetArchived(form.IsArchived)
if err := issues_model.UpdateLabel(l); err != nil {
if err := issues_model.UpdateLabel(ctx, l); err != nil {
ctx.ServerError("UpdateLabel", err)
return
}
@ -154,7 +154,7 @@ func UpdateLabel(ctx *context.Context) {
// DeleteLabel delete a label
func DeleteLabel(ctx *context.Context) {
if err := issues_model.DeleteLabel(ctx.Repo.Repository.ID, ctx.FormInt64("id")); err != nil {
if err := issues_model.DeleteLabel(ctx, ctx.Repo.Repository.ID, ctx.FormInt64("id")); err != nil {
ctx.Flash.Error("DeleteLabel: " + err.Error())
} else {
ctx.Flash.Success(ctx.Tr("repo.issues.label_deletion_success"))
@ -173,7 +173,7 @@ func UpdateIssueLabel(ctx *context.Context) {
switch action := ctx.FormString("action"); action {
case "clear":
for _, issue := range issues {
if err := issue_service.ClearLabels(issue, ctx.Doer); err != nil {
if err := issue_service.ClearLabels(ctx, issue, ctx.Doer); err != nil {
ctx.ServerError("ClearLabels", err)
return
}
@ -208,14 +208,14 @@ func UpdateIssueLabel(ctx *context.Context) {
if action == "attach" {
for _, issue := range issues {
if err = issue_service.AddLabel(issue, ctx.Doer, label); err != nil {
if err = issue_service.AddLabel(ctx, issue, ctx.Doer, label); err != nil {
ctx.ServerError("AddLabel", err)
return
}
}
} else {
for _, issue := range issues {
if err = issue_service.RemoveLabel(issue, ctx.Doer, label); err != nil {
if err = issue_service.RemoveLabel(ctx, issue, ctx.Doer, label); err != nil {
ctx.ServerError("RemoveLabel", err)
return
}

View file

@ -22,7 +22,7 @@ func IssueStopwatch(c *context.Context) {
var showSuccessMessage bool
if !issues_model.StopwatchExists(c.Doer.ID, issue.ID) {
if !issues_model.StopwatchExists(c, c.Doer.ID, issue.ID) {
showSuccessMessage = true
}
@ -31,7 +31,7 @@ func IssueStopwatch(c *context.Context) {
return
}
if err := issues_model.CreateOrStopIssueStopwatch(c.Doer, issue); err != nil {
if err := issues_model.CreateOrStopIssueStopwatch(c, c.Doer, issue); err != nil {
c.ServerError("CreateOrStopIssueStopwatch", err)
return
}
@ -55,12 +55,12 @@ func CancelStopwatch(c *context.Context) {
return
}
if err := issues_model.CancelStopwatch(c.Doer, issue); err != nil {
if err := issues_model.CancelStopwatch(c, c.Doer, issue); err != nil {
c.ServerError("CancelStopwatch", err)
return
}
stopwatches, err := issues_model.GetUserStopwatches(c.Doer.ID, db.ListOptions{})
stopwatches, err := issues_model.GetUserStopwatches(c, c.Doer.ID, db.ListOptions{})
if err != nil {
c.ServerError("GetUserStopwatches", err)
return

View file

@ -47,7 +47,7 @@ func IssueWatch(ctx *context.Context) {
return
}
if err := issues_model.CreateOrUpdateIssueWatch(ctx.Doer.ID, issue.ID, watch); err != nil {
if err := issues_model.CreateOrUpdateIssueWatch(ctx, ctx.Doer.ID, issue.ID, watch); err != nil {
ctx.ServerError("CreateOrUpdateIssueWatch", err)
return
}

View file

@ -232,13 +232,13 @@ func MigratePost(ctx *context.Context) {
opts.Releases = false
}
err = repo_model.CheckCreateRepository(ctx.Doer, ctxUser, opts.RepoName, false)
err = repo_model.CheckCreateRepository(ctx, ctx.Doer, ctxUser, opts.RepoName, false)
if err != nil {
handleMigrateError(ctx, ctxUser, err, "MigratePost", tpl, form)
return
}
err = task.MigrateRepository(ctx.Doer, ctxUser, opts)
err = task.MigrateRepository(ctx, ctx.Doer, ctxUser, opts)
if err == nil {
ctx.Redirect(ctxUser.HomeLink() + "/" + url.PathEscape(opts.RepoName))
return
@ -260,7 +260,7 @@ func setMigrationContextData(ctx *context.Context, serviceType structs.GitServic
}
func MigrateRetryPost(ctx *context.Context) {
if err := task.RetryMigrateTask(ctx.Repo.Repository.ID); err != nil {
if err := task.RetryMigrateTask(ctx, ctx.Repo.Repository.ID); err != nil {
log.Error("Retry task failed: %v", err)
ctx.ServerError("task.RetryMigrateTask", err)
return
@ -269,7 +269,7 @@ func MigrateRetryPost(ctx *context.Context) {
}
func MigrateCancelPost(ctx *context.Context) {
migratingTask, err := admin_model.GetMigratingTask(ctx.Repo.Repository.ID)
migratingTask, err := admin_model.GetMigratingTask(ctx, ctx.Repo.Repository.ID)
if err != nil {
log.Error("GetMigratingTask: %v", err)
ctx.Redirect(ctx.Repo.Repository.Link())
@ -277,7 +277,7 @@ func MigrateCancelPost(ctx *context.Context) {
}
if migratingTask.Status == structs.TaskStatusRunning {
taskUpdate := &admin_model.Task{ID: migratingTask.ID, Status: structs.TaskStatusFailed, Message: "canceled"}
if err = taskUpdate.UpdateCols("status", "message"); err != nil {
if err = taskUpdate.UpdateCols(ctx, "status", "message"); err != nil {
ctx.ServerError("task.UpdateCols", err)
return
}

View file

@ -65,7 +65,7 @@ func Milestones(ctx *context.Context) {
return
}
stats, err := issues_model.GetMilestonesStatsByRepoCondAndKw(builder.And(builder.Eq{"id": ctx.Repo.Repository.ID}), keyword)
stats, err := issues_model.GetMilestonesStatsByRepoCondAndKw(ctx, builder.And(builder.Eq{"id": ctx.Repo.Repository.ID}), keyword)
if err != nil {
ctx.ServerError("GetMilestoneStats", err)
return
@ -74,7 +74,7 @@ func Milestones(ctx *context.Context) {
ctx.Data["ClosedCount"] = stats.ClosedCount
if ctx.Repo.Repository.IsTimetrackerEnabled(ctx) {
if err := miles.LoadTotalTrackedTimes(); err != nil {
if err := miles.LoadTotalTrackedTimes(ctx); err != nil {
ctx.ServerError("LoadTotalTrackedTimes", err)
return
}
@ -142,7 +142,7 @@ func NewMilestonePost(ctx *context.Context) {
}
deadline = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, deadline.Location())
if err = issues_model.NewMilestone(&issues_model.Milestone{
if err = issues_model.NewMilestone(ctx, &issues_model.Milestone{
RepoID: ctx.Repo.Repository.ID,
Name: form.Title,
Content: form.Content,
@ -214,7 +214,7 @@ func EditMilestonePost(ctx *context.Context) {
m.Name = form.Title
m.Content = form.Content
m.DeadlineUnix = timeutil.TimeStamp(deadline.Unix())
if err = issues_model.UpdateMilestone(m, m.IsClosed); err != nil {
if err = issues_model.UpdateMilestone(ctx, m, m.IsClosed); err != nil {
ctx.ServerError("UpdateMilestone", err)
return
}
@ -236,7 +236,7 @@ func ChangeMilestoneStatus(ctx *context.Context) {
}
id := ctx.ParamsInt64(":id")
if err := issues_model.ChangeMilestoneStatusByRepoIDAndID(ctx.Repo.Repository.ID, id, toClose); err != nil {
if err := issues_model.ChangeMilestoneStatusByRepoIDAndID(ctx, ctx.Repo.Repository.ID, id, toClose); err != nil {
if issues_model.IsErrMilestoneNotExist(err) {
ctx.NotFound("", err)
} else {
@ -249,7 +249,7 @@ func ChangeMilestoneStatus(ctx *context.Context) {
// DeleteMilestone delete a milestone
func DeleteMilestone(ctx *context.Context) {
if err := issues_model.DeleteMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.FormInt64("id")); err != nil {
if err := issues_model.DeleteMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, ctx.FormInt64("id")); err != nil {
ctx.Flash.Error("DeleteMilestoneByRepoID: " + err.Error())
} else {
ctx.Flash.Success(ctx.Tr("repo.milestones.deletion_success"))

View file

@ -1270,7 +1270,7 @@ func MergePullRequest(ctx *context.Context) {
}
log.Trace("Pull request merged: %d", pr.ID)
if err := stopTimerIfAvailable(ctx.Doer, issue); err != nil {
if err := stopTimerIfAvailable(ctx, ctx.Doer, issue); err != nil {
ctx.ServerError("CreateOrStopIssueStopwatch", err)
return
}
@ -1326,9 +1326,9 @@ func CancelAutoMergePullRequest(ctx *context.Context) {
ctx.Redirect(fmt.Sprintf("%s/pulls/%d", ctx.Repo.RepoLink, issue.Index))
}
func stopTimerIfAvailable(user *user_model.User, issue *issues_model.Issue) error {
if issues_model.StopwatchExists(user.ID, issue.ID) {
if err := issues_model.CreateOrStopIssueStopwatch(user, issue); err != nil {
func stopTimerIfAvailable(ctx *context.Context, user *user_model.User, issue *issues_model.Issue) error {
if issues_model.StopwatchExists(ctx, user.ID, issue.ID) {
if err := issues_model.CreateOrStopIssueStopwatch(ctx, user, issue); err != nil {
return err
}
}

View file

@ -344,7 +344,7 @@ func acceptOrRejectRepoTransfer(ctx *context.Context, accept bool) error {
return err
}
if !repoTransfer.CanUserAcceptTransfer(ctx.Doer) {
if !repoTransfer.CanUserAcceptTransfer(ctx, ctx.Doer) {
return errors.New("user does not have enough permissions")
}
@ -359,7 +359,7 @@ func acceptOrRejectRepoTransfer(ctx *context.Context, accept bool) error {
}
ctx.Flash.Success(ctx.Tr("repo.settings.transfer.success"))
} else {
if err := models.CancelRepositoryTransfer(ctx.Repo.Repository); err != nil {
if err := models.CancelRepositoryTransfer(ctx, ctx.Repo.Repository); err != nil {
return err
}
ctx.Flash.Success(ctx.Tr("repo.settings.transfer.rejected"))

View file

@ -127,7 +127,7 @@ func ChangeCollaborationAccessMode(ctx *context.Context) {
// DeleteCollaboration delete a collaboration for a repository
func DeleteCollaboration(ctx *context.Context) {
if err := repo_service.DeleteCollaboration(ctx.Repo.Repository, ctx.FormInt64("id")); err != nil {
if err := repo_service.DeleteCollaboration(ctx, ctx.Repo.Repository, ctx.FormInt64("id")); err != nil {
ctx.Flash.Error("DeleteCollaboration: " + err.Error())
} else {
ctx.Flash.Success(ctx.Tr("repo.settings.remove_collaborator_success"))

View file

@ -799,7 +799,7 @@ func SettingsPost(ctx *context.Context) {
return
}
if err := models.CancelRepositoryTransfer(ctx.Repo.Repository); err != nil {
if err := models.CancelRepositoryTransfer(ctx, ctx.Repo.Repository); err != nil {
ctx.ServerError("CancelRepositoryTransfer", err)
return
}
@ -863,7 +863,7 @@ func SettingsPost(ctx *context.Context) {
return
}
if err := repo_model.SetArchiveRepoState(repo, true); err != nil {
if err := repo_model.SetArchiveRepoState(ctx, repo, true); err != nil {
log.Error("Tried to archive a repo: %s", err)
ctx.Flash.Error(ctx.Tr("repo.settings.archive.error"))
ctx.Redirect(ctx.Repo.RepoLink + "/settings")
@ -881,7 +881,7 @@ func SettingsPost(ctx *context.Context) {
return
}
if err := repo_model.SetArchiveRepoState(repo, false); err != nil {
if err := repo_model.SetArchiveRepoState(ctx, repo, false); err != nil {
log.Error("Tried to unarchive a repo: %s", err)
ctx.Flash.Error(ctx.Tr("repo.settings.unarchive.error"))
ctx.Redirect(ctx.Repo.RepoLink + "/settings")

View file

@ -45,7 +45,7 @@ func TopicsPost(ctx *context.Context) {
return
}
err := repo_model.SaveTopics(ctx.Repo.Repository.ID, validTopics...)
err := repo_model.SaveTopics(ctx, ctx.Repo.Repository.ID, validTopics...)
if err != nil {
log.Error("SaveTopics failed: %v", err)
ctx.JSON(http.StatusInternalServerError, map[string]any{

View file

@ -640,7 +640,7 @@ func safeURL(address string) string {
func checkHomeCodeViewable(ctx *context.Context) {
if len(ctx.Repo.Units) > 0 {
if ctx.Repo.Repository.IsBeingCreated() {
task, err := admin_model.GetMigratingTask(ctx.Repo.Repository.ID)
task, err := admin_model.GetMigratingTask(ctx, ctx.Repo.Repository.ID)
if err != nil {
if admin_model.IsErrTaskDoesNotExist(err) {
ctx.Data["Repo"] = ctx.Repo
@ -893,7 +893,7 @@ func renderLanguageStats(ctx *context.Context) {
}
func renderRepoTopics(ctx *context.Context) {
topics, _, err := repo_model.FindTopics(&repo_model.FindTopicOptions{
topics, _, err := repo_model.FindTopics(ctx, &repo_model.FindTopicOptions{
RepoID: ctx.Repo.Repository.ID,
})
if err != nil {

View file

@ -30,7 +30,7 @@ func prepareContextForCommonProfile(ctx *context.Context) {
func PrepareContextForProfileBigAvatar(ctx *context.Context) {
prepareContextForCommonProfile(ctx)
ctx.Data["IsFollowing"] = ctx.Doer != nil && user_model.IsFollowing(ctx.Doer.ID, ctx.ContextUser.ID)
ctx.Data["IsFollowing"] = ctx.Doer != nil && user_model.IsFollowing(ctx, ctx.Doer.ID, ctx.ContextUser.ID)
ctx.Data["ShowUserEmail"] = setting.UI.ShowUserEmail && ctx.ContextUser.Email != "" && ctx.IsSigned && !ctx.ContextUser.KeepEmailPrivate
// Show OpenID URIs

View file

@ -59,7 +59,7 @@ func getDashboardContextUser(ctx *context.Context) *user_model.User {
}
ctx.Data["ContextUser"] = ctxUser
orgs, err := organization.GetUserOrgsList(ctx.Doer)
orgs, err := organization.GetUserOrgsList(ctx, ctx.Doer)
if err != nil {
ctx.ServerError("GetUserOrgsList", err)
return nil
@ -213,13 +213,13 @@ func Milestones(ctx *context.Context) {
}
}
counts, err := issues_model.CountMilestonesByRepoCondAndKw(userRepoCond, keyword, isShowClosed)
counts, err := issues_model.CountMilestonesByRepoCondAndKw(ctx, userRepoCond, keyword, isShowClosed)
if err != nil {
ctx.ServerError("CountMilestonesByRepoIDs", err)
return
}
milestones, err := issues_model.SearchMilestones(repoCond, page, isShowClosed, sortType, keyword)
milestones, err := issues_model.SearchMilestones(ctx, repoCond, page, isShowClosed, sortType, keyword)
if err != nil {
ctx.ServerError("SearchMilestones", err)
return
@ -256,7 +256,7 @@ func Milestones(ctx *context.Context) {
}
if milestones[i].Repo.IsTimetrackerEnabled(ctx) {
err := milestones[i].LoadTotalTrackedTime()
err := milestones[i].LoadTotalTrackedTime(ctx)
if err != nil {
ctx.ServerError("LoadTotalTrackedTime", err)
return
@ -265,7 +265,7 @@ func Milestones(ctx *context.Context) {
i++
}
milestoneStats, err := issues_model.GetMilestonesStatsByRepoCondAndKw(repoCond, keyword)
milestoneStats, err := issues_model.GetMilestonesStatsByRepoCondAndKw(ctx, repoCond, keyword)
if err != nil {
ctx.ServerError("GetMilestoneStats", err)
return
@ -275,7 +275,7 @@ func Milestones(ctx *context.Context) {
if len(repoIDs) == 0 {
totalMilestoneStats = milestoneStats
} else {
totalMilestoneStats, err = issues_model.GetMilestonesStatsByRepoCondAndKw(userRepoCond, keyword)
totalMilestoneStats, err = issues_model.GetMilestonesStatsByRepoCondAndKw(ctx, userRepoCond, keyword)
if err != nil {
ctx.ServerError("GetMilestoneStats", err)
return

View file

@ -292,9 +292,9 @@ func Action(ctx *context.Context) {
var err error
switch ctx.FormString("action") {
case "follow":
err = user_model.FollowUser(ctx.Doer.ID, ctx.ContextUser.ID)
err = user_model.FollowUser(ctx, ctx.Doer.ID, ctx.ContextUser.ID)
case "unfollow":
err = user_model.UnfollowUser(ctx.Doer.ID, ctx.ContextUser.ID)
err = user_model.UnfollowUser(ctx, ctx.Doer.ID, ctx.ContextUser.ID)
}
if err != nil {

View file

@ -59,7 +59,7 @@ func loadSecurityData(ctx *context.Context) {
}
ctx.Data["TOTPEnrolled"] = enrolled
credentials, err := auth_model.GetWebAuthnCredentialsByUID(ctx.Doer.ID)
credentials, err := auth_model.GetWebAuthnCredentialsByUID(ctx, ctx.Doer.ID)
if err != nil {
ctx.ServerError("GetWebAuthnCredentialsByUID", err)
return

View file

@ -29,7 +29,7 @@ func WebAuthnRegister(ctx *context.Context) {
form.Name = strconv.FormatInt(time.Now().UnixNano(), 16)
}
cred, err := auth.GetWebAuthnCredentialByName(ctx.Doer.ID, form.Name)
cred, err := auth.GetWebAuthnCredentialByName(ctx, ctx.Doer.ID, form.Name)
if err != nil && !auth.IsErrWebAuthnCredentialNotExist(err) {
ctx.ServerError("GetWebAuthnCredentialsByUID", err)
return
@ -88,7 +88,7 @@ func WebauthnRegisterPost(ctx *context.Context) {
return
}
dbCred, err := auth.GetWebAuthnCredentialByName(ctx.Doer.ID, name)
dbCred, err := auth.GetWebAuthnCredentialByName(ctx, ctx.Doer.ID, name)
if err != nil && !auth.IsErrWebAuthnCredentialNotExist(err) {
ctx.ServerError("GetWebAuthnCredentialsByUID", err)
return
@ -99,7 +99,7 @@ func WebauthnRegisterPost(ctx *context.Context) {
}
// Create the credential
_, err = auth.CreateCredential(ctx.Doer.ID, name, cred)
_, err = auth.CreateCredential(ctx, ctx.Doer.ID, name, cred)
if err != nil {
ctx.ServerError("CreateCredential", err)
return
@ -112,7 +112,7 @@ func WebauthnRegisterPost(ctx *context.Context) {
// WebauthnDelete deletes an security key by id
func WebauthnDelete(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.WebauthnDeleteForm)
if _, err := auth.DeleteCredential(form.ID, ctx.Doer.ID); err != nil {
if _, err := auth.DeleteCredential(ctx, form.ID, ctx.Doer.ID); err != nil {
ctx.ServerError("GetWebAuthnCredentialByID", err)
return
}

View file

@ -14,7 +14,7 @@ import (
// GetStopwatches get all stopwatches
func GetStopwatches(ctx *context.Context) {
sws, err := issues_model.GetUserStopwatches(ctx.Doer.ID, db.ListOptions{
sws, err := issues_model.GetUserStopwatches(ctx, ctx.Doer.ID, db.ListOptions{
Page: ctx.FormInt("page"),
PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")),
})
@ -23,7 +23,7 @@ func GetStopwatches(ctx *context.Context) {
return
}
count, err := issues_model.CountUserStopwatches(ctx.Doer.ID)
count, err := issues_model.CountUserStopwatches(ctx, ctx.Doer.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, err.Error())
return

View file

@ -14,7 +14,7 @@ import (
// TaskStatus returns task's status
func TaskStatus(ctx *context.Context) {
task, opts, err := admin_model.GetMigratingTaskByID(ctx.ParamsInt64("task"), ctx.Doer.ID)
task, opts, err := admin_model.GetMigratingTaskByID(ctx, ctx.ParamsInt64("task"), ctx.Doer.ID)
if err != nil {
if admin_model.IsErrTaskDoesNotExist(err) {
ctx.JSON(http.StatusNotFound, map[string]any{