summaryrefslogtreecommitdiffstats
path: root/routers/web/web.go
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2022-03-26 10:04:22 +0100
committerGitHub <noreply@github.com>2022-03-26 17:04:22 +0800
commit59b867dc2dfc1ecb0ee703ff44e1be9c5c53cf86 (patch)
tree7114b991554e6e7dcb4123c0aa365c674d8411a0 /routers/web/web.go
parentf36701c702dc67011999cfaaf37e002c13e7a87e (diff)
downloadgitea-59b867dc2dfc1ecb0ee703ff44e1be9c5c53cf86.tar.gz
gitea-59b867dc2dfc1ecb0ee703ff44e1be9c5c53cf86.zip
Add `ContextUser` to http request context (#18798)
This PR adds a middleware which sets a ContextUser (like GetUserByParams before) in a single place which can be used by other methods. For routes which represent a repo or org the respective middlewares set the field too. Also fix a bug in modules/context/org.go during refactoring.
Diffstat (limited to 'routers/web/web.go')
-rw-r--r--routers/web/web.go18
1 files changed, 15 insertions, 3 deletions
diff --git a/routers/web/web.go b/routers/web/web.go
index b40a43058d..f4cabaab6e 100644
--- a/routers/web/web.go
+++ b/routers/web/web.go
@@ -29,12 +29,14 @@ import (
"code.gitea.io/gitea/routers/web/dev"
"code.gitea.io/gitea/routers/web/events"
"code.gitea.io/gitea/routers/web/explore"
+ "code.gitea.io/gitea/routers/web/feed"
"code.gitea.io/gitea/routers/web/org"
"code.gitea.io/gitea/routers/web/repo"
"code.gitea.io/gitea/routers/web/user"
user_setting "code.gitea.io/gitea/routers/web/user/setting"
"code.gitea.io/gitea/routers/web/user/setting/security"
auth_service "code.gitea.io/gitea/services/auth"
+ context_service "code.gitea.io/gitea/services/context"
"code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/lfs"
"code.gitea.io/gitea/services/mailer"
@@ -496,11 +498,21 @@ func RegisterRoutes(m *web.Route) {
// ***** END: Admin *****
m.Group("", func() {
- m.Get("/{username}", user.Profile)
+ m.Get("/favicon.ico", func(ctx *context.Context) {
+ ctx.ServeFile(path.Join(setting.StaticRootPath, "public/img/favicon.png"))
+ })
+ m.Group("/{username}", func() {
+ m.Get(".png", func(ctx *context.Context) { ctx.Error(http.StatusNotFound) })
+ m.Get(".keys", user.ShowSSHKeys)
+ m.Get(".gpg", user.ShowGPGKeys)
+ m.Get(".rss", feed.ShowUserFeedRSS)
+ m.Get(".atom", feed.ShowUserFeedAtom)
+ m.Get("", user.Profile)
+ }, context_service.UserAssignmentWeb())
m.Get("/attachments/{uuid}", repo.GetAttachment)
}, ignSignIn)
- m.Post("/{username}", reqSignIn, user.Action)
+ m.Post("/{username}", reqSignIn, context_service.UserAssignmentWeb(), user.Action)
if !setting.IsProd {
m.Get("/template/*", dev.TemplatePreview)
@@ -1107,7 +1119,7 @@ func RegisterRoutes(m *web.Route) {
m.GetOptions("/objects/{head:[0-9a-f]{2}}/{hash:[0-9a-f]{38}}", repo.GetLooseObject)
m.GetOptions("/objects/pack/pack-{file:[0-9a-f]{40}}.pack", repo.GetPackFile)
m.GetOptions("/objects/pack/pack-{file:[0-9a-f]{40}}.idx", repo.GetIdxFile)
- }, ignSignInAndCsrf)
+ }, ignSignInAndCsrf, context_service.UserAssignmentWeb())
})
})
// ***** END: Repository *****