Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/richdocuments.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-10-04 16:52:13 +0300
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-10-04 16:53:36 +0300
commitd6b65b79835bc499f720d15bb6c00441079b2fd6 (patch)
treecfd89c186eeab232dcb8d3586c47aebd6b5b5bf5
parent63c74865f0a8911b1e211e14f336b68ee54bb96d (diff)
bccu#2033 Respect WOPI action names
Don't assume that the action name is 'edit' all the time. Instead, if it's view, then initialize leaflet with permission=readonly.
-rw-r--r--controller/documentcontroller.php18
-rw-r--r--js/documents.js11
2 files changed, 20 insertions, 9 deletions
diff --git a/controller/documentcontroller.php b/controller/documentcontroller.php
index 18872a4c..9e310ec3 100644
--- a/controller/documentcontroller.php
+++ b/controller/documentcontroller.php
@@ -67,16 +67,18 @@ class DocumentController extends Controller {
/**
* @param \SimpleXMLElement $discovery
* @param string $mimetype
- * @param string $action
*/
- private function getWopiSrcUrl($discovery_parsed, $mimetype, $action) {
+ private function getWopiSrcUrl($discovery_parsed, $mimetype) {
if(is_null($discovery_parsed) || $discovery_parsed == false) {
return null;
}
- $result = $discovery_parsed->xpath(sprintf('/wopi-discovery/net-zone/app[@name=\'%s\']/action[@name=\'%s\']', $mimetype, $action));
+ $result = $discovery_parsed->xpath(sprintf('/wopi-discovery/net-zone/app[@name=\'%s\']/action', $mimetype));
if ($result && count($result) > 0) {
- return (string)$result[0]['urlsrc'];
+ return array(
+ 'urlsrc' => (string)$result[0]['urlsrc'],
+ 'action' => (string)$result[0]['name']
+ );
}
return null;
@@ -214,7 +216,9 @@ class DocumentController extends Controller {
}
$documents[$key]['icon'] = preg_replace('/\.png$/', '.svg', \OCP\Template::mimetype_icon($document['mimetype']));
$documents[$key]['hasPreview'] = \OC::$server->getPreviewManager()->isMimeSupported($document['mimetype']);
- $documents[$key]['urlsrc'] = $this->getWopiSrcUrl($discovery_parsed, $document['mimetype'], 'edit');
+ $ret = $this->getWopiSrcUrl($discovery_parsed, $document['mimetype']);
+ $documents[$key]['urlsrc'] = $ret['urlsrc'];
+ $documents[$key]['action'] = $ret['action'];
$documents[$key]['lolang'] = $lolang;
$fileIds[] = $document['fileid'];
}
@@ -354,10 +358,12 @@ class DocumentController extends Controller {
if ($content && $view->file_put_contents($path, $content)){
$info = $view->getFileInfo($path);
+ $ret = $this->getWopiSrcUrl($discovery_parsed, $mimetype);
$response = array(
'status' => 'success',
'fileid' => $info['fileid'],
- 'urlsrc' => $this->getWopiSrcUrl($discovery_parsed, $mimetype, 'edit'),
+ 'urlsrc' => $ret['urlsrc'],
+ 'action' => $ret['action'],
'lolang' => $this->settings->getUserValue($this->uid, 'core', 'lang', 'en'),
'data' => \OCA\Files\Helper::formatFileInfo($info)
);
diff --git a/js/documents.js b/js/documents.js
index 2fe101c8..105926ba 100644
--- a/js/documents.js
+++ b/js/documents.js
@@ -33,6 +33,7 @@ $.widget('oc.documentGrid', {
.attr('title', document.path)
.attr('original-title', document.path)
.attr('urlsrc', document.urlsrc)
+ .attr('action', document.action)
.attr('lolang', document.lolang)
.find('label').text(document.name)
;
@@ -408,7 +409,7 @@ var documentsMain = {
$('#revisionsContainer li').first().find('.versionPreview').click();
},
- showEditor : function(title){
+ showEditor : function(title, action){
if (documentsMain.isGuest){
// !Login page mess wih WebODF toolbars
$(document.body).attr('id', 'body-user');
@@ -420,7 +421,7 @@ var documentsMain = {
}
if (!documentsMain.renderComplete) {
- setTimeout(function() { documentsMain.UI.showEditor(title); }, 500);
+ setTimeout(function() { documentsMain.UI.showEditor(title, action); }, 500);
console.log('Waiting for page to render ...');
return;
}
@@ -454,6 +455,9 @@ var documentsMain = {
"&lang=" + $('li[data-id='+ documentsMain.fileId +']>a').attr('lolang') +
"&closebutton=1" +
"&revisionhistory=1";
+ if (action === "view") {
+ urlsrc += "&permission=readonly";
+ }
// access_token - must be passed via a form post
var access_token = encodeURIComponent(result.token);
@@ -785,7 +789,8 @@ var documentsMain = {
},
loadDocument: function() {
- documentsMain.UI.showEditor(documentsMain.fileName);
+ var action = $('li[data-id='+ documentsMain.fileId +']>a').attr('action');
+ documentsMain.UI.showEditor(documentsMain.fileName, action);
},
renameDocument: function(name) {