mirror of
https://github.com/go-gitea/gitea
synced 2025-09-17 14:18:15 +00:00
Remove incorrect "db.DefaultContext" usages (#35366)
This commit is contained in:
@@ -72,13 +72,13 @@ import (
|
||||
|
||||
actions_model "code.gitea.io/gitea/models/actions"
|
||||
auth_model "code.gitea.io/gitea/models/auth"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/organization"
|
||||
"code.gitea.io/gitea/models/perm"
|
||||
access_model "code.gitea.io/gitea/models/perm/access"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
@@ -780,7 +780,7 @@ func buildAuthGroup() *auth.Group {
|
||||
group.Add(&auth.ReverseProxy{})
|
||||
}
|
||||
|
||||
if setting.IsWindows && auth_model.IsSSPIEnabled(db.DefaultContext) {
|
||||
if setting.IsWindows && auth_model.IsSSPIEnabled(graceful.GetManager().ShutdownContext()) {
|
||||
group.Add(&auth.SSPI{}) // it MUST be the last, see the comment of SSPI
|
||||
}
|
||||
|
||||
|
@@ -180,20 +180,20 @@ func checkDatabase(ctx *context.Context, form *forms.InstallForm) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
err = db_install.CheckDatabaseConnection()
|
||||
err = db_install.CheckDatabaseConnection(ctx)
|
||||
if err != nil {
|
||||
ctx.Data["Err_DbSetting"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("install.invalid_db_setting", err), tplInstall, form)
|
||||
return false
|
||||
}
|
||||
|
||||
hasPostInstallationUser, err := db_install.HasPostInstallationUsers()
|
||||
hasPostInstallationUser, err := db_install.HasPostInstallationUsers(ctx)
|
||||
if err != nil {
|
||||
ctx.Data["Err_DbSetting"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("install.invalid_db_table", "user", err), tplInstall, form)
|
||||
return false
|
||||
}
|
||||
dbMigrationVersion, err := db_install.GetMigrationVersion()
|
||||
dbMigrationVersion, err := db_install.GetMigrationVersion(ctx)
|
||||
if err != nil {
|
||||
ctx.Data["Err_DbSetting"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("install.invalid_db_table", "version", err), tplInstall, form)
|
||||
|
@@ -6,7 +6,6 @@ package private
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
pull_model "code.gitea.io/gitea/models/pull"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
@@ -21,13 +20,13 @@ import (
|
||||
|
||||
func TestHandlePullRequestMerging(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
pr, err := issues_model.GetUnmergedPullRequest(db.DefaultContext, 1, 1, "branch2", "master", issues_model.PullRequestFlowGithub)
|
||||
pr, err := issues_model.GetUnmergedPullRequest(t.Context(), 1, 1, "branch2", "master", issues_model.PullRequestFlowGithub)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, pr.LoadBaseRepo(db.DefaultContext))
|
||||
assert.NoError(t, pr.LoadBaseRepo(t.Context()))
|
||||
|
||||
user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||
|
||||
err = pull_model.ScheduleAutoMerge(db.DefaultContext, user1, pr.ID, repo_model.MergeStyleSquash, "squash merge a pr", false)
|
||||
err = pull_model.ScheduleAutoMerge(t.Context(), user1, pr.ID, repo_model.MergeStyleSquash, "squash merge a pr", false)
|
||||
assert.NoError(t, err)
|
||||
|
||||
autoMerge := unittest.AssertExistsAndLoadBean(t, &pull_model.AutoMerge{PullID: pr.ID})
|
||||
@@ -40,7 +39,7 @@ func TestHandlePullRequestMerging(t *testing.T) {
|
||||
{NewCommitID: "01234567"},
|
||||
})
|
||||
assert.Empty(t, resp.Body.String())
|
||||
pr, err = issues_model.GetPullRequestByID(db.DefaultContext, pr.ID)
|
||||
pr, err = issues_model.GetPullRequestByID(t.Context(), pr.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, pr.HasMerged)
|
||||
assert.Equal(t, "01234567", pr.MergedCommitID)
|
||||
|
@@ -9,7 +9,6 @@ import (
|
||||
"testing"
|
||||
|
||||
auth_model "code.gitea.io/gitea/models/auth"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/session"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
@@ -24,7 +23,7 @@ import (
|
||||
|
||||
func addOAuth2Source(t *testing.T, authName string, cfg oauth2.Source) {
|
||||
cfg.Provider = util.IfZero(cfg.Provider, "gitea")
|
||||
err := auth_model.CreateSource(db.DefaultContext, &auth_model.Source{
|
||||
err := auth_model.CreateSource(t.Context(), &auth_model.Source{
|
||||
Type: auth_model.OAuth2,
|
||||
Name: authName,
|
||||
IsActive: true,
|
||||
|
@@ -7,7 +7,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/auth"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/services/oauth2_provider"
|
||||
@@ -21,7 +20,7 @@ func createAndParseToken(t *testing.T, grant *auth.OAuth2Grant) *oauth2_provider
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, signingKey)
|
||||
|
||||
response, terr := oauth2_provider.NewAccessTokenResponse(db.DefaultContext, grant, signingKey, signingKey)
|
||||
response, terr := oauth2_provider.NewAccessTokenResponse(t.Context(), grant, signingKey, signingKey)
|
||||
assert.Nil(t, terr)
|
||||
assert.NotNil(t, response)
|
||||
|
||||
@@ -43,7 +42,7 @@ func createAndParseToken(t *testing.T, grant *auth.OAuth2Grant) *oauth2_provider
|
||||
func TestNewAccessTokenResponse_OIDCToken(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
grants, err := auth.GetOAuth2GrantsByUserID(db.DefaultContext, 3)
|
||||
grants, err := auth.GetOAuth2GrantsByUserID(t.Context(), 3)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, grants, 1)
|
||||
|
||||
@@ -59,7 +58,7 @@ func TestNewAccessTokenResponse_OIDCToken(t *testing.T) {
|
||||
assert.False(t, oidcToken.EmailVerified)
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5})
|
||||
grants, err = auth.GetOAuth2GrantsByUserID(db.DefaultContext, user.ID)
|
||||
grants, err = auth.GetOAuth2GrantsByUserID(t.Context(), user.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, grants, 1)
|
||||
|
||||
@@ -68,7 +67,7 @@ func TestNewAccessTokenResponse_OIDCToken(t *testing.T) {
|
||||
assert.Equal(t, user.DisplayName(), oidcToken.Name)
|
||||
assert.Equal(t, user.Name, oidcToken.PreferredUsername)
|
||||
assert.Equal(t, user.HTMLURL(t.Context()), oidcToken.Profile)
|
||||
assert.Equal(t, user.AvatarLink(db.DefaultContext), oidcToken.Picture)
|
||||
assert.Equal(t, user.AvatarLink(t.Context()), oidcToken.Picture)
|
||||
assert.Equal(t, user.Website, oidcToken.Website)
|
||||
assert.Equal(t, user.UpdatedUnix, oidcToken.UpdatedAt)
|
||||
assert.Equal(t, user.Email, oidcToken.Email)
|
||||
|
@@ -58,13 +58,13 @@ func Worktime(ctx *context.Context) {
|
||||
var err error
|
||||
switch worktimeBy {
|
||||
case "milestones":
|
||||
worktimeSumResult, err = organization.GetWorktimeByMilestones(ctx.Org.Organization, unixFrom, unixTo)
|
||||
worktimeSumResult, err = organization.GetWorktimeByMilestones(ctx, ctx.Org.Organization, unixFrom, unixTo)
|
||||
ctx.Data["WorktimeByMilestones"] = true
|
||||
case "members":
|
||||
worktimeSumResult, err = organization.GetWorktimeByMembers(ctx.Org.Organization, unixFrom, unixTo)
|
||||
worktimeSumResult, err = organization.GetWorktimeByMembers(ctx, ctx.Org.Organization, unixFrom, unixTo)
|
||||
ctx.Data["WorktimeByMembers"] = true
|
||||
default: /* by repos */
|
||||
worktimeSumResult, err = organization.GetWorktimeByRepos(ctx.Org.Organization, unixFrom, unixTo)
|
||||
worktimeSumResult, err = organization.GetWorktimeByRepos(ctx, ctx.Org.Organization, unixFrom, unixTo)
|
||||
ctx.Data["WorktimeByRepos"] = true
|
||||
}
|
||||
if err != nil {
|
||||
|
@@ -162,7 +162,7 @@ func TestReadWorkflow_WorkflowDispatchConfig(t *testing.T) {
|
||||
func Test_loadIsRefDeleted(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
|
||||
runs, total, err := db.FindAndCount[actions_model.ActionRun](db.DefaultContext,
|
||||
runs, total, err := db.FindAndCount[actions_model.ActionRun](t.Context(),
|
||||
actions_model.FindRunOptions{RepoID: 4, Ref: "refs/heads/test"})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, runs, 1)
|
||||
@@ -171,7 +171,7 @@ func Test_loadIsRefDeleted(t *testing.T) {
|
||||
assert.False(t, run.IsRefDeleted)
|
||||
}
|
||||
|
||||
assert.NoError(t, loadIsRefDeleted(db.DefaultContext, 4, runs))
|
||||
assert.NoError(t, loadIsRefDeleted(t.Context(), 4, runs))
|
||||
for _, run := range runs {
|
||||
assert.True(t, run.IsRefDeleted)
|
||||
}
|
||||
|
@@ -23,10 +23,10 @@ import (
|
||||
func TestRenderConversation(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
|
||||
pr, _ := issues_model.GetPullRequestByID(db.DefaultContext, 2)
|
||||
_ = pr.LoadIssue(db.DefaultContext)
|
||||
_ = pr.Issue.LoadPoster(db.DefaultContext)
|
||||
_ = pr.Issue.LoadRepo(db.DefaultContext)
|
||||
pr, _ := issues_model.GetPullRequestByID(t.Context(), 2)
|
||||
_ = pr.LoadIssue(t.Context())
|
||||
_ = pr.Issue.LoadPoster(t.Context())
|
||||
_ = pr.Issue.LoadRepo(t.Context())
|
||||
|
||||
run := func(name string, cb func(t *testing.T, ctx *context.Context, resp *httptest.ResponseRecorder)) {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
@@ -73,7 +73,7 @@ func TestRenderConversation(t *testing.T) {
|
||||
assert.Contains(t, resp.Body.String(), `<div id="code-comments-`)
|
||||
})
|
||||
run("diff non-existing review", func(t *testing.T, ctx *context.Context, resp *httptest.ResponseRecorder) {
|
||||
err := db.TruncateBeans(db.DefaultContext, &issues_model.Review{})
|
||||
err := db.TruncateBeans(t.Context(), &issues_model.Review{})
|
||||
assert.NoError(t, err)
|
||||
ctx.Data["ShowOutdatedComments"] = true
|
||||
renderConversation(ctx, preparedComment, "diff")
|
||||
@@ -81,7 +81,7 @@ func TestRenderConversation(t *testing.T) {
|
||||
assert.NotContains(t, resp.Body.String(), `status-page-500`)
|
||||
})
|
||||
run("timeline non-existing review", func(t *testing.T, ctx *context.Context, resp *httptest.ResponseRecorder) {
|
||||
err := db.TruncateBeans(db.DefaultContext, &issues_model.Review{})
|
||||
err := db.TruncateBeans(t.Context(), &issues_model.Review{})
|
||||
assert.NoError(t, err)
|
||||
ctx.Data["ShowOutdatedComments"] = true
|
||||
renderConversation(ctx, preparedComment, "timeline")
|
||||
|
@@ -8,7 +8,6 @@ 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"
|
||||
@@ -231,7 +230,7 @@ func TestAddTeamPost(t *testing.T) {
|
||||
|
||||
AddTeamPost(ctx)
|
||||
|
||||
assert.True(t, repo_service.HasRepository(db.DefaultContext, team, re.ID))
|
||||
assert.True(t, repo_service.HasRepository(t.Context(), team, re.ID))
|
||||
assert.Equal(t, http.StatusSeeOther, ctx.Resp.WrittenStatus())
|
||||
assert.Empty(t, ctx.Flash.ErrorMsg)
|
||||
}
|
||||
@@ -271,7 +270,7 @@ func TestAddTeamPost_NotAllowed(t *testing.T) {
|
||||
|
||||
AddTeamPost(ctx)
|
||||
|
||||
assert.False(t, repo_service.HasRepository(db.DefaultContext, team, re.ID))
|
||||
assert.False(t, repo_service.HasRepository(t.Context(), team, re.ID))
|
||||
assert.Equal(t, http.StatusSeeOther, ctx.Resp.WrittenStatus())
|
||||
assert.NotEmpty(t, ctx.Flash.ErrorMsg)
|
||||
}
|
||||
@@ -312,7 +311,7 @@ func TestAddTeamPost_AddTeamTwice(t *testing.T) {
|
||||
AddTeamPost(ctx)
|
||||
|
||||
AddTeamPost(ctx)
|
||||
assert.True(t, repo_service.HasRepository(db.DefaultContext, team, re.ID))
|
||||
assert.True(t, repo_service.HasRepository(t.Context(), team, re.ID))
|
||||
assert.Equal(t, http.StatusSeeOther, ctx.Resp.WrittenStatus())
|
||||
assert.NotEmpty(t, ctx.Flash.ErrorMsg)
|
||||
}
|
||||
@@ -385,5 +384,5 @@ func TestDeleteTeam(t *testing.T) {
|
||||
|
||||
DeleteTeam(ctx)
|
||||
|
||||
assert.False(t, repo_service.HasRepository(db.DefaultContext, team, re.ID))
|
||||
assert.False(t, repo_service.HasRepository(t.Context(), team, re.ID))
|
||||
}
|
||||
|
@@ -9,7 +9,6 @@ import (
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
@@ -242,11 +241,11 @@ func TestDefaultWikiBranch(t *testing.T) {
|
||||
// repo with no wiki
|
||||
repoWithNoWiki := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
|
||||
assert.False(t, repoWithNoWiki.HasWiki())
|
||||
assert.NoError(t, wiki_service.ChangeDefaultWikiBranch(db.DefaultContext, repoWithNoWiki, "main"))
|
||||
assert.NoError(t, wiki_service.ChangeDefaultWikiBranch(t.Context(), repoWithNoWiki, "main"))
|
||||
|
||||
// repo with wiki
|
||||
assert.NoError(t, repo_model.UpdateRepositoryColsNoAutoTime(
|
||||
db.DefaultContext,
|
||||
t.Context(),
|
||||
&repo_model.Repository{ID: 1, DefaultWikiBranch: "wrong-branch"},
|
||||
"default_wiki_branch",
|
||||
),
|
||||
@@ -261,17 +260,17 @@ func TestDefaultWikiBranch(t *testing.T) {
|
||||
assert.Equal(t, "master", ctx.Repo.Repository.DefaultWikiBranch)
|
||||
|
||||
// invalid branch name should fail
|
||||
assert.Error(t, wiki_service.ChangeDefaultWikiBranch(db.DefaultContext, repo, "the bad name"))
|
||||
assert.Error(t, wiki_service.ChangeDefaultWikiBranch(t.Context(), repo, "the bad name"))
|
||||
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
assert.Equal(t, "master", repo.DefaultWikiBranch)
|
||||
|
||||
// the same branch name, should succeed (actually a no-op)
|
||||
assert.NoError(t, wiki_service.ChangeDefaultWikiBranch(db.DefaultContext, repo, "master"))
|
||||
assert.NoError(t, wiki_service.ChangeDefaultWikiBranch(t.Context(), repo, "master"))
|
||||
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
assert.Equal(t, "master", repo.DefaultWikiBranch)
|
||||
|
||||
// change to another name
|
||||
assert.NoError(t, wiki_service.ChangeDefaultWikiBranch(db.DefaultContext, repo, "main"))
|
||||
assert.NoError(t, wiki_service.ChangeDefaultWikiBranch(t.Context(), repo, "main"))
|
||||
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
assert.Equal(t, "main", repo.DefaultWikiBranch)
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
@@ -28,7 +27,7 @@ func TestArchivedIssues(t *testing.T) {
|
||||
ctx.Req.Form.Set("state", "open")
|
||||
|
||||
// Assume: User 30 has access to two Repos with Issues, one of the Repos being archived.
|
||||
repos, _, _ := repo_model.GetUserRepositories(db.DefaultContext, repo_model.SearchRepoOptions{Actor: ctx.Doer})
|
||||
repos, _, _ := repo_model.GetUserRepositories(t.Context(), repo_model.SearchRepoOptions{Actor: ctx.Doer})
|
||||
assert.Len(t, repos, 3)
|
||||
IsArchived := make(map[int64]bool)
|
||||
NumIssues := make(map[int64]int)
|
||||
|
@@ -8,10 +8,10 @@ import (
|
||||
"strings"
|
||||
|
||||
auth_model "code.gitea.io/gitea/models/auth"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/perm"
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/metrics"
|
||||
"code.gitea.io/gitea/modules/public"
|
||||
@@ -107,7 +107,7 @@ func buildAuthGroup() *auth_service.Group {
|
||||
}
|
||||
group.Add(&auth_service.Session{})
|
||||
|
||||
if setting.IsWindows && auth_model.IsSSPIEnabled(db.DefaultContext) {
|
||||
if setting.IsWindows && auth_model.IsSSPIEnabled(graceful.GetManager().ShutdownContext()) {
|
||||
group.Add(&auth_service.SSPI{}) // it MUST be the last, see the comment of SSPI
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user