Skip to content

Commit

Permalink
Merge pull request #72 from cernbox/cernbox-prod-8.2.2-allow-folder-c…
Browse files Browse the repository at this point in the history
…reation-on-links

Support to create folder on directories shared by public link
  • Loading branch information
NadirRoGue authored Aug 31, 2016
2 parents 02352b3 + 1cbd0fc commit 3a56450
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 19 deletions.
52 changes: 51 additions & 1 deletion apps/files/ajax/newfolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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) {
Expand Down
98 changes: 80 additions & 18 deletions apps/files/js/newfilemenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
},

Expand Down

0 comments on commit 3a56450

Please sign in to comment.