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

Issue #83: Refactor wopi controller #84

Draft
wants to merge 48 commits into
base: main
Choose a base branch
from

Conversation

donquixote
Copy link
Collaborator

@donquixote donquixote commented Jan 8, 2025

… in services.yml, and setting Content-Type header.

Without that, the ExceptionWopiSubscriber was not actually registered as an event subscriber.
It did not matter because routes with any '_format' other than 'html' already behave in the desired way.
Now, to replicate the prior behavior, we must explicitly set the 'Content-Type' header to 'text/plain'.
…t keep 403.

Changes:
- Use wildcard loading for media entity in WopiController.
- Change 'not found' response code and message for WOPI requests, to replicate old behavior.

Subsequent commit will change to actual 404.
@donquixote donquixote force-pushed the issue-83-refactor-wopi-controller branch from 628315d to fa01d4c Compare January 8, 2025 23:53
@donquixote donquixote force-pushed the issue-83-refactor-wopi-controller branch from fa01d4c to 23836ab Compare January 9, 2025 00:07
@donquixote donquixote force-pushed the issue-83-refactor-wopi-controller branch from 1883815 to 0a91f3a Compare January 9, 2025 14:23
Copy link
Collaborator

@AaronGilMartinez AaronGilMartinez left a comment

Choose a reason for hiding this comment

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

I think is going to the right direction, added some remarks just in case.

@@ -175,7 +175,7 @@ protected function getSubject(Request $request): string {
pack('N', strlen($url)),
strtoupper($url),
pack('N', 8),
pack('J', $timestamp_ticks)
pack('J', $timestamp_ticks),
Copy link
Collaborator

Choose a reason for hiding this comment

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

phpcs missed this?


if ($wopi_stamp != $file_stamp) {
$this->logger->error('Conflict saving file ' . $id . ' wopi: ' . $wopi_stamp->format('c') . ' differs from file: ' . $file_stamp->format('c'));
$this->logger->error('Save reason: ' . $save_reason);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we log an error always?

@@ -342,12 +364,12 @@ protected function verifyTokenForMediaId(
if ($values === NULL) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Line: 361 Typo in the context message variable name

* @return string
* Formatted date string in ISO 8601 format, in UTC.
*/
public static function format(int $timestamp): string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Format as function name seems a bit generic.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we add license here? Other files may need it too.

],
$request,
);
$this->assertTrue($this->logger->hasRecord('Save reason: ' . $reason_message));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should check the type of record too.

* This is expected to be an array.
*/
protected function assertPartialArray(array $expected, mixed $actual): void {
$this->assertIsArray($actual);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why mixed type and not require an array as parameter?

// The file name is preserved.
$this->assertSame('test.txt', $new_file->getFilename());
// The file owner is preserved.
$this->assertSame($this->fileOwner->id(), $new_file->getOwnerId());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe is good to add a check to see that it is permanent.

$i = $this->getCounterValue();
// The request time is always the same.
$file_changed_time = \DateTimeImmutable::createFromFormat('U', (string) $this->file->getChangedTime());
$new_file_content = "File content $i.";
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about an incremental content to see that size changes?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I miss some tests or checks:

  • Test with missing access_token. Message: 'Missing access token.'
  • Test with no file attached to media. Message: 'No file attached to media.'
  • Test token that can't be decoded: Message: 'Malformed token.'
  • Check Info response with user picture.

There is also the case where the $action doesn't exist in wopi() but not sure if can be easily tested, and same for $can_write = FALSE in wopiPutFile().

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.

Refactor WopiController
2 participants