Skip to content

Commit

Permalink
Merge pull request #647 from ONLYOFFICE/develop
Browse files Browse the repository at this point in the history
Release/7.5.0
  • Loading branch information
LinneyS authored Jun 16, 2022
2 parents 3dc7015 + 75425b7 commit b58253d
Show file tree
Hide file tree
Showing 56 changed files with 2,414 additions and 276 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Change Log

## 7.5.0
## Changed
- fix viewer app
- Nextcloud v22 is no longer supported
- Nextcloud v23 is no longer supported

## 7.4.0
## Added
- advanced access rights
- macro launch setting
- opening file location from viewer
- Catalan translation
- theme setting

## Changed
- fix editor lang

## 7.3.4
## Added
- Turkish and Galician empty file templates
Expand Down
19 changes: 19 additions & 0 deletions appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use OCA\Onlyoffice\Controller\CallbackController;
use OCA\Onlyoffice\Controller\EditorController;
use OCA\Onlyoffice\Controller\EditorApiController;
use OCA\Onlyoffice\Controller\SharingApiController;
use OCA\Onlyoffice\Controller\SettingsController;
use OCA\Onlyoffice\Controller\TemplateController;
use OCA\Onlyoffice\Listeners\FilesListener;
Expand All @@ -58,6 +59,7 @@
use OCA\Onlyoffice\Preview;
use OCA\Onlyoffice\TemplateManager;
use OCA\Onlyoffice\TemplateProvider;
use OCA\Onlyoffice\SettingsData;

use Psr\Container\ContainerInterface;

Expand Down Expand Up @@ -127,6 +129,10 @@ public function register(IRegistrationContext $context): void {
);
});

$context->registerService("SettingsData", function (ContainerInterface $c) {
return new SettingsData($this->appConfig);
});

// Controllers
$context->registerService("SettingsController", function (ContainerInterface $c) {
return new SettingsController(
Expand Down Expand Up @@ -158,6 +164,19 @@ public function register(IRegistrationContext $context): void {
);
});

$context->registerService("SharingApiController", function (ContainerInterface $c) {
return new SharingApiController(
$c->get("AppName"),
$c->get("Request"),
$c->get("RootStorage"),
$c->get("Logger"),
$c->get("UserSession"),
$c->get("UserManager"),
$c->get("IManager"),
$this->appConfig
);
});

$context->registerService("EditorApiController", function (ContainerInterface $c) {
return new EditorApiController(
$c->get("AppName"),
Expand Down
4 changes: 2 additions & 2 deletions 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="[email protected]" homepage="https://www.onlyoffice.com/">Ascensio System SIA</author>
<version>7.3.4</version>
<version>7.5.0</version>
<namespace>Onlyoffice</namespace>
<types>
<prevent_group_restriction/>
Expand All @@ -29,7 +29,7 @@
<screenshot>https://raw.githubusercontent.com/ONLYOFFICE/onlyoffice-nextcloud/master/screenshots/new.png</screenshot>
<screenshot>https://raw.githubusercontent.com/ONLYOFFICE/onlyoffice-nextcloud/master/screenshots/open.png</screenshot>
<dependencies>
<nextcloud min-version="22" max-version="24"/>
<nextcloud min-version="24" max-version="24"/>
</dependencies>
<settings>
<admin>OCA\Onlyoffice\AdminSettings</admin>
Expand Down
7 changes: 4 additions & 3 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
["name" => "editor#restore", "url" => "/ajax/restore", "verb" => "PUT"],
["name" => "settings#save_address", "url" => "/ajax/settings/address", "verb" => "PUT"],
["name" => "settings#save_common", "url" => "/ajax/settings/common", "verb" => "PUT"],
["name" => "settings#save_watermark", "url" => "/ajax/settings/watermark", "verb" => "PUT"],
["name" => "settings#get_settings", "url" => "/ajax/settings", "verb" => "GET"],
["name" => "settings#save_security", "url" => "/ajax/settings/security", "verb" => "PUT"],
["name" => "settings#clear_history", "url" => "/ajax/settings/history", "verb" => "DELETE"],
["name" => "template#add_template", "url" => "/ajax/template", "verb" => "POST"],
["name" => "template#delete_template", "url" => "/ajax/template", "verb" => "DELETE"],
Expand All @@ -48,6 +47,8 @@
"ocs" => [
["name" => "federation#key", "url" => "/api/v1/key", "verb" => "POST"],
["name" => "federation#keylock", "url" => "/api/v1/keylock", "verb" => "POST"],
["name" => "editorapi#config", "url" => "/api/v1/config/{fileId}", "verb" => "GET"]
["name" => "editorapi#config", "url" => "/api/v1/config/{fileId}", "verb" => "GET"],
["name" => "sharingapi#get_shares", "url" => "/api/v1/shares/{fileId}", "verb" => "GET"],
["name" => "sharingapi#set_shares", "url" => "/api/v1/shares", "verb" => "PUT"]
]
];
35 changes: 23 additions & 12 deletions controller/callbackcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,6 @@ public function track($doc, $users, $key, $status, $url, $token, $history, $chan
$user = $this->userManager->get($userId);
if (!empty($user)) {
\OC_User::setUserId($userId);
\OC_Util::setupFS($userId);

if ($userId === $hashData->userId) {
$filePath = $hashData->filePath;
}
} else {
if (empty($shareToken)) {
$this->logger->error("Track without token: $fileId status $status", ["app" => $this->appName]);
Expand All @@ -480,20 +475,36 @@ public function track($doc, $users, $key, $status, $url, $token, $history, $chan
$this->logger->debug("Track $fileId by token for $userId", ["app" => $this->appName]);
}

// owner of file from the callback link
$ownerId = $hashData->ownerId;
$owner = $this->userManager->get($ownerId);

if (!empty($owner)) {
$userId = $ownerId;
} else {
$callbackUserId = $hashData->userId;
$callbackUser = $this->userManager->get($callbackUserId);

if (!empty($callbackUser)) {
// author of the callback link
$userId = $callbackUserId;

// path for author of the callback link
$filePath = $hashData->filePath;
}
}

if (!empty($userId)) {
\OC_Util::setupFS($userId);
}

list ($file, $error) = empty($shareToken) ? $this->getFile($userId, $fileId, $filePath) : $this->getFileByToken($fileId, $shareToken);

if (isset($error)) {
$this->logger->error("track error $fileId " . json_encode($error->getData()), ["app" => $this->appName]);
return $error;
}

if (empty($user)) {
$owner = $file->getFileInfo()->getOwner();
if ($owner !== null) {
\OC_Util::setupFS($owner->getUID());
}
}

$url = $this->config->ReplaceDocumentServerUrlToInternal($url);

$prevVersion = $file->getFileInfo()->getMtime();
Expand Down
91 changes: 81 additions & 10 deletions controller/editorapicontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
use OCA\Onlyoffice\DocumentService;
use OCA\Onlyoffice\FileUtility;
use OCA\Onlyoffice\TemplateManager;
use OCA\Onlyoffice\ExtraPermissions;

/**
* Controller with the main functions
Expand Down Expand Up @@ -130,6 +131,13 @@ class EditorApiController extends OCSController {
*/
private $tagManager;

/**
* Extra permissions
*
* @var ExtraPermissions
*/
private $extraPermissions;

/**
* Mobile regex from https://github.com/ONLYOFFICE/CommunityServer/blob/v9.1.1/web/studio/ASC.Web.Studio/web.appsettings.config#L35
*/
Expand Down Expand Up @@ -184,6 +192,11 @@ public function __construct($AppName,
}
}

if ($this->config->GetAdvanced()
&& \OC::$server->getAppManager()->isInstalled("files_sharing")) {
$this->extraPermissions = new ExtraPermissions($AppName, $logger, $shareManager, $config);
}

$this->fileUtility = new FileUtility($AppName, $trans, $logger, $config, $shareManager, $session);
}

Expand All @@ -196,6 +209,7 @@ public function __construct($AppName,
* @param string $directToken - direct token
* @param integer $version - file version
* @param bool $inframe - open in frame
* @param bool $inviewer - open in viewer
* @param bool $desktop - desktop label
* @param string $guestName - nickname not logged user
* @param bool $template - file is template
Expand All @@ -206,7 +220,7 @@ public function __construct($AppName,
* @NoAdminRequired
* @PublicPage
*/
public function config($fileId, $filePath = null, $shareToken = null, $directToken = null, $version = 0, $inframe = false, $desktop = false, $guestName = null, $template = false, $anchor = null) {
public function config($fileId, $filePath = null, $shareToken = null, $directToken = null, $version = 0, $inframe = false, $inviewer = false, $desktop = false, $guestName = null, $template = false, $anchor = null) {

if (!empty($directToken)) {
list ($directData, $error) = $this->crypt->ReadHash($directToken);
Expand Down Expand Up @@ -257,7 +271,7 @@ public function config($fileId, $filePath = null, $shareToken = null, $directTok

$fileName = $file->getName();
$ext = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
$format = !empty($ext) ? $this->config->FormatsSetting()[$ext] : null;
$format = !empty($ext) && array_key_exists($ext, $this->config->FormatsSetting()) ? $this->config->FormatsSetting()[$ext] : null;
if (!isset($format)) {
$this->logger->info("Format is not supported for editing: $fileName", ["app" => $this->appName]);
return new JSONResponse(["error" => $this->trans->t("Format is not supported")]);
Expand Down Expand Up @@ -294,8 +308,8 @@ public function config($fileId, $filePath = null, $shareToken = null, $directTok
],
"documentType" => $format["type"],
"editorConfig" => [
"lang" => str_replace("_", "-", \OC::$server->getL10NFactory()->get("onlyoffice")->getLanguageCode()),
"region" => str_replace("_", "-", \OC::$server->getL10NFactory()->get("onlyoffice")->getLocaleCode())
"lang" => str_replace("_", "-", \OC::$server->getL10NFactory()->get("")->getLanguageCode()),
"region" => str_replace("_", "-", \OC::$server->getL10NFactory()->get("")->getLocaleCode())
]
];

Expand All @@ -304,6 +318,48 @@ public function config($fileId, $filePath = null, $shareToken = null, $directTok
$params["document"]["permissions"]["modifyFilter"] = $permissions_modifyFilter;
}

$restrictedEditing = false;
$fileStorage = $file->getStorage();
if (empty($shareToken) && $fileStorage->instanceOfStorage("\OCA\Files_Sharing\SharedStorage")) {
$shareId = $fileStorage->getShareId();

$extraPermissions = null;
if ($this->extraPermissions !== null) {
$extraPermissions = $this->extraPermissions->getExtra($shareId);
}

if (!empty($extraPermissions)) {
if (isset($format["review"]) && $format["review"]) {
$reviewPermission = ($extraPermissions["permissions"] & ExtraPermissions::Review) === ExtraPermissions::Review;
if ($reviewPermission) {
$restrictedEditing = true;
$params["document"]["permissions"]["review"] = true;
}
}

if (isset($format["comment"]) && $format["comment"]) {
$commentPermission = ($extraPermissions["permissions"] & ExtraPermissions::Comment) === ExtraPermissions::Comment;
if ($commentPermission) {
$restrictedEditing = true;
$params["document"]["permissions"]["comment"] = true;
}
}

if (isset($format["fillForms"]) && $format["fillForms"]) {
$fillFormsPermission = ($extraPermissions["permissions"] & ExtraPermissions::FillForms) === ExtraPermissions::FillForms;
if ($fillFormsPermission) {
$restrictedEditing = true;
$params["document"]["permissions"]["fillForms"] = true;
}
}

if (isset($format["modifyFilter"]) && $format["modifyFilter"]) {
$modifyFilter = ($extraPermissions["permissions"] & ExtraPermissions::ModifyFilter) === ExtraPermissions::ModifyFilter;
$params["document"]["permissions"]["modifyFilter"] = $modifyFilter;
}
}
}

$isTempLock = false;
if ($version < 1
&& \OC::$server->getAppManager()->isInstalled("files_lock")) {
Expand Down Expand Up @@ -334,8 +390,14 @@ public function config($fileId, $filePath = null, $shareToken = null, $directTok
&& !$isTempLock
&& (empty($shareToken) || ($share->getPermissions() & Constants::PERMISSION_UPDATE) === Constants::PERMISSION_UPDATE);
$params["document"]["permissions"]["edit"] = $editable;
if ($editable && ($canEdit || $canFillForms)) {
$hashCallback = $this->crypt->GetHash(["userId" => $userId, "fileId" => $file->getId(), "filePath" => $filePath, "shareToken" => $shareToken, "action" => "track"]);
if (($editable || $restrictedEditing) && ($canEdit || $canFillForms)) {
$ownerId = null;
$owner = $file->getOwner();
if (!empty($owner)) {
$ownerId = $owner->getUID();
}

$hashCallback = $this->crypt->GetHash(["userId" => $userId, "ownerId" => $ownerId, "fileId" => $file->getId(), "filePath" => $filePath, "shareToken" => $shareToken, "action" => "track"]);
$callback = $this->urlGenerator->linkToRouteAbsolute($this->appName . ".callback.track", ["doc" => $hashCallback]);

if (!empty($this->config->GetStorageUrl())) {
Expand Down Expand Up @@ -458,7 +520,7 @@ public function config($fileId, $filePath = null, $shareToken = null, $directTok
"url" => $folderLink
];

if (!$desktop) {
if (!$desktop && !$inviewer) {
if ($this->config->GetSameTab()) {
$params["editorConfig"]["customization"]["goback"]["blank"] = false;
}
Expand Down Expand Up @@ -589,8 +651,7 @@ private function getUrl($file, $user = null, $shareToken = null, $version = 0, $

$fileUrl = $this->urlGenerator->linkToRouteAbsolute($this->appName . ".callback.download", ["doc" => $hashUrl]);

if (!empty($this->config->GetStorageUrl())
&& !$changes) {
if (!empty($this->config->GetStorageUrl())) {
$fileUrl = str_replace($this->urlGenerator->getAbsoluteURL("/"), $this->config->GetStorageUrl(), $fileUrl);
}

Expand Down Expand Up @@ -649,11 +710,21 @@ private function setCustomization($params) {
$params["editorConfig"]["customization"]["reviewDisplay"] = $reviewDisplay;
}

$theme = $this->config->GetCustomizationTheme();
if (isset($theme)) {
$params["editorConfig"]["customization"]["uiTheme"] = $theme;
}

//default is false
if ($this->config->GetCustomizationToolbarNoTabs() === true) {
$params["editorConfig"]["customization"]["toolbarNoTabs"] = true;
}

//default is true
if($this->config->GetCustomizationMacros() === false) {
$params["editorConfig"]["customization"]["macros"] = false;
}


/* from system config */

Expand Down Expand Up @@ -707,7 +778,7 @@ private function setWatermark($params, $isPublic, $userId, $file) {

if ($watermarkTemplate !== false) {
$replacements = [
"userId" => $userId,
"userId" => isset($userId) ? $userId : $this->trans->t('Anonymous'),
"date" => (new \DateTime())->format("Y-m-d H:i:s"),
"themingName" => \OC::$server->getThemingDefaults()->getName()
];
Expand Down
Loading

0 comments on commit b58253d

Please sign in to comment.