diff --git a/apps/files/ajax/newfolder.php b/apps/files/ajax/newfolder.php index a2897dd437ac..f7ce1a00031a 100644 --- a/apps/files/ajax/newfolder.php +++ b/apps/files/ajax/newfolder.php @@ -29,13 +29,13 @@ // Init owncloud -OCP\JSON::checkLoggedIn(); OCP\JSON::callCheck(); \OC::$server->getSession()->close(); // Get the params $dir = isset($_POST['dir']) ? (string)$_POST['dir'] : ''; $folderName = isset($_POST['foldername']) ?(string) $_POST['foldername'] : ''; +$token = isset($_POST['token']) ? (string) $_POST['token'] : false; $l10n = \OC::$server->getL10N('files'); @@ -44,6 +44,56 @@ 'data' => NULL ); +if($token) +{ + \OC_User::setIncognitoMode(true); + + // return only read permissions for public upload + //$allowedPermissions = \OCP\Constants::PERMISSION_READ; + //$publicDirectory = !empty($_POST['subdir']) ? (string)$_POST['subdir'] : '/'; + + $linkItem = OCP\Share::getShareByToken($token); + if ($linkItem === false) { + OCP\JSON::error(array('data' => array_merge(array('message' => $l10n->t('Invalid Token'))))); + die(); + } + + if (!($linkItem['permissions'] & \OCP\Constants::PERMISSION_CREATE)) { + OCP\JSON::checkLoggedIn(); + } else { + // resolve reshares + $rootLinkItem = OCP\Share::resolveReShare($linkItem); + + OCP\JSON::checkUserExists($rootLinkItem['uid_owner']); + // Setup FS with owner + OC_Util::tearDownFS(); + OC_Util::setupFS($rootLinkItem['uid_owner']); + + // The token defines the target directory (security reasons) + $path = \OC\Files\Filesystem::getPath($linkItem['file_source']); + if($path === null) { + OCP\JSON::error(array('data' => array_merge(array('message' => $l10n->t('Unable to set upload directory.'))))); + die(); + } + $dir = sprintf( + "/%s/%s", + $path, + $dir + ); + + if (!$dir || empty($dir) || $dir === false) { + OCP\JSON::error(array('data' => array_merge(array('message' => $l10n->t('Unable to set upload directory.'))))); + die(); + } + + $dir = rtrim($dir, '/'); + } +} +else +{ + OCP\JSON::checkLoggedIn(); +} + try { \OC\Files\Filesystem::getView()->verifyPath($dir, $folderName); } catch (\OCP\Files\InvalidPathException $ex) { diff --git a/apps/files/js/newfilemenu.js b/apps/files/js/newfilemenu.js index 0a67aba202bc..17a2b423b2c1 100644 --- a/apps/files/js/newfilemenu.js +++ b/apps/files/js/newfilemenu.js @@ -184,34 +184,96 @@ this._fileList.createFile(name); break; case 'folder': - this._fileList.createDirectory(name); + if($('#isPublic').attr('value') === '1') + { + this._createFolderOnPublicLink(name); + } + else + { + this._fileList.createDirectory(name); + } break; default: console.warn('Unknown file type "' + fileType + '"'); } }, + + _createFolderOnPublicLink: function(name) + { + var self = this._fileList; + var deferred = $.Deferred(); + var promise = deferred.promise(); + + OCA.Files.Files.isFileNameValid(name); + name = self.getUniqueName(name); + + if (this.lastAction) { + this.lastAction(); + } + + $.post( + OC.generateUrl('/apps/files/ajax/newfolder.php'), + { + dir: self.getCurrentDirectory(), + foldername: name, + token: $('#sharingToken').attr('value') + }, + function(result) { + if (result.status === 'success') { + self.add(result.data, {animate: true, scrollTo: true}); + deferred.resolve(result.status, result.data); + } else { + if (result.data && result.data.message) { + OC.Notification.showTemporary(result.data.message); + } else { + OC.Notification.showTemporary(t('core', 'Could not create folder')); + } + deferred.reject(result.status); + } + } + ); + }, /** * Renders the menu with the currently set items */ render: function() { - this.$el.html(this.template({ - uploadMaxHumanFileSize: 'TODO', - uploadLabel: t('files', 'Upload'), - items: [{ - id: 'file', - displayName: t('files', 'Text file'), - templateName: t('files', 'New text file.txt'), - iconClass: 'icon-filetype-text', - fileType: 'file' - }, { - id: 'folder', - displayName: t('files', 'Folder'), - templateName: t('files', 'New folder'), - iconClass: 'icon-folder', - fileType: 'folder' - }] - })); + + if($('#isPublic').attr('value') === '1') + { + this.$el.html(this.template({ + uploadMaxHumanFileSize: 'TODO', + uploadLabel: t('files', 'Upload'), + items: [{ + id: 'folder', + displayName: t('files', 'Folder'), + templateName: t('files', 'New folder'), + iconClass: 'icon-folder', + fileType: 'folder' + }] + })); + } + else + { + this.$el.html(this.template({ + uploadMaxHumanFileSize: 'TODO', + uploadLabel: t('files', 'Upload'), + items: [{ + id: 'file', + displayName: t('files', 'Text file'), + templateName: t('files', 'New text file.txt'), + iconClass: 'icon-filetype-text', + fileType: 'file' + }, { + id: 'folder', + displayName: t('files', 'Folder'), + templateName: t('files', 'New folder'), + iconClass: 'icon-folder', + fileType: 'folder' + }] + })); + } + OC.Util.scaleFixForIE8(this.$('.svg')); },