Skip to content

adding a bulk delete files method#153

Merged
lmarini merged 14 commits into
developfrom
bulk-delete-file-api
Apr 27, 2021
Merged

adding a bulk delete files method#153
lmarini merged 14 commits into
developfrom
bulk-delete-file-api

Conversation

@tcnichol
Copy link
Copy Markdown
Contributor

There was an issue (#12) about bulk delete files tagged api.

Multiple files can be deleted using the marked feature in datasets, but I noticed that there was still no bulk delete endpoint in the api that fit what was requested in the issue.

@tcnichol tcnichol linked an issue Dec 20, 2020 that may be closed by this pull request
@lmarini lmarini requested review from max-zilla and removed request for bingzhang January 20, 2021 15:38
@lmarini
Copy link
Copy Markdown
Member

lmarini commented Jan 20, 2021

@max-zilla can you help me review this one? I believe it is related to some of the batch actions you have implemented on files in a dataset. Thank you.

Comment thread app/api/Files.scala
}
}

def bulkDeleteFiles() = PrivateServerAction (parse.json) {implicit request=>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This action would let anyone logged in call this action and the removeFile call doesn't seem to reinforce permissions. We should use something like def removeFile(id: UUID) = PermissionAction(Permission.DeleteFile, Some(ResourceRef(ResourceRef.file, id))) but I am not sure which permission to use since I don't believe we can pass in a list of resources.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Would another option be to files the FileService removeFile method to take permissions into account? It looks like it's supposed to do that, but just doesn't.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I made a commit that does that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I implemented the ability to check a list of resources at once a while ago: https://github.com/clowder-framework/clowder/blob/develop/app/api/Permissions.scala#L282 I also added a bulk GET for a list of files: https://github.com/clowder-framework/clowder/blob/develop/app/services/FileService.scala#L104

You can use these in combination like this:
https://github.com/clowder-framework/clowder/blob/develop/app/util/SearchUtils.scala#L302

both of these calls return little objects that tell you what does/doesn't have permission and what was/wasn't found (if you asked for multiple files). Please use this pattern instead. The changes here, you added a new permission check inside the file service but existing uses of that call in api Files have already done the check so now it is checking twice.
If you remove the permission check in the service, and use the pattern above inside bulkDeleteFiles, it will use existing code and be a bit more efficient.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@max-zilla thanks. that will be much better. i'll get this changed and push a new commit later today.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I removed that check. Also merged develop into the branch.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@tcnichol @max-zilla not sure about the changes to https://github.com/clowder-framework/clowder/blob/develop/app/services/mongodb/MongoDBFileService.scala#L818. I don't see are reference to permissions and the changes in the branch just look like spacing changes? Am I looking in the wrong place? Thank you.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That commit is just spacing changes.

The actual change in checking permissions is in this file:

https://github.com/clowder-framework/clowder/pull/153/files'

line 1627 uses the new checkPermission method that takes in a list of resourceRef. I then removed any permission checks elsewhere.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yeah, I saw the change to the controller, I understand that part. I am not sure I saw a change related to what @max-zilla said above regarding "Can you please also remove the permission check in 818 of MongoDB File Service as well, so we don't have redundant calls there." that's the file where there is white space changes, but nothing else?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It looks like I removed the redundant check he mentioned a few commits ago on this one.

tcnichol added 4 commits March 3, 2021 14:59
needs to be improved, moved to separate method
this might not be the best approach
only deletes files with proper permission
datasets.index(fileDataset.id)
}
val currentResourceRef = ResourceRef(ResourceRef.file, file.id)
val hasPermission = Permission.checkPermission(user.get,Permission.DeleteFile, currentResourceRef)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This call is redundant and has already been done in most cases for this function.

Comment thread app/api/Files.scala Outdated
if (fileIds.isEmpty){
BadRequest("No file ids supplied")
} else {
for (fileId <- fileIds){
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you can use a pattern like this to check many file permissions at once https://github.com/clowder-framework/clowder/blob/develop/app/util/SearchUtils.scala#L302

@max-zilla
Copy link
Copy Markdown
Contributor

Also please add entry to swagger.yml for your new endpoint.

Comment thread app/api/Files.scala
}
}

def bulkDeleteFiles() = PrivateServerAction (parse.json) {implicit request=>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The changed calls here look good! Can you please also remove the permission check in 818 of MongoDB File Service as well, so we don't have redundant calls there. Then I should be able to approve

Comment thread conf/routes
Copy link
Copy Markdown
Member

@lmarini lmarini left a comment

Choose a reason for hiding this comment

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

Just a question about one of the proposed changes, otherwise the rest looks good. Need to add changelog entry.

Comment thread app/api/Files.scala
}
}

def bulkDeleteFiles() = PrivateServerAction (parse.json) {implicit request=>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@tcnichol @max-zilla not sure about the changes to https://github.com/clowder-framework/clowder/blob/develop/app/services/mongodb/MongoDBFileService.scala#L818. I don't see are reference to permissions and the changes in the branch just look like spacing changes? Am I looking in the wrong place? Thank you.

Copy link
Copy Markdown
Member

@lmarini lmarini left a comment

Choose a reason for hiding this comment

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

It works well. Two followups:

  • @tcnichol I have created a followup issue #209
  • @max-zilla can you double check your comment and my comments below regarding "remove the permission check in 818 of MongoDB File Service" and see if we missed something?

@lmarini lmarini merged commit 041c9d0 into develop Apr 27, 2021
@robkooper robkooper deleted the bulk-delete-file-api branch September 10, 2022 03:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bulk delete files

4 participants