diff --git a/models/user/user.go b/models/user/user.go index 053d6680cdde..46c4440e5f07 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -346,7 +346,7 @@ func GetUserFollowing(ctx context.Context, u, viewer *User, listOptions db.ListO Select("`user`.*"). Join("LEFT", "follow", "`user`.id=follow.follow_id"). Where("follow.user_id=?", u.ID). - And("`user`.type=?", UserTypeIndividual). + And("`user`.type IN (?, ?)", UserTypeIndividual, UserTypeOrganization). And(isUserVisibleToViewerCond(viewer)) if listOptions.Page != 0 { @@ -1210,23 +1210,25 @@ func isUserVisibleToViewerCond(viewer *User) builder.Cond { return builder.Neq{ "`user`.visibility": structs.VisibleTypePrivate, }.Or( + // viewer's following builder.In("`user`.id", builder. Select("`follow`.user_id"). From("follow"). Where(builder.Eq{"`follow`.follow_id": viewer.ID})), - builder.In("`user`.id", - builder. - Select("`team_user`.uid"). - From("team_user"). - Join("INNER", "`team_user` AS t2", "`team_user`.id = `t2`.id"). - Where(builder.Eq{"`t2`.uid": viewer.ID})), + // viewer's org user builder.In("`user`.id", builder. Select("`team_user`.uid"). From("team_user"). Join("INNER", "`team_user` AS t2", "`team_user`.org_id = `t2`.org_id"). - Where(builder.Eq{"`t2`.uid": viewer.ID}))) + Where(builder.Eq{"`t2`.uid": viewer.ID})), + // viewer's org + builder.In("`user`.id", + builder. + Select("`team_user`.org_id"). + From("team_user"). + Where(builder.Eq{"`team_user`.uid": viewer.ID}))) } // IsUserVisibleToViewer check if viewer is able to see user profile diff --git a/routers/web/org/home.go b/routers/web/org/home.go index 201eefa61402..7f38ec51ba6e 100644 --- a/routers/web/org/home.go +++ b/routers/web/org/home.go @@ -10,6 +10,7 @@ import ( "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/organization" repo_model "code.gitea.io/gitea/models/repo" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/markup" @@ -143,6 +144,11 @@ func Home(ctx *context.Context) { return } + var isFollowing bool + if ctx.Doer != nil { + isFollowing = user_model.IsFollowing(ctx.Doer.ID, ctx.ContextUser.ID) + } + ctx.Data["Repos"] = repos ctx.Data["Total"] = count ctx.Data["MembersTotal"] = membersCount @@ -150,6 +156,7 @@ func Home(ctx *context.Context) { ctx.Data["Teams"] = ctx.Org.Teams ctx.Data["DisableNewPullMirrors"] = setting.Mirror.DisableNewPull ctx.Data["PageIsViewRepositories"] = true + ctx.Data["IsFollowing"] = isFollowing pager := context.NewPagination(int(count), setting.UI.User.RepoPagingNum, page, 5) pager.SetDefaultParams(ctx) diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go index 367bb306b83c..ef91d89d14e9 100644 --- a/routers/web/user/profile.go +++ b/routers/web/user/profile.go @@ -167,30 +167,31 @@ func Profile(ctx *context.Context) { language := ctx.FormTrim("language") ctx.Data["Language"] = language + followers, numFollowers, err := user_model.GetUserFollowers(ctx, ctx.ContextUser, ctx.Doer, db.ListOptions{ + PageSize: pagingNum, + Page: page, + }) + if err != nil { + ctx.ServerError("GetUserFollowers", err) + return + } + ctx.Data["NumFollowers"] = numFollowers + following, numFollowing, err := user_model.GetUserFollowing(ctx, ctx.ContextUser, ctx.Doer, db.ListOptions{ + PageSize: pagingNum, + Page: page, + }) + if err != nil { + ctx.ServerError("GetUserFollowing", err) + return + } + ctx.Data["NumFollowing"] = numFollowing + switch tab { case "followers": - items, count, err := user_model.GetUserFollowers(ctx, ctx.ContextUser, ctx.Doer, db.ListOptions{ - PageSize: pagingNum, - Page: page, - }) - if err != nil { - ctx.ServerError("GetUserFollowers", err) - return - } - ctx.Data["Cards"] = items - + ctx.Data["Cards"] = followers total = int(count) case "following": - items, count, err := user_model.GetUserFollowing(ctx, ctx.ContextUser, ctx.Doer, db.ListOptions{ - PageSize: pagingNum, - Page: page, - }) - if err != nil { - ctx.ServerError("GetUserFollowing", err) - return - } - ctx.Data["Cards"] = items - + ctx.Data["Cards"] = following total = int(count) case "activity": date := ctx.FormString("date") diff --git a/templates/org/home.tmpl b/templates/org/home.tmpl index 1bd017d11990..afd7d61ca9f8 100644 --- a/templates/org/home.tmpl +++ b/templates/org/home.tmpl @@ -19,6 +19,18 @@ {{if .Org.Website}}
{{svg "octicon-link"}} {{.Org.Website}}
{{end}} + {{template "org/menu" .}} diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index c3a06a16ee1b..9f454a82f19f 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -22,7 +22,7 @@ {{svg "octicon-rss" 18}} {{end}}
- {{svg "octicon-person" 18 "gt-mr-2"}}{{.ContextUser.NumFollowers}} {{.locale.Tr "user.followers"}} · {{.ContextUser.NumFollowing}} {{.locale.Tr "user.following"}} + {{svg "octicon-person" 18 "gt-mr-2"}}{{.NumFollowers}} {{.locale.Tr "user.followers"}} · {{.NumFollowing}} {{.locale.Tr "user.following"}}