Skip to content

Commit a433ab2

Browse files
authored
Merge pull request #65 from anyproto/GO-3125-shared-spaces-limit
GO-3125 use acl.IsEmpty
2 parents 091b56f + aab40dd commit a433ab2

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

coordinator/coordinator.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -357,24 +357,13 @@ func (c *coordinator) MakeSpaceUnshareable(ctx context.Context, spaceId, aclHead
357357
return coordinatorproto.ErrAclHeadIsMissing
358358
}
359359

360-
var (
361-
activeMembers int
362-
hasInvites bool
363-
)
364-
err = c.acl.ReadState(ctx, spaceId, func(s *list.AclState) error {
365-
for _, acc := range s.CurrentAccounts() {
366-
if acc.Permissions.NoPermissions() {
367-
continue
368-
}
369-
activeMembers++
370-
}
371-
if len(s.Invites()) > 0 {
372-
hasInvites = true
360+
if err = c.acl.ReadState(ctx, spaceId, func(s *list.AclState) error {
361+
if !s.IsEmpty() {
362+
return coordinatorproto.ErrAclNonEmpty
373363
}
374364
return nil
375-
})
376-
if hasInvites || activeMembers > 1 {
377-
return coordinatorproto.ErrAclNonEmpty
365+
}); err != nil {
366+
return
378367
}
379368

380369
return c.spaceStatus.MakeUnshareable(ctx, spaceId)

coordinator/coordinator_test.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,20 @@ func TestCoordinator_MakeSpaceUnshareable(t *testing.T) {
138138
IsShareable: true,
139139
}, nil)
140140
fx.acl.EXPECT().HasRecord(ctx, spaceId, headId).Return(true, nil)
141-
fx.acl.EXPECT().ReadState(ctx, spaceId, gomock.Any()).Do(func(ctx context.Context, spaceId string, f func(s *list.AclState) error) {
142-
s := list.NewTestAclStateWithUsers(5, 5, 5)
143-
require.NoError(t, f(s))
141+
fx.acl.EXPECT().ReadState(ctx, spaceId, gomock.Any()).DoAndReturn(func(ctx context.Context, spaceId string, f func(s *list.AclState) error) error {
142+
a := list.NewAclExecutor("spaceId")
143+
cmds := []string{
144+
"a.init::a",
145+
"a.invite::invId",
146+
"b.join::invId",
147+
"a.revoke::invId",
148+
"a.approve::b,r",
149+
}
150+
for _, cmd := range cmds {
151+
err := a.Execute(cmd)
152+
require.NoError(t, err)
153+
}
154+
return f(a.ActualAccounts()["a"].Acl.AclState())
144155
})
145156
require.ErrorIs(t, fx.MakeSpaceUnshareable(ctx, spaceId, headId), coordinatorproto.ErrAclNonEmpty)
146157
})

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ toolchain go1.22.1
66

77
require (
88
github.com/ahmetb/govvv v0.3.0
9-
github.com/anyproto/any-sync v0.4.0
9+
github.com/anyproto/any-sync v0.4.1
1010
github.com/gogo/protobuf v1.3.2
1111
github.com/stretchr/testify v1.9.0
1212
go.mongodb.org/mongo-driver v1.14.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ github.com/VictoriaMetrics/fastcache v1.12.1/go.mod h1:tX04vaqcNoQeGLD+ra5pU5sWk
1111
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
1212
github.com/ahmetb/govvv v0.3.0 h1:YGLGwEyiUwHFy5eh/RUhdupbuaCGBYn5T5GWXp+WJB0=
1313
github.com/ahmetb/govvv v0.3.0/go.mod h1:4WRFpdWtc/YtKgPFwa1dr5+9hiRY5uKAL08bOlxOR6s=
14-
github.com/anyproto/any-sync v0.4.0 h1:EF9tjSd6er3zpuoO5gJhKuF65sx7YSSJjEvrWqVUZdI=
15-
github.com/anyproto/any-sync v0.4.0/go.mod h1:LclTfV2oKjwGqeMzWkRglivCg8+NmcDHZXeozyHho6w=
14+
github.com/anyproto/any-sync v0.4.1 h1:/MFgzCaUSUqRFYkCNbiwmIZtRR2+s4qqAq070KE+eew=
15+
github.com/anyproto/any-sync v0.4.1/go.mod h1:LclTfV2oKjwGqeMzWkRglivCg8+NmcDHZXeozyHho6w=
1616
github.com/anyproto/go-chash v0.1.0 h1:I9meTPjXFRfXZHRJzjOHC/XF7Q5vzysKkiT/grsogXY=
1717
github.com/anyproto/go-chash v0.1.0/go.mod h1:0UjNQi3PDazP0fINpFYu6VKhuna+W/V+1vpXHAfNgLY=
1818
github.com/anyproto/go-slip10 v1.0.0 h1:uAEtSuudR3jJBOfkOXf3bErxVoxbuKwdoJN55M1i6IA=

0 commit comments

Comments
 (0)