diff --git a/appinfo/routes.php b/appinfo/routes.php index 67dfc3fa..2e043da3 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -17,6 +17,7 @@ return [ ['name' => 'document#index', 'url' => 'index', 'verb' => 'GET'], ['name' => 'document#publicPage', 'url' => '/public', 'verb' => 'GET'], ['name' => 'document#create', 'url' => 'ajax/documents/create', 'verb' => 'POST'], + ['name' => 'document#generate', 'url' => 'ajax/generate.php', 'verb' => 'GET'], // WOPI access ['name' => 'wopi#checkFileInfo', 'url' => 'wopi/files/{fileId}', 'verb' => 'GET'], diff --git a/js/viewer/viewer.js b/js/viewer/viewer.js index 9a314c49..025a5ae9 100644 --- a/js/viewer/viewer.js +++ b/js/viewer/viewer.js @@ -107,6 +107,26 @@ var odfViewer = { $('#app-content #controls').addClass('hidden'); $('#app-content').append($iframe); + + $.ajax({type: 'GET', + url: OC.filePath('richdocuments', 'ajax', 'generate.php'), + data: {id: context.$file.attr('data-id')}, + async: false, + success: function(result) { + if(result.status==='success'){ + var $chatroom = $('
'); + $chatroom.attr('id','chatroom'); + $chatroom.data('chatroom-password',result.password); + $chatroom.data('chatroom-name',result.name); + $chatroom.data('chatroom-title',fileName); + $('#app-content').append($chatroom); + } else { + console.log(result.message); + } + }, error: function(xhr, textStatus, errorThrown){ + console.log(errorThrown); + } + }); }, onClose: function() { @@ -115,6 +135,7 @@ var odfViewer = { } $('#app-content #controls').removeClass('hidden'); $('#richdocumentsframe').remove(); + $('#chatroom').remove(); }, registerFilesMenu: function(response) { diff --git a/lib/Controller/DocumentController.php b/lib/Controller/DocumentController.php index ccbc46ee..a5b59770 100644 --- a/lib/Controller/DocumentController.php +++ b/lib/Controller/DocumentController.php @@ -288,4 +288,42 @@ class DocumentController extends Controller { return $response; } + + /** + * @NoAdminRequired + */ + public function generate($id) { + + if (empty($id)) { + return array( + 'status' => 'error', + 'message' => 'no id received' + ); + } + $view = \OC\Files\Filesystem::getView(); + try { + $path = $view->getPath($id); + if ($view->is_file($path) && $view->isReadable($path)) { + $secret = \OC::$server->getConfig()->getSystemValue('secret'); + $instanceID = \OC::$server->getConfig()->getSystemValue('instanceid'); + $chatRoomPassword = hash('sha512', 'chatroom-password'.$instanceID.$secret.$id); + $chatRoomName = hash('sha512','chatroom-name'.$instanceID.$secret.$id); + return array( + 'status' => 'success', + 'password' => $chatRoomPassword, + 'name' => $chatRoomName + ); + } else { + return array( + 'status' => 'error', + 'message' => 'user unauthorised to view file' + ); + } + } catch (\Exception $e) { + return array( + 'status' => 'error', + 'message' => 'user unauthorised to view file' + ); + } + } }