Skip to content

Commit

Permalink
Fix broken following organization (#29005)
Browse files Browse the repository at this point in the history
- following organization is broken from #28908
- add login check for the follow button in organization profile page
  • Loading branch information
yp05327 authored Feb 17, 2024
1 parent e936d2b commit 6822799
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
14 changes: 12 additions & 2 deletions routers/web/user/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

const (
tplProfileBigAvatar base.TplName = "shared/user/profile_big_avatar"
tplFollowUnfollow base.TplName = "shared/user/follow_unfollow"
)

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

shared_user.PrepareContextForProfileBigAvatar(ctx)
ctx.HTML(http.StatusOK, tplProfileBigAvatar)
if ctx.ContextUser.IsIndividual() {
shared_user.PrepareContextForProfileBigAvatar(ctx)
ctx.HTML(http.StatusOK, tplProfileBigAvatar)
return
} else if ctx.ContextUser.IsOrganization() {
ctx.Data["IsFollowing"] = ctx.Doer != nil && user_model.IsFollowing(ctx, ctx.Doer.ID, ctx.ContextUser.ID)
ctx.HTML(http.StatusOK, tplFollowUnfollow)
return
}
log.Error("Failed to apply action %q: unsupport context user type: %s", ctx.FormString("action"), ctx.ContextUser.Type)
ctx.Error(http.StatusBadRequest, fmt.Sprintf("Action %q failed", ctx.FormString("action")))
}
16 changes: 9 additions & 7 deletions templates/org/home.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
{{svg "octicon-rss" 24}}
</a>
{{end}}
<button class="link-action ui basic button gt-mr-0" data-url="{{.Org.HomeLink}}?action={{if $.IsFollowing}}unfollow{{else}}follow{{end}}">
{{if $.IsFollowing}}
{{ctx.Locale.Tr "user.unfollow"}}
{{else}}
{{ctx.Locale.Tr "user.follow"}}
{{end}}
</button>
{{if .IsSigned}}
<button class="ui basic button gt-mr-0" hx-post="{{.Org.HomeLink}}?action={{if $.IsFollowing}}unfollow{{else}}follow{{end}}">
{{if $.IsFollowing}}
{{ctx.Locale.Tr "user.unfollow"}}
{{else}}
{{ctx.Locale.Tr "user.follow"}}
{{end}}
</button>
{{end}}
</div>
</div>

Expand Down

0 comments on commit 6822799

Please sign in to comment.