Skip to content

Commit cc64a92

Browse files
yp05327silverwindGiteaBot
authored
1 parent 94d6b5b commit cc64a92

File tree

5 files changed

+48
-26
lines changed

5 files changed

+48
-26
lines changed

models/user/user.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func GetUserFollowing(ctx context.Context, u, viewer *User, listOptions db.ListO
346346
Select("`user`.*").
347347
Join("LEFT", "follow", "`user`.id=follow.follow_id").
348348
Where("follow.user_id=?", u.ID).
349-
And("`user`.type=?", UserTypeIndividual).
349+
And("`user`.type IN (?, ?)", UserTypeIndividual, UserTypeOrganization).
350350
And(isUserVisibleToViewerCond(viewer))
351351

352352
if listOptions.Page != 0 {
@@ -1210,23 +1210,25 @@ func isUserVisibleToViewerCond(viewer *User) builder.Cond {
12101210
return builder.Neq{
12111211
"`user`.visibility": structs.VisibleTypePrivate,
12121212
}.Or(
1213+
// viewer's following
12131214
builder.In("`user`.id",
12141215
builder.
12151216
Select("`follow`.user_id").
12161217
From("follow").
12171218
Where(builder.Eq{"`follow`.follow_id": viewer.ID})),
1219+
// viewer's org user
12181220
builder.In("`user`.id",
12191221
builder.
12201222
Select("`team_user`.uid").
12211223
From("team_user").
1222-
Join("INNER", "`team_user` AS t2", "`team_user`.id = `t2`.id").
1224+
Join("INNER", "`team_user` AS t2", "`team_user`.org_id = `t2`.org_id").
12231225
Where(builder.Eq{"`t2`.uid": viewer.ID})),
1226+
// viewer's org
12241227
builder.In("`user`.id",
12251228
builder.
1226-
Select("`team_user`.uid").
1229+
Select("`team_user`.org_id").
12271230
From("team_user").
1228-
Join("INNER", "`team_user` AS t2", "`team_user`.org_id = `t2`.org_id").
1229-
Where(builder.Eq{"`t2`.uid": viewer.ID})))
1231+
Where(builder.Eq{"`team_user`.uid": viewer.ID})))
12301232
}
12311233

12321234
// IsUserVisibleToViewer check if viewer is able to see user profile

routers/web/org/home.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"code.gitea.io/gitea/models/db"
1111
"code.gitea.io/gitea/models/organization"
1212
repo_model "code.gitea.io/gitea/models/repo"
13+
user_model "code.gitea.io/gitea/models/user"
1314
"code.gitea.io/gitea/modules/base"
1415
"code.gitea.io/gitea/modules/context"
1516
"code.gitea.io/gitea/modules/markup"
@@ -143,13 +144,19 @@ func Home(ctx *context.Context) {
143144
return
144145
}
145146

147+
var isFollowing bool
148+
if ctx.Doer != nil {
149+
isFollowing = user_model.IsFollowing(ctx.Doer.ID, ctx.ContextUser.ID)
150+
}
151+
146152
ctx.Data["Repos"] = repos
147153
ctx.Data["Total"] = count
148154
ctx.Data["MembersTotal"] = membersCount
149155
ctx.Data["Members"] = members
150156
ctx.Data["Teams"] = ctx.Org.Teams
151157
ctx.Data["DisableNewPullMirrors"] = setting.Mirror.DisableNewPull
152158
ctx.Data["PageIsViewRepositories"] = true
159+
ctx.Data["IsFollowing"] = isFollowing
153160

154161
pager := context.NewPagination(int(count), setting.UI.User.RepoPagingNum, page, 5)
155162
pager.SetDefaultParams(ctx)

routers/web/user/profile.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -167,30 +167,31 @@ func Profile(ctx *context.Context) {
167167
language := ctx.FormTrim("language")
168168
ctx.Data["Language"] = language
169169

170+
followers, numFollowers, err := user_model.GetUserFollowers(ctx, ctx.ContextUser, ctx.Doer, db.ListOptions{
171+
PageSize: pagingNum,
172+
Page: page,
173+
})
174+
if err != nil {
175+
ctx.ServerError("GetUserFollowers", err)
176+
return
177+
}
178+
ctx.Data["NumFollowers"] = numFollowers
179+
following, numFollowing, err := user_model.GetUserFollowing(ctx, ctx.ContextUser, ctx.Doer, db.ListOptions{
180+
PageSize: pagingNum,
181+
Page: page,
182+
})
183+
if err != nil {
184+
ctx.ServerError("GetUserFollowing", err)
185+
return
186+
}
187+
ctx.Data["NumFollowing"] = numFollowing
188+
170189
switch tab {
171190
case "followers":
172-
items, count, err := user_model.GetUserFollowers(ctx, ctx.ContextUser, ctx.Doer, db.ListOptions{
173-
PageSize: pagingNum,
174-
Page: page,
175-
})
176-
if err != nil {
177-
ctx.ServerError("GetUserFollowers", err)
178-
return
179-
}
180-
ctx.Data["Cards"] = items
181-
191+
ctx.Data["Cards"] = followers
182192
total = int(count)
183193
case "following":
184-
items, count, err := user_model.GetUserFollowing(ctx, ctx.ContextUser, ctx.Doer, db.ListOptions{
185-
PageSize: pagingNum,
186-
Page: page,
187-
})
188-
if err != nil {
189-
ctx.ServerError("GetUserFollowing", err)
190-
return
191-
}
192-
ctx.Data["Cards"] = items
193-
194+
ctx.Data["Cards"] = following
194195
total = int(count)
195196
case "activity":
196197
date := ctx.FormString("date")

templates/org/home.tmpl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@
1919
{{if .Org.Website}}<div class="item">{{svg "octicon-link"}} <a target="_blank" rel="noopener noreferrer me" href="{{.Org.Website}}">{{.Org.Website}}</a></div>{{end}}
2020
</div>
2121
</div>
22+
<div class="right stackable menu">
23+
<form method="post" action="{{.Link}}?action={{if $.IsFollowing}}unfollow{{else}}follow{{end}}&redirect_to={{$.Link}}">
24+
{{$.CsrfTokenHtml}}
25+
<button type="submit" class="ui basic button gt-mr-0">
26+
{{if $.IsFollowing}}
27+
{{.locale.Tr "user.unfollow"}}
28+
{{else}}
29+
{{.locale.Tr "user.follow"}}
30+
{{end}}
31+
</button>
32+
</form>
33+
</div>
2234
</div>
2335

2436
{{template "org/menu" .}}

templates/user/profile.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<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>
2323
{{end}}
2424
<div class="gt-mt-3">
25-
<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>
25+
<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>
2626
</div>
2727
</div>
2828
<div class="extra content gt-word-break">

0 commit comments

Comments
 (0)