Skip to content

Fix broken following organization #29005

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

Merged
merged 9 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
13 changes: 1 addition & 12 deletions routers/web/org/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,11 @@ func Home(ctx *context.Context) {
if ctx.Written() {
return
}

shared_user.PrepareContextForOrgProfileBigAvatar(ctx)
org := ctx.Org.Organization

ctx.Data["PageIsUserProfile"] = true
ctx.Data["Title"] = org.DisplayName()
if len(org.Description) != 0 {
desc, err := markdown.RenderString(&markup.RenderContext{
Ctx: ctx,
Metas: map[string]string{"mode": "document"},
}, org.Description)
if err != nil {
ctx.ServerError("RenderString", err)
return
}
ctx.Data["RenderedDescription"] = desc
}

var orderBy db.SearchOrderBy
ctx.Data["SortType"] = ctx.FormString("sort")
Expand Down
19 changes: 19 additions & 0 deletions routers/web/shared/user/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ func prepareContextForCommonProfile(ctx *context.Context) {
ctx.Data["FeedURL"] = ctx.ContextUser.HomeLink()
}

// PrepareContextForProfileBigAvatar set the context for big avatar view on the org profile page
func PrepareContextForOrgProfileBigAvatar(ctx *context.Context) {
prepareContextForCommonProfile(ctx)

ctx.Data["IsFollowing"] = ctx.Doer != nil && user_model.IsFollowing(ctx, ctx.Doer.ID, ctx.ContextUser.ID)

if len(ctx.ContextUser.Description) != 0 {
desc, err := markdown.RenderString(&markup.RenderContext{
Ctx: ctx,
Metas: map[string]string{"mode": "document"},
}, ctx.ContextUser.Description)
if err != nil {
ctx.ServerError("RenderString", err)
return
}
ctx.Data["RenderedDescription"] = desc
}
}

// PrepareContextForProfileBigAvatar set the context for big avatar view on the profile page
func PrepareContextForProfileBigAvatar(ctx *context.Context) {
prepareContextForCommonProfile(ctx)
Expand Down
16 changes: 13 additions & 3 deletions routers/web/user/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import (
)

const (
tplProfileBigAvatar base.TplName = "shared/user/profile_big_avatar"
tplProfileBigAvatar base.TplName = "shared/user/profile_big_avatar"
tplOrgProfileBigAvatar base.TplName = "shared/user/org_profile_big_avatar"
)

// 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() {
shared_user.PrepareContextForOrgProfileBigAvatar(ctx)
ctx.HTML(http.StatusOK, tplOrgProfileBigAvatar)
return
}
log.Error("Failed to apply action %q: unsupport context user type: %s", ctx.FormString("action"), ctx.ContextUser.Type)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctx.ContextUser.Type is not a %s.

ctx.Error(http.StatusBadRequest, fmt.Sprintf("Action %q failed", ctx.FormString("action")))
}
35 changes: 1 addition & 34 deletions templates/org/home.tmpl
Original file line number Diff line number Diff line change
@@ -1,39 +1,6 @@
{{template "base/head" .}}
<div role="main" aria-label="{{.Title}}" class="page-content organization profile">
<div class="ui container gt-df">
{{ctx.AvatarUtils.Avatar .Org 140 "org-avatar"}}
<div id="org-info">
<div class="ui header">
{{.Org.DisplayName}}
<span class="org-visibility">
{{if .Org.Visibility.IsLimited}}<span class="ui large basic horizontal label">{{ctx.Locale.Tr "org.settings.visibility.limited_shortname"}}</span>{{end}}
{{if .Org.Visibility.IsPrivate}}<span class="ui large basic horizontal label">{{ctx.Locale.Tr "org.settings.visibility.private_shortname"}}</span>{{end}}
</span>
</div>
{{if $.RenderedDescription}}<div class="render-content markup">{{$.RenderedDescription|Str2html}}</div>{{end}}
<div class="text grey meta">
{{if .Org.Location}}<div class="flex-text-block">{{svg "octicon-location"}} <span>{{.Org.Location}}</span></div>{{end}}
{{if .Org.Website}}<div class="flex-text-block">{{svg "octicon-link"}} <a target="_blank" rel="noopener noreferrer me" href="{{.Org.Website}}">{{.Org.Website}}</a></div>{{end}}
{{if $.IsSigned}}
{{if .Org.Email}}<div class="flex-text-block">{{svg "octicon-mail"}} <a class="muted" href="mailto:{{.Org.Email}}">{{.Org.Email}}</a></div>{{end}}
{{end}}
</div>
</div>
<div class="right menu">
{{if .EnableFeed}}
<a class="ui basic label button gt-mr-0" href="{{$.Org.HomeLink}}.rss" data-tooltip-content="{{ctx.Locale.Tr "rss_feed"}}">
{{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>
</div>
</div>
{{template "shared/user/org_profile_big_avatar" .}}

{{template "org/menu" .}}

Expand Down
36 changes: 36 additions & 0 deletions templates/shared/user/org_profile_big_avatar.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<div class="ui container gt-df" id="org-profile-avatar-container">
{{ctx.AvatarUtils.Avatar .ContextUser 140 "org-avatar"}}
<div id="org-info">
<div class="ui header">
{{.ContextUser.DisplayName}}
<span class="org-visibility">
{{if .ContextUser.Visibility.IsLimited}}<span class="ui large basic horizontal label">{{ctx.Locale.Tr "org.settings.visibility.limited_shortname"}}</span>{{end}}
{{if .ContextUser.Visibility.IsPrivate}}<span class="ui large basic horizontal label">{{ctx.Locale.Tr "org.settings.visibility.private_shortname"}}</span>{{end}}
</span>
</div>
{{if $.RenderedDescription}}<div class="render-content markup">{{$.RenderedDescription|Str2html}}</div>{{end}}
<div class="text grey meta">
{{if .ContextUser.Location}}<div class="flex-text-block">{{svg "octicon-location"}} <span>{{.ContextUser.Location}}</span></div>{{end}}
{{if .ContextUser.Website}}<div class="flex-text-block">{{svg "octicon-link"}} <a target="_blank" rel="noopener noreferrer me" href="{{.ContextUser.Website}}">{{.ContextUser.Website}}</a></div>{{end}}
{{if $.IsSigned}}
{{if .ContextUser.Email}}<div class="flex-text-block">{{svg "octicon-mail"}} <a class="muted" href="mailto:{{.ContextUser.Email}}">{{.ContextUser.Email}}</a></div>{{end}}
{{end}}
</div>
</div>
<div class="right menu">
{{if .EnableFeed}}
<a class="ui basic label button gt-mr-0" href="{{$.ContextUser.HomeLink}}.rss" data-tooltip-content="{{ctx.Locale.Tr "rss_feed"}}">
{{svg "octicon-rss" 24}}
</a>
{{end}}
{{if .IsSigned}}
<button class="ui basic button gt-mr-0" hx-post="{{.ContextUser.HomeLink}}?action={{if $.IsFollowing}}unfollow{{else}}follow{{end}}" hx-target="#org-profile-avatar-container" hx-indicator="#org-profile-avatar-container">
{{if $.IsFollowing}}
{{ctx.Locale.Tr "user.unfollow"}}
{{else}}
{{ctx.Locale.Tr "user.follow"}}
{{end}}
</button>
{{end}}
</div>
</div>