Skip to content

Commit

Permalink
Merge pull request #1279 from anyproto/go-3203-check-restrictions-on-dnd
Browse files Browse the repository at this point in the history


GO-3203 Check restrictions in DnD
  • Loading branch information
KirillSto authored May 28, 2024
2 parents 1d6dd65 + edd138b commit df0b26e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/block/editor/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ func (sf *sfile) updateFile(ctx session.Context, id, groupId string, apply func(
}

func (sf *sfile) DropFiles(req pb.RpcFileDropRequest) (err error) {
if err = sf.Restrictions().Object.Check(model.Restrictions_Blocks); err != nil {
return err
}
proc := &dropFilesProcess{
spaceID: sf.SpaceID(),
processService: sf.processService,
Expand Down
19 changes: 19 additions & 0 deletions core/block/editor/file/file_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package file

import (
"errors"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/anyproto/anytype-heart/core/block/cache/mock_cache"
"github.com/anyproto/anytype-heart/core/block/editor/smartblock/smarttest"
"github.com/anyproto/anytype-heart/core/block/restriction"
"github.com/anyproto/anytype-heart/pb"
"github.com/anyproto/anytype-heart/pkg/lib/bundle"
"github.com/anyproto/anytype-heart/pkg/lib/pb/model"
"github.com/anyproto/anytype-heart/tests/blockbuilder"
Expand Down Expand Up @@ -101,3 +105,18 @@ func TestFile(t *testing.T) {
})
}
}

func TestDropFiles(t *testing.T) {
t.Run("do not drop files to object with Blocks restriction", func(t *testing.T) {
// given
fx := newFixture(t)
fx.sb.SetRestrictions(restriction.Restrictions{Object: restriction.ObjectRestrictions{model.Restrictions_Blocks}})

// when
err := fx.sfile.DropFiles(pb.RpcFileDropRequest{})

// then
assert.Error(t, err)
assert.True(t, errors.Is(err, restriction.ErrRestricted))
})
}

0 comments on commit df0b26e

Please sign in to comment.