Fix broken following organization (#29005)

- following organization is broken from #28908
- add login check for the follow button in organization profile page

(cherry picked from commit 68227996a7a84a240b36c304d04c5c8d82948df8)
This commit is contained in:
yp05327 2024-02-17 14:13:37 +09:00 committed by Earl Warren
parent 1ad195aa40
commit fd3b4afa2b
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 0579CB2928A78A00
2 changed files with 21 additions and 9 deletions

View file

@ -31,6 +31,7 @@ import (
const ( const (
tplProfileBigAvatar base.TplName = "shared/user/profile_big_avatar" 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) // OwnerProfile render profile page for a user or a organization (aka, repo owner)
@ -349,6 +350,15 @@ func Action(ctx *context.Context) {
return return
} }
shared_user.PrepareContextForProfileBigAvatar(ctx) if ctx.ContextUser.IsIndividual() {
ctx.HTML(http.StatusOK, tplProfileBigAvatar) 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")))
} }

View file

@ -30,13 +30,15 @@
{{svg "octicon-rss" 24}} {{svg "octicon-rss" 24}}
</a> </a>
{{end}} {{end}}
<button class="link-action ui basic button gt-mr-0" data-url="{{.Org.HomeLink}}?action={{if $.IsFollowing}}unfollow{{else}}follow{{end}}"> {{if .IsSigned}}
{{if $.IsFollowing}} <button class="ui basic button gt-mr-0" hx-post="{{.Org.HomeLink}}?action={{if $.IsFollowing}}unfollow{{else}}follow{{end}}">
{{ctx.Locale.Tr "user.unfollow"}} {{if $.IsFollowing}}
{{else}} {{ctx.Locale.Tr "user.unfollow"}}
{{ctx.Locale.Tr "user.follow"}} {{else}}
{{end}} {{ctx.Locale.Tr "user.follow"}}
</button> {{end}}
</button>
{{end}}
</div> </div>
</div> </div>