nextcloud / richdocuments

📑 Collabora Online for Nextcloud
https://nextcloud.com/collaboraonline
355 stars 116 forks source link

Wrong argument order in a call to `generateFileToken` #1654

Closed mikekaganski closed 3 months ago

mikekaganski commented 3 years ago

https://github.com/nextcloud/richdocuments/blob/master/lib/TokenManager.php#L286 calls generateFileToken, and passes $direct where generateFileToken expects $hideDownload.

See discussion at https://github.com/nextcloud/richdocuments/commit/28c0e502ba05f125cdf955de2658278ac07d751f#.

gitsan13 commented 1 year ago

Hi! Will you accept a PR for this? I would like to look into it:)

Raudius commented 1 year ago

Hi @gitsan13

Contributions are very welcome :)

gitsan13 commented 1 year ago

Thank you for the approval @Raudius :)

gitsan13 commented 1 year ago

As I looked into the file TokenManager.php, this is the anamoly in the generateToken function that I found, Screenshot (88)

gitsan13 commented 1 year ago

Could you please throw some light on what is the 'shareToken' value that is passed in both the cases? Also, what would be the 'templateDestination' and 'hideDownload' field values if the capabilitiesService object has no template source?

Raudius commented 1 year ago

@gitsan13

Thanks for looking into this issue.

Could you please throw some light on what is the 'shareToken' value that is passed in both the cases?

The shareToken is an identifier for a "share" object. This argument is only required when we are opening a file that has been shared. In this case we are creating a new file so a shareToken would not be expected.

Also, what would be the 'templateDestination' and 'hideDownload' field values if the capabilitiesService object has no template source?

The template destination I think can be kept as $targetFile->getId().

The hideDownload field should be false. This is only true for shared files that have the download permission removed.

gitsan13 commented 1 year ago

Heyy thanks for explaining it so clearly :) Here are the changes that I made to the generateFileToken function:- Screenshot (90)

Does the changes look apt to you?

Raudius commented 1 year ago

I think the changes are not quite right. But I could not find much documentation online, so here is what I have gathered on what the "has template source" check is about.

In summary I think the legacy function does not need many changes, the only issue currently is that it is missing the $allowDownload parameter, before the $direct parameter.

Also I think we can continue to omit the $share parameter, because the default (null) value is sufficient.

gitsan13 commented 1 year ago

Hi @Raudius I went through your concise explanation and came up with the following changes:-

Screenshot (105)

As you said, if the Collabora server does not accept the request by CheckFileInfo() method to define the resource for storing templates, then we need to pass the legacy method. In the legacy method, we need to add the allowDownload parameter to make necessary modification. In the image attached below, I thought of using "DownloadAsPostMessage" to get Download option in the legacy method.

Screenshot (104)

The final changes made to the TokenManager.php file is attached below:- Screenshot (103)

What do you say?

joshtrichards commented 3 months ago

Fixed / no longer applicable.