1
1
mirror of https://github.com/go-gitea/gitea synced 2025-09-17 22:28:13 +00:00

Final round of db.DefaultContext refactor (#27587)

Last part of #27065
This commit is contained in:
JakobDev
2023-10-14 10:37:24 +02:00
committed by GitHub
parent ae419fa494
commit 76a85a4ce9
64 changed files with 250 additions and 242 deletions

View File

@@ -108,7 +108,7 @@ func httpBase(ctx *context.Context) *serviceHandler {
repo, err := repo_model.GetRepositoryByName(ctx, owner.ID, reponame)
if err != nil {
if repo_model.IsErrRepoNotExist(err) {
if redirectRepoID, err := repo_model.LookupRedirect(owner.ID, reponame); err == nil {
if redirectRepoID, err := repo_model.LookupRedirect(ctx, owner.ID, reponame); err == nil {
context.RedirectToRepo(ctx.Base, redirectRepoID)
return nil
}

View File

@@ -830,7 +830,7 @@ func RetrieveRepoMetas(ctx *context.Context, repo *repo_model.Repository, isPull
}
// Contains true if the user can create issue dependencies
ctx.Data["CanCreateIssueDependencies"] = ctx.Repo.CanCreateIssueDependencies(ctx.Doer, isPull)
ctx.Data["CanCreateIssueDependencies"] = ctx.Repo.CanCreateIssueDependencies(ctx, ctx.Doer, isPull)
return labels
}
@@ -1548,7 +1548,7 @@ func ViewIssue(ctx *context.Context) {
ctx.Data["OtherStopwatchURL"] = swIssue.Link()
}
}
ctx.Data["CanUseTimetracker"] = ctx.Repo.CanUseTimetracker(issue, ctx.Doer)
ctx.Data["CanUseTimetracker"] = ctx.Repo.CanUseTimetracker(ctx, issue, ctx.Doer)
} else {
ctx.Data["CanUseTimetracker"] = false
}
@@ -1559,7 +1559,7 @@ func ViewIssue(ctx *context.Context) {
}
// Check if the user can use the dependencies
ctx.Data["CanCreateIssueDependencies"] = ctx.Repo.CanCreateIssueDependencies(ctx.Doer, issue.IsPull)
ctx.Data["CanCreateIssueDependencies"] = ctx.Repo.CanCreateIssueDependencies(ctx, ctx.Doer, issue.IsPull)
// check if dependencies can be created across repositories
ctx.Data["AllowCrossRepositoryDependencies"] = setting.Service.AllowCrossRepositoryDependencies

View File

@@ -22,7 +22,7 @@ func AddDependency(ctx *context.Context) {
}
// Check if the Repo is allowed to have dependencies
if !ctx.Repo.CanCreateIssueDependencies(ctx.Doer, issue.IsPull) {
if !ctx.Repo.CanCreateIssueDependencies(ctx, ctx.Doer, issue.IsPull) {
ctx.Error(http.StatusForbidden, "CanCreateIssueDependencies")
return
}
@@ -97,7 +97,7 @@ func RemoveDependency(ctx *context.Context) {
}
// Check if the Repo is allowed to have dependencies
if !ctx.Repo.CanCreateIssueDependencies(ctx.Doer, issue.IsPull) {
if !ctx.Repo.CanCreateIssueDependencies(ctx, ctx.Doer, issue.IsPull) {
ctx.Error(http.StatusForbidden, "CanCreateIssueDependencies")
return
}

View File

@@ -26,7 +26,7 @@ func IssueStopwatch(c *context.Context) {
showSuccessMessage = true
}
if !c.Repo.CanUseTimetracker(issue, c.Doer) {
if !c.Repo.CanUseTimetracker(c, issue, c.Doer) {
c.NotFound("CanUseTimetracker", nil)
return
}
@@ -50,7 +50,7 @@ func CancelStopwatch(c *context.Context) {
if c.Written() {
return
}
if !c.Repo.CanUseTimetracker(issue, c.Doer) {
if !c.Repo.CanUseTimetracker(c, issue, c.Doer) {
c.NotFound("CanUseTimetracker", nil)
return
}

View File

@@ -22,7 +22,7 @@ func AddTimeManually(c *context.Context) {
if c.Written() {
return
}
if !c.Repo.CanUseTimetracker(issue, c.Doer) {
if !c.Repo.CanUseTimetracker(c, issue, c.Doer) {
c.NotFound("CanUseTimetracker", nil)
return
}
@@ -56,7 +56,7 @@ func DeleteTime(c *context.Context) {
if c.Written() {
return
}
if !c.Repo.CanUseTimetracker(issue, c.Doer) {
if !c.Repo.CanUseTimetracker(c, issue, c.Doer) {
c.NotFound("CanUseTimetracker", nil)
return
}

View File

@@ -1170,7 +1170,7 @@ func MergePullRequest(ctx *context.Context) {
// handle manually-merged mark
if manuallyMerged {
if err := pull_service.MergedManually(pr, ctx.Doer, ctx.Repo.GitRepo, form.MergeCommitID); err != nil {
if err := pull_service.MergedManually(ctx, pr, ctx.Doer, ctx.Repo.GitRepo, form.MergeCommitID); err != nil {
switch {
case models.IsErrInvalidMergeStyle(err):

View File

@@ -70,7 +70,7 @@ func DeployKeysPost(ctx *context.Context) {
return
}
key, err := asymkey_model.AddDeployKey(ctx.Repo.Repository.ID, form.Title, content, !form.IsWritable)
key, err := asymkey_model.AddDeployKey(ctx, ctx.Repo.Repository.ID, form.Title, content, !form.IsWritable)
if err != nil {
ctx.Data["HasError"] = true
switch {

View File

@@ -300,7 +300,7 @@ func editWebhook(ctx *context.Context, params webhookParams) {
if err := w.UpdateEvent(); err != nil {
ctx.ServerError("UpdateEvent", err)
return
} else if err := webhook.UpdateWebhook(w); err != nil {
} else if err := webhook.UpdateWebhook(ctx, w); err != nil {
ctx.ServerError("UpdateWebhook", err)
return
}
@@ -589,9 +589,9 @@ func checkWebhook(ctx *context.Context) (*ownerRepoCtx, *webhook.Webhook) {
var w *webhook.Webhook
if orCtx.RepoID > 0 {
w, err = webhook.GetWebhookByRepoID(orCtx.RepoID, ctx.ParamsInt64(":id"))
w, err = webhook.GetWebhookByRepoID(ctx, orCtx.RepoID, ctx.ParamsInt64(":id"))
} else if orCtx.OwnerID > 0 {
w, err = webhook.GetWebhookByOwnerID(orCtx.OwnerID, ctx.ParamsInt64(":id"))
w, err = webhook.GetWebhookByOwnerID(ctx, orCtx.OwnerID, ctx.ParamsInt64(":id"))
} else if orCtx.IsAdmin {
w, err = webhook.GetSystemOrDefaultWebhook(ctx, ctx.ParamsInt64(":id"))
}
@@ -618,7 +618,7 @@ func checkWebhook(ctx *context.Context) (*ownerRepoCtx, *webhook.Webhook) {
ctx.Data["PackagistHook"] = webhook_service.GetPackagistHook(w)
}
ctx.Data["History"], err = w.History(1)
ctx.Data["History"], err = w.History(ctx, 1)
if err != nil {
ctx.ServerError("History", err)
}
@@ -643,7 +643,7 @@ func WebHooksEdit(ctx *context.Context) {
// TestWebhook test if web hook is work fine
func TestWebhook(ctx *context.Context) {
hookID := ctx.ParamsInt64(":id")
w, err := webhook.GetWebhookByRepoID(ctx.Repo.Repository.ID, hookID)
w, err := webhook.GetWebhookByRepoID(ctx, ctx.Repo.Repository.ID, hookID)
if err != nil {
ctx.Flash.Error("GetWebhookByRepoID: " + err.Error())
ctx.Status(http.StatusInternalServerError)
@@ -724,7 +724,7 @@ func ReplayWebhook(ctx *context.Context) {
// DeleteWebhook delete a webhook
func DeleteWebhook(ctx *context.Context) {
if err := webhook.DeleteWebhookByRepoID(ctx.Repo.Repository.ID, ctx.FormInt64("id")); err != nil {
if err := webhook.DeleteWebhookByRepoID(ctx, ctx.Repo.Repository.ID, ctx.FormInt64("id")); err != nil {
ctx.Flash.Error("DeleteWebhookByRepoID: " + err.Error())
} else {
ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success"))