Skip to content

Commit a818a48

Browse files
authored
Move POST /{username}/action/{action} to simply POST /{username} (#18045) (#18046)
Backport #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 76e1c13 commit a818a48

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
@@ -321,15 +321,15 @@ func Action(ctx *context.Context) {
321321
}
322322

323323
var err error
324-
switch ctx.Params(":action") {
324+
switch ctx.Query("action") {
325325
case "follow":
326326
err = models.FollowUser(ctx.User.ID, u.ID)
327327
case "unfollow":
328328
err = models.UnfollowUser(ctx.User.ID, u.ID)
329329
}
330330

331331
if err != nil {
332-
ctx.ServerError(fmt.Sprintf("Action (%s)", ctx.Params(":action")), err)
332+
ctx.ServerError(fmt.Sprintf("Action (%s)", ctx.Query("action")), err)
333333
return
334334
}
335335

routers/web/web.go

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

464-
m.Group("/{username}", func() {
465-
m.Post("/action/{action}", user.Action)
466-
}, reqSignIn)
464+
m.Post("/{username}", reqSignIn, user.Action)
467465

468466
if !setting.IsProd() {
469467
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 .SignedUser.IsFollowing .Owner.ID}}
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)