Skip to content

Commit ad98e70

Browse files
committed
Remove unnecessary functions and fix test
1 parent 34a6f4c commit ad98e70

File tree

3 files changed

+12
-26
lines changed

3 files changed

+12
-26
lines changed

integrations/org_count_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ func doCheckOrgCounts(username string, orgCounts map[string]int, strict bool, ca
116116
Name: username,
117117
}).(*models.User)
118118

119-
orgs, err := models.GetOrgsByUserID(user.ID, true)
119+
orgs, err := models.FindOrgs(models.FindOrgOptions{
120+
UserID: user.ID,
121+
IncludePrivate: true,
122+
})
120123
assert.NoError(t, err)
121124

122125
calcOrgCounts := map[string]int{}

models/org.go

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -440,24 +440,6 @@ func getUsersWhoCanCreateOrgRepo(e db.Engine, orgID int64) ([]*User, error) {
440440
And("team_user.org_id = ?", orgID).Asc("`user`.name").Find(&users)
441441
}
442442

443-
func getOrgsByUserID(e db.Engine, userID int64, showAll bool) ([]*Organization, error) {
444-
orgs := make([]*Organization, 0, 10)
445-
sess := e.Where("`org_user`.uid=?", userID)
446-
if !showAll {
447-
sess = sess.And("`org_user`.is_public=?", true)
448-
}
449-
return orgs, sess.
450-
Join("INNER", "`org_user`", "`org_user`.org_id=`user`.id").
451-
Asc("`user`.name").
452-
Find(&orgs)
453-
}
454-
455-
// GetOrgsByUserID returns a list of organizations that the given user ID
456-
// has joined.
457-
func GetOrgsByUserID(userID int64, showAll bool) ([]*Organization, error) {
458-
return getOrgsByUserID(db.GetEngine(db.DefaultContext), userID, showAll)
459-
}
460-
461443
// MinimalOrg represents a simple orgnization with only needed columns
462444
type MinimalOrg = Organization
463445

@@ -526,17 +508,18 @@ type FindOrgOptions struct {
526508
IncludePrivate bool
527509
}
528510

529-
func queryUserOrgIDs(userID int64) *builder.Builder {
530-
return builder.Select("org_id").From("org_user").
531-
Where(builder.Eq{
532-
"uid": userID,
533-
})
511+
func queryUserOrgIDs(userID int64, includePrivate bool) *builder.Builder {
512+
var cond = builder.Eq{"uid": userID}
513+
if !includePrivate {
514+
cond["is_public"] = true
515+
}
516+
return builder.Select("org_id").From("org_user").Where(cond)
534517
}
535518

536519
func (opts FindOrgOptions) toConds() builder.Cond {
537520
var cond = builder.NewCond()
538521
if opts.UserID > 0 {
539-
cond = cond.And(builder.In("`user`.`id`", queryUserOrgIDs(opts.UserID)))
522+
cond = cond.And(builder.In("`user`.`id`", queryUserOrgIDs(opts.UserID, opts.IncludePrivate)))
540523
}
541524
if !opts.IncludePrivate {
542525
cond = cond.And(builder.Eq{"`user`.visibility": structs.VisibleTypePublic})

models/org_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ func TestFindOrgs(t *testing.T) {
324324
IncludePrivate: false,
325325
})
326326
assert.NoError(t, err)
327-
assert.EqualValues(t, 1, len(orgs))
327+
assert.EqualValues(t, 0, len(orgs))
328328

329329
total, err := CountOrgs(FindOrgOptions{
330330
UserID: 4,

0 commit comments

Comments
 (0)