Skip to content

Commit 0ac8450

Browse files
authored
Move POST /{username}/action/{action} to simply POST /{username} (#18045)
The current code unfortunately requires that `action` be a reserved repository name as it prevents posts to change the settings for action repositories. However, we can simply change action handler to work on POST /{username} instead. Fix #18037 Signed-off-by: Andrew Thornton <[email protected]>
1 parent ce840bb commit 0ac8450

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

routers/web/user/profile.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -363,15 +363,15 @@ func Action(ctx *context.Context) {
363363
}
364364

365365
var err error
366-
switch ctx.Params(":action") {
366+
switch ctx.FormString("action") {
367367
case "follow":
368368
err = user_model.FollowUser(ctx.User.ID, u.ID)
369369
case "unfollow":
370370
err = user_model.UnfollowUser(ctx.User.ID, u.ID)
371371
}
372372

373373
if err != nil {
374-
ctx.ServerError(fmt.Sprintf("Action (%s)", ctx.Params(":action")), err)
374+
ctx.ServerError(fmt.Sprintf("Action (%s)", ctx.FormString("action")), err)
375375
return
376376
}
377377
// FIXME: We should check this URL and make sure that it's a valid Gitea URL

routers/web/web.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,7 @@ func RegisterRoutes(m *web.Route) {
484484
m.Get("/attachments/{uuid}", repo.GetAttachment)
485485
}, ignSignIn)
486486

487-
m.Group("/{username}", func() {
488-
m.Post("/action/{action}", user.Action)
489-
}, reqSignIn)
487+
m.Post("/{username}", reqSignIn, user.Action)
490488

491489
if !setting.IsProd {
492490
m.Get("/template/*", dev.TemplatePreview)

templates/user/profile.tmpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@
6666
{{if and .IsSigned (ne .SignedUserName .Owner.Name)}}
6767
<li class="follow">
6868
{{if $.IsFollowing}}
69-
<form method="post" action="{{.Link}}/action/unfollow?redirect_to={{$.Link}}">
69+
<form method="post" action="{{.Link}}?action=unfollow&redirect_to={{$.Link}}">
7070
{{$.CsrfTokenHtml}}
7171
<button type="submit" class="ui basic red button">{{svg "octicon-person"}} {{.i18n.Tr "user.unfollow"}}</button>
7272
</form>
7373
{{else}}
74-
<form method="post" action="{{.Link}}/action/follow?redirect_to={{$.Link}}">
74+
<form method="post" action="{{.Link}}?action=follow&redirect_to={{$.Link}}">
7575
{{$.CsrfTokenHtml}}
7676
<button type="submit" class="ui basic green button">{{svg "octicon-person"}} {{.i18n.Tr "user.follow"}}</button>
7777
</form>

0 commit comments

Comments
 (0)