mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-08 14:07:02 +09:00
aclService: readState method
This commit is contained in:
parent
ad704c85eb
commit
ccbb8caecd
3 changed files with 51 additions and 0 deletions
11
acl/acl.go
11
acl/acl.go
|
@ -39,6 +39,7 @@ type AclService interface {
|
||||||
RecordsAfter(ctx context.Context, spaceId, aclHead string) (result []*consensusproto.RawRecordWithId, err error)
|
RecordsAfter(ctx context.Context, spaceId, aclHead string) (result []*consensusproto.RawRecordWithId, err error)
|
||||||
Permissions(ctx context.Context, identity crypto.PubKey, spaceId string) (res list.AclPermissions, err error)
|
Permissions(ctx context.Context, identity crypto.PubKey, spaceId string) (res list.AclPermissions, err error)
|
||||||
OwnerPubKey(ctx context.Context, spaceId string) (ownerIdentity crypto.PubKey, err error)
|
OwnerPubKey(ctx context.Context, spaceId string) (ownerIdentity crypto.PubKey, err error)
|
||||||
|
ReadState(ctx context.Context, spaceId string, f func(s *list.AclState) error) (err error)
|
||||||
app.ComponentRunnable
|
app.ComponentRunnable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,6 +160,16 @@ func (as *aclService) Permissions(ctx context.Context, identity crypto.PubKey, s
|
||||||
return acl.AclState().Permissions(identity), nil
|
return acl.AclState().Permissions(identity), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (as *aclService) ReadState(ctx context.Context, spaceId string, f func(s *list.AclState) error) (err error) {
|
||||||
|
acl, err := as.get(ctx, spaceId)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
acl.RLock()
|
||||||
|
defer acl.RUnlock()
|
||||||
|
return f(acl.AclState())
|
||||||
|
}
|
||||||
|
|
||||||
func (as *aclService) Run(ctx context.Context) (err error) {
|
func (as *aclService) Run(ctx context.Context) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,6 +149,32 @@ func TestAclService(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAclService_ReadState(t *testing.T) {
|
||||||
|
ownerKeys, err := accountdata.NewRandom()
|
||||||
|
require.NoError(t, err)
|
||||||
|
spaceId := "spaceId"
|
||||||
|
ownerAcl, err := list.NewTestDerivedAcl(spaceId, ownerKeys)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
fx := newFixture(t)
|
||||||
|
defer fx.finish(t)
|
||||||
|
|
||||||
|
fx.consCl.EXPECT().Watch(spaceId, gomock.Any()).DoAndReturn(func(spaceId string, w consensusclient.Watcher) error {
|
||||||
|
go func() {
|
||||||
|
w.AddConsensusRecords([]*consensusproto.RawRecordWithId{
|
||||||
|
ownerAcl.Root(),
|
||||||
|
})
|
||||||
|
}()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
fx.consCl.EXPECT().UnWatch(spaceId)
|
||||||
|
|
||||||
|
require.NoError(t, fx.ReadState(ctx, spaceId, func(s *list.AclState) error {
|
||||||
|
assert.NotNil(t, s)
|
||||||
|
return nil
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
func newFixture(t *testing.T) *fixture {
|
func newFixture(t *testing.T) *fixture {
|
||||||
ctrl := gomock.NewController(t)
|
ctrl := gomock.NewController(t)
|
||||||
fx := &fixture{
|
fx := &fixture{
|
||||||
|
|
|
@ -131,6 +131,20 @@ func (mr *MockAclServiceMockRecorder) Permissions(arg0, arg1, arg2 any) *gomock.
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Permissions", reflect.TypeOf((*MockAclService)(nil).Permissions), arg0, arg1, arg2)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Permissions", reflect.TypeOf((*MockAclService)(nil).Permissions), arg0, arg1, arg2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReadState mocks base method.
|
||||||
|
func (m *MockAclService) ReadState(arg0 context.Context, arg1 string, arg2 func(*list.AclState) error) error {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "ReadState", arg0, arg1, arg2)
|
||||||
|
ret0, _ := ret[0].(error)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadState indicates an expected call of ReadState.
|
||||||
|
func (mr *MockAclServiceMockRecorder) ReadState(arg0, arg1, arg2 any) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReadState", reflect.TypeOf((*MockAclService)(nil).ReadState), arg0, arg1, arg2)
|
||||||
|
}
|
||||||
|
|
||||||
// RecordsAfter mocks base method.
|
// RecordsAfter mocks base method.
|
||||||
func (m *MockAclService) RecordsAfter(arg0 context.Context, arg1, arg2 string) ([]*consensusproto.RawRecordWithId, error) {
|
func (m *MockAclService) RecordsAfter(arg0 context.Context, arg1, arg2 string) ([]*consensusproto.RawRecordWithId, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue