mirror of
https://github.com/gogs/gogs.git
synced 2026-01-18 05:12:19 +01:00
orgsCount
This commit is contained in:
@@ -420,7 +420,7 @@ func (db *organizations) List(ctx context.Context, opts ListOrganizationsOptions
|
||||
*/
|
||||
conds := db.WithContext(ctx).Where("type = ?", UserTypeOrganization)
|
||||
|
||||
if opts.MemberID > 0 || opts.OwnerID > 0 || !opts.IncludePrivateMembers {
|
||||
if opts.MemberID > 0 || opts.OwnerID > 0 {
|
||||
conds.Joins(dbutil.Quote("JOIN org_user ON org_user.org_id = %s.id", "user"))
|
||||
}
|
||||
if opts.MemberID > 0 {
|
||||
@@ -428,7 +428,7 @@ func (db *organizations) List(ctx context.Context, opts ListOrganizationsOptions
|
||||
} else if opts.OwnerID > 0 {
|
||||
conds.Where("org_user.uid = ? AND org_user.is_owner = ?", opts.OwnerID, true)
|
||||
}
|
||||
if !opts.IncludePrivateMembers {
|
||||
if (opts.MemberID > 0 || opts.OwnerID > 0) && !opts.IncludePrivateMembers {
|
||||
conds.Where("org_user.is_public = ?", true)
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ func TestOrganizations(t *testing.T) {
|
||||
{"SearchByName", orgsSearchByName},
|
||||
{"List", orgsList},
|
||||
{"CountByUser", orgsCountByUser},
|
||||
{"Count", orgsCount},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Cleanup(func() {
|
||||
@@ -308,3 +309,23 @@ func orgsCountByUser(t *testing.T, ctx context.Context, db *organizations) {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(0), got)
|
||||
}
|
||||
|
||||
func orgsCount(t *testing.T, db *organizations) {
|
||||
ctx := context.Background()
|
||||
|
||||
// Has no organization initially
|
||||
got := db.Count(ctx)
|
||||
assert.Equal(t, int64(0), got)
|
||||
|
||||
tempPictureAvatarUploadPath := filepath.Join(os.TempDir(), "usersCount-tempPictureAvatarUploadPath")
|
||||
conf.SetMockPicture(t, conf.PictureOpts{AvatarUploadPath: tempPictureAvatarUploadPath})
|
||||
|
||||
_, err := db.Create(ctx, "org1", 1, CreateOrganizationOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create a user shouldn't count
|
||||
_, err = NewUsersStore(db.DB).Create(ctx, "alice", "alice@example.com", CreateUserOptions{})
|
||||
require.NoError(t, err)
|
||||
got = db.Count(ctx)
|
||||
assert.Equal(t, int64(1), got)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user