Skip to content

Commit 9c39ff0

Browse files
committed
fix(wopi): Generating setting token for guest users
Signed-off-by: codewithvk <[email protected]>
1 parent 0bea79c commit 9c39ff0

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

lib/Controller/WopiController.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,6 @@ public function checkFileInfo(string $fileId, string $access_token): JSONRespons
129129
$isSmartPickerEnabled = (bool)$wopi->getCanwrite() && !$isPublic && !$wopi->getDirect();
130130
$isTaskProcessingEnabled = $isSmartPickerEnabled && $this->taskProcessingManager->isTaskProcessingEnabled();
131131

132-
$userSettings = $this->generateSettings($wopi, 'userconfig');
133-
$sharedSettings = $this->generateSettings($wopi, 'systemconfig');
134-
135132
// If the file is locked manually by a user we want to open it read only for all others
136133
$canWriteThroughLock = true;
137134
try {
@@ -140,11 +137,16 @@ public function checkFileInfo(string $fileId, string $access_token): JSONRespons
140137
} catch (NoLockProviderException|PreConditionNotMetException) {
141138
}
142139

140+
$userId = !$isPublic ? $wopi->getEditorUid() : $guestUserId;
141+
142+
$userSettings = $this->generateSettings($userId, 'userconfig');
143+
$sharedSettings = $this->generateSettings($userId, 'systemconfig');
144+
143145
$response = [
144146
'BaseFileName' => $file->getName(),
145147
'Size' => $file->getSize(),
146148
'Version' => $version,
147-
'UserId' => !$isPublic ? $wopi->getEditorUid() : $guestUserId,
149+
'UserId' => $userId,
148150
'OwnerId' => $wopi->getOwnerUid(),
149151
'UserFriendlyName' => $userDisplayName,
150152
'UserExtraInfo' => [],
@@ -976,15 +978,13 @@ private function getWopiUrlForTemplate(Wopi $wopi): string {
976978
$nextcloudUrl = $this->appConfig->getNextcloudUrl() ?: trim($this->urlGenerator->getAbsoluteURL(''), '/');
977979
return $nextcloudUrl . '/index.php/apps/richdocuments/wopi/template/' . $wopi->getTemplateId() . '?access_token=' . $wopi->getToken();
978980
}
979-
private function generateSettingToken(Wopi $wopi): string {
980-
$userId = $wopi->getEditorUid();
981-
$res = $this->settingsService->generateIframeToken('user', $userId);
982-
return $res['token'];
981+
private function generateSettingToken(string $userId): string {
982+
return $this->settingsService->generateIframeToken('user', $userId)['token'];
983983
}
984984
// todo extract nextcloud url from everything
985-
private function generateSettings(Wopi $wopi, string $type): array {
985+
private function generateSettings(string $userId, string $type): array {
986986
$nextcloudUrl = $this->appConfig->getNextcloudUrl() ?: trim($this->urlGenerator->getAbsoluteURL(''), '/');
987-
$uri = $nextcloudUrl . '/index.php/apps/richdocuments/wopi/settings' . '?type=' . $type . '&access_token=' . $this->generateSettingToken($wopi) . '&fileId=' . '-1';
987+
$uri = $nextcloudUrl . '/index.php/apps/richdocuments/wopi/settings' . '?type=' . $type . '&access_token=' . $this->generateSettingToken($userId) . '&fileId=' . '-1';
988988
return [
989989
'uri' => $uri,
990990
'stamp' => time()

0 commit comments

Comments
 (0)