Skip to content

Commit 3c9f161

Browse files
authored
Merge branch 'main' into kd/ci-playwright_go_test
2 parents db18686 + acbbbbf commit 3c9f161

File tree

6 files changed

+75
-34
lines changed

6 files changed

+75
-34
lines changed

models/user/user.go

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,37 +316,45 @@ func (u *User) GenerateEmailActivateCode(email string) string {
316316
}
317317

318318
// GetUserFollowers returns range of user's followers.
319-
func GetUserFollowers(u *User, listOptions db.ListOptions) ([]*User, error) {
320-
sess := db.GetEngine(db.DefaultContext).
319+
func GetUserFollowers(ctx context.Context, u, viewer *User, listOptions db.ListOptions) ([]*User, int64, error) {
320+
sess := db.GetEngine(ctx).
321+
Select("`user`.*").
322+
Join("LEFT", "follow", "`user`.id=follow.user_id").
321323
Where("follow.follow_id=?", u.ID).
322-
Join("LEFT", "follow", "`user`.id=follow.user_id")
324+
And(isUserVisibleToViewerCond(viewer))
323325

324326
if listOptions.Page != 0 {
325327
sess = db.SetSessionPagination(sess, &listOptions)
326328

327329
users := make([]*User, 0, listOptions.PageSize)
328-
return users, sess.Find(&users)
330+
count, err := sess.FindAndCount(&users)
331+
return users, count, err
329332
}
330333

331334
users := make([]*User, 0, 8)
332-
return users, sess.Find(&users)
335+
count, err := sess.FindAndCount(&users)
336+
return users, count, err
333337
}
334338

335339
// GetUserFollowing returns range of user's following.
336-
func GetUserFollowing(u *User, listOptions db.ListOptions) ([]*User, error) {
340+
func GetUserFollowing(ctx context.Context, u, viewer *User, listOptions db.ListOptions) ([]*User, int64, error) {
337341
sess := db.GetEngine(db.DefaultContext).
342+
Select("`user`.*").
343+
Join("LEFT", "follow", "`user`.id=follow.follow_id").
338344
Where("follow.user_id=?", u.ID).
339-
Join("LEFT", "follow", "`user`.id=follow.follow_id")
345+
And(isUserVisibleToViewerCond(viewer))
340346

341347
if listOptions.Page != 0 {
342348
sess = db.SetSessionPagination(sess, &listOptions)
343349

344350
users := make([]*User, 0, listOptions.PageSize)
345-
return users, sess.Find(&users)
351+
count, err := sess.FindAndCount(&users)
352+
return users, count, err
346353
}
347354

348355
users := make([]*User, 0, 8)
349-
return users, sess.Find(&users)
356+
count, err := sess.FindAndCount(&users)
357+
return users, count, err
350358
}
351359

352360
// NewGitSig generates and returns the signature of given user.
@@ -1222,6 +1230,39 @@ func GetAdminUser() (*User, error) {
12221230
return &admin, nil
12231231
}
12241232

1233+
func isUserVisibleToViewerCond(viewer *User) builder.Cond {
1234+
if viewer != nil && viewer.IsAdmin {
1235+
return builder.NewCond()
1236+
}
1237+
1238+
if viewer == nil || viewer.IsRestricted {
1239+
return builder.Eq{
1240+
"`user`.visibility": structs.VisibleTypePublic,
1241+
}
1242+
}
1243+
1244+
return builder.Neq{
1245+
"`user`.visibility": structs.VisibleTypePrivate,
1246+
}.Or(
1247+
builder.In("`user`.id",
1248+
builder.
1249+
Select("`follow`.user_id").
1250+
From("follow").
1251+
Where(builder.Eq{"`follow`.follow_id": viewer.ID})),
1252+
builder.In("`user`.id",
1253+
builder.
1254+
Select("`team_user`.uid").
1255+
From("team_user").
1256+
Join("INNER", "`team_user` AS t2", "`team_user`.id = `t2`.id").
1257+
Where(builder.Eq{"`t2`.uid": viewer.ID})),
1258+
builder.In("`user`.id",
1259+
builder.
1260+
Select("`team_user`.uid").
1261+
From("team_user").
1262+
Join("INNER", "`team_user` AS t2", "`team_user`.org_id = `t2`.org_id").
1263+
Where(builder.Eq{"`t2`.uid": viewer.ID})))
1264+
}
1265+
12251266
// IsUserVisibleToViewer check if viewer is able to see user profile
12261267
func IsUserVisibleToViewer(ctx context.Context, u, viewer *User) bool {
12271268
if viewer != nil && viewer.IsAdmin {

package-lock.json

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"less": "4.1.2",
2323
"less-loader": "11.0.0",
2424
"license-checker-webpack-plugin": "0.2.1",
25-
"mermaid": "9.1.1",
25+
"mermaid": "9.1.2",
2626
"mini-css-extract-plugin": "2.6.0",
2727
"monaco-editor": "0.33.0",
2828
"monaco-editor-webpack-plugin": "7.0.1",

routers/api/v1/user/follower.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ func responseAPIUsers(ctx *context.APIContext, users []*user_model.User) {
2424
}
2525

2626
func listUserFollowers(ctx *context.APIContext, u *user_model.User) {
27-
users, err := user_model.GetUserFollowers(u, utils.GetListOptions(ctx))
27+
users, count, err := user_model.GetUserFollowers(ctx, u, ctx.Doer, utils.GetListOptions(ctx))
2828
if err != nil {
2929
ctx.Error(http.StatusInternalServerError, "GetUserFollowers", err)
3030
return
3131
}
3232

33-
ctx.SetTotalCountHeader(int64(u.NumFollowers))
33+
ctx.SetTotalCountHeader(count)
3434
responseAPIUsers(ctx, users)
3535
}
3636

@@ -86,13 +86,13 @@ func ListFollowers(ctx *context.APIContext) {
8686
}
8787

8888
func listUserFollowing(ctx *context.APIContext, u *user_model.User) {
89-
users, err := user_model.GetUserFollowing(u, utils.GetListOptions(ctx))
89+
users, count, err := user_model.GetUserFollowing(ctx, u, ctx.Doer, utils.GetListOptions(ctx))
9090
if err != nil {
9191
ctx.Error(http.StatusInternalServerError, "GetUserFollowing", err)
9292
return
9393
}
9494

95-
ctx.SetTotalCountHeader(int64(u.NumFollowing))
95+
ctx.SetTotalCountHeader(count)
9696
responseAPIUsers(ctx, users)
9797
}
9898

routers/web/user/profile.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func Profile(ctx *context.Context) {
157157

158158
switch tab {
159159
case "followers":
160-
items, err := user_model.GetUserFollowers(ctx.ContextUser, db.ListOptions{
160+
items, count, err := user_model.GetUserFollowers(ctx, ctx.ContextUser, ctx.Doer, db.ListOptions{
161161
PageSize: setting.UI.User.RepoPagingNum,
162162
Page: page,
163163
})
@@ -167,9 +167,9 @@ func Profile(ctx *context.Context) {
167167
}
168168
ctx.Data["Cards"] = items
169169

170-
total = ctx.ContextUser.NumFollowers
170+
total = int(count)
171171
case "following":
172-
items, err := user_model.GetUserFollowing(ctx.ContextUser, db.ListOptions{
172+
items, count, err := user_model.GetUserFollowing(ctx, ctx.ContextUser, ctx.Doer, db.ListOptions{
173173
PageSize: setting.UI.User.RepoPagingNum,
174174
Page: page,
175175
})
@@ -179,7 +179,7 @@ func Profile(ctx *context.Context) {
179179
}
180180
ctx.Data["Cards"] = items
181181

182-
total = ctx.ContextUser.NumFollowing
182+
total = int(count)
183183
case "activity":
184184
ctx.Data["Feeds"], err = models.GetFeeds(ctx, models.GetFeedsOptions{
185185
RequestedUser: ctx.ContextUser,

services/auth/source/ldap/source_search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func checkRestricted(l *ldap.Conn, ls *Source, userDN string) bool {
199199
// List all group memberships of a user
200200
func (source *Source) listLdapGroupMemberships(l *ldap.Conn, uid string) []string {
201201
var ldapGroups []string
202-
groupFilter := fmt.Sprintf("(%s=%s)", source.GroupMemberUID, uid)
202+
groupFilter := fmt.Sprintf("(%s=%s)", source.GroupMemberUID, ldap.EscapeFilter(uid))
203203
result, err := l.Search(ldap.NewSearchRequest(
204204
source.GroupDN,
205205
ldap.ScopeWholeSubtree,

0 commit comments

Comments
 (0)