diff --git a/ajax/documentController.php b/ajax/documentController.php index ae186611..eb0c826c 100644 --- a/ajax/documentController.php +++ b/ajax/documentController.php @@ -55,6 +55,25 @@ class DocumentController extends Controller{ $download = new Download($sessionData['owner'], $filename); $download->sendResponse(); } + + + public static function rename($args){ + $fileId = intval(@$args['file_id']); + $name = @$_POST['name']; + $file = new File($fileId); + $l = new \OC_L10n('documents'); + + if (isset($name) && $file->getPermissions() & \OCP\PERMISSION_UPDATE) { + if ($file->renameTo($name)) { + // TODO: propagate to other clients + \OCP\JSON::success(); + return; + } + } + \OCP\JSON::error(array( + 'message' => $l->t('You don\'t have permission to rename this document') + )); + } /** * lists the documents the user has access to (including shared files, once the code in core has been fixed) diff --git a/ajax/sessionController.php b/ajax/sessionController.php index df2ba10d..008f1a97 100644 --- a/ajax/sessionController.php +++ b/ajax/sessionController.php @@ -22,24 +22,6 @@ class SessionController extends Controller{ self::join($uid, $file); } - public static function renameDocument($args){ - $fileId = intval(@$args['file_id']); - $name = @$_POST['name']; - $file = new File($fileId); - $l = new \OC_L10n('documents'); - - if (isset($name) && $file->getPermissions() & \OCP\PERMISSION_UPDATE) { - if ($file->renameTo($name)) { - // TODO: propagate to other clients - \OCP\JSON::success(); - return; - } - } - \OCP\JSON::error(array( - 'message' => $l->t('You don\'t have permission to rename this document') - )); - } - public static function joinAsUser($args){ $uid = self::preDispatch(); $fileId = intval(@$args['file_id']); diff --git a/appinfo/routes.php b/appinfo/routes.php index 8c4c2d53..6c57cd7d 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -21,6 +21,10 @@ $this->create('documents_genesis', 'ajax/genesis/{es_id}') ->post() ->action('\OCA\Documents\DocumentController', 'serve') ; +$this->create('documents_rename', 'ajax/documents/rename/{file_id}') + ->post() + ->action('\OCA\Documents\DocumentController', 'rename') +; $this->create('documents_genesis', 'ajax/genesis/{es_id}') ->get() ->action('\OCA\Documents\DocumentController', 'serve') @@ -73,10 +77,6 @@ $this->create('documents_session_joinasguest', 'ajax/session/joinasguest/{token} ->post() ->action('\OCA\Documents\SessionController', 'joinAsGuest') ; -$this->create('documents_session_renamedocument', 'ajax/session/renamedocument/{file_id}') - ->post() - ->action('\OCA\Documents\SessionController', 'renameDocument') -; $this->create('documents_session_save', 'ajax/session/save') ->post() diff --git a/js/documents.js b/js/documents.js index 612b0fea..75adaa05 100644 --- a/js/documents.js +++ b/js/documents.js @@ -290,7 +290,7 @@ var documentsMain = { }, renameDocument: function(name) { - var url = OC.Router.generate('documents_session_renamedocument') + '/' + documentsMain.fileId; + var url = OC.Router.generate('documents_rename') + '/' + documentsMain.fileId; $.post( url, { name : name },