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

Storages new folder API endpoint #17375

Merged
merged 2 commits into from
Dec 11, 2024

Conversation

brunopagno
Copy link
Contributor

@brunopagno brunopagno commented Dec 5, 2024

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

  • Added/updated tests

@brunopagno brunopagno self-assigned this Dec 5, 2024
@brunopagno brunopagno force-pushed the impl/59900-storages-new-folder-endpoint branch 2 times, most recently from 5d95c73 to f3782e7 Compare December 6, 2024 14:49
.call(storage: @storage, user: current_user, file_id: parent_id)
.match(
on_success: lambda { |folder_info|
path = URI.decode_uri_component(folder_info.location)
Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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!

@brunopagno brunopagno requested review from Kharonus and a team December 9, 2024 16:38
Copy link
Contributor

@mereghost mereghost left a 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.

.call(storage: @storage, user: current_user, file_id: parent_id)
.match(
on_success: lambda { |folder_info|
path = URI.decode_uri_component(folder_info.location)
Copy link
Contributor

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)
Copy link
Contributor

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?

Comment on lines 89 to 92
Storages::Peripherals::Registry.stub(
"nextcloud.queries.file_info",
->(_) { ServiceResult.success(result: file_info) }
)
Copy link
Contributor

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)

Copy link
Contributor Author

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

Copy link
Contributor Author

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 :)

@brunopagno brunopagno force-pushed the impl/59900-storages-new-folder-endpoint branch from 1615a1d to 22ea280 Compare December 10, 2024 09:31
@brunopagno brunopagno marked this pull request as ready for review December 10, 2024 13:04
@brunopagno brunopagno force-pushed the impl/59900-storages-new-folder-endpoint branch from 22ea280 to e711b17 Compare December 10, 2024 17:08
@brunopagno brunopagno requested a review from mereghost December 10, 2024 17:15
@brunopagno brunopagno changed the title WIP storages new folder API endpoint Storages new folder API endpoint Dec 11, 2024
Copy link
Contributor

@mereghost mereghost left a comment

Choose a reason for hiding this comment

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

Nice work!

@brunopagno brunopagno merged commit 49e5ac2 into dev Dec 11, 2024
13 checks passed
@brunopagno brunopagno deleted the impl/59900-storages-new-folder-endpoint branch December 11, 2024 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants