1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-30 06:08:35 +00:00

Even more db.DefaultContext refactor (#27352)

Part of #27065

---------

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: delvh <dev.lh@web.de>
This commit is contained in:
JakobDev
2023-10-03 12:30:41 +02:00
committed by GitHub
parent 08507e2760
commit cc5df26680
97 changed files with 298 additions and 294 deletions

View File

@@ -608,7 +608,7 @@ func disableOrEnableWorkflowFile(ctx *context_module.Context, isEnable bool) {
cfg.DisableWorkflow(workflow)
}
if err := repo_model.UpdateRepoUnit(cfgUnit); err != nil {
if err := repo_model.UpdateRepoUnit(ctx, cfgUnit); err != nil {
ctx.ServerError("UpdateRepoUnit", err)
return
}

View File

@@ -45,7 +45,7 @@ func uploadAttachment(ctx *context.Context, repoID int64, allowedTypes string) {
}
defer file.Close()
attach, err := attachment.UploadAttachment(file, allowedTypes, header.Size, &repo_model.Attachment{
attach, err := attachment.UploadAttachment(ctx, file, allowedTypes, header.Size, &repo_model.Attachment{
Name: header.Filename,
UploaderID: ctx.Doer.ID,
RepoID: repoID,

View File

@@ -305,7 +305,7 @@ func Diff(ctx *context.Context) {
maxLines, maxFiles = -1, -1
}
diff, err := gitdiff.GetDiff(gitRepo, &gitdiff.DiffOptions{
diff, err := gitdiff.GetDiff(ctx, gitRepo, &gitdiff.DiffOptions{
AfterCommitID: commitID,
SkipTo: ctx.FormString("skip-to"),
MaxLines: maxLines,

View File

@@ -609,7 +609,7 @@ func PrepareCompareDiff(
maxLines, maxFiles = -1, -1
}
diff, err := gitdiff.GetDiff(ci.HeadGitRepo,
diff, err := gitdiff.GetDiff(ctx, ci.HeadGitRepo,
&gitdiff.DiffOptions{
BeforeCommitID: beforeCommitID,
AfterCommitID: headCommitID,

View File

@@ -305,7 +305,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
// Check read status
if !ctx.IsSigned {
issues[i].IsRead = true
} else if err = issues[i].GetIsRead(ctx.Doer.ID); err != nil {
} else if err = issues[i].GetIsRead(ctx, ctx.Doer.ID); err != nil {
ctx.ServerError("GetIsRead", err)
return
}
@@ -1270,7 +1270,7 @@ func roleDescriptor(ctx stdCtx.Context, repo *repo_model.Repository, poster *use
}
// Otherwise check if poster is the real repo admin.
ok, err := access_model.IsUserRealRepoAdmin(repo, poster)
ok, err := access_model.IsUserRealRepoAdmin(ctx, repo, poster)
if err != nil {
return roleDescriptor, err
}
@@ -1554,7 +1554,7 @@ func ViewIssue(ctx *context.Context) {
} else {
ctx.Data["CanUseTimetracker"] = false
}
if ctx.Data["WorkingUsers"], err = issues_model.TotalTimesForEachUser(&issues_model.FindTrackedTimesOptions{IssueID: issue.ID}); err != nil {
if ctx.Data["WorkingUsers"], err = issues_model.TotalTimesForEachUser(ctx, &issues_model.FindTrackedTimesOptions{IssueID: issue.ID}); err != nil {
ctx.ServerError("TotalTimesForEachUser", err)
return
}
@@ -1728,7 +1728,7 @@ func ViewIssue(ctx *context.Context) {
comment.Type == issues_model.CommentTypeStopTracking ||
comment.Type == issues_model.CommentTypeDeleteTimeManual {
// drop error since times could be pruned from DB..
_ = comment.LoadTime()
_ = comment.LoadTime(ctx)
if comment.Content != "" {
// Content before v1.21 did store the formated string instead of seconds,
// so "|" is used as delimeter to mark the new format
@@ -3579,7 +3579,7 @@ func handleTeamMentions(ctx *context.Context) {
if ctx.Doer.IsAdmin {
isAdmin = true
} else {
isAdmin, err = org.IsOwnedBy(ctx.Doer.ID)
isAdmin, err = org.IsOwnedBy(ctx, ctx.Doer.ID)
if err != nil {
ctx.ServerError("IsOwnedBy", err)
return
@@ -3587,13 +3587,13 @@ func handleTeamMentions(ctx *context.Context) {
}
if isAdmin {
teams, err = org.LoadTeams()
teams, err = org.LoadTeams(ctx)
if err != nil {
ctx.ServerError("LoadTeams", err)
return
}
} else {
teams, err = org.GetUserTeams(ctx.Doer.ID)
teams, err = org.GetUserTeams(ctx, ctx.Doer.ID)
if err != nil {
ctx.ServerError("GetUserTeams", err)
return

View File

@@ -85,7 +85,7 @@ func RetrieveLabels(ctx *context.Context) {
return
}
if ctx.Doer != nil {
ctx.Org.IsOwner, err = org.IsOwnedBy(ctx.Doer.ID)
ctx.Org.IsOwner, err = org.IsOwnedBy(ctx, ctx.Doer.ID)
if err != nil {
ctx.ServerError("org.IsOwnedBy", err)
return

View File

@@ -61,7 +61,7 @@ func DeleteTime(c *context.Context) {
return
}
t, err := issues_model.GetTrackedTimeByID(c.ParamsInt64(":timeid"))
t, err := issues_model.GetTrackedTimeByID(c, c.ParamsInt64(":timeid"))
if err != nil {
if db.IsErrNotExist(err) {
c.NotFound("time not found", err)
@@ -77,7 +77,7 @@ func DeleteTime(c *context.Context) {
return
}
if err = issues_model.DeleteTime(t); err != nil {
if err = issues_model.DeleteTime(c, t); err != nil {
c.ServerError("DeleteTime", err)
return
}

View File

@@ -265,7 +265,7 @@ func ForkPost(ctx *context.Context) {
// Check if user is allowed to create repo's on the organization.
if ctxUser.IsOrganization() {
isAllowedToFork, err := organization.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx.Doer.ID)
isAllowedToFork, err := organization.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx, ctx.Doer.ID)
if err != nil {
ctx.ServerError("CanCreateOrgRepo", err)
return
@@ -908,7 +908,7 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi
// as the viewed information is designed to be loaded only on latest PR
// diff and if you're signed in.
if !ctx.IsSigned || willShowSpecifiedCommit || willShowSpecifiedCommitRange {
diff, err = gitdiff.GetDiff(gitRepo, diffOptions, files...)
diff, err = gitdiff.GetDiff(ctx, gitRepo, diffOptions, files...)
methodWithError = "GetDiff"
} else {
diff, err = gitdiff.SyncAndGetUserSpecificDiff(ctx, ctx.Doer.ID, pull, gitRepo, diffOptions, files...)

View File

@@ -119,7 +119,7 @@ func checkContextUser(ctx *context.Context, uid int64) *user_model.User {
return nil
}
if !ctx.Doer.IsAdmin {
canCreate, err := organization.OrgFromUser(org).CanCreateOrgRepo(ctx.Doer.ID)
canCreate, err := organization.OrgFromUser(org).CanCreateOrgRepo(ctx, ctx.Doer.ID)
if err != nil {
ctx.ServerError("CanCreateOrgRepo", err)
return nil

View File

@@ -70,7 +70,7 @@ func SettingsProtectedBranch(c *context.Context) {
c.Data["PageIsSettingsBranches"] = true
c.Data["Title"] = c.Tr("repo.settings.protected_branch") + " - " + rule.RuleName
users, err := access_model.GetRepoReaders(c.Repo.Repository)
users, err := access_model.GetRepoReaders(c, c.Repo.Repository)
if err != nil {
c.ServerError("Repo.Repository.GetReaders", err)
return
@@ -84,7 +84,7 @@ func SettingsProtectedBranch(c *context.Context) {
c.Data["recent_status_checks"] = contexts
if c.Repo.Owner.IsOrganization() {
teams, err := organization.OrgFromUser(c.Repo.Owner).TeamsWithAccessToRepo(c.Repo.Repository.ID, perm.AccessModeRead)
teams, err := organization.OrgFromUser(c.Repo.Owner).TeamsWithAccessToRepo(c, c.Repo.Repository.ID, perm.AccessModeRead)
if err != nil {
c.ServerError("Repo.Owner.TeamsWithAccessToRepo", err)
return

View File

@@ -147,7 +147,7 @@ func setTagsContext(ctx *context.Context) error {
}
ctx.Data["ProtectedTags"] = protectedTags
users, err := access_model.GetRepoReaders(ctx.Repo.Repository)
users, err := access_model.GetRepoReaders(ctx, ctx.Repo.Repository)
if err != nil {
ctx.ServerError("Repo.Repository.GetReaders", err)
return err
@@ -155,7 +155,7 @@ func setTagsContext(ctx *context.Context) error {
ctx.Data["Users"] = users
if ctx.Repo.Owner.IsOrganization() {
teams, err := organization.OrgFromUser(ctx.Repo.Owner).TeamsWithAccessToRepo(ctx.Repo.Repository.ID, perm.AccessModeRead)
teams, err := organization.OrgFromUser(ctx.Repo.Owner).TeamsWithAccessToRepo(ctx, ctx.Repo.Repository.ID, perm.AccessModeRead)
if err != nil {
ctx.ServerError("Repo.Owner.TeamsWithAccessToRepo", err)
return err

View File

@@ -594,7 +594,7 @@ func SettingsPost(ctx *context.Context) {
return
}
if err := repo_model.UpdateRepositoryUnits(repo, units, deleteUnitTypes); err != nil {
if err := repo_model.UpdateRepositoryUnits(ctx, repo, units, deleteUnitTypes); err != nil {
ctx.ServerError("UpdateRepositoryUnits", err)
return
}
@@ -761,7 +761,7 @@ func SettingsPost(ctx *context.Context) {
}
if newOwner.Type == user_model.UserTypeOrganization {
if !ctx.Doer.IsAdmin && newOwner.Visibility == structs.VisibleTypePrivate && !organization.OrgFromUser(newOwner).HasMemberWithUserID(ctx.Doer.ID) {
if !ctx.Doer.IsAdmin && newOwner.Visibility == structs.VisibleTypePrivate && !organization.OrgFromUser(newOwner).HasMemberWithUserID(ctx, ctx.Doer.ID) {
// The user shouldn't know about this organization
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_owner_name"), tplSettingsOptions, nil)
return