diff --git a/cmd/admin.go b/cmd/admin.go
index 70d44c39e047d..52081348a8c98 100644
--- a/cmd/admin.go
+++ b/cmd/admin.go
@@ -493,7 +493,7 @@ func runChangePassword(c *cli.Context) error {
return err
}
- if err = user_model.UpdateUserCols(db.DefaultContext, user, "passwd", "passwd_hash_algo", "salt"); err != nil {
+ if err = user_model.UpdateUserCols(ctx, user, "passwd", "passwd_hash_algo", "salt"); err != nil {
return err
}
diff --git a/modules/context/repo.go b/modules/context/repo.go
index d64380dd95a60..f8b07ffb05a93 100644
--- a/modules/context/repo.go
+++ b/modules/context/repo.go
@@ -15,7 +15,6 @@ import (
"strings"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
unit_model "code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
@@ -256,7 +255,7 @@ func RetrieveBaseRepo(ctx *Context, repo *repo_model.Repository) {
}
ctx.ServerError("GetBaseRepo", err)
return
- } else if err = repo.BaseRepo.GetOwner(db.DefaultContext); err != nil {
+ } else if err = repo.BaseRepo.GetOwner(ctx); err != nil {
ctx.ServerError("BaseRepo.GetOwner", err)
return
}
@@ -273,7 +272,7 @@ func RetrieveTemplateRepo(ctx *Context, repo *repo_model.Repository) {
}
ctx.ServerError("GetTemplateRepo", err)
return
- } else if err = templateRepo.GetOwner(db.DefaultContext); err != nil {
+ } else if err = templateRepo.GetOwner(ctx); err != nil {
ctx.ServerError("TemplateRepo.GetOwner", err)
return
}
@@ -341,7 +340,7 @@ func RedirectToRepo(ctx *Context, redirectRepoID int64) {
func repoAssignment(ctx *Context, repo *repo_model.Repository) {
var err error
- if err = repo.GetOwner(db.DefaultContext); err != nil {
+ if err = repo.GetOwner(ctx); err != nil {
ctx.ServerError("GetOwner", err)
return
}
diff --git a/modules/doctor/checkOldArchives.go b/modules/doctor/checkOldArchives.go
index 6353eaddd28c1..cefb3817bf352 100644
--- a/modules/doctor/checkOldArchives.go
+++ b/modules/doctor/checkOldArchives.go
@@ -17,7 +17,7 @@ import (
func checkOldArchives(ctx context.Context, logger log.Logger, autofix bool) error {
numRepos := 0
numReposUpdated := 0
- err := iterateRepositories(func(repo *repo_model.Repository) error {
+ err := iterateRepositories(ctx, func(repo *repo_model.Repository) error {
if repo.IsEmpty {
return nil
}
diff --git a/modules/doctor/fix16961.go b/modules/doctor/fix16961.go
index e241838068420..92c77ba80f291 100644
--- a/modules/doctor/fix16961.go
+++ b/modules/doctor/fix16961.go
@@ -268,7 +268,7 @@ func fixBrokenRepoUnits16961(ctx context.Context, logger log.Logger, autofix boo
count := 0
err := db.Iterate(
- db.DefaultContext,
+ ctx,
new(RepoUnit),
builder.Gt{
"id": 0,
diff --git a/modules/doctor/mergebase.go b/modules/doctor/mergebase.go
index a655826e1cd69..5a780ed2a215d 100644
--- a/modules/doctor/mergebase.go
+++ b/modules/doctor/mergebase.go
@@ -18,9 +18,9 @@ import (
"xorm.io/builder"
)
-func iteratePRs(repo *repo_model.Repository, each func(*repo_model.Repository, *models.PullRequest) error) error {
+func iteratePRs(ctx context.Context, repo *repo_model.Repository, each func(*repo_model.Repository, *models.PullRequest) error) error {
return db.Iterate(
- db.DefaultContext,
+ ctx,
new(models.PullRequest),
builder.Eq{"base_repo_id": repo.ID},
func(idx int, bean interface{}) error {
@@ -33,9 +33,9 @@ func checkPRMergeBase(ctx context.Context, logger log.Logger, autofix bool) erro
numRepos := 0
numPRs := 0
numPRsUpdated := 0
- err := iterateRepositories(func(repo *repo_model.Repository) error {
+ err := iterateRepositories(ctx, func(repo *repo_model.Repository) error {
numRepos++
- return iteratePRs(repo, func(repo *repo_model.Repository, pr *models.PullRequest) error {
+ return iteratePRs(ctx, repo, func(repo *repo_model.Repository, pr *models.PullRequest) error {
numPRs++
pr.BaseRepo = repo
repoPath := repo.RepoPath()
diff --git a/modules/doctor/misc.go b/modules/doctor/misc.go
index 2f6baa814d583..e96890fbab4d8 100644
--- a/modules/doctor/misc.go
+++ b/modules/doctor/misc.go
@@ -27,9 +27,9 @@ import (
"xorm.io/builder"
)
-func iterateRepositories(each func(*repo_model.Repository) error) error {
+func iterateRepositories(ctx context.Context, each func(*repo_model.Repository) error) error {
err := db.Iterate(
- db.DefaultContext,
+ ctx,
new(repo_model.Repository),
builder.Gt{"id": 0},
func(idx int, bean interface{}) error {
@@ -50,7 +50,7 @@ func checkScriptType(ctx context.Context, logger log.Logger, autofix bool) error
}
func checkHooks(ctx context.Context, logger log.Logger, autofix bool) error {
- if err := iterateRepositories(func(repo *repo_model.Repository) error {
+ if err := iterateRepositories(ctx, func(repo *repo_model.Repository) error {
results, err := repository.CheckDelegateHooks(repo.RepoPath())
if err != nil {
logger.Critical("Unable to check delegate hooks for repo %-v. ERROR: %v", repo, err)
@@ -86,7 +86,7 @@ func checkEnablePushOptions(ctx context.Context, logger log.Logger, autofix bool
numRepos := 0
numNeedUpdate := 0
- if err := iterateRepositories(func(repo *repo_model.Repository) error {
+ if err := iterateRepositories(ctx, func(repo *repo_model.Repository) error {
numRepos++
r, err := git.OpenRepositoryCtx(git.DefaultContext, repo.RepoPath())
if err != nil {
@@ -132,13 +132,13 @@ func checkDaemonExport(ctx context.Context, logger log.Logger, autofix bool) err
logger.Critical("Unable to create cache: %v", err)
return err
}
- if err := iterateRepositories(func(repo *repo_model.Repository) error {
+ if err := iterateRepositories(ctx, func(repo *repo_model.Repository) error {
numRepos++
if owner, has := cache.Get(repo.OwnerID); has {
repo.Owner = owner.(*user_model.User)
} else {
- if err := repo.GetOwner(db.DefaultContext); err != nil {
+ if err := repo.GetOwner(ctx); err != nil {
return err
}
cache.Add(repo.OwnerID, repo.Owner)
diff --git a/modules/repository/repo.go b/modules/repository/repo.go
index 13710bd4abfc0..98388bbd7b2ef 100644
--- a/modules/repository/repo.go
+++ b/modules/repository/repo.go
@@ -156,7 +156,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
}
}
- if err = models.UpdateRepoSize(db.DefaultContext, repo); err != nil {
+ if err = models.UpdateRepoSize(ctx, repo); err != nil {
log.Error("Failed to update size for repository: %v", err)
}
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index 2a189ec9b3f2b..d11f3e65eb62a 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -89,13 +89,15 @@ var (
// AppDataPath is the default path for storing data.
// It maps to ini:"APP_DATA_PATH" and defaults to AppWorkPath + "/data"
AppDataPath string
+ // LocalURL is the url for locally running applications to contact Gitea. It always has a '/' suffix
+ // It maps to ini:"LOCAL_ROOT_URL"
+ LocalURL string
// Server settings
Protocol Scheme
Domain string
HTTPAddr string
HTTPPort string
- LocalURL string
RedirectOtherPort bool
PortToRedirect string
OfflineMode bool
@@ -747,6 +749,7 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
}
}
LocalURL = sec.Key("LOCAL_ROOT_URL").MustString(defaultLocalURL)
+ LocalURL = strings.TrimRight(LocalURL, "/") + "/"
RedirectOtherPort = sec.Key("REDIRECT_OTHER_PORT").MustBool(false)
PortToRedirect = sec.Key("PORT_TO_REDIRECT").MustString("80")
OfflineMode = sec.Key("OFFLINE_MODE").MustBool()
diff --git a/modules/storage/local.go b/modules/storage/local.go
index 8d9aa603d09ec..701b0b1a9f3cc 100644
--- a/modules/storage/local.go
+++ b/modules/storage/local.go
@@ -6,7 +6,6 @@ package storage
import (
"context"
- "errors"
"io"
"net/url"
"os"
@@ -18,8 +17,6 @@ import (
"code.gitea.io/gitea/modules/util"
)
-// ErrLocalPathNotSupported represents an error that path is not supported
-var ErrLocalPathNotSupported = errors.New("local path is not supported")
var _ ObjectStorage = &LocalStorage{}
// LocalStorageType is the type descriptor for local storage
@@ -62,21 +59,18 @@ func NewLocalStorage(ctx context.Context, cfg interface{}) (ObjectStorage, error
}, nil
}
+func (l *LocalStorage) buildLocalPath(p string) string {
+ return filepath.Join(l.dir, path.Clean("/" + strings.ReplaceAll(p, "\\", "/"))[1:])
+}
+
// Open a file
func (l *LocalStorage) Open(path string) (Object, error) {
- if !isLocalPathValid(path) {
- return nil, ErrLocalPathNotSupported
- }
- return os.Open(filepath.Join(l.dir, path))
+ return os.Open(l.buildLocalPath(path))
}
// Save a file
func (l *LocalStorage) Save(path string, r io.Reader, size int64) (int64, error) {
- if !isLocalPathValid(path) {
- return 0, ErrLocalPathNotSupported
- }
-
- p := filepath.Join(l.dir, path)
+ p := l.buildLocalPath(path)
if err := os.MkdirAll(filepath.Dir(p), os.ModePerm); err != nil {
return 0, err
}
@@ -116,24 +110,12 @@ func (l *LocalStorage) Save(path string, r io.Reader, size int64) (int64, error)
// Stat returns the info of the file
func (l *LocalStorage) Stat(path string) (os.FileInfo, error) {
- return os.Stat(filepath.Join(l.dir, path))
-}
-
-func isLocalPathValid(p string) bool {
- a := path.Clean(p)
- if strings.HasPrefix(a, "../") || strings.HasPrefix(a, "..\\") {
- return false
- }
- return a == p
+ return os.Stat(l.buildLocalPath(path))
}
// Delete delete a file
func (l *LocalStorage) Delete(path string) error {
- if !isLocalPathValid(path) {
- return ErrLocalPathNotSupported
- }
- p := filepath.Join(l.dir, path)
- return util.Remove(p)
+ return util.Remove(l.buildLocalPath(path))
}
// URL gets the redirect URL to a file
diff --git a/modules/storage/local_test.go b/modules/storage/local_test.go
index 8714f37f0da65..0749036cb7ef2 100644
--- a/modules/storage/local_test.go
+++ b/modules/storage/local_test.go
@@ -10,36 +10,44 @@ import (
"github.com/stretchr/testify/assert"
)
-func TestLocalPathIsValid(t *testing.T) {
+func TestBuildLocalPath(t *testing.T) {
kases := []struct {
- path string
- valid bool
+ localDir string
+ path string
+ expected string
}{
{
+ "a",
+ "0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
"a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
- true,
},
{
- "../a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
- false,
+ "a",
+ "../0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
+ "a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
},
{
- "a\\0\\a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
- true,
+ "a",
+ "0\\a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
+ "a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
},
{
- "b/../a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
- false,
+ "b",
+ "a/../0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
+ "b/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
},
{
- "..\\a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
- false,
+ "b",
+ "a\\..\\0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
+ "b/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
},
}
for _, k := range kases {
t.Run(k.path, func(t *testing.T) {
- assert.EqualValues(t, k.valid, isLocalPathValid(k.path))
+ l := LocalStorage{dir: k.localDir}
+
+ assert.EqualValues(t, k.expected, l.buildLocalPath(k.path))
})
}
}
diff --git a/modules/storage/minio.go b/modules/storage/minio.go
index f35f4092a9967..f7b42d674c044 100644
--- a/modules/storage/minio.go
+++ b/modules/storage/minio.go
@@ -117,7 +117,7 @@ func NewMinioStorage(ctx context.Context, cfg interface{}) (ObjectStorage, error
}
func (m *MinioStorage) buildMinioPath(p string) string {
- return strings.TrimPrefix(path.Join(m.basePath, p), "/")
+ return strings.TrimPrefix(path.Join(m.basePath, path.Clean("/" + strings.ReplaceAll(p, "\\", "/"))[1:]), "/")
}
// Open open a file
diff --git a/modules/test/context_tests.go b/modules/test/context_tests.go
index e5cea26eb9ca5..e43f0429e7378 100644
--- a/modules/test/context_tests.go
+++ b/modules/test/context_tests.go
@@ -14,7 +14,6 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
@@ -87,7 +86,7 @@ func LoadUser(t *testing.T, ctx *context.Context, userID int64) {
// LoadGitRepo load a git repo into a test context. Requires that ctx.Repo has
// already been populated.
func LoadGitRepo(t *testing.T, ctx *context.Context) {
- assert.NoError(t, ctx.Repo.Repository.GetOwner(db.DefaultContext))
+ assert.NoError(t, ctx.Repo.Repository.GetOwner(ctx))
var err error
ctx.Repo.GitRepo, err = git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.RepoPath())
assert.NoError(t, err)
diff --git a/options/locale/locale_pl-PL.ini b/options/locale/locale_pl-PL.ini
index 7f54c18c31a95..f50a25582b8d3 100644
--- a/options/locale/locale_pl-PL.ini
+++ b/options/locale/locale_pl-PL.ini
@@ -625,7 +625,7 @@ ssh_key_verify=Weryfikuj
ssh_token_required=Musisz podać podpis poniższego tokenu
ssh_token=Token
ssh_token_help=Możesz wygenerować podpis używając:
-ssh_token_code=echo -n "%s" | ssh-keygen -Y znak -n gitea -f /ścieżka_do_twojego_klucza_publicznego
+ssh_token_code=echo -n "%s" | ssh-keygen -Y sign -n gitea -f /ścieżka_do_twojego_klucza_publicznego
ssh_token_signature=Wzmocniony podpis SSH
key_signature_ssh_placeholder=Zaczyna się od '-----BEGIN SSH SIGNATURE-----'
verify_ssh_key_success=Klucz SSH '%s' został zweryfikowany.
diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go
index a920b49a8490e..63cc0e9d39a64 100644
--- a/routers/api/v1/org/org.go
+++ b/routers/api/v1/org/org.go
@@ -346,7 +346,7 @@ func Edit(ctx *context.APIContext) {
if form.RepoAdminChangeTeamAccess != nil {
org.RepoAdminChangeTeamAccess = *form.RepoAdminChangeTeamAccess
}
- if err := user_model.UpdateUserCols(db.DefaultContext, org.AsUser(),
+ if err := user_model.UpdateUserCols(ctx, org.AsUser(),
"full_name", "description", "website", "location",
"visibility", "repo_admin_change_team_access",
); err != nil {
diff --git a/routers/api/v1/repo/issue_stopwatch.go b/routers/api/v1/repo/issue_stopwatch.go
index 19ee983b84715..382f294346bb7 100644
--- a/routers/api/v1/repo/issue_stopwatch.go
+++ b/routers/api/v1/repo/issue_stopwatch.go
@@ -9,7 +9,6 @@ import (
"net/http"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/routers/api/v1/utils"
@@ -56,7 +55,7 @@ func StartIssueStopwatch(ctx *context.APIContext) {
return
}
- if err := models.CreateIssueStopwatch(db.DefaultContext, ctx.Doer, issue); err != nil {
+ if err := models.CreateIssueStopwatch(ctx, ctx.Doer, issue); err != nil {
ctx.Error(http.StatusInternalServerError, "CreateOrStopIssueStopwatch", err)
return
}
@@ -105,7 +104,7 @@ func StopIssueStopwatch(ctx *context.APIContext) {
return
}
- if err := models.FinishIssueStopwatch(db.DefaultContext, ctx.Doer, issue); err != nil {
+ if err := models.FinishIssueStopwatch(ctx, ctx.Doer, issue); err != nil {
ctx.Error(http.StatusInternalServerError, "CreateOrStopIssueStopwatch", err)
return
}
diff --git a/routers/api/v1/repo/key.go b/routers/api/v1/repo/key.go
index 568f92d7fbcb3..0c780eb97d0c6 100644
--- a/routers/api/v1/repo/key.go
+++ b/routers/api/v1/repo/key.go
@@ -87,7 +87,7 @@ func ListDeployKeys(ctx *context.APIContext) {
Fingerprint: ctx.FormString("fingerprint"),
}
- keys, err := asymkey_model.ListDeployKeys(db.DefaultContext, opts)
+ keys, err := asymkey_model.ListDeployKeys(ctx, opts)
if err != nil {
ctx.InternalServerError(err)
return
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index 3bb32d75d2e5d..d266b3f4f3c2d 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -217,7 +217,7 @@ func Search(ctx *context.APIContext) {
results := make([]*api.Repository, len(repos))
for i, repo := range repos {
- if err = repo.GetOwner(db.DefaultContext); err != nil {
+ if err = repo.GetOwner(ctx); err != nil {
ctx.JSON(http.StatusInternalServerError, api.SearchError{
OK: false,
Error: err.Error(),
diff --git a/routers/api/v1/user/gpg_key.go b/routers/api/v1/user/gpg_key.go
index 5e98b21fb802d..83122355d017e 100644
--- a/routers/api/v1/user/gpg_key.go
+++ b/routers/api/v1/user/gpg_key.go
@@ -18,7 +18,7 @@ import (
)
func listGPGKeys(ctx *context.APIContext, uid int64, listOptions db.ListOptions) {
- keys, err := asymkey_model.ListGPGKeys(db.DefaultContext, uid, listOptions)
+ keys, err := asymkey_model.ListGPGKeys(ctx, uid, listOptions)
if err != nil {
ctx.Error(http.StatusInternalServerError, "ListGPGKeys", err)
return
diff --git a/routers/api/v1/user/repo.go b/routers/api/v1/user/repo.go
index 2b933bea150da..683c300953f58 100644
--- a/routers/api/v1/user/repo.go
+++ b/routers/api/v1/user/repo.go
@@ -8,7 +8,6 @@ import (
"net/http"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/perm"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
@@ -124,7 +123,7 @@ func ListMyRepos(ctx *context.APIContext) {
results := make([]*api.Repository, len(repos))
for i, repo := range repos {
- if err = repo.GetOwner(db.DefaultContext); err != nil {
+ if err = repo.GetOwner(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "GetOwner", err)
return
}
diff --git a/routers/api/v1/utils/hook.go b/routers/api/v1/utils/hook.go
index 1f0a35ce22aa3..d4d4e05524a3b 100644
--- a/routers/api/v1/utils/hook.go
+++ b/routers/api/v1/utils/hook.go
@@ -9,7 +9,6 @@ import (
"net/http"
"strings"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/webhook"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
@@ -164,7 +163,7 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, orgID, repoID
if err := w.UpdateEvent(); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateEvent", err)
return nil, false
- } else if err := webhook.CreateWebhook(db.DefaultContext, w); err != nil {
+ } else if err := webhook.CreateWebhook(ctx, w); err != nil {
ctx.Error(http.StatusInternalServerError, "CreateWebhook", err)
return nil, false
}
diff --git a/routers/web/auth/auth.go b/routers/web/auth/auth.go
index 556fd26d01b05..ab538f0e5f603 100644
--- a/routers/web/auth/auth.go
+++ b/routers/web/auth/auth.go
@@ -107,7 +107,7 @@ func resetLocale(ctx *context.Context, u *user_model.User) error {
// If the user does not have a locale set, we save the current one.
if len(u.Language) == 0 {
u.Language = ctx.Locale.Language()
- if err := user_model.UpdateUserCols(db.DefaultContext, u, "language"); err != nil {
+ if err := user_model.UpdateUserCols(ctx, u, "language"); err != nil {
return err
}
}
@@ -333,7 +333,7 @@ func handleSignInFull(ctx *context.Context, u *user_model.User, remember, obeyRe
// If the user does not have a locale set, we save the current one.
if len(u.Language) == 0 {
u.Language = ctx.Locale.Language()
- if err := user_model.UpdateUserCols(db.DefaultContext, u, "language"); err != nil {
+ if err := user_model.UpdateUserCols(ctx, u, "language"); err != nil {
ctx.ServerError("UpdateUserCols Language", fmt.Errorf("Error updating user language [user: %d, locale: %s]", u.ID, u.Language))
return setting.AppSubURL + "/"
}
@@ -350,7 +350,7 @@ func handleSignInFull(ctx *context.Context, u *user_model.User, remember, obeyRe
// Register last login
u.SetLastLogin()
- if err := user_model.UpdateUserCols(db.DefaultContext, u, "last_login_unix"); err != nil {
+ if err := user_model.UpdateUserCols(ctx, u, "last_login_unix"); err != nil {
ctx.ServerError("UpdateUserCols", err)
return setting.AppSubURL + "/"
}
@@ -606,7 +606,7 @@ func handleUserCreated(ctx *context.Context, u *user_model.User, gothUser *goth.
u.IsAdmin = true
u.IsActive = true
u.SetLastLogin()
- if err := user_model.UpdateUserCols(db.DefaultContext, u, "is_admin", "is_active", "last_login_unix"); err != nil {
+ if err := user_model.UpdateUserCols(ctx, u, "is_admin", "is_active", "last_login_unix"); err != nil {
ctx.ServerError("UpdateUser", err)
return
}
@@ -733,7 +733,7 @@ func handleAccountActivation(ctx *context.Context, user *user_model.User) {
ctx.ServerError("UpdateUser", err)
return
}
- if err := user_model.UpdateUserCols(db.DefaultContext, user, "is_active", "rands"); err != nil {
+ if err := user_model.UpdateUserCols(ctx, user, "is_active", "rands"); err != nil {
if user_model.IsErrUserNotExist(err) {
ctx.NotFound("UpdateUserCols", err)
} else {
diff --git a/routers/web/auth/oauth.go b/routers/web/auth/oauth.go
index 83b58d6cbf3f8..847af52bdbe82 100644
--- a/routers/web/auth/oauth.go
+++ b/routers/web/auth/oauth.go
@@ -16,7 +16,6 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/auth"
- "code.gitea.io/gitea/models/db"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
@@ -1021,7 +1020,7 @@ func handleOAuth2SignIn(ctx *context.Context, source *auth.Source, u *user_model
cols = append(cols, "is_admin", "is_restricted")
}
- if err := user_model.UpdateUserCols(db.DefaultContext, u, cols...); err != nil {
+ if err := user_model.UpdateUserCols(ctx, u, cols...); err != nil {
ctx.ServerError("UpdateUserCols", err)
return
}
@@ -1048,7 +1047,7 @@ func handleOAuth2SignIn(ctx *context.Context, source *auth.Source, u *user_model
changed := setUserGroupClaims(source, u, &gothUser)
if changed {
- if err := user_model.UpdateUserCols(db.DefaultContext, u, "is_admin", "is_restricted"); err != nil {
+ if err := user_model.UpdateUserCols(ctx, u, "is_admin", "is_restricted"); err != nil {
ctx.ServerError("UpdateUserCols", err)
return
}
diff --git a/routers/web/auth/password.go b/routers/web/auth/password.go
index 8e309ebb1a057..d7bf67cffb6f0 100644
--- a/routers/web/auth/password.go
+++ b/routers/web/auth/password.go
@@ -9,7 +9,6 @@ import (
"net/http"
"code.gitea.io/gitea/models/auth"
- "code.gitea.io/gitea/models/db"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
@@ -232,7 +231,7 @@ func ResetPasswdPost(ctx *context.Context) {
return
}
u.MustChangePassword = false
- if err := user_model.UpdateUserCols(db.DefaultContext, u, "must_change_password", "passwd", "passwd_hash_algo", "rands", "salt"); err != nil {
+ if err := user_model.UpdateUserCols(ctx, u, "must_change_password", "passwd", "passwd_hash_algo", "rands", "salt"); err != nil {
ctx.ServerError("UpdateUser", err)
return
}
@@ -327,7 +326,7 @@ func MustChangePasswordPost(ctx *context.Context) {
u.MustChangePassword = false
- if err := user_model.UpdateUserCols(db.DefaultContext, u, "must_change_password", "passwd", "passwd_hash_algo", "salt"); err != nil {
+ if err := user_model.UpdateUserCols(ctx, u, "must_change_password", "passwd", "passwd_hash_algo", "salt"); err != nil {
ctx.ServerError("UpdateUser", err)
return
}
diff --git a/routers/web/base.go b/routers/web/base.go
index f7eb003cc40d6..3e873c5826d00 100644
--- a/routers/web/base.go
+++ b/routers/web/base.go
@@ -11,7 +11,6 @@ import (
"net/http"
"os"
"path"
- "path/filepath"
"strings"
"code.gitea.io/gitea/modules/context"
@@ -28,6 +27,7 @@ import (
)
func storageHandler(storageSetting setting.Storage, prefix string, objStore storage.ObjectStorage) func(next http.Handler) http.Handler {
+ prefix = strings.Trim(prefix, "/")
funcInfo := routing.GetFuncInfo(storageHandler, prefix)
return func(next http.Handler) http.Handler {
if storageSetting.ServeDirect {
@@ -37,13 +37,15 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor
return
}
- if !strings.HasPrefix(req.URL.RequestURI(), "/"+prefix) {
+ if !strings.HasPrefix(req.URL.Path, "/"+prefix+"/") {
next.ServeHTTP(w, req)
return
}
routing.UpdateFuncInfo(req.Context(), funcInfo)
- rPath := strings.TrimPrefix(req.URL.RequestURI(), "/"+prefix)
+ rPath := strings.TrimPrefix(req.URL.Path, "/"+prefix+"/")
+ rPath = path.Clean("/" + strings.ReplaceAll(rPath, "\\", "/"))[1:]
+
u, err := objStore.URL(rPath, path.Base(rPath))
if err != nil {
if os.IsNotExist(err) || errors.Is(err, os.ErrNotExist) {
@@ -55,11 +57,12 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor
http.Error(w, fmt.Sprintf("Error whilst getting URL for %s %s", prefix, rPath), 500)
return
}
+
http.Redirect(
w,
req,
u.String(),
- 301,
+ http.StatusMovedPermanently,
)
})
}
@@ -70,22 +73,18 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor
return
}
- prefix := strings.Trim(prefix, "/")
-
- if !strings.HasPrefix(req.URL.EscapedPath(), "/"+prefix+"/") {
+ if !strings.HasPrefix(req.URL.Path, "/"+prefix+"/") {
next.ServeHTTP(w, req)
return
}
routing.UpdateFuncInfo(req.Context(), funcInfo)
- rPath := strings.TrimPrefix(req.URL.EscapedPath(), "/"+prefix+"/")
- rPath = strings.TrimPrefix(rPath, "/")
+ rPath := strings.TrimPrefix(req.URL.Path, "/"+prefix+"/")
+ rPath = path.Clean("/" + strings.ReplaceAll(rPath, "\\", "/"))[1:]
if rPath == "" {
http.Error(w, "file not found", 404)
return
}
- rPath = path.Clean("/" + filepath.ToSlash(rPath))
- rPath = rPath[1:]
fi, err := objStore.Stat(rPath)
if err == nil && httpcache.HandleTimeCache(req, w, fi) {
diff --git a/routers/web/org/org_labels.go b/routers/web/org/org_labels.go
index 9cc9a92507fbf..0ec6c3ce3b672 100644
--- a/routers/web/org/org_labels.go
+++ b/routers/web/org/org_labels.go
@@ -100,7 +100,7 @@ func InitializeLabels(ctx *context.Context) {
return
}
- if err := models.InitializeLabels(db.DefaultContext, ctx.Org.Organization.ID, form.TemplateName, true); err != nil {
+ if err := models.InitializeLabels(ctx, ctx.Org.Organization.ID, form.TemplateName, true); err != nil {
if models.IsErrIssueLabelTemplateLoad(err) {
originalErr := err.(models.ErrIssueLabelTemplateLoad).OriginalError
ctx.Flash.Error(ctx.Tr("repo.issues.label_templates.fail_to_load_file", form.TemplateName, originalErr))
diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go
index c2ae86d5d0221..23ec662cfae5b 100644
--- a/routers/web/repo/compare.go
+++ b/routers/web/repo/compare.go
@@ -18,7 +18,6 @@ import (
"strings"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
@@ -269,7 +268,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
}
return nil
}
- if err := ci.HeadRepo.GetOwner(db.DefaultContext); err != nil {
+ if err := ci.HeadRepo.GetOwner(ctx); err != nil {
if user_model.IsErrUserNotExist(err) {
ctx.NotFound("GetUserByName", nil)
} else {
diff --git a/routers/web/repo/http.go b/routers/web/repo/http.go
index b706330d6d31c..0207cd7685e53 100644
--- a/routers/web/repo/http.go
+++ b/routers/web/repo/http.go
@@ -21,7 +21,6 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/auth"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/perm"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
@@ -159,7 +158,7 @@ func httpBase(ctx *context.Context) (h *serviceHandler) {
// don't allow anonymous pulls if organization is not public
if isPublicPull {
- if err := repo.GetOwner(db.DefaultContext); err != nil {
+ if err := repo.GetOwner(ctx); err != nil {
ctx.ServerError("GetOwner", err)
return
}
diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go
index 18f352265fc95..adf7e93eac2fe 100644
--- a/routers/web/repo/issue.go
+++ b/routers/web/repo/issue.go
@@ -843,12 +843,19 @@ func NewIssue(ctx *context.Context) {
func NewIssueChooseTemplate(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.issues.new")
ctx.Data["PageIsIssueList"] = true
- ctx.Data["milestone"] = ctx.FormInt64("milestone")
issueTemplates := ctx.IssueTemplatesFromDefaultBranch()
- ctx.Data["NewIssueChooseTemplate"] = len(issueTemplates) > 0
ctx.Data["IssueTemplates"] = issueTemplates
+ if len(issueTemplates) == 0 {
+ // The "issues/new" and "issues/new/choose" share the same query parameters "project" and "milestone", if no template here, just redirect to the "issues/new" page with these parameters.
+ ctx.Redirect(fmt.Sprintf("%s/issues/new?%s", ctx.Repo.Repository.HTMLURL(), ctx.Req.URL.RawQuery), http.StatusSeeOther)
+ return
+ }
+
+ ctx.Data["milestone"] = ctx.FormInt64("milestone")
+ ctx.Data["project"] = ctx.FormInt64("project")
+
ctx.HTML(http.StatusOK, tplIssueChoose)
}
@@ -1944,7 +1951,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
}
if reviewID < 0 {
// negative reviewIDs represent team requests
- if err := issue.Repo.GetOwner(db.DefaultContext); err != nil {
+ if err := issue.Repo.GetOwner(ctx); err != nil {
ctx.ServerError("issue.Repo.GetOwner", err)
return
}
diff --git a/routers/web/repo/issue_content_history.go b/routers/web/repo/issue_content_history.go
index 0d3b2366892ab..21b22aa7109ec 100644
--- a/routers/web/repo/issue_content_history.go
+++ b/routers/web/repo/issue_content_history.go
@@ -12,7 +12,6 @@ import (
"strings"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
issuesModel "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/context"
@@ -32,7 +31,7 @@ func GetContentHistoryOverview(ctx *context.Context) {
}
lang := ctx.Locale.Language()
- editedHistoryCountMap, _ := issuesModel.QueryIssueContentHistoryEditedCountMap(db.DefaultContext, issue.ID)
+ editedHistoryCountMap, _ := issuesModel.QueryIssueContentHistoryEditedCountMap(ctx, issue.ID)
ctx.JSON(http.StatusOK, map[string]interface{}{
"i18n": map[string]interface{}{
"textEdited": i18n.Tr(lang, "repo.issues.content_history.edited"),
@@ -52,7 +51,7 @@ func GetContentHistoryList(ctx *context.Context) {
return
}
- items, _ := issuesModel.FetchIssueContentHistoryList(db.DefaultContext, issue.ID, commentID)
+ items, _ := issuesModel.FetchIssueContentHistoryList(ctx, issue.ID, commentID)
// render history list to HTML for frontend dropdown items: (name, value)
// name is HTML of "avatar + userName + userAction + timeSince"
@@ -119,7 +118,7 @@ func GetContentHistoryDetail(ctx *context.Context) {
}
historyID := ctx.FormInt64("history_id")
- history, prevHistory, err := issuesModel.GetIssueContentHistoryAndPrev(db.DefaultContext, historyID)
+ history, prevHistory, err := issuesModel.GetIssueContentHistoryAndPrev(ctx, historyID)
if err != nil {
ctx.JSON(http.StatusNotFound, map[string]interface{}{
"message": "Can not find the content history",
@@ -196,7 +195,7 @@ func SoftDeleteContentHistory(ctx *context.Context) {
return
}
}
- if history, err = issuesModel.GetIssueContentHistoryByID(db.DefaultContext, historyID); err != nil {
+ if history, err = issuesModel.GetIssueContentHistoryByID(ctx, historyID); err != nil {
log.Error("can not get issue content history %v. err=%v", historyID, err)
return
}
@@ -209,7 +208,7 @@ func SoftDeleteContentHistory(ctx *context.Context) {
return
}
- err = issuesModel.SoftDeleteIssueContentHistory(db.DefaultContext, historyID)
+ err = issuesModel.SoftDeleteIssueContentHistory(ctx, historyID)
log.Debug("soft delete issue content history. issue=%d, comment=%d, history=%d", issue.ID, commentID, historyID)
ctx.JSON(http.StatusOK, map[string]interface{}{
"ok": err == nil,
diff --git a/routers/web/repo/issue_label.go b/routers/web/repo/issue_label.go
index d1470910d44c4..ec04fa16609dd 100644
--- a/routers/web/repo/issue_label.go
+++ b/routers/web/repo/issue_label.go
@@ -39,7 +39,7 @@ func InitializeLabels(ctx *context.Context) {
return
}
- if err := models.InitializeLabels(db.DefaultContext, ctx.Repo.Repository.ID, form.TemplateName, false); err != nil {
+ if err := models.InitializeLabels(ctx, ctx.Repo.Repository.ID, form.TemplateName, false); err != nil {
if models.IsErrIssueLabelTemplateLoad(err) {
originalErr := err.(models.ErrIssueLabelTemplateLoad).OriginalError
ctx.Flash.Error(ctx.Tr("repo.issues.label_templates.fail_to_load_file", form.TemplateName, originalErr))
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go
index 05c1ab7451af9..a4edfd9ee42ef 100644
--- a/routers/web/repo/pull.go
+++ b/routers/web/repo/pull.go
@@ -99,7 +99,7 @@ func getForkRepository(ctx *context.Context) *repo_model.Repository {
return nil
}
- if err := forkRepo.GetOwner(db.DefaultContext); err != nil {
+ if err := forkRepo.GetOwner(ctx); err != nil {
ctx.ServerError("GetOwner", err)
return nil
}
@@ -1255,7 +1255,7 @@ func CleanUpPullRequest(ctx *context.Context) {
} else if err = pr.LoadBaseRepo(); err != nil {
ctx.ServerError("LoadBaseRepo", err)
return
- } else if err = pr.HeadRepo.GetOwner(db.DefaultContext); err != nil {
+ } else if err = pr.HeadRepo.GetOwner(ctx); err != nil {
ctx.ServerError("HeadRepo.GetOwner", err)
return
}
diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go
index 7e08a8af00715..4e07d47203bf8 100644
--- a/routers/web/repo/repo.go
+++ b/routers/web/repo/repo.go
@@ -353,7 +353,7 @@ func RedirectDownload(ctx *context.Context) {
)
tagNames := []string{vTag}
curRepo := ctx.Repo.Repository
- releases, err := models.GetReleasesByRepoIDAndNames(db.DefaultContext, curRepo.ID, tagNames)
+ releases, err := models.GetReleasesByRepoIDAndNames(ctx, curRepo.ID, tagNames)
if err != nil {
if repo_model.IsErrAttachmentNotExist(err) {
ctx.Error(http.StatusNotFound)
@@ -394,7 +394,7 @@ func Download(ctx *context.Context) {
return
}
- archiver, err := repo_model.GetRepoArchiver(db.DefaultContext, aReq.RepoID, aReq.Type, aReq.CommitID)
+ archiver, err := repo_model.GetRepoArchiver(ctx, aReq.RepoID, aReq.Type, aReq.CommitID)
if err != nil {
ctx.ServerError("models.GetRepoArchiver", err)
return
@@ -424,7 +424,7 @@ func Download(ctx *context.Context) {
return
}
times++
- archiver, err = repo_model.GetRepoArchiver(db.DefaultContext, aReq.RepoID, aReq.Type, aReq.CommitID)
+ archiver, err = repo_model.GetRepoArchiver(ctx, aReq.RepoID, aReq.Type, aReq.CommitID)
if err != nil {
ctx.ServerError("archiver_service.StartArchive", err)
return
@@ -480,7 +480,7 @@ func InitiateDownload(ctx *context.Context) {
return
}
- archiver, err := repo_model.GetRepoArchiver(db.DefaultContext, aReq.RepoID, aReq.Type, aReq.CommitID)
+ archiver, err := repo_model.GetRepoArchiver(ctx, aReq.RepoID, aReq.Type, aReq.CommitID)
if err != nil {
ctx.ServerError("archiver_service.StartArchive", err)
return
diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go
index 8c8f627fad25e..e3a424ea41c2b 100644
--- a/routers/web/repo/setting.go
+++ b/routers/web/repo/setting.go
@@ -595,7 +595,7 @@ func SettingsPost(ctx *context.Context) {
ctx.Error(http.StatusNotFound)
return
}
- if err := repo.GetOwner(db.DefaultContext); err != nil {
+ if err := repo.GetOwner(ctx); err != nil {
ctx.ServerError("Convert Fork", err)
return
}
@@ -1055,7 +1055,7 @@ func DeployKeys(ctx *context.Context) {
ctx.Data["PageIsSettingsKeys"] = true
ctx.Data["DisableSSH"] = setting.SSH.Disabled
- keys, err := asymkey_model.ListDeployKeys(db.DefaultContext, &asymkey_model.ListDeployKeysOptions{RepoID: ctx.Repo.Repository.ID})
+ keys, err := asymkey_model.ListDeployKeys(ctx, &asymkey_model.ListDeployKeysOptions{RepoID: ctx.Repo.Repository.ID})
if err != nil {
ctx.ServerError("ListDeployKeys", err)
return
@@ -1071,7 +1071,7 @@ func DeployKeysPost(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.deploy_keys")
ctx.Data["PageIsSettingsKeys"] = true
- keys, err := asymkey_model.ListDeployKeys(db.DefaultContext, &asymkey_model.ListDeployKeysOptions{RepoID: ctx.Repo.Repository.ID})
+ keys, err := asymkey_model.ListDeployKeys(ctx, &asymkey_model.ListDeployKeysOptions{RepoID: ctx.Repo.Repository.ID})
if err != nil {
ctx.ServerError("ListDeployKeys", err)
return
diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go
index 3bdcefa4c40e4..7fc178cf31164 100644
--- a/routers/web/repo/view.go
+++ b/routers/web/repo/view.go
@@ -884,7 +884,7 @@ func renderCode(ctx *context.Context) {
ctx.ServerError("UpdateRepositoryCols", err)
return
}
- if err = models.UpdateRepoSize(db.DefaultContext, ctx.Repo.Repository); err != nil {
+ if err = models.UpdateRepoSize(ctx, ctx.Repo.Repository); err != nil {
ctx.ServerError("UpdateRepoSize", err)
return
}
@@ -1017,7 +1017,7 @@ func Forks(ctx *context.Context) {
}
for _, fork := range forks {
- if err = fork.GetOwner(db.DefaultContext); err != nil {
+ if err = fork.GetOwner(ctx); err != nil {
ctx.ServerError("GetOwner", err)
return
}
diff --git a/routers/web/repo/webhook.go b/routers/web/repo/webhook.go
index d457bcb190b42..7ffea1724af46 100644
--- a/routers/web/repo/webhook.go
+++ b/routers/web/repo/webhook.go
@@ -13,7 +13,6 @@ import (
"path"
"strings"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/perm"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/models/webhook"
@@ -227,7 +226,7 @@ func GiteaHooksNewPost(ctx *context.Context) {
if err := w.UpdateEvent(); err != nil {
ctx.ServerError("UpdateEvent", err)
return
- } else if err := webhook.CreateWebhook(db.DefaultContext, w); err != nil {
+ } else if err := webhook.CreateWebhook(ctx, w); err != nil {
ctx.ServerError("CreateWebhook", err)
return
}
@@ -281,7 +280,7 @@ func newGogsWebhookPost(ctx *context.Context, form forms.NewGogshookForm, kind w
if err := w.UpdateEvent(); err != nil {
ctx.ServerError("UpdateEvent", err)
return
- } else if err := webhook.CreateWebhook(db.DefaultContext, w); err != nil {
+ } else if err := webhook.CreateWebhook(ctx, w); err != nil {
ctx.ServerError("CreateWebhook", err)
return
}
@@ -333,7 +332,7 @@ func DiscordHooksNewPost(ctx *context.Context) {
if err := w.UpdateEvent(); err != nil {
ctx.ServerError("UpdateEvent", err)
return
- } else if err := webhook.CreateWebhook(db.DefaultContext, w); err != nil {
+ } else if err := webhook.CreateWebhook(ctx, w); err != nil {
ctx.ServerError("CreateWebhook", err)
return
}
@@ -376,7 +375,7 @@ func DingtalkHooksNewPost(ctx *context.Context) {
if err := w.UpdateEvent(); err != nil {
ctx.ServerError("UpdateEvent", err)
return
- } else if err := webhook.CreateWebhook(db.DefaultContext, w); err != nil {
+ } else if err := webhook.CreateWebhook(ctx, w); err != nil {
ctx.ServerError("CreateWebhook", err)
return
}
@@ -428,7 +427,7 @@ func TelegramHooksNewPost(ctx *context.Context) {
if err := w.UpdateEvent(); err != nil {
ctx.ServerError("UpdateEvent", err)
return
- } else if err := webhook.CreateWebhook(db.DefaultContext, w); err != nil {
+ } else if err := webhook.CreateWebhook(ctx, w); err != nil {
ctx.ServerError("CreateWebhook", err)
return
}
@@ -483,7 +482,7 @@ func MatrixHooksNewPost(ctx *context.Context) {
if err := w.UpdateEvent(); err != nil {
ctx.ServerError("UpdateEvent", err)
return
- } else if err := webhook.CreateWebhook(db.DefaultContext, w); err != nil {
+ } else if err := webhook.CreateWebhook(ctx, w); err != nil {
ctx.ServerError("CreateWebhook", err)
return
}
@@ -526,7 +525,7 @@ func MSTeamsHooksNewPost(ctx *context.Context) {
if err := w.UpdateEvent(); err != nil {
ctx.ServerError("UpdateEvent", err)
return
- } else if err := webhook.CreateWebhook(db.DefaultContext, w); err != nil {
+ } else if err := webhook.CreateWebhook(ctx, w); err != nil {
ctx.ServerError("CreateWebhook", err)
return
}
@@ -586,7 +585,7 @@ func SlackHooksNewPost(ctx *context.Context) {
if err := w.UpdateEvent(); err != nil {
ctx.ServerError("UpdateEvent", err)
return
- } else if err := webhook.CreateWebhook(db.DefaultContext, w); err != nil {
+ } else if err := webhook.CreateWebhook(ctx, w); err != nil {
ctx.ServerError("CreateWebhook", err)
return
}
@@ -629,7 +628,7 @@ func FeishuHooksNewPost(ctx *context.Context) {
if err := w.UpdateEvent(); err != nil {
ctx.ServerError("UpdateEvent", err)
return
- } else if err := webhook.CreateWebhook(db.DefaultContext, w); err != nil {
+ } else if err := webhook.CreateWebhook(ctx, w); err != nil {
ctx.ServerError("CreateWebhook", err)
return
}
@@ -673,7 +672,7 @@ func WechatworkHooksNewPost(ctx *context.Context) {
if err := w.UpdateEvent(); err != nil {
ctx.ServerError("UpdateEvent", err)
return
- } else if err := webhook.CreateWebhook(db.DefaultContext, w); err != nil {
+ } else if err := webhook.CreateWebhook(ctx, w); err != nil {
ctx.ServerError("CreateWebhook", err)
return
}
@@ -726,7 +725,7 @@ func PackagistHooksNewPost(ctx *context.Context) {
if err := w.UpdateEvent(); err != nil {
ctx.ServerError("UpdateEvent", err)
return
- } else if err := webhook.CreateWebhook(db.DefaultContext, w); err != nil {
+ } else if err := webhook.CreateWebhook(ctx, w); err != nil {
ctx.ServerError("CreateWebhook", err)
return
}
diff --git a/routers/web/user/home.go b/routers/web/user/home.go
index 7489f08b17512..afdc344b69ea2 100644
--- a/routers/web/user/home.go
+++ b/routers/web/user/home.go
@@ -74,7 +74,7 @@ func Dashboard(ctx *context.Context) {
ctx.Data["Title"] = ctxUser.DisplayName() + " - " + ctx.Tr("dashboard")
ctx.Data["PageIsDashboard"] = true
ctx.Data["PageIsNews"] = true
- cnt, _ := models.GetOrganizationCount(db.DefaultContext, ctxUser)
+ cnt, _ := models.GetOrganizationCount(ctx, ctxUser)
ctx.Data["UserOrgsCount"] = cnt
var uid int64
@@ -730,7 +730,7 @@ func ShowSSHKeys(ctx *context.Context, uid int64) {
// ShowGPGKeys output all the public GPG keys of user by uid
func ShowGPGKeys(ctx *context.Context, uid int64) {
- keys, err := asymkey_model.ListGPGKeys(db.DefaultContext, uid, db.ListOptions{})
+ keys, err := asymkey_model.ListGPGKeys(ctx, uid, db.ListOptions{})
if err != nil {
ctx.ServerError("ListGPGKeys", err)
return
diff --git a/routers/web/user/setting/account.go b/routers/web/user/setting/account.go
index 468d5ca6512ef..a5854991a00e2 100644
--- a/routers/web/user/setting/account.go
+++ b/routers/web/user/setting/account.go
@@ -11,7 +11,6 @@ import (
"time"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
@@ -75,7 +74,7 @@ func AccountPost(ctx *context.Context) {
ctx.ServerError("UpdateUser", err)
return
}
- if err := user_model.UpdateUserCols(db.DefaultContext, ctx.Doer, "salt", "passwd_hash_algo", "passwd"); err != nil {
+ if err := user_model.UpdateUserCols(ctx, ctx.Doer, "salt", "passwd_hash_algo", "passwd"); err != nil {
ctx.ServerError("UpdateUser", err)
return
}
diff --git a/routers/web/user/setting/keys.go b/routers/web/user/setting/keys.go
index 2cc627ecdeaa1..a8d07ea47a9d4 100644
--- a/routers/web/user/setting/keys.go
+++ b/routers/web/user/setting/keys.go
@@ -269,7 +269,7 @@ func loadKeysData(ctx *context.Context) {
}
ctx.Data["ExternalKeys"] = externalKeys
- gpgkeys, err := asymkey_model.ListGPGKeys(db.DefaultContext, ctx.Doer.ID, db.ListOptions{})
+ gpgkeys, err := asymkey_model.ListGPGKeys(ctx, ctx.Doer.ID, db.ListOptions{})
if err != nil {
ctx.ServerError("ListGPGKeys", err)
return
diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go
index 72cbf33e5f955..09871ef7631b5 100644
--- a/routers/web/user/setting/profile.go
+++ b/routers/web/user/setting/profile.go
@@ -185,7 +185,7 @@ func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser *
}
}
- if err := user_model.UpdateUserCols(db.DefaultContext, ctxUser, "avatar", "avatar_email", "use_custom_avatar"); err != nil {
+ if err := user_model.UpdateUserCols(ctx, ctxUser, "avatar", "avatar_email", "use_custom_avatar"); err != nil {
return fmt.Errorf("UpdateUser: %v", err)
}
diff --git a/services/asymkey/sign.go b/services/asymkey/sign.go
index c2c6829d61e19..fa0afe0a5723c 100644
--- a/services/asymkey/sign.go
+++ b/services/asymkey/sign.go
@@ -143,7 +143,7 @@ Loop:
case always:
break Loop
case pubkey:
- keys, err := asymkey_model.ListGPGKeys(db.DefaultContext, u.ID, db.ListOptions{})
+ keys, err := asymkey_model.ListGPGKeys(ctx, u.ID, db.ListOptions{})
if err != nil {
return false, "", nil, err
}
@@ -179,7 +179,7 @@ Loop:
case always:
break Loop
case pubkey:
- keys, err := asymkey_model.ListGPGKeys(db.DefaultContext, u.ID, db.ListOptions{})
+ keys, err := asymkey_model.ListGPGKeys(ctx, u.ID, db.ListOptions{})
if err != nil {
return false, "", nil, err
}
@@ -232,7 +232,7 @@ Loop:
case always:
break Loop
case pubkey:
- keys, err := asymkey_model.ListGPGKeys(db.DefaultContext, u.ID, db.ListOptions{})
+ keys, err := asymkey_model.ListGPGKeys(ctx, u.ID, db.ListOptions{})
if err != nil {
return false, "", nil, err
}
@@ -294,7 +294,7 @@ Loop:
case always:
break Loop
case pubkey:
- keys, err := asymkey_model.ListGPGKeys(db.DefaultContext, u.ID, db.ListOptions{})
+ keys, err := asymkey_model.ListGPGKeys(ctx, u.ID, db.ListOptions{})
if err != nil {
return false, "", nil, err
}
diff --git a/services/auth/source/ldap/source_sync.go b/services/auth/source/ldap/source_sync.go
index 0d4d94a3ad565..b7ea1f05841e1 100644
--- a/services/auth/source/ldap/source_sync.go
+++ b/services/auth/source/ldap/source_sync.go
@@ -202,7 +202,7 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error {
log.Trace("SyncExternalUsers[%s]: Deactivating user %s", source.authSource.Name, usr.Name)
usr.IsActive = false
- err = user_model.UpdateUserCols(db.DefaultContext, usr, "is_active")
+ err = user_model.UpdateUserCols(ctx, usr, "is_active")
if err != nil {
log.Error("SyncExternalUsers[%s]: Error deactivating user %s: %v", source.authSource.Name, usr.Name, err)
}
diff --git a/services/mailer/mail.go b/services/mailer/mail.go
index 8c99b05620b80..8e04e7e4d2266 100644
--- a/services/mailer/mail.go
+++ b/services/mailer/mail.go
@@ -7,6 +7,7 @@ package mailer
import (
"bytes"
+ "context"
"fmt"
"html/template"
"mime"
@@ -414,6 +415,7 @@ func SendIssueAssignedMail(issue *models.Issue, doer *user_model.User, content s
for lang, tos := range langMap {
msgs, err := composeIssueCommentMessages(&mailCommentContext{
+ Context: context.TODO(), // TODO: use a correct context
Issue: issue,
Doer: doer,
ActionType: models.ActionType(0),
diff --git a/services/mailer/mail_issue.go b/services/mailer/mail_issue.go
index 1451150347872..7f0fb9a3e1bc5 100644
--- a/services/mailer/mail_issue.go
+++ b/services/mailer/mail_issue.go
@@ -9,7 +9,6 @@ import (
"fmt"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
@@ -81,7 +80,7 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_mo
// =========== Repo watchers ===========
// Make repo watchers last, since it's likely the list with the most users
if !(ctx.Issue.IsPull && ctx.Issue.PullRequest.IsWorkInProgress() && ctx.ActionType != models.ActionCreatePullRequest) {
- ids, err = repo_model.GetRepoWatchersIDs(db.DefaultContext, ctx.Issue.RepoID)
+ ids, err = repo_model.GetRepoWatchersIDs(ctx, ctx.Issue.RepoID)
if err != nil {
return fmt.Errorf("GetRepoWatchersIDs(%d): %v", ctx.Issue.RepoID, err)
}
@@ -186,6 +185,7 @@ func MailParticipants(issue *models.Issue, doer *user_model.User, opType models.
}
if err := mailIssueCommentToParticipants(
&mailCommentContext{
+ Context: context.TODO(), // TODO: use a correct context
Issue: issue,
Doer: doer,
ActionType: opType,
diff --git a/services/mailer/mail_release.go b/services/mailer/mail_release.go
index 1ca9ad02d72ee..76dceb2387b40 100644
--- a/services/mailer/mail_release.go
+++ b/services/mailer/mail_release.go
@@ -9,7 +9,6 @@ import (
"context"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
@@ -32,7 +31,7 @@ func MailNewRelease(ctx context.Context, rel *models.Release) {
return
}
- watcherIDList, err := repo_model.GetRepoWatchersIDs(db.DefaultContext, rel.RepoID)
+ watcherIDList, err := repo_model.GetRepoWatchersIDs(ctx, rel.RepoID)
if err != nil {
log.Error("GetRepoWatchersIDs(%d): %v", rel.RepoID, err)
return
diff --git a/services/mailer/mail_test.go b/services/mailer/mail_test.go
index ba82fc6ff8454..c06bae1b9874a 100644
--- a/services/mailer/mail_test.go
+++ b/services/mailer/mail_test.go
@@ -6,6 +6,7 @@ package mailer
import (
"bytes"
+ "context"
"fmt"
"html/template"
"strings"
@@ -70,7 +71,8 @@ func TestComposeIssueCommentMessage(t *testing.T) {
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
msgs, err := composeIssueCommentMessages(&mailCommentContext{
- Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue,
+ Context: context.TODO(), // TODO: use a correct context
+ Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue,
Content: "test body", Comment: comment,
}, "en-US", recipients, false, "issue comment")
assert.NoError(t, err)
@@ -99,7 +101,8 @@ func TestComposeIssueMessage(t *testing.T) {
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
msgs, err := composeIssueCommentMessages(&mailCommentContext{
- Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue,
+ Context: context.TODO(), // TODO: use a correct context
+ Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue,
Content: "test body",
}, "en-US", recipients, false, "issue create")
assert.NoError(t, err)
@@ -145,13 +148,15 @@ func TestTemplateSelection(t *testing.T) {
}
msg := testComposeIssueCommentMessage(t, &mailCommentContext{
- Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue,
+ Context: context.TODO(), // TODO: use a correct context
+ Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue,
Content: "test body",
}, recipients, false, "TestTemplateSelection")
expect(t, msg, "issue/new/subject", "issue/new/body")
msg = testComposeIssueCommentMessage(t, &mailCommentContext{
- Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue,
+ Context: context.TODO(), // TODO: use a correct context
+ Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue,
Content: "test body", Comment: comment,
}, recipients, false, "TestTemplateSelection")
expect(t, msg, "issue/default/subject", "issue/default/body")
@@ -159,13 +164,15 @@ func TestTemplateSelection(t *testing.T) {
pull := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 2, Repo: repo, Poster: doer}).(*models.Issue)
comment = unittest.AssertExistsAndLoadBean(t, &models.Comment{ID: 4, Issue: pull}).(*models.Comment)
msg = testComposeIssueCommentMessage(t, &mailCommentContext{
- Issue: pull, Doer: doer, ActionType: models.ActionCommentPull,
+ Context: context.TODO(), // TODO: use a correct context
+ Issue: pull, Doer: doer, ActionType: models.ActionCommentPull,
Content: "test body", Comment: comment,
}, recipients, false, "TestTemplateSelection")
expect(t, msg, "pull/comment/subject", "pull/comment/body")
msg = testComposeIssueCommentMessage(t, &mailCommentContext{
- Issue: issue, Doer: doer, ActionType: models.ActionCloseIssue,
+ Context: context.TODO(), // TODO: use a correct context
+ Issue: issue, Doer: doer, ActionType: models.ActionCloseIssue,
Content: "test body", Comment: comment,
}, recipients, false, "TestTemplateSelection")
expect(t, msg, "Re: [user2/repo1] issue1 (#1)", "issue/close/body")
@@ -184,7 +191,8 @@ func TestTemplateServices(t *testing.T) {
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}}
msg := testComposeIssueCommentMessage(t, &mailCommentContext{
- Issue: issue, Doer: doer, ActionType: actionType,
+ Context: context.TODO(), // TODO: use a correct context
+ Issue: issue, Doer: doer, ActionType: actionType,
Content: "test body", Comment: comment,
}, recipients, fromMention, "TestTemplateServices")
@@ -226,7 +234,7 @@ func testComposeIssueCommentMessage(t *testing.T, ctx *mailCommentContext, recip
func TestGenerateAdditionalHeaders(t *testing.T) {
doer, _, issue, _ := prepareMailerTest(t)
- ctx := &mailCommentContext{Issue: issue, Doer: doer}
+ ctx := &mailCommentContext{Context: context.TODO() /* TODO: use a correct context */, Issue: issue, Doer: doer}
recipient := &user_model.User{Name: "Test", Email: "test@gitea.com"}
headers := generateAdditionalHeaders(ctx, "dummy-reason", recipient)
diff --git a/services/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go
index 2faa0a1f2a4dd..607dd0a076575 100644
--- a/services/migrations/gitea_uploader.go
+++ b/services/migrations/gitea_uploader.go
@@ -817,7 +817,7 @@ func (g *GiteaLocalUploader) Finish() error {
return err
}
- if err := models.UpdateRepoStats(db.DefaultContext, g.repo.ID); err != nil {
+ if err := models.UpdateRepoStats(g.ctx, g.repo.ID); err != nil {
return err
}
diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go
index 6c9c4a04838d2..979ef7f03cf1a 100644
--- a/services/mirror/mirror_pull.go
+++ b/services/mirror/mirror_pull.go
@@ -12,7 +12,6 @@ import (
"code.gitea.io/gitea/models"
admin_model "code.gitea.io/gitea/models/admin"
- "code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/git"
@@ -287,7 +286,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
gitRepo.Close()
log.Trace("SyncMirrors [repo: %-v]: updating size of repository", m.Repo)
- if err := models.UpdateRepoSize(db.DefaultContext, m.Repo); err != nil {
+ if err := models.UpdateRepoSize(ctx, m.Repo); err != nil {
log.Error("SyncMirrors [repo: %-v]: failed to update size for mirror repository: %v", m.Repo, err)
}
diff --git a/services/pull/check.go b/services/pull/check.go
index b1e9237d11c4c..3c79abf4b87e6 100644
--- a/services/pull/check.go
+++ b/services/pull/check.go
@@ -13,7 +13,6 @@ import (
"strings"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
@@ -168,7 +167,7 @@ func manuallyMerged(ctx context.Context, pr *models.PullRequest) bool {
// When the commit author is unknown set the BaseRepo owner as merger
if merger == nil {
if pr.BaseRepo.Owner == nil {
- if err = pr.BaseRepo.GetOwner(db.DefaultContext); err != nil {
+ if err = pr.BaseRepo.GetOwner(ctx); err != nil {
log.Error("BaseRepo.GetOwner[%d]: %v", pr.ID, err)
return false
}
diff --git a/services/pull/merge.go b/services/pull/merge.go
index cb857cc60dbc7..6108a7956e1d6 100644
--- a/services/pull/merge.go
+++ b/services/pull/merge.go
@@ -17,7 +17,6 @@ import (
"time"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
@@ -80,7 +79,7 @@ func Merge(ctx context.Context, pr *models.PullRequest, doer *user_model.User, b
if err := pr.Issue.LoadRepo(); err != nil {
log.Error("loadRepo for issue [%d]: %v", pr.ID, err)
}
- if err := pr.Issue.Repo.GetOwner(db.DefaultContext); err != nil {
+ if err := pr.Issue.Repo.GetOwner(ctx); err != nil {
log.Error("GetOwner for issue repo [%d]: %v", pr.ID, err)
}
@@ -487,7 +486,7 @@ func rawMerge(ctx context.Context, pr *models.PullRequest, doer *user_model.User
}
var headUser *user_model.User
- err = pr.HeadRepo.GetOwner(db.DefaultContext)
+ err = pr.HeadRepo.GetOwner(ctx)
if err != nil {
if !user_model.IsErrUserNotExist(err) {
log.Error("Can't find user: %d for head repository - %v", pr.HeadRepo.OwnerID, err)
diff --git a/services/pull/pull.go b/services/pull/pull.go
index 82deb74a4e11e..7a746d937faab 100644
--- a/services/pull/pull.go
+++ b/services/pull/pull.go
@@ -69,7 +69,7 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, pull *mode
return err
}
- mentions, err := pull.FindAndUpdateIssueMentions(db.DefaultContext, pull.Poster, pull.Content)
+ mentions, err := pull.FindAndUpdateIssueMentions(ctx, pull.Poster, pull.Content)
if err != nil {
return err
}
diff --git a/services/pull/review.go b/services/pull/review.go
index 25eef78d97739..7f9797579a5a2 100644
--- a/services/pull/review.go
+++ b/services/pull/review.go
@@ -61,7 +61,7 @@ func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git.
return nil, err
}
- mentions, err := issue.FindAndUpdateIssueMentions(db.DefaultContext, doer, comment.Content)
+ mentions, err := issue.FindAndUpdateIssueMentions(ctx, doer, comment.Content)
if err != nil {
return nil, err
}
diff --git a/services/pull/temp_repo.go b/services/pull/temp_repo.go
index 831d98745e4ca..c6c6d8b6e7865 100644
--- a/services/pull/temp_repo.go
+++ b/services/pull/temp_repo.go
@@ -13,7 +13,6 @@ import (
"strings"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
@@ -38,10 +37,10 @@ func createTemporaryRepo(ctx context.Context, pr *models.PullRequest) (string, e
return "", &repo_model.ErrRepoNotExist{
ID: pr.BaseRepoID,
}
- } else if err := pr.HeadRepo.GetOwner(db.DefaultContext); err != nil {
+ } else if err := pr.HeadRepo.GetOwner(ctx); err != nil {
log.Error("HeadRepo.GetOwner: %v", err)
return "", fmt.Errorf("HeadRepo.GetOwner: %v", err)
- } else if err := pr.BaseRepo.GetOwner(db.DefaultContext); err != nil {
+ } else if err := pr.BaseRepo.GetOwner(ctx); err != nil {
log.Error("BaseRepo.GetOwner: %v", err)
return "", fmt.Errorf("BaseRepo.GetOwner: %v", err)
}
diff --git a/services/release/release.go b/services/release/release.go
index 0df8635230f43..4d16e66aec98e 100644
--- a/services/release/release.go
+++ b/services/release/release.go
@@ -130,7 +130,7 @@ func CreateRelease(gitRepo *git.Repository, rel *models.Release, attachmentUUIDs
return err
}
- if err = models.AddReleaseAttachments(db.DefaultContext, rel.ID, attachmentUUIDs); err != nil {
+ if err = models.AddReleaseAttachments(gitRepo.Ctx, rel.ID, attachmentUUIDs); err != nil {
return err
}
@@ -319,7 +319,7 @@ func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, del
} else {
rel.IsTag = true
- if err = models.UpdateRelease(db.DefaultContext, rel); err != nil {
+ if err = models.UpdateRelease(ctx, rel); err != nil {
return fmt.Errorf("Update: %v", err)
}
}
diff --git a/services/repository/check.go b/services/repository/check.go
index 6adb8479c4a06..6962090f8441e 100644
--- a/services/repository/check.go
+++ b/services/repository/check.go
@@ -27,7 +27,7 @@ func GitFsck(ctx context.Context, timeout time.Duration, args []string) error {
log.Trace("Doing: GitFsck")
if err := db.Iterate(
- db.DefaultContext,
+ ctx,
new(repo_model.Repository),
builder.Expr("id>0 AND is_fsck_enabled=?", true),
func(idx int, bean interface{}) error {
@@ -62,7 +62,7 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...string) erro
args = append([]string{"gc"}, args...)
if err := db.Iterate(
- db.DefaultContext,
+ ctx,
new(repo_model.Repository),
builder.Gt{"id": 0},
func(idx int, bean interface{}) error {
@@ -97,7 +97,7 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...string) erro
}
// Now update the size of the repository
- if err := models.UpdateRepoSize(db.DefaultContext, repo); err != nil {
+ if err := models.UpdateRepoSize(ctx, repo); err != nil {
log.Error("Updating size as part of garbage collection failed for %v. Stdout: %s\nError: %v", repo, stdout, err)
desc := fmt.Sprintf("Updating size as part of garbage collection failed for %s. Stdout: %s\nError: %v", repo.RepoPath(), stdout, err)
if err = admin_model.CreateRepositoryNotice(desc); err != nil {
@@ -119,7 +119,7 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...string) erro
func gatherMissingRepoRecords(ctx context.Context) ([]*repo_model.Repository, error) {
repos := make([]*repo_model.Repository, 0, 10)
if err := db.Iterate(
- db.DefaultContext,
+ ctx,
new(repo_model.Repository),
builder.Gt{"id": 0},
func(idx int, bean interface{}) error {
diff --git a/services/repository/hooks.go b/services/repository/hooks.go
index 3905249499180..40303d5937837 100644
--- a/services/repository/hooks.go
+++ b/services/repository/hooks.go
@@ -23,7 +23,7 @@ func SyncRepositoryHooks(ctx context.Context) error {
log.Trace("Doing: SyncRepositoryHooks")
if err := db.Iterate(
- db.DefaultContext,
+ ctx,
new(repo_model.Repository),
builder.Gt{"id": 0},
func(idx int, bean interface{}) error {
diff --git a/services/repository/push.go b/services/repository/push.go
index fafe4736ab4e5..6cdfa1b4c2b5d 100644
--- a/services/repository/push.go
+++ b/services/repository/push.go
@@ -95,7 +95,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
}
defer gitRepo.Close()
- if err = models.UpdateRepoSize(db.DefaultContext, repo); err != nil {
+ if err = models.UpdateRepoSize(ctx, repo); err != nil {
log.Error("Failed to update size for repository: %v", err)
}
diff --git a/services/user/user.go b/services/user/user.go
index 21f1a74f62f62..e31b174c0c2cf 100644
--- a/services/user/user.go
+++ b/services/user/user.go
@@ -78,7 +78,7 @@ func DeleteUser(u *user_model.User) error {
path := user_model.UserPath(u.Name)
if err := util.RemoveAll(path); err != nil {
err = fmt.Errorf("Failed to RemoveAll %s: %v", path, err)
- _ = admin_model.CreateNotice(db.DefaultContext, admin_model.NoticeTask, fmt.Sprintf("delete user '%s': %v", u.Name, err))
+ _ = admin_model.CreateNotice(ctx, admin_model.NoticeTask, fmt.Sprintf("delete user '%s': %v", u.Name, err))
return err
}
@@ -86,7 +86,7 @@ func DeleteUser(u *user_model.User) error {
avatarPath := u.CustomAvatarRelativePath()
if err := storage.Avatars.Delete(avatarPath); err != nil {
err = fmt.Errorf("Failed to remove %s: %v", avatarPath, err)
- _ = admin_model.CreateNotice(db.DefaultContext, admin_model.NoticeTask, fmt.Sprintf("delete user '%s': %v", u.Name, err))
+ _ = admin_model.CreateNotice(ctx, admin_model.NoticeTask, fmt.Sprintf("delete user '%s': %v", u.Name, err))
return err
}
}
diff --git a/templates/base/footer_content.tmpl b/templates/base/footer_content.tmpl
index ef183191a4a49..52e7c7e77e965 100644
--- a/templates/base/footer_content.tmpl
+++ b/templates/base/footer_content.tmpl
@@ -1,7 +1,20 @@
diff --git a/templates/repo/issue/choose.tmpl b/templates/repo/issue/choose.tmpl
index 0cec1ef63cbbe..4a26e4f6894d8 100644
--- a/templates/repo/issue/choose.tmpl
+++ b/templates/repo/issue/choose.tmpl
@@ -14,7 +14,7 @@
{{.About | RenderEmojiPlain}}