1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 05:57:03 +09:00

Use filterable changes

This commit is contained in:
mcrakhman 2024-02-15 14:45:47 +01:00
parent 95dac55978
commit e210a91c64
No known key found for this signature in database
GPG key ID: DED12CFEF5B8396B
3 changed files with 8 additions and 18 deletions

View file

@ -148,7 +148,7 @@ func TestObjectTree(t *testing.T) {
}, aAccount.Acl)
require.NoError(t, err)
aStore, _ := treestorage.NewInMemoryTreeStorage(root, []string{root.Id}, []*treechangeproto.RawTreeChangeWithId{root})
aTree, err := BuildKeyVerifiableObjectTree(aStore, aAccount.Acl)
aTree, err := BuildKeyFilterableObjectTree(aStore, aAccount.Acl)
require.NoError(t, err)
_, err = aTree.AddContent(ctx, SignableChangeContent{
Data: []byte("some"),
@ -159,7 +159,7 @@ func TestObjectTree(t *testing.T) {
})
require.NoError(t, err)
bStore := aTree.Storage().(*treestorage.InMemoryTreeStorage).Copy()
bTree, err := BuildKeyVerifiableObjectTree(bStore, bAccount.Acl)
bTree, err := BuildKeyFilterableObjectTree(bStore, bAccount.Acl)
require.NoError(t, err)
err = exec.Execute("a.remove:b")
require.NoError(t, err)
@ -176,17 +176,17 @@ func TestObjectTree(t *testing.T) {
NewHeads: aTree.Heads(),
RawChanges: res.Added,
})
require.Equal(t, ErrHasInvalidChanges, err)
require.Equal(t, oldHeads, bTree.Heads())
bStore = aTree.Storage().(*treestorage.InMemoryTreeStorage).Copy()
root, _ = bStore.Root()
heads, _ := bStore.Heads()
_, err = ValidateRawTreeBuildFunc(treestorage.TreeStorageCreatePayload{
filteredPayload, err := ValidateFilterRawTree(treestorage.TreeStorageCreatePayload{
RootRawChange: root,
Changes: bStore.AllChanges(),
Heads: heads,
}, BuildKeyVerifiableObjectTree, bAccount.Acl)
require.Equal(t, ErrHasInvalidChanges, err)
}, bAccount.Acl)
require.NoError(t, err)
require.Equal(t, 2, len(filteredPayload.Changes))
err = aTree.IterateRoot(func(change *Change, decrypted []byte) (any, error) {
return nil, nil
}, func(change *Change) bool {

View file

@ -136,16 +136,6 @@ func BuildEmptyDataTestableTree(treeStorage treestorage.TreeStorage, aclList lis
return buildObjectTree(deps)
}
func BuildKeyVerifiableObjectTree(treeStorage treestorage.TreeStorage, aclList list.AclList) (ObjectTree, error) {
rootChange, err := treeStorage.Root()
if err != nil {
return nil, err
}
deps := defaultObjectTreeDeps(rootChange, treeStorage, aclList)
deps.validator = newTreeValidator(true, false)
return buildObjectTree(deps)
}
func BuildKeyFilterableObjectTree(treeStorage treestorage.TreeStorage, aclList list.AclList) (ObjectTree, error) {
rootChange, err := treeStorage.Root()
if err != nil {

View file

@ -93,7 +93,7 @@ func (v *objectTreeValidator) FilterChanges(aclList list.AclList, heads []string
var existingHeadsCount int
for idx, c := range changes {
// only taking changes which we can read
if _, exists := state.Keys()[c.ReadKeyId]; exists {
if keys, exists := state.Keys()[c.ReadKeyId]; exists && keys.ReadKey != nil {
if slice.FindPos(heads, c.Id) != -1 {
existingHeadsCount++
}
@ -183,7 +183,7 @@ func ValidateRawTreeBuildFunc(payload treestorage.TreeStorageCreatePayload, buil
return payload, nil
}
func ValidateFilterReadKeyRawTreeBuildFunc(payload treestorage.TreeStorageCreatePayload, buildFunc BuildObjectTreeFunc, aclList list.AclList) (retPayload treestorage.TreeStorageCreatePayload, err error) {
func ValidateFilterRawTree(payload treestorage.TreeStorageCreatePayload, aclList list.AclList) (retPayload treestorage.TreeStorageCreatePayload, err error) {
aclList.RLock()
if !aclList.AclState().HadReadPermissions(aclList.AclState().Identity()) {
aclList.RUnlock()