Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move POST /{username}/action/{action} to simply POST /{username} (#18045) #18046

Merged
merged 2 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions routers/web/user/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,15 @@ func Action(ctx *context.Context) {
}

var err error
switch ctx.Params(":action") {
switch ctx.Query("action") {
case "follow":
err = models.FollowUser(ctx.User.ID, u.ID)
case "unfollow":
err = models.UnfollowUser(ctx.User.ID, u.ID)
}

if err != nil {
ctx.ServerError(fmt.Sprintf("Action (%s)", ctx.Params(":action")), err)
ctx.ServerError(fmt.Sprintf("Action (%s)", ctx.Query("action")), err)
return
}

Expand Down
4 changes: 1 addition & 3 deletions routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,7 @@ func RegisterRoutes(m *web.Route) {
m.Get("/attachments/{uuid}", repo.GetAttachment)
}, ignSignIn)

m.Group("/{username}", func() {
m.Post("/action/{action}", user.Action)
}, reqSignIn)
m.Post("/{username}", reqSignIn, user.Action)

if !setting.IsProd() {
m.Get("/template/*", dev.TemplatePreview)
Expand Down
4 changes: 2 additions & 2 deletions templates/user/profile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@
{{if and .IsSigned (ne .SignedUserName .Owner.Name)}}
<li class="follow">
{{if .SignedUser.IsFollowing .Owner.ID}}
<form method="post" action="{{.Link}}/action/unfollow?redirect_to={{$.Link}}">
<form method="post" action="{{.Link}}?action=unfollow&redirect_to={{$.Link}}">
{{$.CsrfTokenHtml}}
<button type="submit" class="ui basic red button">{{svg "octicon-person"}} {{.i18n.Tr "user.unfollow"}}</button>
</form>
{{else}}
<form method="post" action="{{.Link}}/action/follow?redirect_to={{$.Link}}">
<form method="post" action="{{.Link}}?action=follow&redirect_to={{$.Link}}">
{{$.CsrfTokenHtml}}
<button type="submit" class="ui basic green button">{{svg "octicon-person"}} {{.i18n.Tr "user.follow"}}</button>
</form>
Expand Down