Skip to content

Commit

Permalink
Merge branch 'feature/nc-25' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	controller/editorcontroller.php
#	lib/fileversions.php
  • Loading branch information
LinneyS committed Dec 12, 2023
2 parents ba2224e + 084f521 commit f268e09
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 47 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

##
## Changed
- fix author in group folder

## 7.9.4
## Changed
- remove link to docs cloud
Expand Down
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<description>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.</description>
<licence>apache</licence>
<author mail="dev@onlyoffice.com" homepage="https://www.onlyoffice.com/">Ascensio System SIA</author>
<version>7.9.4</version>
<version>7.9.6</version>
<namespace>Onlyoffice</namespace>
<types>
<prevent_group_restriction/>
Expand Down
2 changes: 1 addition & 1 deletion controller/callbackcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,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);
Expand Down
10 changes: 5 additions & 5 deletions controller/editorcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,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();

Expand All @@ -853,7 +853,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"];
Expand All @@ -875,7 +875,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"]),
Expand All @@ -888,7 +888,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"];
Expand Down Expand Up @@ -974,7 +974,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;

Expand Down
103 changes: 67 additions & 36 deletions lib/fileversions.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ class FileVersions {
*/
private static $authorExt = "_author.json";

/**
* Groupfolder name
*
* @var string
*/
private static $groupFolderName = "__groupfolders";

/**
* Split file path and version id
*
Expand Down Expand Up @@ -103,13 +110,23 @@ 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) {
$view = new View("/" . $userId);
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);
}

$path = self::$appName;
if (!self::checkFolderExist($view, $path, $createIfNotExist)) {
Expand All @@ -132,20 +149,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;
}
Expand Down Expand Up @@ -185,17 +203,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;
}
Expand All @@ -208,17 +226,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;
}
Expand Down Expand Up @@ -270,7 +289,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;
Expand All @@ -292,18 +311,22 @@ 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]);

if ($ownerId === null) {
return;
}

list($view, $path) = self::getView($ownerId, $fileId);
list($view, $path) = self::getView($ownerId, $fileInfo);
if ($view === null) {
return;
}
Expand All @@ -315,22 +338,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;
}
Expand Down Expand Up @@ -358,13 +381,18 @@ public static function clearHistory() {
$userIds = $userDatabase->getUsers();

$view = new View("/");
$groupFolderView = new View("/" . self::$groupFolderName);

foreach ($userIds as $userId) {
$path = $userId . "/" . self::$appName;

if ($view->file_exists($path)) {
$view->unlink($path);
}

if ($groupFolderView->file_exists($path)) {
$groupFolderView->unlink($path);
}
}

$logger->debug("clear all history", ["app" => self::$appName]);
Expand Down Expand Up @@ -396,7 +424,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;
Expand All @@ -418,17 +446,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;
}
Expand All @@ -450,22 +479,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;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,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]);
}
Expand Down Expand Up @@ -152,8 +152,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]);
}
Expand Down Expand Up @@ -188,7 +188,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]);
}
Expand Down

0 comments on commit f268e09

Please sign in to comment.