Compare commits

...

15 Commits

Author SHA1 Message Date
Lunny Xiao
7e084341fe Fix wrong redirect on org labels (#18128) (#18134)
* Fix wrong redirect on org labels (#18128)

Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
2021-12-30 17:08:42 +01:00
DuckDuckWhale
7d75eede04 Doc: add missing bug fix to changelog (#18133) 2021-12-30 16:42:25 +01:00
zeripath
3db98bef99 Changelog v1.15.9 (#18115)
* BUGFIXES
  * Revert "Fix delete u2f keys bug (#18042)" (#18107)
  * Migrating wiki don't require token, so we should move it out of the require form (#17645) (#18104)
  * Prevent NPE if gitea uploader fails to open url (#18080) (#18101)
  * Reset locale on login (#17734) (#18100)
  * Correctly handle failed migrations (#17575) (#18099)
  * Instead of using routerCtx just escape the url before routing (#18086) (#18098)
  * Quote references to the user table in consistency checks (#18072) (#18073)
  * Add NotFound handler (#18062) (#18067)
  * Ensure that git repository is closed before transfer (#18049) (#18057)
  * Use common sessioner for API and web routes (#18114)
* TRANSLATION
  * Fix code search result hint on zh-CN (#18053)

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-12-30 13:03:04 +08:00
DuckDuckWhale
484fe075f4 Fix: unstable sort skips/duplicates issues across pages (#18095)
When viewing issues in sorted order, some issues are duplicated across
pages and some are missing.  This is caused by the lack of tie-breakers
in database queries, making pagination inconsistent.

Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2021-12-29 19:44:34 +08:00
zeripath
de3216ee55 Use common sessioner for API and web routes (#18114)
* Use common sessioner for API and web routes

Since the regenerate session ID PR some users of the memory session provider have been
reporting difficulties with getting API results.

I am uncertain as to why this is happening - but I think that the sessioner being
created twice may be a potential cause for this. Therefore this PR attempts to move
this out to a common sessioner as it is in 1.16.

Fix #18070

Signed-off-by: Andrew Thornton <art27@cantab.net>

* Update routers/init.go
2021-12-28 22:15:01 +00:00
Lunny Xiao
353d88a42e Migrating wiki don't require token, so we should move it out of the require form (#17645) (#18104)
* Migrating wiki don't require token, so we should move it out of the require form

* Fix lint

Co-authored-by: techknowlogick <techknowlogick@gitea.io>
2021-12-27 09:33:32 +08:00
Lunny Xiao
a17fce31a9 Revert "Fix delete u2f keys bug (#18042)" (#18107)
This reverts commit 91f5be889a.
2021-12-26 22:57:00 +08:00
zeripath
71e1ebfa60 Instead of using routerCtx just escape the url before routing (#18086) (#18098)
Backport #18086

A consequence of forcibly setting the RoutePath to the escaped url is that the
auto routing to endpoints without terminal slashes fails (Causing #18060.) This
failure raises the possibility that forcibly setting the RoutePath causes other
unexpected behaviors too.

Therefore, instead we should simply pre-escape the URL in the process registering
handler. Then the request URL will be properly escaped for all the following calls.

Fix #17938
Fix #18060
Replace #18062
Replace #17997

Signed-off-by: Andrew Thornton <art27@cantab.net>
2021-12-26 10:32:04 +00:00
zeripath
afe9d2cadd Prevent NPE if gitea uploader fails to open url (#18080) (#18101)
Backport #18080

If http.Get() returns an error return nil and err before attempting to
use the broken file.

Thanks to walker xiong for spotting this bug.

Signed-off-by: Andrew Thornton <art27@cantab.net>
2021-12-26 09:22:10 +00:00
zeripath
012e45a4c1 Correctly handle failed migrations (#17575) (#18099)
* Correctly handle failed migrations

There is a bug in handling failed migrations whereby the migration task gets decoupled
from the migration repository. This leads to a failure of the task to get deleted with
the repository and also leads to the migration failed page resulting in a ISE.

This PR removes the zeroing out of the task id from the migration but also makes
the migration handler tolerate missing tasks much nicer.

Fix #17571

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2021-12-25 15:45:51 +00:00
zeripath
d25ff0d695 Reset locale on login (#17734) (#18100)
Backport #17734

When logging in reset the user's locale to ensure that it matches their
preferred locale.

Fix #15612

Signed-off-by: Andrew Thornton <art27@cantab.net>
2021-12-25 21:31:23 +08:00
zeripath
6eaebda1b5 Quote references to the user table in consistency checks (#18072) (#18073)
Backport #18072

Although #17487 ensured that the table was quoted in the join it missed that the
query part of the check also needed to be quoted.

Fix #17485

Signed-off-by: Andrew Thornton <art27@cantab.net>
2021-12-22 23:29:05 +00:00
zeripath
6100935a77 Add NotFound handler (#18062) (#18067)
Backport #18062

PR #17997 means that urls with terminal '/' are no longer immediately mapped
to the url without a terminal slash. However, it has revealed that the NotFound handler
appears to have been lost.

This PR adds back in a NotFound handler that simply redirects to a path without the
terminal slash or runs the NotFound handler.

Fix #18060

Signed-off-by: Andrew Thornton <art27@cantab.net>
2021-12-22 15:26:37 +00:00
zeripath
6de75224de Ensure that git repository is closed before transfer (#18049) (#18057)
Backport #18049

Repository Transfer requires that the repository directory is renamed - which
is not possible on Windows if the git repository is open.

Fix #17885

Signed-off-by: Andrew Thornton <art27@cantab.net>
2021-12-21 18:27:46 +00:00
Lunny Xiao
9086916eb7 Fix code search result hint on zh-CN (#18053) 2021-12-21 16:08:06 +08:00
30 changed files with 193 additions and 111 deletions

View File

@@ -4,6 +4,24 @@ This changelog goes through all the changes that have been made in each release
without substantial changes to our git log; to see the highlights of what has without substantial changes to our git log; to see the highlights of what has
been added to each release, please refer to the [blog](https://blog.gitea.io). been added to each release, please refer to the [blog](https://blog.gitea.io).
## [1.15.9](https://github.com/go-gitea/gitea/releases/tag/v1.15.9) - 2021-12-30
* BUGFIXES
* Fix wrong redirect on org labels (#18128) (#18134)
* Fix: unstable sort skips/duplicates issues across pages (#18094) (#18095)
* Revert "Fix delete u2f keys bug (#18042)" (#18107)
* Migrating wiki don't require token, so we should move it out of the require form (#17645) (#18104)
* Prevent NPE if gitea uploader fails to open url (#18080) (#18101)
* Reset locale on login (#17734) (#18100)
* Correctly handle failed migrations (#17575) (#18099)
* Instead of using routerCtx just escape the url before routing (#18086) (#18098)
* Quote references to the user table in consistency checks (#18072) (#18073)
* Add NotFound handler (#18062) (#18067)
* Ensure that git repository is closed before transfer (#18049) (#18057)
* Use common sessioner for API and web routes (#18114)
* TRANSLATION
* Fix code search result hint on zh-CN (#18053)
## [1.15.8](https://github.com/go-gitea/gitea/releases/tag/v1.15.8) - 2021-12-20 ## [1.15.8](https://github.com/go-gitea/gitea/releases/tag/v1.15.8) - 2021-12-20
* BUGFIXES * BUGFIXES

View File

@@ -33,6 +33,7 @@ func TestLinksNoLogin(t *testing.T) {
"/user/forgot_password", "/user/forgot_password",
"/api/swagger", "/api/swagger",
"/user2/repo1", "/user2/repo1",
"/user2/repo1/",
"/user2/repo1/projects", "/user2/repo1/projects",
"/user2/repo1/projects/1", "/user2/repo1/projects/1",
"/assets/img/404.png", "/assets/img/404.png",

View File

@@ -18,7 +18,7 @@ func TestSignOut(t *testing.T) {
session.MakeRequest(t, req, http.StatusFound) session.MakeRequest(t, req, http.StatusFound)
// try to view a private repo, should fail // try to view a private repo, should fail
req = NewRequest(t, "GET", "/user2/repo2/") req = NewRequest(t, "GET", "/user2/repo2")
session.MakeRequest(t, req, http.StatusNotFound) session.MakeRequest(t, req, http.StatusNotFound)
// invalidate cached cookies for user2, for subsequent tests // invalidate cached cookies for user2, for subsequent tests

View File

@@ -1145,17 +1145,17 @@ type IssuesOptions struct {
func sortIssuesSession(sess *xorm.Session, sortType string, priorityRepoID int64) { func sortIssuesSession(sess *xorm.Session, sortType string, priorityRepoID int64) {
switch sortType { switch sortType {
case "oldest": case "oldest":
sess.Asc("issue.created_unix") sess.Asc("issue.created_unix").Asc("issue.id")
case "recentupdate": case "recentupdate":
sess.Desc("issue.updated_unix") sess.Desc("issue.updated_unix").Desc("issue.created_unix").Desc("issue.id")
case "leastupdate": case "leastupdate":
sess.Asc("issue.updated_unix") sess.Asc("issue.updated_unix").Asc("issue.created_unix").Asc("issue.id")
case "mostcomment": case "mostcomment":
sess.Desc("issue.num_comments") sess.Desc("issue.num_comments").Desc("issue.created_unix").Desc("issue.id")
case "leastcomment": case "leastcomment":
sess.Asc("issue.num_comments") sess.Asc("issue.num_comments").Desc("issue.created_unix").Desc("issue.id")
case "priority": case "priority":
sess.Desc("issue.priority") sess.Desc("issue.priority").Desc("issue.created_unix").Desc("issue.id")
case "nearduedate": case "nearduedate":
// 253370764800 is 01/01/9999 @ 12:00am (UTC) // 253370764800 is 01/01/9999 @ 12:00am (UTC)
sess.Join("LEFT", "milestone", "issue.milestone_id = milestone.id"). sess.Join("LEFT", "milestone", "issue.milestone_id = milestone.id").
@@ -1163,17 +1163,25 @@ func sortIssuesSession(sess *xorm.Session, sortType string, priorityRepoID int64
"WHEN issue.deadline_unix = 0 AND (milestone.deadline_unix = 0 OR milestone.deadline_unix IS NULL) THEN 253370764800 " + "WHEN issue.deadline_unix = 0 AND (milestone.deadline_unix = 0 OR milestone.deadline_unix IS NULL) THEN 253370764800 " +
"WHEN milestone.deadline_unix = 0 OR milestone.deadline_unix IS NULL THEN issue.deadline_unix " + "WHEN milestone.deadline_unix = 0 OR milestone.deadline_unix IS NULL THEN issue.deadline_unix " +
"WHEN milestone.deadline_unix < issue.deadline_unix OR issue.deadline_unix = 0 THEN milestone.deadline_unix " + "WHEN milestone.deadline_unix < issue.deadline_unix OR issue.deadline_unix = 0 THEN milestone.deadline_unix " +
"ELSE issue.deadline_unix END ASC") "ELSE issue.deadline_unix END ASC").
Desc("issue.created_unix").
Desc("issue.id")
case "farduedate": case "farduedate":
sess.Join("LEFT", "milestone", "issue.milestone_id = milestone.id"). sess.Join("LEFT", "milestone", "issue.milestone_id = milestone.id").
OrderBy("CASE " + OrderBy("CASE " +
"WHEN milestone.deadline_unix IS NULL THEN issue.deadline_unix " + "WHEN milestone.deadline_unix IS NULL THEN issue.deadline_unix " +
"WHEN milestone.deadline_unix < issue.deadline_unix OR issue.deadline_unix = 0 THEN milestone.deadline_unix " + "WHEN milestone.deadline_unix < issue.deadline_unix OR issue.deadline_unix = 0 THEN milestone.deadline_unix " +
"ELSE issue.deadline_unix END DESC") "ELSE issue.deadline_unix END DESC").
Desc("issue.created_unix").
Desc("issue.id")
case "priorityrepo": case "priorityrepo":
sess.OrderBy("CASE WHEN issue.repo_id = " + strconv.FormatInt(priorityRepoID, 10) + " THEN 1 ELSE 2 END, issue.created_unix DESC") sess.OrderBy("CASE " +
"WHEN issue.repo_id = " + strconv.FormatInt(priorityRepoID, 10) + " THEN 1 " +
"ELSE 2 END ASC").
Desc("issue.created_unix").
Desc("issue.id")
default: default:
sess.Desc("issue.created_unix") sess.Desc("issue.created_unix").Desc("issue.id")
} }
} }

View File

@@ -223,6 +223,9 @@ func APIAuth(authMethod auth.Auth) func(*APIContext) {
// Get user from session if logged in. // Get user from session if logged in.
ctx.User = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session) ctx.User = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
if ctx.User != nil { if ctx.User != nil {
if ctx.Locale.Language() != ctx.User.Language {
ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req)
}
ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == new(auth.Basic).Name() ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == new(auth.Basic).Name()
ctx.IsSigned = true ctx.IsSigned = true
ctx.Data["IsSigned"] = ctx.IsSigned ctx.Data["IsSigned"] = ctx.IsSigned

View File

@@ -642,6 +642,9 @@ func Auth(authMethod auth.Auth) func(*Context) {
return func(ctx *Context) { return func(ctx *Context) {
ctx.User = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session) ctx.User = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
if ctx.User != nil { if ctx.User != nil {
if ctx.Locale.Language() != ctx.User.Language {
ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req)
}
ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == new(auth.Basic).Name() ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == new(auth.Basic).Name()
ctx.IsSigned = true ctx.IsSigned = true
ctx.Data["IsSigned"] = ctx.IsSigned ctx.Data["IsSigned"] = ctx.IsSigned
@@ -670,9 +673,6 @@ func Contexter() func(next http.Handler) http.Handler {
var startTime = time.Now() var startTime = time.Now()
var link = setting.AppSubURL + strings.TrimSuffix(req.URL.EscapedPath(), "/") var link = setting.AppSubURL + strings.TrimSuffix(req.URL.EscapedPath(), "/")
chiCtx := chi.RouteContext(req.Context())
chiCtx.RoutePath = req.URL.EscapedPath()
var ctx = Context{ var ctx = Context{
Resp: NewResponse(resp), Resp: NewResponse(resp),
Cache: mc.GetCache(), Cache: mc.GetCache(),

View File

@@ -159,13 +159,13 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
"lfs_lock", "repository", "lfs_lock.repo_id=repository.id"), "lfs_lock", "repository", "lfs_lock.repo_id=repository.id"),
// find collaborations without users // find collaborations without users
genericOrphanCheck("Collaborations without existing user", genericOrphanCheck("Collaborations without existing user",
"collaboration", "user", "collaboration.user_id=user.id"), "collaboration", "user", "collaboration.user_id=`user`.id"),
// find collaborations without repository // find collaborations without repository
genericOrphanCheck("Collaborations without existing repository", genericOrphanCheck("Collaborations without existing repository",
"collaboration", "repository", "collaboration.repo_id=repository.id"), "collaboration", "repository", "collaboration.repo_id=repository.id"),
// find access without users // find access without users
genericOrphanCheck("Access entries without existing user", genericOrphanCheck("Access entries without existing user",
"access", "user", "access.user_id=user.id"), "access", "user", "access.user_id=`user`.id"),
// find access without repository // find access without repository
genericOrphanCheck("Access entries without existing repository", genericOrphanCheck("Access entries without existing repository",
"access", "repository", "access.repo_id=repository.id"), "access", "repository", "access.repo_id=repository.id"),

View File

@@ -58,6 +58,9 @@ func runMigrateTask(t *models.Task) (err error) {
t.EndTime = timeutil.TimeStampNow() t.EndTime = timeutil.TimeStampNow()
t.Status = structs.TaskStatusFailed t.Status = structs.TaskStatusFailed
t.Message = err.Error() t.Message = err.Error()
// Ensure that the repo loaded before we zero out the repo ID from the task - thus ensuring that we can delete it
_ = t.LoadRepo()
t.RepoID = 0 t.RepoID = 0
if err := t.UpdateCols("status", "errors", "repo_id", "end_time"); err != nil { if err := t.UpdateCols("status", "errors", "repo_id", "end_time"); err != nil {
log.Error("Task UpdateCols failed: %v", err) log.Error("Task UpdateCols failed: %v", err)

View File

@@ -92,7 +92,7 @@ func CreateMigrateTask(doer, u *models.User, opts base.MigrateOptions) (*models.
return nil, err return nil, err
} }
var task = models.Task{ var task = &models.Task{
DoerID: doer.ID, DoerID: doer.ID,
OwnerID: u.ID, OwnerID: u.ID,
Type: structs.TaskTypeMigrateRepo, Type: structs.TaskTypeMigrateRepo,
@@ -100,7 +100,7 @@ func CreateMigrateTask(doer, u *models.User, opts base.MigrateOptions) (*models.
PayloadContent: string(bs), PayloadContent: string(bs),
} }
if err := models.CreateTask(&task); err != nil { if err := models.CreateTask(task); err != nil {
return nil, err return nil, err
} }
@@ -128,5 +128,5 @@ func CreateMigrateTask(doer, u *models.User, opts base.MigrateOptions) (*models.
return nil, err return nil, err
} }
return &task, nil return task, nil
} }

View File

@@ -31,7 +31,10 @@ func Open(uriStr string) (io.ReadCloser, error) {
switch strings.ToLower(u.Scheme) { switch strings.ToLower(u.Scheme) {
case "http", "https": case "http", "https":
f, err := http.Get(uriStr) f, err := http.Get(uriStr)
return f.Body, err if err != nil {
return nil, err
}
return f.Body, nil
case "file": case "file":
return os.Open(u.Path) return os.Open(u.Path)
default: default:

View File

@@ -896,11 +896,12 @@ migrate.migrate = Migrate From %s
migrate.migrating = Migrating from <b>%s</b> ... migrate.migrating = Migrating from <b>%s</b> ...
migrate.migrating_failed = Migrating from <b>%s</b> failed. migrate.migrating_failed = Migrating from <b>%s</b> failed.
migrate.migrating_failed.error = Error: %s migrate.migrating_failed.error = Error: %s
migrate.github.description = Migrating data from Github.com or Github Enterprise. migrate.github.description = Migrate data from github.com or other Github instances.
migrate.git.description = Migrating or Mirroring git data from Git services migrate.git.description = Migrate a repository only from any Git service.
migrate.gitlab.description = Migrating data from GitLab.com or Self-Hosted gitlab server. migrate.gitlab.description = Migrate data from gitlab.com or other GitLab instances.
migrate.gitea.description = Migrating data from Gitea.com or Self-Hosted Gitea server. migrate.gitea.description = Migrate data from gitea.com or other Gitea instances.
migrate.gogs.description = Migrating data from notabug.org or other Self-Hosted Gogs server. migrate.gogs.description = Migrate data from notabug.org or other Gogs instances.
migrate.onedev.description = Migrate data from code.onedev.io or other OneDev instances.
migrate.migrating_git = Migrating Git Data migrate.migrating_git = Migrating Git Data
migrate.migrating_topics = Migrating Topics migrate.migrating_topics = Migrating Topics
migrate.migrating_milestones = Migrating Milestones migrate.migrating_milestones = Migrating Milestones

View File

@@ -630,8 +630,8 @@ last_used=上次使用在
no_activity=没有最近活动 no_activity=没有最近活动
can_read_info=读取 can_read_info=读取
can_write_info=写入 can_write_info=写入
key_state_desc=7 天内使用过该密钥 key_state_desc=7 天内使用过该密钥
token_state_desc=7 天内使用过该密钥 token_state_desc=7 天内使用过该密钥
principal_state_desc=7 天内使用过该规则 principal_state_desc=7 天内使用过该规则
show_openid=在个人信息上显示 show_openid=在个人信息上显示
hide_openid=在个人信息上隐藏 hide_openid=在个人信息上隐藏
@@ -808,7 +808,7 @@ watchers=关注者
stargazers=称赞者 stargazers=称赞者
forks=派生仓库 forks=派生仓库
pick_reaction=选择你的表情 pick_reaction=选择你的表情
reactions_more=再加载 %d reactions_more=再加载 %d
unit_disabled=站点管理员已禁用此仓库单元。 unit_disabled=站点管理员已禁用此仓库单元。
language_other=其它 language_other=其它
adopt_search=输入用户名以搜索未被收录的仓库... (留空以查找全部) adopt_search=输入用户名以搜索未被收录的仓库... (留空以查找全部)
@@ -1611,7 +1611,7 @@ search=搜索
search.search_repo=搜索仓库... search.search_repo=搜索仓库...
search.fuzzy=模糊 search.fuzzy=模糊
search.match=匹配 search.match=匹配
search.results=在 <a href="%s"> %s </a> 中搜索 "%s" 的结果 search.results=在 <a href="%[2]s"> %[3]s </a> 中搜索 "%[1]s" 的结果
settings=设置 settings=设置
settings.desc=设置是你可以管理仓库设置的地方 settings.desc=设置是你可以管理仓库设置的地方

View File

@@ -87,7 +87,6 @@ import (
"code.gitea.io/gitea/services/forms" "code.gitea.io/gitea/services/forms"
"gitea.com/go-chi/binding" "gitea.com/go-chi/binding"
"gitea.com/go-chi/session"
"github.com/go-chi/cors" "github.com/go-chi/cors"
) )
@@ -547,20 +546,10 @@ func bind(obj interface{}) http.HandlerFunc {
} }
// Routes registers all v1 APIs routes to web application. // Routes registers all v1 APIs routes to web application.
func Routes() *web.Route { func Routes(sessioner func(next http.Handler) http.Handler) *web.Route {
var m = web.NewRoute() var m = web.NewRoute()
m.Use(session.Sessioner(session.Options{ m.Use(sessioner)
Provider: setting.SessionConfig.Provider,
ProviderConfig: setting.SessionConfig.ProviderConfig,
CookieName: setting.SessionConfig.CookieName,
CookiePath: setting.SessionConfig.CookiePath,
Gclifetime: setting.SessionConfig.Gclifetime,
Maxlifetime: setting.SessionConfig.Maxlifetime,
Secure: setting.SessionConfig.Secure,
SameSite: setting.SessionConfig.SameSite,
Domain: setting.SessionConfig.Domain,
}))
m.Use(securityHeaders()) m.Use(securityHeaders())
if setting.CORSConfig.Enabled { if setting.CORSConfig.Enabled {
m.Use(cors.Handler(cors.Options{ m.Use(cors.Handler(cors.Options{

View File

@@ -96,6 +96,11 @@ func Transfer(ctx *context.APIContext) {
} }
} }
if ctx.Repo.GitRepo != nil {
ctx.Repo.GitRepo.Close()
ctx.Repo.GitRepo = nil
}
if err := repo_service.StartRepositoryTransfer(ctx.User, newOwner, ctx.Repo.Repository, teams); err != nil { if err := repo_service.StartRepositoryTransfer(ctx.User, newOwner, ctx.Repo.Repository, teams); err != nil {
if models.IsErrRepoTransferInProgress(err) { if models.IsErrRepoTransferInProgress(err) {
ctx.Error(http.StatusConflict, "CreatePendingRepositoryTransfer", err) ctx.Error(http.StatusConflict, "CreatePendingRepositoryTransfer", err)

View File

@@ -22,6 +22,9 @@ func Middlewares() []func(http.Handler) http.Handler {
var handlers = []func(http.Handler) http.Handler{ var handlers = []func(http.Handler) http.Handler{
func(next http.Handler) http.Handler { func(next http.Handler) http.Handler {
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) { return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
// First of all escape the URL RawPath to ensure that all routing is done using a correctly escaped URL
req.URL.RawPath = req.URL.EscapedPath()
next.ServeHTTP(context.NewResponse(resp), req) next.ServeHTTP(context.NewResponse(resp), req)
}) })
}, },

View File

@@ -40,6 +40,8 @@ import (
pull_service "code.gitea.io/gitea/services/pull" pull_service "code.gitea.io/gitea/services/pull"
"code.gitea.io/gitea/services/repository" "code.gitea.io/gitea/services/repository"
"code.gitea.io/gitea/services/webhook" "code.gitea.io/gitea/services/webhook"
"gitea.com/go-chi/session"
) )
// NewServices init new services // NewServices init new services
@@ -144,8 +146,20 @@ func NormalRoutes() *web.Route {
r.Use(middle) r.Use(middle)
} }
r.Mount("/", web_routers.Routes()) sessioner := session.Sessioner(session.Options{
r.Mount("/api/v1", apiv1.Routes()) Provider: setting.SessionConfig.Provider,
ProviderConfig: setting.SessionConfig.ProviderConfig,
CookieName: setting.SessionConfig.CookieName,
CookiePath: setting.SessionConfig.CookiePath,
Gclifetime: setting.SessionConfig.Gclifetime,
Maxlifetime: setting.SessionConfig.Maxlifetime,
Secure: setting.SessionConfig.Secure,
SameSite: setting.SessionConfig.SameSite,
Domain: setting.SessionConfig.Domain,
})
r.Mount("/", web_routers.Routes(sessioner))
r.Mount("/api/v1", apiv1.Routes(sessioner))
r.Mount("/api/internal", private.Routes()) r.Mount("/api/internal", private.Routes())
return r return r
} }

View File

@@ -94,7 +94,7 @@ func DeleteLabel(ctx *context.Context) {
func InitializeLabels(ctx *context.Context) { func InitializeLabels(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.InitializeLabelsForm) form := web.GetForm(ctx).(*forms.InitializeLabelsForm)
if ctx.HasError() { if ctx.HasError() {
ctx.Redirect(ctx.Repo.RepoLink + "/labels") ctx.Redirect(ctx.Org.OrgLink + "/labels")
return return
} }

View File

@@ -319,6 +319,11 @@ func acceptOrRejectRepoTransfer(ctx *context.Context, accept bool) error {
} }
if accept { if accept {
if ctx.Repo.GitRepo != nil {
ctx.Repo.GitRepo.Close()
ctx.Repo.GitRepo = nil
}
if err := repo_service.TransferOwnership(repoTransfer.Doer, repoTransfer.Recipient, ctx.Repo.Repository, repoTransfer.Teams); err != nil { if err := repo_service.TransferOwnership(repoTransfer.Doer, repoTransfer.Recipient, ctx.Repo.Repository, repoTransfer.Teams); err != nil {
return err return err
} }

View File

@@ -619,6 +619,13 @@ func Home(ctx *context.Context) {
if ctx.Repo.Repository.IsBeingCreated() { if ctx.Repo.Repository.IsBeingCreated() {
task, err := models.GetMigratingTask(ctx.Repo.Repository.ID) task, err := models.GetMigratingTask(ctx.Repo.Repository.ID)
if err != nil { if err != nil {
if models.IsErrTaskDoesNotExist(err) {
ctx.Data["Repo"] = ctx.Repo
ctx.Data["CloneAddr"] = ""
ctx.Data["Failed"] = true
ctx.HTML(http.StatusOK, tplMigrating)
return
}
ctx.ServerError("models.GetMigratingTask", err) ctx.ServerError("models.GetMigratingTask", err)
return return
} }

View File

@@ -584,6 +584,10 @@ func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyR
middleware.SetLocaleCookie(ctx.Resp, u.Language, 0) middleware.SetLocaleCookie(ctx.Resp, u.Language, 0)
if ctx.Locale.Language() != u.Language {
ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req)
}
// Clear whatever CSRF has right now, force to generate a new one // Clear whatever CSRF has right now, force to generate a new one
middleware.DeleteCSRFCookie(ctx.Resp) middleware.DeleteCSRFCookie(ctx.Resp)

View File

@@ -6,6 +6,7 @@ package user
import ( import (
"net/http" "net/http"
"strconv"
"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
@@ -16,6 +17,12 @@ import (
func TaskStatus(ctx *context.Context) { func TaskStatus(ctx *context.Context) {
task, opts, err := models.GetMigratingTaskByID(ctx.ParamsInt64("task"), ctx.User.ID) task, opts, err := models.GetMigratingTaskByID(ctx.ParamsInt64("task"), ctx.User.ID)
if err != nil { if err != nil {
if models.IsErrTaskDoesNotExist(err) {
ctx.JSON(http.StatusNotFound, map[string]interface{}{
"error": "task `" + strconv.FormatInt(ctx.ParamsInt64("task"), 10) + "` does not exist",
})
return
}
ctx.JSON(http.StatusInternalServerError, map[string]interface{}{ ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
"err": err, "err": err,
}) })

View File

@@ -39,7 +39,6 @@ import (
_ "code.gitea.io/gitea/modules/session" _ "code.gitea.io/gitea/modules/session"
"gitea.com/go-chi/captcha" "gitea.com/go-chi/captcha"
"gitea.com/go-chi/session"
"github.com/NYTimes/gziphandler" "github.com/NYTimes/gziphandler"
"github.com/go-chi/chi/middleware" "github.com/go-chi/chi/middleware"
"github.com/go-chi/cors" "github.com/go-chi/cors"
@@ -71,7 +70,7 @@ func CorsHandler() func(next http.Handler) http.Handler {
} }
// Routes returns all web routes // Routes returns all web routes
func Routes() *web.Route { func Routes(sessioner func(next http.Handler) http.Handler) *web.Route {
routes := web.NewRoute() routes := web.NewRoute()
routes.Use(public.AssetsHandler(&public.Options{ routes.Use(public.AssetsHandler(&public.Options{
@@ -80,17 +79,7 @@ func Routes() *web.Route {
CorsHandler: CorsHandler(), CorsHandler: CorsHandler(),
})) }))
routes.Use(session.Sessioner(session.Options{ routes.Use(sessioner)
Provider: setting.SessionConfig.Provider,
ProviderConfig: setting.SessionConfig.ProviderConfig,
CookieName: setting.SessionConfig.CookieName,
CookiePath: setting.SessionConfig.CookiePath,
Gclifetime: setting.SessionConfig.Gclifetime,
Maxlifetime: setting.SessionConfig.Maxlifetime,
Secure: setting.SessionConfig.Secure,
SameSite: setting.SessionConfig.SameSite,
Domain: setting.SessionConfig.Domain,
}))
routes.Use(Recovery()) routes.Use(Recovery())
@@ -1036,4 +1025,9 @@ func RegisterRoutes(m *web.Route) {
if setting.API.EnableSwagger { if setting.API.EnableSwagger {
m.Get("/swagger.v1.json", SwaggerV1Json) m.Get("/swagger.v1.json", SwaggerV1Json)
} }
m.NotFound(func(w http.ResponseWriter, req *http.Request) {
ctx := context.GetContext(req)
ctx.NotFound("", nil)
})
} }

View File

@@ -26,19 +26,16 @@
{{template "repo/migrate/options" .}} {{template "repo/migrate/options" .}}
<span class="help">{{.i18n.Tr "repo.migrate.migrate_items_options"}}</span> <div class="inline field">
<div id="migrate_items"> <label>{{.i18n.Tr "repo.migrate_items"}}</label>
<div class="inline field"> <div class="ui checkbox">
<label>{{.i18n.Tr "repo.migrate_items"}}</label> <input name="wiki" type="checkbox" {{if .wiki}} checked{{end}}>
<div class="ui checkbox"> <label>{{.i18n.Tr "repo.migrate_items_wiki" | Safe}}</label>
<input name="wiki" type="checkbox" {{if .wiki}} checked{{end}}>
<label>{{.i18n.Tr "repo.migrate_items_wiki" | Safe}}</label>
</div>
<div class="ui checkbox">
<input name="milestones" type="checkbox" {{if .milestones}} checked{{end}}>
<label>{{.i18n.Tr "repo.migrate_items_milestones" | Safe}}</label>
</div>
</div> </div>
</div>
<div id="migrate_items">
<span class="help">{{.i18n.Tr "repo.migrate.migrate_items_options"}}</span>
<div class="inline field"> <div class="inline field">
<label></label> <label></label>
<div class="ui checkbox"> <div class="ui checkbox">
@@ -61,6 +58,13 @@
<label>{{.i18n.Tr "repo.migrate_items_releases" | Safe}}</label> <label>{{.i18n.Tr "repo.migrate_items_releases" | Safe}}</label>
</div> </div>
</div> </div>
<div class="inline field">
<label></label>
<div class="ui checkbox">
<input name="milestones" type="checkbox" {{if .milestones}} checked{{end}}>
<label>{{.i18n.Tr "repo.migrate_items_milestones" | Safe}}</label>
</div>
</div>
</div> </div>
<div class="ui divider"></div> <div class="ui divider"></div>

View File

@@ -26,19 +26,15 @@
{{template "repo/migrate/options" .}} {{template "repo/migrate/options" .}}
<span class="help">{{.i18n.Tr "repo.migrate.migrate_items_options"}}</span> <div class="inline field">
<div id="migrate_items"> <label>{{.i18n.Tr "repo.migrate_items"}}</label>
<div class="inline field"> <div class="ui checkbox">
<label>{{.i18n.Tr "repo.migrate_items"}}</label> <input name="wiki" type="checkbox" {{if .wiki}}checked{{end}}>
<div class="ui checkbox"> <label>{{.i18n.Tr "repo.migrate_items_wiki" | Safe}}</label>
<input name="wiki" type="checkbox" {{if .wiki}}checked{{end}}>
<label>{{.i18n.Tr "repo.migrate_items_wiki" | Safe}}</label>
</div>
<div class="ui checkbox">
<input name="milestones" type="checkbox" {{if .milestones}}checked{{end}}>
<label>{{.i18n.Tr "repo.migrate_items_milestones" | Safe}}</label>
</div>
</div> </div>
</div>
<div id="migrate_items">
<span class="help">{{.i18n.Tr "repo.migrate.migrate_items_options"}}</span>
<div class="inline field"> <div class="inline field">
<label></label> <label></label>
<div class="ui checkbox"> <div class="ui checkbox">
@@ -61,6 +57,13 @@
<label>{{.i18n.Tr "repo.migrate_items_releases" | Safe}}</label> <label>{{.i18n.Tr "repo.migrate_items_releases" | Safe}}</label>
</div> </div>
</div> </div>
<div class="inline field">
<label></label>
<div class="ui checkbox">
<input name="milestones" type="checkbox" {{if .milestones}}checked{{end}}>
<label>{{.i18n.Tr "repo.migrate_items_milestones" | Safe}}</label>
</div>
</div>
</div> </div>
<div class="ui divider"></div> <div class="ui divider"></div>

View File

@@ -26,19 +26,15 @@
{{template "repo/migrate/options" .}} {{template "repo/migrate/options" .}}
<span class="help">{{.i18n.Tr "repo.migrate.migrate_items_options"}}</span> <div class="inline field">
<div id="migrate_items"> <label>{{.i18n.Tr "repo.migrate_items"}}</label>
<div class="inline field"> <div class="ui checkbox">
<label>{{.i18n.Tr "repo.migrate_items"}}</label> <input name="wiki" type="checkbox" {{if .wiki}}checked{{end}}>
<div class="ui checkbox"> <label>{{.i18n.Tr "repo.migrate_items_wiki" | Safe}}</label>
<input name="wiki" type="checkbox" {{if .wiki}}checked{{end}}>
<label>{{.i18n.Tr "repo.migrate_items_wiki" | Safe}}</label>
</div>
<div class="ui checkbox">
<input name="milestones" type="checkbox" {{if .milestones}}checked{{end}}>
<label>{{.i18n.Tr "repo.migrate_items_milestones" | Safe}}</label>
</div>
</div> </div>
</div>
<div id="migrate_items">
<span class="help">{{.i18n.Tr "repo.migrate.migrate_items_options"}}</span>
<div class="inline field"> <div class="inline field">
<label></label> <label></label>
<div class="ui checkbox"> <div class="ui checkbox">
@@ -61,6 +57,13 @@
<label>{{.i18n.Tr "repo.migrate_items_releases" | Safe}}</label> <label>{{.i18n.Tr "repo.migrate_items_releases" | Safe}}</label>
</div> </div>
</div> </div>
<div class="inline field">
<label></label>
<div class="ui checkbox">
<input name="milestones" type="checkbox" {{if .milestones}}checked{{end}}>
<label>{{.i18n.Tr "repo.migrate_items_milestones" | Safe}}</label>
</div>
</div>
</div> </div>
<div class="ui divider"></div> <div class="ui divider"></div>

View File

@@ -26,19 +26,16 @@
{{template "repo/migrate/options" .}} {{template "repo/migrate/options" .}}
<span class="help">{{.i18n.Tr "repo.migrate.migrate_items_options"}}</span> <div class="inline field">
<div id="migrate_items"> <label>{{.i18n.Tr "repo.migrate_items"}}</label>
<div class="inline field"> <div class="ui checkbox">
<label>{{.i18n.Tr "repo.migrate_items"}}</label> <input name="wiki" type="checkbox" {{if .wiki}} checked{{end}}>
<div class="ui checkbox"> <label>{{.i18n.Tr "repo.migrate_items_wiki" | Safe}}</label>
<input name="wiki" type="checkbox" {{if .wiki}} checked{{end}}>
<label>{{.i18n.Tr "repo.migrate_items_wiki" | Safe}}</label>
</div>
<div class="ui checkbox">
<input name="milestones" type="checkbox" {{if .milestones}} checked{{end}}>
<label>{{.i18n.Tr "repo.migrate_items_milestones" | Safe}}</label>
</div>
</div> </div>
</div>
<div id="migrate_items">
<span class="help">{{.i18n.Tr "repo.migrate.migrate_items_options"}}</span>
<div class="inline field"> <div class="inline field">
<label></label> <label></label>
<div class="ui checkbox"> <div class="ui checkbox">
@@ -50,6 +47,13 @@
<label>{{.i18n.Tr "repo.migrate_items_issues" | Safe}}</label> <label>{{.i18n.Tr "repo.migrate_items_issues" | Safe}}</label>
</div> </div>
</div> </div>
<div class="inline field">
<label></label>
<div class="ui checkbox">
<input name="milestones" type="checkbox" {{if .milestones}} checked{{end}}>
<label>{{.i18n.Tr "repo.migrate_items_milestones" | Safe}}</label>
</div>
</div>
<!-- Gogs do not support it <!-- Gogs do not support it
<div class="inline field"> <div class="inline field">
<label></label> <label></label>

View File

@@ -25,7 +25,11 @@
<p id="repo_migrating_progress_message"></p> <p id="repo_migrating_progress_message"></p>
</div> </div>
<div id="repo_migrating_failed" hidden> <div id="repo_migrating_failed" hidden>
<p>{{.i18n.Tr "repo.migrate.migrating_failed" .CloneAddr | Safe}}</p> {{if .CloneAddr}}
<p>{{.i18n.Tr "repo.migrate.migrating_failed" .CloneAddr | Safe}}</p>
{{else}}
<p>{{.i18n.Tr "repo.migrate.migrating_failed" "<nil>" | Safe}}</p>
{{end}}
<p id="repo_migrating_failed_error"></p> <p id="repo_migrating_failed_error"></p>
</div> </div>
{{if and .Failed .Permission.IsAdmin}} {{if and .Failed .Permission.IsAdmin}}

View File

@@ -8,7 +8,7 @@
{{range .U2FRegistrations}} {{range .U2FRegistrations}}
<div class="item"> <div class="item">
<div class="right floated content"> <div class="right floated content">
<button class="ui red tiny button delete-button" modal-id="delete-registration" data-url="{{$.Link}}/u2f/delete" data-id="{{.ID}}"> <button class="ui red tiny button delete-button" id="delete-registration" data-url="{{$.Link}}/u2f/delete" data-id="{{.ID}}">
{{$.i18n.Tr "settings.delete_key"}} {{$.i18n.Tr "settings.delete_key"}}
</button> </button>
</div> </div>

View File

@@ -2959,8 +2959,8 @@ $(() => {
function showDeletePopup() { function showDeletePopup() {
const $this = $(this); const $this = $(this);
let filter = ''; let filter = '';
if ($this.attr('modal-id')) { if ($this.attr('id')) {
filter += `#${$this.attr('modal-id')}`; filter += `#${$this.attr('id')}`;
} }
const dialog = $(`.delete.modal${filter}`); const dialog = $(`.delete.modal${filter}`);

View File

@@ -135,7 +135,6 @@ textarea:focus,
.form { .form {
.help { .help {
color: #999999; color: #999999;
padding-top: .6em;
padding-bottom: .6em; padding-bottom: .6em;
display: inline-block; display: inline-block;
} }