Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GO-3526 drag and drop files to collection add them to collection #1622

Conversation

Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
Copy link

github-actions bot commented Sep 30, 2024

Previous Coverage 49.4% of statements
New Coverage 49.6% of statements
Patch Coverage 90.7% of changed statements (39/43)

Coverage provided by https://github.com/seriousben/go-patch-cover-action

@@ -119,4 +140,122 @@ func TestDropFiles(t *testing.T) {
assert.Error(t, err)
assert.True(t, errors.Is(err, restriction.ErrRestricted))
})
t.Run("drop files in collection", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what these tests verify

if layout, ok := sf.Layout(); ok && layout == model.ObjectType_collection {
s := sf.NewState()
store := s.GetStoreSlice(template.CollectionStoreKey)
if !slices.Contains(store, info.file.TargetObjectId) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the store already contains methods to verify if some object is already present.
https://en.wikipedia.org/wiki/Separation_of_concerns

@@ -220,8 +222,10 @@ 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
if layout, ok := sf.Layout(); !ok || layout != model.ObjectType_collection {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make a method called isCollection

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make it like so func isCollection(sb any), here you can check everything, is object a smartblock? does it have layout? is the layout collection?

@@ -303,6 +306,14 @@ func (sf *sfile) dropFilesSetInfo(info dropFileInfo) (err error) {
s.Unlink(info.blockId)
return sf.Apply(s)
}
if layout, ok := sf.Layout(); ok && layout == model.ObjectType_collection {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the same method here

@@ -476,6 +487,24 @@ func (dp *dropFilesProcess) Start(rootId, targetId string, pos model.BlockPositi
return
}
err = cache.Do(dp.picker, smartBlockIds[idx], func(sb File) error {
smartBlock, ok := sb.(smartblock.SmartBlock)
if ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reuse the same check

@@ -476,6 +487,24 @@ func (dp *dropFilesProcess) Start(rootId, targetId string, pos model.BlockPositi
return
}
err = cache.Do(dp.picker, smartBlockIds[idx], func(sb File) error {
smartBlock, ok := sb.(smartblock.SmartBlock)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls don't call everywhere smartblock[idx], flatEntries[idx], I know it was here before, but put them in a separate vars

if layout, ok := smartBlock.Layout(); ok && layout == model.ObjectType_collection {
for _, entry := range flatEntries[idx] {
if entry.isDir {
smartBlockIds = append(smartBlockIds, rootId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we appending rootId? can we do it multiple times if we do it in a loop?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do it only once we should structure the code in a way that it would be evident that this happens only once

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also extract this in a separate func

Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
@AnastasiaShemyakinskaya AnastasiaShemyakinskaya merged commit b83c71e into main Oct 30, 2024
5 checks passed
@AnastasiaShemyakinskaya AnastasiaShemyakinskaya deleted the go-3526-drag-and-drop-files-to-collection-add-them-to-collection branch October 30, 2024 13:23
@github-actions github-actions bot locked and limited conversation to collaborators Oct 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants