1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 14:07:02 +09:00

Update syncacl

This commit is contained in:
mcrakhman 2024-02-26 21:03:28 +01:00
parent 3f98cba48c
commit b853fefd30
No known key found for this signature in database
GPG key ID: DED12CFEF5B8396B
4 changed files with 17 additions and 14 deletions

View file

@ -58,7 +58,7 @@ type AclList interface {
KeyStorage() crypto.KeyStorage KeyStorage() crypto.KeyStorage
RecordBuilder() AclRecordBuilder RecordBuilder() AclRecordBuilder
ValidateRawRecord(record *consensusproto.RawRecord) (err error) ValidateRawRecord(rawRec *consensusproto.RawRecord, afterValid func(state *AclState) error) (err error)
AddRawRecord(rawRec *consensusproto.RawRecordWithId) (err error) AddRawRecord(rawRec *consensusproto.RawRecordWithId) (err error)
AddRawRecords(rawRecords []*consensusproto.RawRecordWithId) (err error) AddRawRecords(rawRecords []*consensusproto.RawRecordWithId) (err error)
@ -192,12 +192,17 @@ func (a *aclList) Records() []*AclRecord {
return a.records return a.records
} }
func (a *aclList) ValidateRawRecord(rawRec *consensusproto.RawRecord) (err error) { func (a *aclList) ValidateRawRecord(rawRec *consensusproto.RawRecord, afterValid func(state *AclState) error) (err error) {
record, err := a.recordBuilder.Unmarshall(rawRec) record, err := a.recordBuilder.Unmarshall(rawRec)
if err != nil { if err != nil {
return return
} }
return a.aclState.Copy().ApplyRecord(record) stateCopy := a.aclState.Copy()
err = stateCopy.ApplyRecord(record)
if err != nil || afterValid == nil {
return
}
return afterValid(stateCopy)
} }
func (a *aclList) AddRawRecords(rawRecords []*consensusproto.RawRecordWithId) error { func (a *aclList) AddRawRecords(rawRecords []*consensusproto.RawRecordWithId) error {

View file

@ -87,7 +87,7 @@ func (fx *aclFixture) inviteAccount(t *testing.T, perms AclPermissions) {
}) })
require.NoError(t, err) require.NoError(t, err)
// validate // validate
err = ownerAcl.ValidateRawRecord(requestAccept) err = ownerAcl.ValidateRawRecord(requestAccept, nil)
require.NoError(t, err) require.NoError(t, err)
requestAcceptRec := WrapAclRecord(requestAccept) requestAcceptRec := WrapAclRecord(requestAccept)
fx.addRec(t, requestAcceptRec) fx.addRec(t, requestAcceptRec)

View file

@ -5,7 +5,6 @@
// //
// mockgen -destination mock_list/mock_list.go github.com/anyproto/any-sync/commonspace/object/acl/list AclList // mockgen -destination mock_list/mock_list.go github.com/anyproto/any-sync/commonspace/object/acl/list AclList
// //
// Package mock_list is a generated GoMock package. // Package mock_list is a generated GoMock package.
package mock_list package mock_list
@ -344,15 +343,15 @@ func (mr *MockAclListMockRecorder) Unlock() *gomock.Call {
} }
// ValidateRawRecord mocks base method. // ValidateRawRecord mocks base method.
func (m *MockAclList) ValidateRawRecord(arg0 *consensusproto.RawRecord) error { func (m *MockAclList) ValidateRawRecord(arg0 *consensusproto.RawRecord, arg1 func(*list.AclState) error) error {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ValidateRawRecord", arg0) ret := m.ctrl.Call(m, "ValidateRawRecord", arg0, arg1)
ret0, _ := ret[0].(error) ret0, _ := ret[0].(error)
return ret0 return ret0
} }
// ValidateRawRecord indicates an expected call of ValidateRawRecord. // ValidateRawRecord indicates an expected call of ValidateRawRecord.
func (mr *MockAclListMockRecorder) ValidateRawRecord(arg0 any) *gomock.Call { func (mr *MockAclListMockRecorder) ValidateRawRecord(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateRawRecord", reflect.TypeOf((*MockAclList)(nil).ValidateRawRecord), arg0) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateRawRecord", reflect.TypeOf((*MockAclList)(nil).ValidateRawRecord), arg0, arg1)
} }

View file

@ -5,7 +5,6 @@
// //
// mockgen -destination mock_syncacl/mock_syncacl.go github.com/anyproto/any-sync/commonspace/object/acl/syncacl SyncAcl,SyncClient,RequestFactory,AclSyncProtocol // mockgen -destination mock_syncacl/mock_syncacl.go github.com/anyproto/any-sync/commonspace/object/acl/syncacl SyncAcl,SyncClient,RequestFactory,AclSyncProtocol
// //
// Package mock_syncacl is a generated GoMock package. // Package mock_syncacl is a generated GoMock package.
package mock_syncacl package mock_syncacl
@ -456,17 +455,17 @@ func (mr *MockSyncAclMockRecorder) Unlock() *gomock.Call {
} }
// ValidateRawRecord mocks base method. // ValidateRawRecord mocks base method.
func (m *MockSyncAcl) ValidateRawRecord(arg0 *consensusproto.RawRecord) error { func (m *MockSyncAcl) ValidateRawRecord(arg0 *consensusproto.RawRecord, arg1 func(*list.AclState) error) error {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ValidateRawRecord", arg0) ret := m.ctrl.Call(m, "ValidateRawRecord", arg0, arg1)
ret0, _ := ret[0].(error) ret0, _ := ret[0].(error)
return ret0 return ret0
} }
// ValidateRawRecord indicates an expected call of ValidateRawRecord. // ValidateRawRecord indicates an expected call of ValidateRawRecord.
func (mr *MockSyncAclMockRecorder) ValidateRawRecord(arg0 any) *gomock.Call { func (mr *MockSyncAclMockRecorder) ValidateRawRecord(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateRawRecord", reflect.TypeOf((*MockSyncAcl)(nil).ValidateRawRecord), arg0) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateRawRecord", reflect.TypeOf((*MockSyncAcl)(nil).ValidateRawRecord), arg0, arg1)
} }
// MockSyncClient is a mock of SyncClient interface. // MockSyncClient is a mock of SyncClient interface.