From 98507c15e49f9bd61a55331a1dfe008fee007e1c Mon Sep 17 00:00:00 2001 From: rivexe Date: Wed, 29 Nov 2023 15:12:42 +0300 Subject: [PATCH 1/5] FileVersions class methods now work with FileInfo instances instead of fileId strings --- lib/fileversions.php | 84 ++++++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/lib/fileversions.php b/lib/fileversions.php index e7399df5..94e684e4 100644 --- a/lib/fileversions.php +++ b/lib/fileversions.php @@ -105,12 +105,17 @@ private static function checkFolderExist($view, $path, $createIfNotExist = false * Get view and path for changes * * @param string $userId - user id - * @param string $fileId - file id + * @param FileInfo $fileInfo - file info * @param bool $createIfNotExist - create folder if not exist * * @return array */ - private static function getView($userId, $fileId, $createIfNotExist = false) { + private static function getView($userId, $fileInfo, $createIfNotExist = false) { + $fileId = null; + if ($fileInfo !== null) { + $fileId = $fileInfo->getId(); + } + $view = new View("/" . $userId); $path = self::$appName; @@ -134,20 +139,21 @@ private static function getView($userId, $fileId, $createIfNotExist = false) { * Get changes from stored to history object * * @param string $ownerId - file owner id - * @param string $fileId - file id + * @param FileInfo $fileInfo - file info * @param string $versionId - file version * @param string $prevVersion - previous version for check * * @return array */ - public static function getHistoryData($ownerId, $fileId, $versionId, $prevVersion) { + public static function getHistoryData($ownerId, $fileInfo, $versionId, $prevVersion) { $logger = \OC::$server->getLogger(); - if ($ownerId === null || $fileId === null) { + if ($ownerId === null || $fileInfo === null) { return null; } - list ($view, $path) = self::getView($ownerId, $fileId); + $fileId = $fileInfo->getId(); + list($view, $path) = self::getView($ownerId, $fileInfo); if ($view === null) { return null; } @@ -187,17 +193,17 @@ public static function getHistoryData($ownerId, $fileId, $versionId, $prevVersio * Check if changes is stored * * @param string $ownerId - file owner id - * @param string $fileId - file id + * @param FileInfo $fileInfo - file info * @param string $versionId - file version * * @return bool */ - public static function hasChanges($ownerId, $fileId, $versionId) { - if ($ownerId === null || $fileId === null) { + public static function hasChanges($ownerId, $fileInfo, $versionId) { + if ($ownerId === null || $fileInfo === null) { return false; } - list ($view, $path) = self::getView($ownerId, $fileId); + list($view, $path) = self::getView($ownerId, $fileInfo); if ($view === null) { return false; } @@ -210,17 +216,18 @@ public static function hasChanges($ownerId, $fileId, $versionId) { * Get changes file * * @param string $ownerId - file owner id - * @param string $fileId - file id + * @param FileInfo $fileInfo - file info * @param string $versionId - file version * * @return File */ - public static function getChangesFile($ownerId, $fileId, $versionId) { - if ($ownerId === null || $fileId === null) { + public static function getChangesFile($ownerId, $fileInfo, $versionId) { + if ($ownerId === null || $fileInfo === null) { return null; } + $fileId = $fileInfo->getId(); - list ($view, $path) = self::getView($ownerId, $fileId); + list($view, $path) = self::getView($ownerId, $fileInfo); if ($view === null) { return null; } @@ -272,7 +279,7 @@ public static function saveHistory($fileInfo, $history, $changes, $prevVersion) $fileId = $fileInfo->getId(); $versionId = $fileInfo->getMtime(); - list ($view, $path) = self::getView($ownerId, $fileId, true); + list($view, $path) = self::getView($ownerId, $fileInfo, true); try { $changesPath = $path . "/" . $versionId . self::$changesExt; @@ -294,10 +301,14 @@ public static function saveHistory($fileInfo, $history, $changes, $prevVersion) * Delete all versions of file * * @param string $ownerId - file owner id - * @param string $fileId - file id + * @param FileInfo $fileInfo - file info */ - public static function deleteAllVersions($ownerId, $fileId = null) { + public static function deleteAllVersions($ownerId, $fileInfo = null) { $logger = \OC::$server->getLogger(); + $fileId = null; + if ($fileInfo !== null) { + $fileId = $fileInfo->getId(); + } $logger->debug("deleteAllVersions $ownerId $fileId", ["app" => self::$appName]); @@ -305,7 +316,7 @@ public static function deleteAllVersions($ownerId, $fileId = null) { return; } - list ($view, $path) = self::getView($ownerId, $fileId); + list($view, $path) = self::getView($ownerId, $fileInfo); if ($view === null) { return; } @@ -317,22 +328,22 @@ public static function deleteAllVersions($ownerId, $fileId = null) { * Delete changes and history * * @param string $ownerId - file owner id - * @param string $fileId - file id + * @param FileInfo $fileInfo - file info * @param string $versionId - file version */ - public static function deleteVersion($ownerId, $fileId, $versionId) { - $logger = \OC::$server->getLogger(); - - $logger->debug("deleteVersion $fileId ($versionId)", ["app" => self::$appName]); - + public static function deleteVersion($ownerId, $fileInfo, $versionId) { if ($ownerId === null) { return; } - if ($fileId === null || empty($versionId)) { + if ($fileInfo === null || empty($versionId)) { return; } - list ($view, $path) = self::getView($ownerId, $fileId); + $logger = \OC::$server->getLogger(); + $fileId = $fileInfo->getId(); + $logger->debug("deleteVersion $fileId ($versionId)", ["app" => self::$appName]); + + list($view, $path) = self::getView($ownerId, $fileInfo); if ($view === null) { return null; } @@ -398,7 +409,7 @@ public static function saveAuthor($fileInfo, $author) { $fileId = $fileInfo->getId(); $versionId = $fileInfo->getMtime(); - list ($view, $path) = self::getView($ownerId, $fileId, true); + list($view, $path) = self::getView($ownerId, $fileInfo, true); try { $authorPath = $path . "/" . $versionId . self::$authorExt; @@ -420,17 +431,18 @@ public static function saveAuthor($fileInfo, $author) { * Get version author id and name * * @param string $ownerId - file owner id - * @param string $fileId - file id + * @param FileInfo $fileInfo - file info * @param string $versionId - file version * * @return array */ - public static function getAuthor($ownerId, $fileId, $versionId) { - if ($ownerId === null || $fileId === null) { + public static function getAuthor($ownerId, $fileInfo, $versionId) { + if ($ownerId === null || $fileInfo === null) { return null; } - list ($view, $path) = self::getView($ownerId, $fileId); + $fileId = $fileInfo->getId(); + list($view, $path) = self::getView($ownerId, $fileInfo); if ($view === null) { return null; } @@ -452,22 +464,24 @@ public static function getAuthor($ownerId, $fileId, $versionId) { * Delete version author info * * @param string $ownerId - file owner id - * @param string $fileId - file id + * @param FileInfo $fileInfo - file info * @param string $versionId - file version */ - public static function deleteAuthor($ownerId, $fileId, $versionId) { + public static function deleteAuthor($ownerId, $fileInfo, $versionId) { $logger = \OC::$server->getLogger(); + $fileId = $fileInfo->getId(); + $logger->debug("deleteAuthor $fileId ($versionId)", ["app" => self::$appName]); if ($ownerId === null) { return; } - if ($fileId === null || empty($versionId)) { + if ($fileInfo === null || empty($versionId)) { return; } - list ($view, $path) = self::getView($ownerId, $fileId); + list($view, $path) = self::getView($ownerId, $fileInfo); if ($view === null) { return null; } From f7632aedf624f295be3e20786c8c872ffc3c9682 Mon Sep 17 00:00:00 2001 From: rivexe Date: Wed, 29 Nov 2023 15:14:25 +0300 Subject: [PATCH 2/5] hooks now pass FileInfo instances to methods of the FileVersions class --- lib/hooks.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/hooks.php b/lib/hooks.php index 0ee3274c..00e0b399 100644 --- a/lib/hooks.php +++ b/lib/hooks.php @@ -122,7 +122,7 @@ public static function fileDelete($params) { KeyManager::delete($fileId, true); - FileVersions::deleteAllVersions($ownerId, $fileId); + FileVersions::deleteAllVersions($ownerId, $fileInfo); } catch (\Exception $e) { \OC::$server->getLogger()->logException($e, ["message" => "Hook: fileDelete " . json_encode($params), "app" => self::$appName]); } @@ -157,8 +157,8 @@ public static function fileVersionDelete($params) { $fileId = $fileInfo->getId(); - FileVersions::deleteVersion($ownerId, $fileId, $versionId); - FileVersions::deleteAuthor($ownerId, $fileId, $versionId); + FileVersions::deleteVersion($ownerId, $fileInfo, $versionId); + FileVersions::deleteAuthor($ownerId, $fileInfo, $versionId); } catch (\Exception $e) { \OC::$server->getLogger()->logException($e, ["message" => "Hook: fileVersionDelete " . json_encode($params), "app" => self::$appName]); } @@ -193,7 +193,7 @@ public static function fileVersionRestore($params) { KeyManager::delete($fileId); - FileVersions::deleteVersion($ownerId, $fileId, $versionId); + FileVersions::deleteVersion($ownerId, $fileInfo, $versionId); } catch (\Exception $e) { \OC::$server->getLogger()->logException($e, ["message" => "Hook: fileVersionRestore " . json_encode($params), "app" => self::$appName]); } From 279982ade5098ba838c1b2c5e5048cfc2aaac9d2 Mon Sep 17 00:00:00 2001 From: rivexe Date: Wed, 29 Nov 2023 15:15:18 +0300 Subject: [PATCH 3/5] controllers now pass FileInfo instances to methods of the FileVersions class --- controller/callbackcontroller.php | 2 +- controller/editorcontroller.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/controller/callbackcontroller.php b/controller/callbackcontroller.php index 8bbfa0bc..b1de378b 100644 --- a/controller/callbackcontroller.php +++ b/controller/callbackcontroller.php @@ -292,7 +292,7 @@ public function download($doc) { $versionId = $fileVersion->getRevisionId(); } - $changesFile = FileVersions::getChangesFile($owner->getUID(), $fileId, $versionId); + $changesFile = FileVersions::getChangesFile($owner->getUID(), $file->getFileInfo(), $versionId); if ($changesFile === null) { $this->logger->error("Download: changes $fileId ($version) was not found", ["app" => $this->appName]); return new JSONResponse(["message" => $this->trans->t("Files not found")], Http::STATUS_NOT_FOUND); diff --git a/controller/editorcontroller.php b/controller/editorcontroller.php index 2bc09ae5..a89fca40 100644 --- a/controller/editorcontroller.php +++ b/controller/editorcontroller.php @@ -846,7 +846,7 @@ public function history($fileId) { $versionId = $version->getRevisionId(); - $author = FileVersions::getAuthor($ownerId, $fileId, $versionId); + $author = FileVersions::getAuthor($ownerId, $file->getFileInfo(), $versionId); $authorId = $author !== null ? $author["id"] : $ownerId; $authorName = $author !== null ? $author["name"] : $owner->getDisplayName(); @@ -855,7 +855,7 @@ public function history($fileId) { "name" => $authorName ]; - $historyData = FileVersions::getHistoryData($ownerId, $fileId, $versionId, $prevVersion); + $historyData = FileVersions::getHistoryData($ownerId, $file->getFileInfo(), $versionId, $prevVersion); if ($historyData !== null) { $historyItem["changes"] = $historyData["changes"]; $historyItem["serverVersion"] = $historyData["serverVersion"]; @@ -877,7 +877,7 @@ public function history($fileId) { $versionId = $file->getFileInfo()->getMtime(); - $author = FileVersions::getAuthor($ownerId, $fileId, $versionId); + $author = FileVersions::getAuthor($ownerId, $file->getFileInfo(), $versionId); if ($author !== null) { $historyItem["user"] = [ "id" => $this->buildUserId($author["id"]), @@ -890,7 +890,7 @@ public function history($fileId) { ]; } - $historyData = FileVersions::getHistoryData($ownerId, $fileId, $versionId, $prevVersion); + $historyData = FileVersions::getHistoryData($ownerId, $file->getFileInfo(), $versionId, $prevVersion); if ($historyData !== null) { $historyItem["changes"] = $historyData["changes"]; $historyItem["serverVersion"] = $historyData["serverVersion"]; @@ -976,7 +976,7 @@ public function version($fileId, $version) { if ($version > 1 && count($versions) >= $version - 1 - && FileVersions::hasChanges($ownerId, $fileId, $versionId)) { + && FileVersions::hasChanges($ownerId, $file->getFileInfo(), $versionId)) { $changesUrl = $this->getUrl($file, $user, null, $version, true); $result["changesUrl"] = $changesUrl; From bd5a6870caca7745eafeb13c7ffa49dbb5fa3317 Mon Sep 17 00:00:00 2001 From: Sergey Linnik Date: Thu, 30 Nov 2023 10:42:28 +0300 Subject: [PATCH 4/5] fix version's author in group folder --- lib/fileversions.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/fileversions.php b/lib/fileversions.php index 94e684e4..a504560c 100644 --- a/lib/fileversions.php +++ b/lib/fileversions.php @@ -64,6 +64,13 @@ class FileVersions { */ private static $authorExt = "_author.json"; + /** + * Groupfolder name + * + * @var string + */ + private static $groupFolderName = "__groupfolders"; + /** * Split file path and version id * @@ -114,10 +121,15 @@ private static function getView($userId, $fileInfo, $createIfNotExist = false) { $fileId = null; if ($fileInfo !== null) { $fileId = $fileInfo->getId(); + if ($fileInfo->getStorage()->instanceOfStorage(\OCA\GroupFolders\Mount\GroupFolderStorage::class)) { + $view = new View("/" . self::$groupFolderName); + } else { + $view = new View("/" . $userId); + } + } else { + $view = new View("/" . $userId); } - $view = new View("/" . $userId); - $path = self::$appName; if (!self::checkFolderExist($view, $path, $createIfNotExist)) { return [null, null]; @@ -371,6 +383,7 @@ public static function clearHistory() { $userIds = $userDatabase->getUsers(); $view = new View("/"); + $groupFolderView = new View("/" . self::$groupFolderName); foreach ($userIds as $userId) { $path = $userId . "/" . self::$appName; @@ -378,6 +391,10 @@ public static function clearHistory() { if ($view->file_exists($path)) { $view->unlink($path); } + + if ($groupFolderView->file_exists($path)) { + $groupFolderView->unlink($path); + } } $logger->debug("clear all history", ["app" => self::$appName]); From 084f52151474daaab3c3b633865734366d62260a Mon Sep 17 00:00:00 2001 From: Sergey Linnik Date: Mon, 11 Dec 2023 11:38:34 +0300 Subject: [PATCH 5/5] 7.9.6 --- CHANGELOG.md | 4 ++++ appinfo/info.xml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69fbdb22..9a2d8560 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 7.9.6 +## ChangeŠ² +- fix author in group folder + ## 7.9.4 ## Changed - remove link to docs cloud diff --git a/appinfo/info.xml b/appinfo/info.xml index 0c6a38ac..fb207a4c 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -6,7 +6,7 @@ ONLYOFFICE connector allows you to view, edit and collaborate on text documents, spreadsheets and presentations within Nextcloud using ONLYOFFICE Docs. This will create a new Edit in ONLYOFFICE action within the document library for Office documents. This allows multiple users to co-author documents in real time from the familiar web interface and save the changes back to your file storage. apache Ascensio System SIA - 7.9.4 + 7.9.6 Onlyoffice