Skip to content

Commit fd3b4af

Browse files
yp05327earl-warren
authored andcommitted
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 (cherry picked from commit 6822799)
1 parent 1ad195a commit fd3b4af

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
@@ -31,6 +31,7 @@ import (
3131

3232
const (
3333
tplProfileBigAvatar base.TplName = "shared/user/profile_big_avatar"
34+
tplFollowUnfollow base.TplName = "shared/user/follow_unfollow"
3435
)
3536

3637
// OwnerProfile render profile page for a user or a organization (aka, repo owner)
@@ -349,6 +350,15 @@ func Action(ctx *context.Context) {
349350
return
350351
}
351352

352-
shared_user.PrepareContextForProfileBigAvatar(ctx)
353-
ctx.HTML(http.StatusOK, tplProfileBigAvatar)
353+
if ctx.ContextUser.IsIndividual() {
354+
shared_user.PrepareContextForProfileBigAvatar(ctx)
355+
ctx.HTML(http.StatusOK, tplProfileBigAvatar)
356+
return
357+
} else if ctx.ContextUser.IsOrganization() {
358+
ctx.Data["IsFollowing"] = ctx.Doer != nil && user_model.IsFollowing(ctx, ctx.Doer.ID, ctx.ContextUser.ID)
359+
ctx.HTML(http.StatusOK, tplFollowUnfollow)
360+
return
361+
}
362+
log.Error("Failed to apply action %q: unsupport context user type: %s", ctx.FormString("action"), ctx.ContextUser.Type)
363+
ctx.Error(http.StatusBadRequest, fmt.Sprintf("Action %q failed", ctx.FormString("action")))
354364
}

templates/org/home.tmpl

+9-7
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@
3030
{{svg "octicon-rss" 24}}
3131
</a>
3232
{{end}}
33-
<button class="link-action ui basic button gt-mr-0" data-url="{{.Org.HomeLink}}?action={{if $.IsFollowing}}unfollow{{else}}follow{{end}}">
34-
{{if $.IsFollowing}}
35-
{{ctx.Locale.Tr "user.unfollow"}}
36-
{{else}}
37-
{{ctx.Locale.Tr "user.follow"}}
38-
{{end}}
39-
</button>
33+
{{if .IsSigned}}
34+
<button class="ui basic button gt-mr-0" hx-post="{{.Org.HomeLink}}?action={{if $.IsFollowing}}unfollow{{else}}follow{{end}}">
35+
{{if $.IsFollowing}}
36+
{{ctx.Locale.Tr "user.unfollow"}}
37+
{{else}}
38+
{{ctx.Locale.Tr "user.follow"}}
39+
{{end}}
40+
</button>
41+
{{end}}
4042
</div>
4143
</div>
4244

0 commit comments

Comments
 (0)