Merge pull request #116 from vmiklos/bccu2033

bccu#2033 Respect WOPI action names
pull/1/head
Andras Timar 8 years ago committed by GitHub
commit 2ffa1b04b3

@ -67,16 +67,18 @@ class DocumentController extends Controller {
/** /**
* @param \SimpleXMLElement $discovery * @param \SimpleXMLElement $discovery
* @param string $mimetype * @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) { if(is_null($discovery_parsed) || $discovery_parsed == false) {
return null; 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) { if ($result && count($result) > 0) {
return (string)$result[0]['urlsrc']; return array(
'urlsrc' => (string)$result[0]['urlsrc'],
'action' => (string)$result[0]['name']
);
} }
return null; 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]['icon'] = preg_replace('/\.png$/', '.svg', \OCP\Template::mimetype_icon($document['mimetype']));
$documents[$key]['hasPreview'] = \OC::$server->getPreviewManager()->isMimeSupported($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; $documents[$key]['lolang'] = $lolang;
$fileIds[] = $document['fileid']; $fileIds[] = $document['fileid'];
} }
@ -354,10 +358,12 @@ class DocumentController extends Controller {
if ($content && $view->file_put_contents($path, $content)){ if ($content && $view->file_put_contents($path, $content)){
$info = $view->getFileInfo($path); $info = $view->getFileInfo($path);
$ret = $this->getWopiSrcUrl($discovery_parsed, $mimetype);
$response = array( $response = array(
'status' => 'success', 'status' => 'success',
'fileid' => $info['fileid'], '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'), 'lolang' => $this->settings->getUserValue($this->uid, 'core', 'lang', 'en'),
'data' => \OCA\Files\Helper::formatFileInfo($info) 'data' => \OCA\Files\Helper::formatFileInfo($info)
); );

@ -33,6 +33,7 @@ $.widget('oc.documentGrid', {
.attr('title', document.path) .attr('title', document.path)
.attr('original-title', document.path) .attr('original-title', document.path)
.attr('urlsrc', document.urlsrc) .attr('urlsrc', document.urlsrc)
.attr('action', document.action)
.attr('lolang', document.lolang) .attr('lolang', document.lolang)
.find('label').text(document.name) .find('label').text(document.name)
; ;
@ -408,7 +409,7 @@ var documentsMain = {
$('#revisionsContainer li').first().find('.versionPreview').click(); $('#revisionsContainer li').first().find('.versionPreview').click();
}, },
showEditor : function(title){ showEditor : function(title, action){
if (documentsMain.isGuest){ if (documentsMain.isGuest){
// !Login page mess wih WebODF toolbars // !Login page mess wih WebODF toolbars
$(document.body).attr('id', 'body-user'); $(document.body).attr('id', 'body-user');
@ -420,7 +421,7 @@ var documentsMain = {
} }
if (!documentsMain.renderComplete) { 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 ...'); console.log('Waiting for page to render ...');
return; return;
} }
@ -454,6 +455,9 @@ var documentsMain = {
"&lang=" + $('li[data-id='+ documentsMain.fileId +']>a').attr('lolang') + "&lang=" + $('li[data-id='+ documentsMain.fileId +']>a').attr('lolang') +
"&closebutton=1" + "&closebutton=1" +
"&revisionhistory=1"; "&revisionhistory=1";
if (action === "view") {
urlsrc += "&permission=readonly";
}
// access_token - must be passed via a form post // access_token - must be passed via a form post
var access_token = encodeURIComponent(result.token); var access_token = encodeURIComponent(result.token);
@ -785,7 +789,8 @@ var documentsMain = {
}, },
loadDocument: function() { 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) { renameDocument: function(name) {

Loading…
Cancel
Save