-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Storages new folder API endpoint #17375
Conversation
docs/api/apiv3/components/schemas/storage_folder_write_model.yml
Outdated
Show resolved
Hide resolved
docs/api/apiv3/components/schemas/storage_folder_write_model.yml
Outdated
Show resolved
Hide resolved
docs/api/apiv3/components/schemas/storage_folder_write_model.yml
Outdated
Show resolved
Hide resolved
5d95c73
to
f3782e7
Compare
.call(storage: @storage, user: current_user, file_id: parent_id) | ||
.match( | ||
on_success: lambda { |folder_info| | ||
path = URI.decode_uri_component(folder_info.location) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if I am missing something here, but I needed to decode URI characters for the fetched information from the provider
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also on OneDrive, FileInfo#location
isn't what you would send up to CreateFolder
, it should be id
Annoying? Yes. Terribly so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT of moving this method to the create folder service under another name like CreateFolderService.with_parent_id(folder_name, parent_id)
, so that the resource ends up with no special business logic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the logic to the service!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall. It might need some more tests using OneDrive as the base storage.
modules/storages/app/services/storages/create_folder_service.rb
Outdated
Show resolved
Hide resolved
.call(storage: @storage, user: current_user, file_id: parent_id) | ||
.match( | ||
on_success: lambda { |folder_info| | ||
path = URI.decode_uri_component(folder_info.location) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also on OneDrive, FileInfo#location
isn't what you would send up to CreateFolder
, it should be id
Annoying? Yes. Terribly so.
.call(storage: @storage, user: current_user, file_id: parent_id) | ||
.match( | ||
on_success: lambda { |folder_info| | ||
path = URI.decode_uri_component(folder_info.location) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT of moving this method to the create folder service under another name like CreateFolderService.with_parent_id(folder_name, parent_id)
, so that the resource ends up with no special business logic?
Storages::Peripherals::Registry.stub( | ||
"nextcloud.queries.file_info", | ||
->(_) { ServiceResult.success(result: file_info) } | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative to just replacing it with a lambda, now that we have validating mocks in place, would be to stub the command/query itself.
It is a bit more verbose, but can help with detecting bad argument passing.
file_info = class_double(Storages::Peripherals::StorageInteraction::Nextcloud::FileInfoQuery)
allow(file_info).to receive(:call).with(valid: :arguments).and_return(ServiceResult.success)
Storages::Peripherals::Registry.stub('nextcloud.queries.file_info', file_info)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I like this 👏
Will give it a try
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I adjusted the specs here. It actually instantly caught a small issue with my setup. Looking better I think :)
1615a1d
to
22ea280
Compare
22ea280
to
e711b17
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
Ticket
https://community.openproject.org/wp/59900
What are you trying to accomplish?
The goal is to expose an API for our frontend to call to create new folders on a storage.
What approach did you choose and why?
It's an API endpoint, and a service that call commands that already exist
Merge checklist