Skip to content

Commit 6822799

Browse files
authored
Fix broken following organization (go-gitea#29005)
- following organization is broken from go-gitea#28908 - add login check for the follow button in organization profile page
1 parent e936d2b commit 6822799

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

routers/web/user/profile.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929

3030
const (
3131
tplProfileBigAvatar base.TplName = "shared/user/profile_big_avatar"
32+
tplFollowUnfollow base.TplName = "shared/user/follow_unfollow"
3233
)
3334

3435
// OwnerProfile render profile page for a user or a organization (aka, repo owner)
@@ -318,6 +319,15 @@ func Action(ctx *context.Context) {
318319
return
319320
}
320321

321-
shared_user.PrepareContextForProfileBigAvatar(ctx)
322-
ctx.HTML(http.StatusOK, tplProfileBigAvatar)
322+
if ctx.ContextUser.IsIndividual() {
323+
shared_user.PrepareContextForProfileBigAvatar(ctx)
324+
ctx.HTML(http.StatusOK, tplProfileBigAvatar)
325+
return
326+
} else if ctx.ContextUser.IsOrganization() {
327+
ctx.Data["IsFollowing"] = ctx.Doer != nil && user_model.IsFollowing(ctx, ctx.Doer.ID, ctx.ContextUser.ID)
328+
ctx.HTML(http.StatusOK, tplFollowUnfollow)
329+
return
330+
}
331+
log.Error("Failed to apply action %q: unsupport context user type: %s", ctx.FormString("action"), ctx.ContextUser.Type)
332+
ctx.Error(http.StatusBadRequest, fmt.Sprintf("Action %q failed", ctx.FormString("action")))
323333
}

templates/org/home.tmpl

+9-7
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@
2525
{{svg "octicon-rss" 24}}
2626
</a>
2727
{{end}}
28-
<button class="link-action ui basic button gt-mr-0" data-url="{{.Org.HomeLink}}?action={{if $.IsFollowing}}unfollow{{else}}follow{{end}}">
29-
{{if $.IsFollowing}}
30-
{{ctx.Locale.Tr "user.unfollow"}}
31-
{{else}}
32-
{{ctx.Locale.Tr "user.follow"}}
33-
{{end}}
34-
</button>
28+
{{if .IsSigned}}
29+
<button class="ui basic button gt-mr-0" hx-post="{{.Org.HomeLink}}?action={{if $.IsFollowing}}unfollow{{else}}follow{{end}}">
30+
{{if $.IsFollowing}}
31+
{{ctx.Locale.Tr "user.unfollow"}}
32+
{{else}}
33+
{{ctx.Locale.Tr "user.follow"}}
34+
{{end}}
35+
</button>
36+
{{end}}
3537
</div>
3638
</div>
3739

0 commit comments

Comments
 (0)