Skip to content

Commit

Permalink
[FIX] WOPI Stakeholder initialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
chfsx committed Oct 29, 2024
1 parent 635e8d8 commit 64deb94
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions Services/WOPI/classes/Handler/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

namespace ILIAS\Services\WOPI\Handler;

use ILIAS\HTTP\Services;
use ILIAS\ResourceStorage\Identification\ResourceIdentification;
use ILIAS\Filesystem\Stream\Streams;
use ILIAS\FileDelivery\Token\DataSigner;
use ILIAS\ResourceStorage\Stakeholder\ResourceStakeholder;
Expand All @@ -40,8 +42,17 @@ final class RequestHandler
public const HEADER_X_WOPI_LOCK = 'X-WOPI-Lock';
public const HEADER_X_WOPI_FILE_CONVERSION = 'X-WOPI-FileConversion';

private \ILIAS\HTTP\Services $http;
/**
* @readonly
*/
private Services $http;
/**
* @readonly
*/
private \ILIAS\ResourceStorage\Services $irss;
/**
* @readonly
*/
private DataSigner $data_signer;
private ?int $token_user_id = null;
private ?string $token_resource_id = null;
Expand All @@ -55,7 +66,6 @@ public function __construct()
$this->http = $DIC->http();
$this->data_signer = $DIC['file_delivery.data_signer'];
$this->irss = $DIC->resourceStorage();
$this->saving_interval = (int) $DIC->settings()->get('saving_interval');
}

protected function checkAuth(): void
Expand All @@ -81,14 +91,14 @@ protected function checkAuth(): void
$this->token_user_id = (int) ($token_data['user_id'] ?? 0);
$this->token_resource_id = (string) ($token_data['resource_id'] ?? '');
$this->editable = (bool) ($token_data['editable'] ?? '');
$stakeholder = $token_data['stakeholder'] ?? null;
if ($stakeholder !== null) {
try {
$this->stakeholder = new WOPIStakeholderWrapper();
$this->stakeholder->init($stakeholder, $this->token_user_id);
} catch (\Throwable $t) {
$this->stakeholder = new WOPIUnknownStakeholder($this->token_user_id);
}

// Init Stakeholder
$stakeholder = $token_data['stakeholder'] ?? WOPIUnknownStakeholder::class;
try {
$this->stakeholder = new WOPIStakeholderWrapper();
$this->stakeholder->init(new $stakeholder(), $this->token_user_id);
} catch (\Throwable) {
$this->stakeholder = new WOPIUnknownStakeholder();
}
}

Expand All @@ -114,7 +124,7 @@ public function handleRequest(): void
}

$resource_id = $this->irss->manage()->find($resource_id);
if (!$resource_id instanceof \ILIAS\ResourceStorage\Identification\ResourceIdentification) {
if (!$resource_id instanceof ResourceIdentification) {
$this->http->close();
}
$resource = $this->irss->manage()->getResource($resource_id);
Expand Down Expand Up @@ -229,9 +239,7 @@ public function handleRequest(): void
$message = $t->getMessage();
// append simple stacktrace
$trace = array_map(
static function ($trace): string {
return $trace['file'] . ':' . $trace['line'];
},
static fn(array $trace): string => $trace['file'] . ':' . $trace['line'],
$t->getTrace()
);

Expand Down

0 comments on commit 64deb94

Please sign in to comment.