Support "." char as user name for User/Orgs in RSS/ATOM/GPG/KEYS path ... (#23874)
- close #22301 workaround for https://github.com/go-chi/chi/issues/781
This commit is contained in:
parent
ca5722a0fa
commit
88033438aa
7 changed files with 107 additions and 15 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models/perm"
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
|
@ -673,16 +674,47 @@ func RegisterRoutes(m *web.Route) {
|
|||
})
|
||||
http.ServeFile(ctx.Resp, ctx.Req, path.Join(setting.StaticRootPath, "public/img/favicon.png"))
|
||||
})
|
||||
m.Group("/{username}", func() {
|
||||
m.Get(".png", user.AvatarByUserName)
|
||||
m.Get(".keys", user.ShowSSHKeys)
|
||||
m.Get(".gpg", user.ShowGPGKeys)
|
||||
m.Get(".rss", feedEnabled, feed.ShowUserFeedRSS)
|
||||
m.Get(".atom", feedEnabled, feed.ShowUserFeedAtom)
|
||||
m.Get("", user.Profile)
|
||||
}, func(ctx *context.Context) {
|
||||
ctx.Data["EnableFeed"] = setting.EnableFeed
|
||||
}, context_service.UserAssignmentWeb())
|
||||
m.Get("/{username}", func(ctx *context.Context) {
|
||||
// WORKAROUND to support usernames with "." in it
|
||||
// https://github.com/go-chi/chi/issues/781
|
||||
username := ctx.Params("username")
|
||||
reloadParam := func(suffix string) (success bool) {
|
||||
ctx.SetParams("username", strings.TrimSuffix(username, suffix))
|
||||
context_service.UserAssignmentWeb()(ctx)
|
||||
return !ctx.Written()
|
||||
}
|
||||
switch {
|
||||
case strings.HasSuffix(username, ".png"):
|
||||
if reloadParam(".png") {
|
||||
user.AvatarByUserName(ctx)
|
||||
}
|
||||
case strings.HasSuffix(username, ".keys"):
|
||||
if reloadParam(".keys") {
|
||||
user.ShowSSHKeys(ctx)
|
||||
}
|
||||
case strings.HasSuffix(username, ".gpg"):
|
||||
if reloadParam(".gpg") {
|
||||
user.ShowGPGKeys(ctx)
|
||||
}
|
||||
case strings.HasSuffix(username, ".rss"):
|
||||
feedEnabled(ctx)
|
||||
if !ctx.Written() && reloadParam(".rss") {
|
||||
context_service.UserAssignmentWeb()(ctx)
|
||||
feed.ShowUserFeedRSS(ctx)
|
||||
}
|
||||
case strings.HasSuffix(username, ".atom"):
|
||||
feedEnabled(ctx)
|
||||
if !ctx.Written() && reloadParam(".atom") {
|
||||
feed.ShowUserFeedAtom(ctx)
|
||||
}
|
||||
default:
|
||||
context_service.UserAssignmentWeb()(ctx)
|
||||
if !ctx.Written() {
|
||||
ctx.Data["EnableFeed"] = setting.EnableFeed
|
||||
user.Profile(ctx)
|
||||
}
|
||||
}
|
||||
})
|
||||
m.Get("/attachments/{uuid}", repo.GetAttachment)
|
||||
}, ignSignIn)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue