diff options
author | yp05327 <576951401@qq.com> | 2023-04-30 04:13:58 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-29 15:13:58 -0400 |
commit | cc64a925602d54f3439dd19f16b5280bd0377a7a (patch) | |
tree | 36b9d91bee60fe8e71a6aaaf2a40fac3f554d46e | |
parent | 94d6b5b09d49b2622c2164a03cfae45dced96c74 (diff) | |
download | gitea-cc64a925602d54f3439dd19f16b5280bd0377a7a.tar.gz gitea-cc64a925602d54f3439dd19f16b5280bd0377a7a.zip |
Add follow organization and fix the logic of following page (#24345)
![image](https://user-images.githubusercontent.com/18380374/234740589-066f2e5c-30c7-4fc3-a539-066100e1f138.png)
![image](https://user-images.githubusercontent.com/18380374/234740605-88efe55d-7eaa-422e-ab86-0b5a402ca11c.png)
Maybe we can fix user card tmpl in #24319?
Or maybe a list is better here
![image](https://user-images.githubusercontent.com/18380374/234451417-7f93df20-4b19-4abb-a62d-4c67e1aa2220.png)
---------
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Giteabot <teabot@gitea.io>
-rw-r--r-- | models/user/user.go | 12 | ||||
-rw-r--r-- | routers/web/org/home.go | 7 | ||||
-rw-r--r-- | routers/web/user/profile.go | 41 | ||||
-rw-r--r-- | templates/org/home.tmpl | 12 | ||||
-rw-r--r-- | templates/user/profile.tmpl | 2 |
5 files changed, 48 insertions, 26 deletions
diff --git a/models/user/user.go b/models/user/user.go index 053d6680cd..46c4440e5f 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})), + // viewer's org user builder.In("`user`.id", builder. Select("`team_user`.uid"). From("team_user"). - Join("INNER", "`team_user` AS t2", "`team_user`.id = `t2`.id"). + Join("INNER", "`team_user` AS t2", "`team_user`.org_id = `t2`.org_id"). Where(builder.Eq{"`t2`.uid": viewer.ID})), + // viewer's org builder.In("`user`.id", builder. - Select("`team_user`.uid"). + Select("`team_user`.org_id"). 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{"`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 201eefa614..7f38ec51ba 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 367bb306b8..ef91d89d14 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 1bd017d119..afd7d61ca9 100644 --- a/templates/org/home.tmpl +++ b/templates/org/home.tmpl @@ -19,6 +19,18 @@ {{if .Org.Website}}<div class="item">{{svg "octicon-link"}} <a target="_blank" rel="noopener noreferrer me" href="{{.Org.Website}}">{{.Org.Website}}</a></div>{{end}} </div> </div> + <div class="right stackable menu"> + <form method="post" action="{{.Link}}?action={{if $.IsFollowing}}unfollow{{else}}follow{{end}}&redirect_to={{$.Link}}"> + {{$.CsrfTokenHtml}} + <button type="submit" class="ui basic button gt-mr-0"> + {{if $.IsFollowing}} + {{.locale.Tr "user.unfollow"}} + {{else}} + {{.locale.Tr "user.follow"}} + {{end}} + </button> + </form> + </div> </div> {{template "org/menu" .}} diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index c3a06a16ee..9f454a82f1 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -22,7 +22,7 @@ <a href="{{.ContextUser.HomeLink}}.rss"><i class="ui text grey gt-ml-3" data-tooltip-content="{{.locale.Tr "rss_feed"}}">{{svg "octicon-rss" 18}}</i></a> {{end}} <div class="gt-mt-3"> - <a class="muted" href="{{.ContextUser.HomeLink}}?tab=followers">{{svg "octicon-person" 18 "gt-mr-2"}}{{.ContextUser.NumFollowers}} {{.locale.Tr "user.followers"}}</a> · <a class="muted" href="{{.ContextUser.HomeLink}}?tab=following">{{.ContextUser.NumFollowing}} {{.locale.Tr "user.following"}}</a> + <a class="muted" href="{{.ContextUser.HomeLink}}?tab=followers">{{svg "octicon-person" 18 "gt-mr-2"}}{{.NumFollowers}} {{.locale.Tr "user.followers"}}</a> · <a class="muted" href="{{.ContextUser.HomeLink}}?tab=following">{{.NumFollowing}} {{.locale.Tr "user.following"}}</a> </div> </div> <div class="extra content gt-word-break"> |