Skip to content

Commit d26fe34

Browse files
Rash419backportbot[bot]
authored andcommitted
preset: fix: adding/removing global template not reflected in sidebar
- this patch appends the presentation template folder etag to shared setting etag so that COOL can detect changes - this patch also update the etag of global templates folder when template is added or removed by admin Signed-off-by: Rashesh Padia <[email protected]>
1 parent 4e75c16 commit d26fe34

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

lib/Controller/WopiController.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function checkFileInfo(string $fileId, string $access_token): JSONRespons
179179
if ($this->capabilitiesService->hasSettingIframeSupport()) {
180180
$token = $this->generateSettingToken($userId);
181181
if (!$isPublic) {
182-
$response['UserSettings'] = $this->generateSettings($token, 'userconfig');
182+
$response['UserSettings'] = $this->generateSettings($token, 'userconfig', $userId);
183183
}
184184
$response['SharedSettings'] = $this->generateSettings($token, 'systemconfig');
185185
}
@@ -994,10 +994,10 @@ private function generateSettingToken(string $userId): string {
994994
return $this->settingsService->generateIframeToken('user', $userId)['token'];
995995
}
996996

997-
private function generateSettings(string $token, string $type): array {
997+
private function generateSettings(string $token, string $type, string $userId = ''): array {
998998
$nextcloudUrl = $this->appConfig->getNextcloudUrl() ?: trim($this->urlGenerator->getAbsoluteURL(''), '/');
999999
$uri = $nextcloudUrl . '/index.php/apps/richdocuments/wopi/settings' . '?type=' . $type . '&access_token=' . $token . '&fileId=' . '-1';
1000-
$etag = $this->settingsService->getFolderEtag($type);
1000+
$etag = $this->settingsService->getFolderEtag($type) . $this->settingsService->getPresentationFolderEtag($type, $userId);
10011001
return [
10021002
'uri' => $uri,
10031003
'stamp' => $etag

lib/Service/SettingsService.php

+18
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,24 @@ public function getFolderEtag($type) : string {
169169
return $this->getTypeFolder($type)->getEtag();
170170
}
171171

172+
/**
173+
*
174+
* @param string $type
175+
* @param string $userId
176+
* @return string
177+
*/
178+
public function getPresentationFolderEtag(string $type, string $userId) : string {
179+
if ($type === 'systemconfig') {
180+
return $this->templateManager->getSystemTemplateDir()->getEtag();
181+
}
182+
try {
183+
$this->templateManager->setUserId($userId);
184+
return $this->templateManager->getUserTemplateDir()->getEtag();
185+
} catch (\Exception $e) {
186+
return '';
187+
}
188+
}
189+
172190
public const SUPPORTED_PRESENTATION_MIMES = [
173191
'application/vnd.oasis.opendocument.presentation',
174192
'application/vnd.oasis.opendocument.presentation-template',

lib/TemplateManager.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public function add($templateName, $templateFile) {
316316
$template = $folder->newFile($templateName);
317317
}
318318
$template->putContent($templateFile);
319-
319+
$folder->getStorage()->getCache()->update($folder->getId(), [ 'etag' => uniqid() ]);
320320
return $this->formatNodeReturn($this->get($template->getId()));
321321
}
322322

@@ -327,11 +327,13 @@ public function add($templateName, $templateFile) {
327327
* @return boolean
328328
* @throws NotFoundException
329329
*/
330-
public function delete($fileId) {
331-
$files = $this->getSystemTemplateDir()->getDirectoryListing();
330+
public function delete($fileId): bool {
331+
$folder = $this->getSystemTemplateDir();
332+
$files = $folder->getDirectoryListing();
332333
foreach ($files as $file) {
333334
if ($file->getId() === $fileId) {
334335
$file->delete();
336+
$folder->getStorage()->getCache()->update($folder->getId(), [ 'etag' => uniqid() ]);
335337
return true;
336338
}
337339
}
@@ -389,7 +391,7 @@ public function getUserTemplateDir() {
389391
/**
390392
* @return Folder
391393
*/
392-
private function getSystemTemplateDir() {
394+
public function getSystemTemplateDir() {
393395
$this->ensureAppDataFolders();
394396
$path = 'appdata_' . $this->config->getSystemValue('instanceid', null) . '/richdocuments/templates';
395397
return $this->rootFolder->get($path);

0 commit comments

Comments
 (0)