Skip to content

Commit

Permalink
Merge pull request #167 from ONLYOFFICE/develop
Browse files Browse the repository at this point in the history
Release/1.3.0
  • Loading branch information
LinneyS authored Mar 22, 2018
2 parents ca756a3 + ee1d6ec commit a56885e
Show file tree
Hide file tree
Showing 43 changed files with 656 additions and 192 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Change Log

## 1.3.0
## Added
- add macro-enabled and template formats
- support shared link for document
- customization editor

## Changed
- update template empty files
- fix collaboration editing
- view without converting

## 1.2.0
## Added
- disabling for incorrect settings
Expand Down
2 changes: 1 addition & 1 deletion appinfo/app.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
*
* (c) Copyright Ascensio System Limited 2010-2017
* (c) Copyright Ascensio System Limited 2010-2018
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
Expand Down
13 changes: 10 additions & 3 deletions appinfo/application.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
*
* (c) Copyright Ascensio System Limited 2010-2017
* (c) Copyright Ascensio System Limited 2010-2018
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
Expand All @@ -27,13 +27,15 @@
namespace OCA\Onlyoffice\AppInfo;

use OCP\AppFramework\App;
use OCP\Share\IManager;
use OCP\Util;

use OCA\Onlyoffice\AppConfig;
use OCA\Onlyoffice\Controller\CallbackController;
use OCA\Onlyoffice\Controller\EditorController;
use OCA\Onlyoffice\Controller\SettingsController;
use OCA\Onlyoffice\Crypt;
use OCA\Onlyoffice\Hookhandler;

class Application extends App {

Expand Down Expand Up @@ -69,6 +71,8 @@ function() {
}
});

Util::connectHook("OCP\Share", "share_link_access", Hookhandler::class, "PublicPage");

require_once __DIR__ . "/../3rdparty/jwt/BeforeValidException.php";
require_once __DIR__ . "/../3rdparty/jwt/ExpiredException.php";
require_once __DIR__ . "/../3rdparty/jwt/SignatureInvalidException.php";
Expand Down Expand Up @@ -120,7 +124,9 @@ function() {
$c->query("L10N"),
$c->query("Logger"),
$this->appConfig,
$this->crypt
$this->crypt,
$c->query("IManager"),
$c->query("Session")
);
});

Expand All @@ -134,7 +140,8 @@ function() {
$c->query("L10N"),
$c->query("Logger"),
$this->appConfig,
$this->crypt
$this->crypt,
$c->query("IManager")
);
});
}
Expand Down
5 changes: 3 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<description>ONLYOFFICE connector enables you to edit Office documents within ONLYOFFICE from the familiar web interface. This will create a new Open in ONLYOFFICE action within the document library for Office documents. This allows multiple users to collaborate in real time and to save back those changes to your file storage.</description>
<licence>agpl</licence>
<author>Ascensio System SIA</author>
<version>1.2.0</version>
<version>1.3.0</version>
<namespace>Onlyoffice</namespace>
<types>
<filesystem/>
Expand All @@ -29,9 +29,10 @@
<screenshot>https://raw.githubusercontent.com/ONLYOFFICE/onlyoffice-owncloud/master/screenshots/settings.png</screenshot>
<dependencies>
<owncloud min-version="9.0" max-version="10.0" />
<nextcloud min-version="11" max-version="13"/>
<nextcloud min-version="12" max-version="13"/>
</dependencies>
<settings>
<admin>OCA\Onlyoffice\AdminSettings</admin>
<admin-section>OCA\Onlyoffice\AdminSection</admin-section>
</settings>
</info>
3 changes: 2 additions & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
*
* (c) Copyright Ascensio System Limited 2010-2017
* (c) Copyright Ascensio System Limited 2010-2018
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
Expand Down Expand Up @@ -30,6 +30,7 @@
["name" => "callback#emptyfile", "url" => "/empty", "verb" => "GET"],
["name" => "callback#track", "url" => "/track", "verb" => "POST"],
["name" => "editor#index", "url" => "/{fileId}", "verb" => "GET"],
["name" => "editor#public_page", "url" => "/s/{token}", "verb" => "GET"],
["name" => "editor#config", "url" => "/ajax/config/{fileId}", "verb" => "GET"],
["name" => "editor#create", "url" => "/ajax/new", "verb" => "POST"],
["name" => "editor#convert", "url" => "/ajax/convert", "verb" => "POST"],
Expand Down
Binary file modified assets/cs/new.docx
Binary file not shown.
Binary file modified assets/cs/new.pptx
Binary file not shown.
Binary file modified assets/de/new.docx
Binary file not shown.
Binary file modified assets/de/new.pptx
Binary file not shown.
Binary file modified assets/de_DE/new.docx
Binary file not shown.
Binary file modified assets/de_DE/new.pptx
Binary file not shown.
Binary file modified assets/el/new.docx
Binary file not shown.
Binary file modified assets/en/new.docx
Binary file not shown.
Binary file modified assets/es/new.docx
Binary file not shown.
Binary file modified assets/fr/new.docx
Binary file not shown.
Binary file modified assets/it/new.docx
Binary file not shown.
Binary file modified assets/ko/new.docx
Binary file not shown.
Binary file modified assets/pl/new.docx
Binary file not shown.
Binary file modified assets/pt_BR/new.docx
Binary file not shown.
Binary file modified assets/pt_PT/new.docx
Binary file not shown.
Binary file modified assets/pt_PT/new.pptx
Binary file not shown.
Binary file modified assets/ru/new.docx
Binary file not shown.
Binary file modified assets/ru/new.pptx
Binary file not shown.
Binary file modified assets/zh_CN/new.docx
Binary file not shown.
148 changes: 115 additions & 33 deletions controller/callbackcontroller.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
*
* (c) Copyright Ascensio System Limited 2010-2017
* (c) Copyright Ascensio System Limited 2010-2018
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
Expand Down Expand Up @@ -30,13 +30,17 @@
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataDownloadResponse;
use OCP\AppFramework\Http\JSONResponse;
use OCP\Constants;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\NotPermittedException;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Share\IManager;

use OCA\Onlyoffice\AppConfig;
use OCA\Onlyoffice\Crypt;
Expand Down Expand Up @@ -98,6 +102,13 @@ class CallbackController extends Controller {
*/
private $crypt;

/**
* Share manager
*
* @var OCP\Share\IManager
*/
private $shareManager;

/**
* Status of the document
*
Expand All @@ -121,6 +132,7 @@ class CallbackController extends Controller {
* @param ILogger $logger - logger
* @param OCA\Onlyoffice\AppConfig $config - application configuration
* @param OCA\Onlyoffice\Crypt $crypt - hash generator
* @param IManager $shareManager - Share manager
*/
public function __construct($AppName,
IRequest $request,
Expand All @@ -130,7 +142,8 @@ public function __construct($AppName,
IL10N $trans,
ILogger $logger,
AppConfig $config,
Crypt $crypt
Crypt $crypt,
IManager $shareManager
) {
parent::__construct($AppName, $request);

Expand All @@ -141,6 +154,7 @@ public function __construct($AppName,
$this->logger = $logger;
$this->config = $config;
$this->crypt = $crypt;
$this->shareManager = $shareManager;
}


Expand Down Expand Up @@ -190,21 +204,16 @@ public function download($doc) {

$userId = $hashData->userId;

$files = $this->root->getUserFolder($userId)->getById($fileId);
if (empty($files)) {
$this->logger->info("Files for download not found: " . $fileId, array("app" => $this->appName));
return new JSONResponse(["message" => $this->trans->t("Files not found")], Http::STATUS_NOT_FOUND);
}
$file = $files[0];
$token = $hashData->token;
list ($file, $error) = empty($token) ? $this->getFile($userId, $fileId) : $this->getFileByToken($fileId, $token);

if (! $file instanceof File) {
$this->logger->info("File for download not found: " . $fileId, array("app" => $this->appName));
return new JSONResponse(["message" => $this->trans->t("File not found")], Http::STATUS_NOT_FOUND);
if (isset($error)) {
return $error;
}

try {
return new DataDownloadResponse($file->getContent(), $file->getName(), $file->getMimeType());
} catch (\OCP\Files\NotPermittedException $e) {
} catch (NotPermittedException $e) {
$this->logger->info("Download Not permitted: " . $fileId . " " . $e->getMessage(), array("app" => $this->appName));
return new JSONResponse(["message" => $this->trans->t("Not permitted")], Http::STATUS_FORBIDDEN);
}
Expand Down Expand Up @@ -263,7 +272,7 @@ public function emptyfile($doc) {

try {
return new DataDownloadResponse($template, "new.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
} catch (\OCP\Files\NotPermittedException $e) {
} catch (NotPermittedException $e) {
$this->logger->info("Download Not permitted: " . $fileId . " " . $e->getMessage(), array("app" => $this->appName));
return new JSONResponse(["message" => $this->trans->t("Not permitted")], Http::STATUS_FORBIDDEN);
}
Expand Down Expand Up @@ -335,21 +344,26 @@ public function track($doc, $users, $key, $status, $url) {
return new JSONResponse(["message" => $this->trans->t("Url not found")], Http::STATUS_BAD_REQUEST);
}

$userId = $hashData->userId;
$userId = $users[0];
$user = $this->userManager->get($userId);
if (!empty($user)) {
$this->logger->info("setupFS " . $userId, array("app" => $this->appName));
\OC_Util::tearDownFS();
\OC_Util::setupFS($userId);

\OC_Util::tearDownFS();
\OC_Util::setupFS($userId);
$this->userSession->setUser($user);
} else {
$ownerId = $hashData->ownerId;

$files = $this->root->getUserFolder($userId)->getById($fileId);
if (empty($files)) {
$this->logger->info("Files for track not found: " . $fileId, array("app" => $this->appName));
return new JSONResponse(["message" => $this->trans->t("Files not found")], Http::STATUS_NOT_FOUND);
\OC_Util::tearDownFS();
\OC_Util::setupFS($ownerId);
}
$file = $files[0];

if (! $file instanceof File) {
$this->logger->info("File for track not found: " . $fileId, array("app" => $this->appName));
return new JSONResponse(["message" => $this->trans->t("File not found")], Http::STATUS_NOT_FOUND);
$token = $hashData->token;
list ($file, $error) = empty($token) ? $this->getFile($userId, $fileId) : $this->getFileByToken($fileId, $token);

if (isset($error)) {
return $error;
}

$fileName = $file->getName();
Expand All @@ -374,7 +388,7 @@ public function track($doc, $users, $key, $status, $url) {

if (!preg_match("/^https?:\/\//i", $from)) {
$parsedUrl = parse_url($url);
$from = $parsedUrl["scheme"] . "://" . $parsedUrl["host"] . (array_key_exists("port", $parsedUrl) ? (":" . $parsedUrl["port"]) : "") . "/";
$from = $parsedUrl["scheme"] . "://" . $parsedUrl["host"] . (array_key_exists("port", $parsedUrl) ? (":" . $parsedUrl["port"]) : "") . $from;
}

if ($from !== $documentServerUrl)
Expand All @@ -384,13 +398,6 @@ public function track($doc, $users, $key, $status, $url) {
}
}

$this->userSession->setUser($this->userManager->get($users[0]));

if (!$file->isUpdateable()) {
$this->logger->error("Save error. File is not updateable: " . $fileId, array("app" => $this->appName));
return new JSONResponse(["message" => $this->trans->t("Access denied")], Http::STATUS_FORBIDDEN);
}

if (($newData = $documentService->Request($url))) {
$file->putContent($newData);
$error = 0;
Expand All @@ -403,6 +410,81 @@ public function track($doc, $users, $key, $status, $url) {
break;
}

return new JSONResponse(["error" => $error], ($error === 0 ? Http::STATUS_OK : Http::STATUS_BAD_REQUEST));
return new JSONResponse(["error" => $error], Http::STATUS_OK);
}


/**
* Getting file by identifier
*
* @param integer $userId - user identifier
* @param integer $fileId - file identifier
*
* @return array
*/
private function getFile($userId, $fileId) {
if (empty($fileId)) {
return [NULL, $this->trans->t("FileId is empty")];
}

$files = $this->root->getUserFolder($userId)->getById($fileId);
if (empty($files)) {
$this->logger->info("Files not found: " . $fileId, array("app" => $this->appName));
return new JSONResponse(["message" => $this->trans->t("Files not found")], Http::STATUS_NOT_FOUND);
}
$file = $files[0];

if (! $file instanceof File) {
$this->logger->info("File not found: " . $fileId, array("app" => $this->appName));
return new JSONResponse(["message" => $this->trans->t("File not found")], Http::STATUS_NOT_FOUND);
}

return [$file, NULL];
}

/**
* Getting file by token
*
* @param integer $fileId - file identifier
* @param string $token - access token
*
* @return array
*/
private function getFileByToken($fileId, $token) {
list ($share, $error) = $this->getShare($token);

if (isset($error)) {
return [NULL, $error];
}

$node = $share->getNode();

if ($node instanceof Folder) {
$file = $node->getById($fileId)[0];
} else {
$file = $node;
}

return [$file, NULL];
}

/**
* Getting share by token
*
* @param string $token - access token
*
* @return array
*/
private function getShare($token) {
if (empty($token)) {
return [NULL, $this->trans->t("FileId is empty")];
}

$share = $this->shareManager->getShareByToken($token);
if ($share === NULL || $share === false) {
return [NULL, $this->trans->t("You do not have enough permissions to view the file")];
}

return [$share, NULL];
}
}
Loading

0 comments on commit a56885e

Please sign in to comment.