Initial mobile edit
* Add OCS endpoint for client to request a view * Endpoint returns an URL * DirectView controller to show info Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Родитель
4d412b35d5
Коммит
21059397a9
|
@ -135,4 +135,43 @@
|
|||
</index>
|
||||
</declaration>
|
||||
</table>
|
||||
|
||||
<table>
|
||||
<name>*dbprefix*richdocuments_direct</name>
|
||||
<declaration>
|
||||
<field>
|
||||
<name>id</name>
|
||||
<type>integer</type>
|
||||
<notnull>true</notnull>
|
||||
<autoincrement>1</autoincrement>
|
||||
<unsigned>true</unsigned>
|
||||
<length>4</length>
|
||||
</field>
|
||||
<field>
|
||||
<name>token</name>
|
||||
<type>text</type>
|
||||
<length>64</length>
|
||||
</field>
|
||||
<field>
|
||||
<name>uid</name>
|
||||
<type>text</type>
|
||||
<length>64</length>
|
||||
</field>
|
||||
<field>
|
||||
<name>fileid</name>
|
||||
<type>integer</type>
|
||||
<notnull>true</notnull>
|
||||
<length>4</length>
|
||||
</field>
|
||||
|
||||
<index>
|
||||
<name>rd_direct_token_idx</name>
|
||||
<unique>true</unique>
|
||||
<field>
|
||||
<name>token</name>
|
||||
<sorting>ascending</sorting>
|
||||
</field>
|
||||
</index>
|
||||
</declaration>
|
||||
</table>
|
||||
</database>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<name>Collabora Online</name>
|
||||
<summary>Edit office documents directly in your browser.</summary>
|
||||
<description>This application can connect to a Collabora Online server (WOPI Client). Nextcloud is the WOPI Host. Please read the documentation to learn more about that.</description>
|
||||
<version>2.0.10</version>
|
||||
<version>2.1.0</version>
|
||||
<licence>agpl</licence>
|
||||
<author>Collabora Productivity based on work of Frank Karlitschek, Victor Dubiniuk</author>
|
||||
<types>
|
||||
|
|
|
@ -30,5 +30,11 @@ return [
|
|||
//settings
|
||||
['name' => 'settings#setSettings', 'url' => 'ajax/admin.php', 'verb' => 'POST'],
|
||||
['name' => 'settings#getSettings', 'url' => 'ajax/settings.php', 'verb' => 'GET'],
|
||||
]
|
||||
|
||||
//Mobile access
|
||||
['name' => 'directView#show', 'url' => '/direct/{token}', 'verb' => 'GET'],
|
||||
],
|
||||
'ocs' => [
|
||||
['name' => 'OCS#create', 'url' => '/api/v1/document', 'verb' => 'POST'],
|
||||
],
|
||||
];
|
||||
|
|
|
@ -19,7 +19,7 @@ $.widget('oc.documentGrid', {
|
|||
|
||||
_load : function(fileId) {
|
||||
// Handle guest user case (let users which are able to write set their name)
|
||||
if (window.top.oc_current_user == null && this._getGuestNameCookie() == ''
|
||||
if (!richdocuments_directEdit && window.top.oc_current_user == null && this._getGuestNameCookie() == ''
|
||||
&& (richdocuments_permissions & OC.PERMISSION_UPDATE)) {
|
||||
$('#documentslist').remove();
|
||||
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2018, Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
namespace OCA\Richdocuments\Controller;
|
||||
|
||||
use OCA\Richdocuments\AppConfig;
|
||||
use OCA\Richdocuments\Db\DirectMapper;
|
||||
use OCA\Richdocuments\TokenManager;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\Files\IRootFolder;
|
||||
use OCP\Files\Node;
|
||||
use OCP\IConfig;
|
||||
use OCP\IRequest;
|
||||
|
||||
class DirectViewController extends Controller {
|
||||
/** @var IRootFolder */
|
||||
private $rootFolder;
|
||||
|
||||
/** @var TokenManager */
|
||||
private $tokenManager;
|
||||
|
||||
/** @var DirectMapper */
|
||||
private $directMapper;
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/** @var AppConfig */
|
||||
private $appConfig;
|
||||
|
||||
public function __construct($appName,
|
||||
IRequest $request,
|
||||
IRootFolder $rootFolder,
|
||||
TokenManager $tokenManager,
|
||||
DirectMapper $directMapper,
|
||||
IConfig $config,
|
||||
AppConfig $appConfig) {
|
||||
parent::__construct($appName, $request);
|
||||
|
||||
$this->rootFolder = $rootFolder;
|
||||
$this->tokenManager = $tokenManager;
|
||||
$this->directMapper = $directMapper;
|
||||
$this->config = $config;
|
||||
$this->appConfig = $appConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @param string $token
|
||||
*/
|
||||
public function show($token) {
|
||||
try {
|
||||
$direct = $this->directMapper->getBytoken($token);
|
||||
} catch (DoesNotExistException $e) {
|
||||
//TODO show 404
|
||||
throw new \Exception('NOPE!');
|
||||
}
|
||||
|
||||
try {
|
||||
$folder = $this->rootFolder->getUserFolder($direct->getUid());
|
||||
$item = $folder->getById($direct->getFileid())[0];
|
||||
if(!($item instanceof Node)) {
|
||||
throw new \Exception();
|
||||
}
|
||||
list($urlSrc, $token) = $this->tokenManager->getToken($item->getId());
|
||||
$params = [
|
||||
'permissions' => $item->getPermissions(),
|
||||
'title' => $item->getName(),
|
||||
'fileId' => $item->getId() . '_' . $this->config->getSystemValue('instanceid'),
|
||||
'token' => $token,
|
||||
'urlsrc' => $urlSrc,
|
||||
'path' => $folder->getRelativePath($item->getPath()),
|
||||
'instanceId' => $this->config->getSystemValue('instanceid'),
|
||||
'canonical_webroot' => $this->appConfig->getAppValue('canonical_webroot'),
|
||||
'direct' => true,
|
||||
];
|
||||
|
||||
$response = new TemplateResponse('richdocuments', 'documents', $params, 'empty');
|
||||
$policy = new ContentSecurityPolicy();
|
||||
$policy->allowInlineScript(true);
|
||||
$policy->addAllowedFrameDomain($this->appConfig->getAppValue('wopi_url'));
|
||||
$response->setContentSecurityPolicy($policy);
|
||||
return $response;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2018, Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
namespace OCA\Richdocuments\Controller;
|
||||
|
||||
use OCA\Richdocuments\Db\DirectMapper;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\OCS\OCSBadRequestException;
|
||||
use OCP\AppFramework\OCS\OCSNotFoundException;
|
||||
use OCP\Files\Folder;
|
||||
use OCP\Files\IRootFolder;
|
||||
use OCP\Files\NotFoundException;
|
||||
use OCP\IRequest;
|
||||
use OCP\IURLGenerator;
|
||||
|
||||
class OCSController extends \OCP\AppFramework\OCSController {
|
||||
/** @var IRootFolder */
|
||||
private $rootFolder;
|
||||
|
||||
/** @var string */
|
||||
private $userId;
|
||||
|
||||
/** @var DirectMapper */
|
||||
private $directMapper;
|
||||
|
||||
/** @var IURLGenerator */
|
||||
private $urlGenerator;
|
||||
|
||||
public function __construct($appName,
|
||||
IRequest $request,
|
||||
IRootFolder $rootFolder,
|
||||
$userId,
|
||||
DirectMapper $directMapper,
|
||||
IURLGenerator $urlGenerator) {
|
||||
parent::__construct($appName, $request);
|
||||
|
||||
$this->rootFolder = $rootFolder;
|
||||
$this->userId = $userId;
|
||||
$this->directMapper = $directMapper;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param int $fileId
|
||||
*/
|
||||
public function create($fileId) {
|
||||
try {
|
||||
$userFolder = $this->rootFolder->getUserFolder($this->userId);
|
||||
$nodes = $userFolder->getById($fileId);
|
||||
|
||||
if ($nodes === []) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
$node = $nodes[0];
|
||||
if ($node instanceof Folder) {
|
||||
throw new OCSBadRequestException('Cannot view folder');
|
||||
}
|
||||
|
||||
//TODO check if we can even edit this file with collabora
|
||||
|
||||
$direct = $this->directMapper->newDirect($this->userId, $fileId);
|
||||
|
||||
return new DataResponse([
|
||||
'url' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.directView.show', [
|
||||
'token' => $direct->getToken()
|
||||
])
|
||||
]);
|
||||
} catch (NotFoundException $e) {
|
||||
throw new OCSNotFoundException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2018, Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Richdocuments\Db;
|
||||
|
||||
use OCP\AppFramework\Db\Entity;
|
||||
|
||||
/**
|
||||
* @method void setToken(string $token)
|
||||
* @method string getToken()
|
||||
* @method void setUid(string $uid)
|
||||
* @method string getUid()
|
||||
* @method void setFileid(int $fileid)
|
||||
* @method int getFileid()
|
||||
*/
|
||||
class Direct extends Entity {
|
||||
/** @var string */
|
||||
protected $token;
|
||||
|
||||
/** @var string */
|
||||
protected $uid;
|
||||
|
||||
/** @var int */
|
||||
protected $fileid;
|
||||
|
||||
public function __construct() {
|
||||
$this->addType('token', 'string');
|
||||
$this->addType('uid', 'string');
|
||||
$this->addType('fileid', 'int');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2018, Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Richdocuments\Db;
|
||||
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Db\Mapper;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\Security\ISecureRandom;
|
||||
use PhpParser\Node\Scalar\MagicConst\Dir;
|
||||
|
||||
class DirectMapper extends Mapper {
|
||||
|
||||
/** @var ISecureRandom */
|
||||
protected $random;
|
||||
|
||||
public function __construct(IDBConnection $db, ISecureRandom $random) {
|
||||
parent::__construct($db, 'richdocuments_direct', Direct::class);
|
||||
|
||||
$this->random = $random;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $uid
|
||||
* @param int $fileid
|
||||
* @return Direct
|
||||
*/
|
||||
public function newDirect($uid, $fileid) {
|
||||
$direct = new Direct();
|
||||
$direct->setUid($uid);
|
||||
$direct->setFileid($fileid);
|
||||
$direct->setToken($this->random->generate(64, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER));
|
||||
|
||||
$direct = $this->insert($direct);
|
||||
return $direct;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $token
|
||||
* @return Direct
|
||||
*/
|
||||
public function getBytoken($token) {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
->from('richdocuments_direct')
|
||||
->where($qb->expr()->eq('token', $qb->createNamedParameter($token)));
|
||||
|
||||
$cursor = $qb->execute();
|
||||
$row = $cursor->fetch();
|
||||
$cursor->closeCursor();
|
||||
|
||||
//There can only be one as the token is unique
|
||||
if ($row === false) {
|
||||
throw new DoesNotExistException('Could not find token.');
|
||||
}
|
||||
|
||||
return Direct::fromRow($row);
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
var richdocuments_path = '<?php p($_['path']) ?>';
|
||||
var instanceId = '<?php p($_['instanceId']) ?>';
|
||||
var richdocuments_canonical_webroot = '<?php p($_['canonical_webroot']) ?>';
|
||||
var richdocuments_directEdit = <?php isset($_['direct']) ? p('true') : p('false') ?>;
|
||||
</script>
|
||||
|
||||
<?php
|
||||
|
|
Загрузка…
Ссылка в новой задаче