openproject icon indicating copy to clipboard operation
openproject copied to clipboard

Add "no permission" message to file links using OneDrive/SharePoint

Open mereghost opened this issue 1 year ago • 0 comments

Related Work Package: OP#51842

What and Why

Those are in the work package linked above, so I'll omit for brevity.

How?

The tooltip is controlled by the file-link-list-item component and renders the related tooltip based on the status.href property the file link that is returned by our API under /work_packages/:id/file_links.

This endpoint, calls the FileLinkService. This service loads the FileLinks from the database and also calls the FilesInfoQuery for the appropriate storage.

From there it updates some metadata and eventually, looking at the status_code of the StorageFileInfo, it sets the ephemeral origin_status ephemeral attribute on the file link. Of our main interest is the view_not_allowed value that's set when the status_code is 403.

And here is where the issue lies. OneDrive behaves slightly different than Nextcloud: the latter returns a 403 saying the file exists but the user has no access to it, the former returns a 404 as the user can't even see the file.

So, to solve this we do a second request if we get a 404 from OneDrive, using the application account. If the application can see it, we construct the StorageFileInfo with a 403, otherwise we return the good old 404.

PS: FilesInfoQuery on OneDrive calls FileInfoQuery, so the fix is implemented on it so they behave the same as Nextcloud.

mereghost avatar Apr 25 '24 08:04 mereghost