summaryrefslogtreecommitdiffstats
path: root/apps/files
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files')
-rw-r--r--apps/files/ajax/newfile.php9
-rw-r--r--apps/files/ajax/newfolder.php9
-rw-r--r--apps/files/ajax/upload.php25
-rw-r--r--apps/files/appinfo/remote.php1
-rw-r--r--apps/files/command/scan.php1
-rw-r--r--apps/files/css/files.css98
-rw-r--r--apps/files/css/upload.css12
-rw-r--r--apps/files/index.php16
-rw-r--r--apps/files/js/admin.js12
-rw-r--r--apps/files/js/file-upload.js37
-rw-r--r--apps/files/js/fileactions.js53
-rw-r--r--apps/files/js/filelist.js60
-rw-r--r--apps/files/js/files.js95
-rw-r--r--apps/files/js/upgrade.js11
-rw-r--r--apps/files/js/upload.js11
-rw-r--r--apps/files/lib/app.php14
-rw-r--r--apps/files/lib/helper.php9
-rw-r--r--apps/files/templates/admin.php2
-rw-r--r--apps/files/templates/index.php17
-rw-r--r--apps/files/templates/part.breadcrumb.php6
-rw-r--r--apps/files/templates/part.list.php2
-rw-r--r--apps/files/tests/ajax_rename.php49
-rw-r--r--apps/files/tests/js/fileactionsSpec.js75
-rw-r--r--apps/files/tests/js/filelistSpec.js65
-rw-r--r--apps/files/tests/js/filesSpec.js85
-rw-r--r--apps/files/triggerupdate.php1
26 files changed, 660 insertions, 115 deletions
diff --git a/apps/files/ajax/newfile.php b/apps/files/ajax/newfile.php
index ec5b716fb2a..1853098c507 100644
--- a/apps/files/ajax/newfile.php
+++ b/apps/files/ajax/newfile.php
@@ -64,6 +64,15 @@ if(strpos($filename, '/') !== false) {
exit();
}
+if (!\OC\Files\Filesystem::file_exists($dir . '/')) {
+ $result['data'] = array('message' => (string)$l10n->t(
+ 'The target folder has been moved or deleted.'),
+ 'code' => 'targetnotfound'
+ );
+ OCP\JSON::error($result);
+ exit();
+}
+
//TODO why is stripslashes used on foldername in newfolder.php but not here?
$target = $dir.'/'.$filename;
diff --git a/apps/files/ajax/newfolder.php b/apps/files/ajax/newfolder.php
index 2cbc8cfeba5..4cfcae3090d 100644
--- a/apps/files/ajax/newfolder.php
+++ b/apps/files/ajax/newfolder.php
@@ -29,6 +29,15 @@ if(strpos($foldername, '/') !== false) {
exit();
}
+if (!\OC\Files\Filesystem::file_exists($dir . '/')) {
+ $result['data'] = array('message' => (string)$l10n->t(
+ 'The target folder has been moved or deleted.'),
+ 'code' => 'targetnotfound'
+ );
+ OCP\JSON::error($result);
+ exit();
+}
+
//TODO why is stripslashes used on foldername here but not in newfile.php?
$target = $dir . '/' . stripslashes($foldername);
diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php
index 0e905f993ac..145f40c50da 100644
--- a/apps/files/ajax/upload.php
+++ b/apps/files/ajax/upload.php
@@ -8,6 +8,7 @@ OCP\JSON::setContentTypeHeader('text/plain');
// If no token is sent along, rely on login only
$allowedPermissions = OCP\PERMISSION_ALL;
+$errorCode = null;
$l = OC_L10N::get('files');
if (empty($_POST['dirToken'])) {
@@ -21,6 +22,7 @@ if (empty($_POST['dirToken'])) {
} else {
// return only read permissions for public upload
$allowedPermissions = OCP\PERMISSION_READ;
+ $public_directory = !empty($_POST['subdir']) ? $_POST['subdir'] : '/';
$linkItem = OCP\Share::getShareByToken($_POST['dirToken']);
if ($linkItem === false) {
@@ -34,6 +36,7 @@ if (empty($_POST['dirToken'])) {
// 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']);
@@ -43,7 +46,7 @@ if (empty($_POST['dirToken'])) {
$dir = sprintf(
"/%s/%s",
$path,
- isset($_POST['subdir']) ? $_POST['subdir'] : ''
+ $public_directory
);
if (!$dir || empty($dir) || $dir === false) {
@@ -110,7 +113,14 @@ if (strpos($dir, '..') === false) {
} else {
$target = \OC\Files\Filesystem::normalizePath(stripslashes($dir).'/'.$files['name'][$i]);
}
-
+
+ $directory = \OC\Files\Filesystem::normalizePath(stripslashes($dir));
+ if (isset($public_directory)) {
+ // If we are uploading from the public app,
+ // we want to send the relative path in the ajax request.
+ $directory = $public_directory;
+ }
+
if ( ! \OC\Files\Filesystem::file_exists($target)
|| (isset($_POST['resolution']) && $_POST['resolution']==='replace')
) {
@@ -124,7 +134,8 @@ if (strpos($dir, '..') === false) {
$meta = \OC\Files\Filesystem::getFileInfo($target);
if ($meta === false) {
- $error = $l->t('Upload failed. Could not get file info.');
+ $error = $l->t('The target folder has been moved or deleted.');
+ $errorCode = 'targetnotfound';
} else {
$result[] = array('status' => 'success',
'mime' => $meta['mimetype'],
@@ -136,7 +147,8 @@ if (strpos($dir, '..') === false) {
'originalname' => $files['tmp_name'][$i],
'uploadMaxFilesize' => $maxUploadFileSize,
'maxHumanFilesize' => $maxHumanFileSize,
- 'permissions' => $meta['permissions'] & $allowedPermissions
+ 'permissions' => $meta['permissions'] & $allowedPermissions,
+ 'directory' => $directory,
);
}
@@ -163,7 +175,8 @@ if (strpos($dir, '..') === false) {
'originalname' => $files['tmp_name'][$i],
'uploadMaxFilesize' => $maxUploadFileSize,
'maxHumanFilesize' => $maxHumanFileSize,
- 'permissions' => $meta['permissions'] & $allowedPermissions
+ 'permissions' => $meta['permissions'] & $allowedPermissions,
+ 'directory' => $directory,
);
}
}
@@ -176,5 +189,5 @@ if ($error === false) {
OCP\JSON::encodedPrint($result);
exit();
} else {
- OCP\JSON::error(array(array('data' => array_merge(array('message' => $error), $storageStats))));
+ OCP\JSON::error(array(array('data' => array_merge(array('message' => $error, 'code' => $errorCode), $storageStats))));
}
diff --git a/apps/files/appinfo/remote.php b/apps/files/appinfo/remote.php
index 9f290796205..ef22fe92188 100644
--- a/apps/files/appinfo/remote.php
+++ b/apps/files/appinfo/remote.php
@@ -52,6 +52,7 @@ $server->addPlugin(new OC_Connector_Sabre_FilesPlugin());
$server->addPlugin(new OC_Connector_Sabre_AbortedUploadDetectionPlugin());
$server->addPlugin(new OC_Connector_Sabre_QuotaPlugin());
$server->addPlugin(new OC_Connector_Sabre_MaintenancePlugin());
+$server->addPlugin(new OC_Connector_Sabre_ExceptionLoggerPlugin('webdav'));
// And off we go!
$server->exec();
diff --git a/apps/files/command/scan.php b/apps/files/command/scan.php
index 25ab70af362..f334f29a939 100644
--- a/apps/files/command/scan.php
+++ b/apps/files/command/scan.php
@@ -58,6 +58,7 @@ class Scan extends Command {
protected function execute(InputInterface $input, OutputInterface $output) {
if ($input->getOption('all')) {
+ \OC_App::loadApps('authentication');
$users = $this->userManager->search('');
} else {
$users = $input->getArgument('user_id');
diff --git a/apps/files/css/files.css b/apps/files/css/files.css
index 2fc86ca537d..3ad167054c2 100644
--- a/apps/files/css/files.css
+++ b/apps/files/css/files.css
@@ -3,7 +3,7 @@
See the COPYING-README file. */
/* FILE MENU */
-.actions { padding:.3em; height:2em; width: 100%; }
+.actions { padding:5px; height:32px; width: 100%; }
.actions input, .actions button, .actions .button { margin:0; float:left; }
.actions .button a { color: #555; }
.actions .button a:hover, .actions .button a:active { color: #333; }
@@ -33,9 +33,9 @@
#new>ul {
display: none;
position: fixed;
- min-width: 7em;
+ min-width: 112px;
z-index: 10;
- padding: .5em;
+ padding: 8px;
padding-bottom: 0;
margin-top: 14px;
margin-left: -1px;
@@ -46,7 +46,7 @@
border-top-left-radius: 0;
box-shadow:0 2px 7px rgba(170,170,170,.4);
}
-#new>ul>li { height:36px; margin:.3em; padding-left:3em; padding-bottom:0.1em;
+#new>ul>li { height:36px; margin:5px; padding-left:48px; padding-bottom:2px;
background-repeat:no-repeat; cursor:pointer; }
#new>ul>li>p { cursor:pointer; padding-top: 7px; padding-bottom: 7px;}
@@ -65,10 +65,15 @@
top: 44px;
width: 100%;
}
-#filestable, #controls {
- min-width: 680px;
+/* make sure there's enough room for the file actions */
+#body-user #filestable {
+ min-width: 750px;
}
-#filestable tbody tr { background-color:#fff; height:2.5em; }
+#body-user #controls {
+ min-width: 600px;
+}
+
+#filestable tbody tr { background-color:#fff; height:40px; }
#filestable tbody tr:hover, tbody tr:active {
background-color: rgb(240,240,240);
}
@@ -79,11 +84,28 @@
background-color: rgb(240,240,240);
}
tbody a { color:#000; }
-span.extension, span.uploading, td.date { color:#999; }
-span.extension { text-transform:lowercase; -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=70)"; filter:alpha(opacity=70); opacity:.7; -webkit-transition:opacity 300ms; -moz-transition:opacity 300ms; -o-transition:opacity 300ms; transition:opacity 300ms; }
-tr:hover span.extension { -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; filter:alpha(opacity=100); opacity:1; color:#777; }
+
+span.extension, span.uploading, td.date {
+ color: #999;
+}
+span.extension {
+ -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=70)";
+ filter: alpha(opacity=70);
+ opacity: .7;
+ -webkit-transition: opacity 300ms;
+ -moz-transition: opacity 300ms;
+ -o-transition: opacity 300ms;
+ transition: opacity 300ms;
+}
+tr:hover span.extension {
+ -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
+ filter: alpha(opacity=100);
+ opacity: 1;
+ color: #777;
+}
+
table tr.mouseOver td { background-color:#eee; }
-table th { height:2em; padding:0 .5em; color:#999; }
+table th { height:24px; padding:0 8px; color:#999; }
table th .name {
position: absolute;
left: 55px;
@@ -98,7 +120,7 @@ table td {
}
table th#headerName {
position: relative;
- width: 100em; /* not really sure why this works better than 100% … table styling */
+ width: 9999px; /* not really sure why this works better than 100% … table styling */
padding: 0;
}
#headerName-container {
@@ -106,15 +128,17 @@ table th#headerName {
height: 50px;
}
table th#headerSize, table td.filesize {
- min-width: 3em;
- padding: 0 1em;
+ min-width: 48px;
+ padding: 0 16px;
text-align: right;
}
table th#headerDate, table td.date {
-moz-box-sizing: border-box;
box-sizing: border-box;
position: relative;
- min-width: 11em;
+ /* this can not be just width, both need to be set … table styling */
+ min-width: 176px;
+ max-width: 176px;
}
/* Multiselect bar */
@@ -140,9 +164,9 @@ table.multiselect thead th {
}
table.multiselect #headerName {
position: relative;
- width: 100%;
+ width: 9999px; /* when we use 100%, the styling breaks on mobile … table styling */
}
-table td.selection, table th.selection, table td.fileaction { width:2em; text-align:center; }
+table td.selection, table th.selection, table td.fileaction { width:32px; text-align:center; }
table td.filename a.name {
position:relative; /* Firefox needs to explicitly have this default set … */
-moz-box-sizing: border-box;
@@ -160,8 +184,8 @@ table td.filename input.filename {
margin-left: 2px;
cursor: text;
}
-table td.filename a, table td.login, table td.logout, table td.download, table td.upload, table td.create, table td.delete { padding:.2em .5em .5em .3em; }
-table td.filename .nametext, .uploadtext, .modified { float:left; padding:.3em 0; }
+table td.filename a, table td.login, table td.logout, table td.download, table td.upload, table td.create, table td.delete { padding:3px 8px 8px 3px; }
+table td.filename .nametext, .uploadtext, .modified { float:left; padding:14px 0; }
#modified {
position: absolute;
@@ -169,6 +193,15 @@ table td.filename .nametext, .uploadtext, .modified { float:left; padding:.3em 0
}
.modified {
position: relative;
+ padding-left: 8px;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ width: 90%;
+}
+/* ellipsize long modified dates to make room for showing delete button */
+#fileList tr:hover .modified,
+#fileList tr:focus .modified {
+ width: 75%;
}
/* TODO fix usability bug (accidental file/folder selection) */
@@ -181,8 +214,8 @@ table td.filename .nametext {
text-overflow: ellipsis;
max-width: 800px;
}
-table td.filename .uploadtext { font-weight:normal; margin-left:.5em; }
-table td.filename form { font-size:.85em; margin-left:3em; margin-right:3em; }
+table td.filename .uploadtext { font-weight:normal; margin-left:8px; }
+table td.filename form { font-size:14px; margin-left:48px; margin-right:48px; }
.ie8 input[type="checkbox"]{
padding: 0;
@@ -217,6 +250,11 @@ table td.filename form { font-size:.85em; margin-left:3em; margin-right:3em; }
width: 50px;
z-index: 5;
}
+#fileList tr td.filename>input[type="checkbox"]{
+ /* sometimes checkbox height is bigger (KDE/Qt), so setting to absolute
+ * to prevent it to increase the height */
+ position: absolute;
+}
#fileList tr td.filename>input[type="checkbox"] + label {
left: 0;
}
@@ -237,7 +275,7 @@ table td.filename form { font-size:.85em; margin-left:3em; margin-right:3em; }
#fileList tr td.filename a.name label {
position: absolute;
- width: 100%;
+ width: 80%;
height: 50px;
}
@@ -248,14 +286,16 @@ table td.filename form { font-size:.85em; margin-left:3em; margin-right:3em; }
position: absolute;
top: 14px;
right: 0;
+ font-size: 11px;
}
-#fileList img.move2trash { display:inline; margin:-.5em 0; padding:1em .5em 1em .5em !important; float:right; }
+#fileList img.move2trash { display:inline; margin:-8px 0; padding:16px 8px 16px 8px !important; float:right; }
#fileList a.action.delete {
position: absolute;
right: 0;
- padding: 9px 14px 19px !important;
+ padding: 28px 14px 19px !important;
}
+
a.action>img { max-height:16px; max-width:16px; vertical-align:text-bottom; }
/* Actions for selected files */
@@ -272,19 +312,23 @@ a.action>img { max-height:16px; max-width:16px; vertical-align:text-bottom; }
}
.selectedActions a img {
position:relative;
- top:.3em;
+ top:5px;
}
#fileList a.action {
display: inline;
- margin: -.5em 0;
- padding: 18px 8px !important;
+ margin: -8px 0;
+ padding: 18px 8px;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
opacity: 0;
display:none;
}
+
+#fileList a.action[data-action="Rename"] {
+ padding:18px 14px !important;
+}
#fileList tr:hover a.action, #fileList a.action.permanent {
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
filter: alpha(opacity=50);
diff --git a/apps/files/css/upload.css b/apps/files/css/upload.css
index ef043569094..06b4d4655fe 100644
--- a/apps/files/css/upload.css
+++ b/apps/files/css/upload.css
@@ -5,7 +5,7 @@
height: 36px;
width: 39px;
padding: 0 !important; /* override default control bar button padding */
- margin-left: .2em;
+ margin-left: 3px;
overflow: hidden;
vertical-align: top;
}
@@ -18,9 +18,6 @@
margin: -5px -3px;
cursor: pointer;
z-index: 10;
- background-image: url('%webroot%/core/img/actions/upload.svg');
- background-repeat: no-repeat;
- background-position: center;
opacity: .65;
}
.file_upload_target { display:none; }
@@ -33,7 +30,7 @@
height: 44px;
margin: -5px -3px;
padding: 0;
- font-size: 1em;
+ font-size: 16px;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; filter:alpha(opacity=0); opacity:0;
z-index: 20;
cursor: pointer;
@@ -119,11 +116,6 @@
.oc-dialog .fileexists .conflict input[type='checkbox'] {
float: left;
}
-.oc-dialog .fileexists .toggle {
- background-image: url('%webroot%/core/img/actions/triangle-e.png');
- width: 16px;
- height: 16px;
-}
.oc-dialog .fileexists #allfileslabel {
float:right;
}
diff --git a/apps/files/index.php b/apps/files/index.php
index 8f6838aa0d9..c9eea6a4174 100644
--- a/apps/files/index.php
+++ b/apps/files/index.php
@@ -63,7 +63,6 @@ $files = array();
$user = OC_User::getUser();
if (\OC\Files\Cache\Upgrade::needUpgrade($user)) { //dont load anything if we need to upgrade the cache
$needUpgrade = true;
- $freeSpace = 0;
} else {
if ($isIE8){
// after the redirect above, the URL will have a format
@@ -77,10 +76,11 @@ if (\OC\Files\Cache\Upgrade::needUpgrade($user)) { //dont load anything if we ne
else{
$files = \OCA\Files\Helper::getFiles($dir);
}
- $freeSpace = \OC\Files\Filesystem::free_space($dir);
$needUpgrade = false;
}
+$config = \OC::$server->getConfig();
+
// Make breadcrumb
$breadcrumb = \OCA\Files\Helper::makeBreadcrumb($dir);
@@ -103,8 +103,10 @@ if ($needUpgrade) {
} else {
// information about storage capacities
$storageInfo=OC_Helper::getStorageInfo($dir);
+ $freeSpace=$storageInfo['free'];
+ $uploadLimit=OCP\Util::uploadLimit();
$maxUploadFilesize=OCP\Util::maxUploadFilesize($dir);
- $publicUploadEnabled = \OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes');
+ $publicUploadEnabled = $config->getAppValue('core', 'shareapi_allow_public_upload', 'yes');
// if the encryption app is disabled, than everything is fine (INIT_SUCCESSFUL status code)
$encryptionInitStatus = 2;
if (OC_App::isEnabled('files_encryption')) {
@@ -134,15 +136,17 @@ if ($needUpgrade) {
$tmpl->assign('files', $files);
$tmpl->assign('trash', $trashEnabled);
$tmpl->assign('trashEmpty', $trashEmpty);
- $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize);
+ $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize); // minimium of freeSpace and uploadLimit
$tmpl->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
+ $tmpl->assign('freeSpace', $freeSpace);
+ $tmpl->assign('uploadLimit', $uploadLimit); // PHP upload limit
$tmpl->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
$tmpl->assign('usedSpacePercent', (int)$storageInfo['relative']);
$tmpl->assign('isPublic', false);
$tmpl->assign('publicUploadEnabled', $publicUploadEnabled);
$tmpl->assign("encryptedFiles", \OCP\Util::encryptedFiles());
- $tmpl->assign("mailNotificationEnabled", \OC_Appconfig::getValue('core', 'shareapi_allow_mail_notification', 'yes'));
- $tmpl->assign("allowShareWithLink", \OC_Appconfig::getValue('core', 'shareapi_allow_links', 'yes'));
+ $tmpl->assign("mailNotificationEnabled", $config->getAppValue('core', 'shareapi_allow_mail_notification', 'yes'));
+ $tmpl->assign("allowShareWithLink", $config->getAppValue('core', 'shareapi_allow_links', 'yes'));
$tmpl->assign("encryptionInitStatus", $encryptionInitStatus);
$tmpl->assign('disableSharing', false);
$tmpl->assign('ajaxLoad', $ajaxLoad);
diff --git a/apps/files/js/admin.js b/apps/files/js/admin.js
index bfa96670635..f735079fcbe 100644
--- a/apps/files/js/admin.js
+++ b/apps/files/js/admin.js
@@ -1,3 +1,13 @@
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
function switchPublicFolder()
{
var publicEnable = $('#publicEnable').is(':checked');
@@ -10,7 +20,7 @@ function switchPublicFolder()
$(document).ready(function(){
switchPublicFolder(); // Execute the function after loading DOM tree
$('#publicEnable').click(function(){
- switchPublicFolder(); // To get rid of onClick()
+ switchPublicFolder(); // To get rid of onClick()
});
$('#allowZipDownload').bind('change', function() {
diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js
index 225c3319107..f962a7044a8 100644
--- a/apps/files/js/file-upload.js
+++ b/apps/files/js/file-upload.js
@@ -1,3 +1,13 @@
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
/**
* The file upload code uses several hooks to interact with blueimps jQuery file upload library:
* 1. the core upload handling hooks are added when initializing the plugin,
@@ -8,6 +18,8 @@
* - TODO music upload button
*/
+/* global OC, t, n */
+
/**
* Function that will allow us to know if Ajax uploads are supported
* @link https://github.com/New-Bamboo/example-ajax-upload/blob/master/public/index.html
@@ -241,10 +253,22 @@ $(document).ready(function() {
// add size
selection.totalBytes += file.size;
- //check max upload size
- if (selection.totalBytes > $('#max_upload').val()) {
+ // check PHP upload limit
+ if (selection.totalBytes > $('#upload_limit').val()) {
+ data.textStatus = 'sizeexceedlimit';
+ data.errorThrown = t('files', 'Total file size {size1} exceeds upload limit {size2}', {
+ 'size1': humanFileSize(selection.totalBytes),
+ 'size2': humanFileSize($('#upload_limit').val())
+ });
+ }
+
+ // check free space
+ if (selection.totalBytes > $('#free_space').val()) {
data.textStatus = 'notenoughspace';
- data.errorThrown = t('files', 'Not enough space available');
+ data.errorThrown = t('files', 'Not enough free space, you are uploading {size1} but only {size2} is left', {
+ 'size1': humanFileSize(selection.totalBytes),
+ 'size2': humanFileSize($('#free_space').val())
+ });
}
// end upload for whole selection on error
@@ -315,6 +339,13 @@ $(document).ready(function() {
} else {
// HTTP connection problem
OC.Notification.show(data.errorThrown);
+ if (data.result) {
+ var result = JSON.parse(data.result);
+ if (result && result[0] && result[0].data && result[0].data.code === 'targetnotfound') {
+ // abort upload of next files if any
+ OC.Upload.cancelUploads();
+ }
+ }
}
//hide notification after 10 sec
setTimeout(function() {
diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js
index 74bb711ef3d..9a69d7b3688 100644
--- a/apps/files/js/fileactions.js
+++ b/apps/files/js/fileactions.js
@@ -1,3 +1,15 @@
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+/* global OC, FileList */
+/* global trashBinApp */
var FileActions = {
actions: {},
defaults: {},
@@ -45,8 +57,9 @@ var FileActions = {
return filteredActions;
},
getDefault: function (mime, type, permissions) {
+ var mimePart;
if (mime) {
- var mimePart = mime.substr(0, mime.indexOf('/'));
+ mimePart = mime.substr(0, mime.indexOf('/'));
}
var name = false;
if (mime && FileActions.defaults[mime]) {
@@ -71,13 +84,15 @@ var FileActions = {
FileActions.currentFile = parent;
var actions = FileActions.get(FileActions.getCurrentMimeType(), FileActions.getCurrentType(), FileActions.getCurrentPermissions());
var file = FileActions.getCurrentFile();
+ var nameLinks;
if (FileList.findFileEl(file).data('renaming')) {
return;
}
// recreate fileactions
- parent.children('a.name').find('.fileactions').remove();
- parent.children('a.name').append('<span class="fileactions" />');
+ nameLinks = parent.children('a.name');
+ nameLinks.find('.fileactions, .nametext .action').remove();
+ nameLinks.append('<span class="fileactions" />');
var defaultAction = FileActions.getDefault(FileActions.getCurrentMimeType(), FileActions.getCurrentType(), FileActions.getCurrentPermissions());
var actionHandler = function (event) {
@@ -97,21 +112,30 @@ var FileActions = {
}
if ((name === 'Download' || action !== defaultAction) && name !== 'Delete') {
- var img = FileActions.icons[name];
+ var img = FileActions.icons[name],
+ actionText = t('files', name),
+ actionContainer = 'a.name>span.fileactions';
+
+ if (name === 'Rename') {
+ // rename has only an icon which appears behind
+ // the file name
+ actionText = '';
+ actionContainer = 'a.name span.nametext';
+ }
if (img.call) {
img = img(file);
}
var html = '<a href="#" class="action" data-action="' + name + '">';
if (img) {
- html += '<img class ="svg" src="' + img + '" /> ';
+ html += '<img class ="svg" src="' + img + '" />';
}
- html += t('files', name) + '</a>';
+ html += '<span> ' + actionText + '</span></a>';
var element = $(html);
element.data('action', name);
//alert(element);
element.on('click', {a: null, elem: parent, actionFunc: actions[name]}, actionHandler);
- parent.find('a.name>span.fileactions').append(element);
+ parent.find(actionContainer).append(element);
}
};
@@ -130,13 +154,14 @@ var FileActions = {
parent.parent().children().last().find('.action.delete').remove();
if (actions['Delete']) {
var img = FileActions.icons['Delete'];
+ var html;
if (img.call) {
img = img(file);
}
if (typeof trashBinApp !== 'undefined' && trashBinApp) {
- var html = '<a href="#" original-title="' + t('files', 'Delete permanently') + '" class="action delete delete-icon" />';
+ html = '<a href="#" original-title="' + t('files', 'Delete permanently') + '" class="action delete delete-icon" />';
} else {
- var html = '<a href="#" class="action delete delete-icon" />';
+ html = '<a href="#" class="action delete delete-icon" />';
}
var element = $(html);
element.data('action', actions['Delete']);
@@ -163,17 +188,21 @@ var FileActions = {
};
$(document).ready(function () {
+ var downloadScope;
if ($('#allowZipDownload').val() == 1) {
- var downloadScope = 'all';
+ downloadScope = 'all';
} else {
- var downloadScope = 'file';
+ downloadScope = 'file';
}
if (typeof disableDownloadActions == 'undefined' || !disableDownloadActions) {
FileActions.register(downloadScope, 'Download', OC.PERMISSION_READ, function () {
return OC.imagePath('core', 'actions/download');
}, function (filename) {
- window.location = OC.filePath('files', 'ajax', 'download.php') + '?files=' + encodeURIComponent(filename) + '&dir=' + encodeURIComponent($('#dir').val());
+ var url = FileList.getDownloadUrl(filename);
+ if (url) {
+ OC.redirect(url);
+ }
});
}
$('#fileList tr').each(function () {
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js
index c02ab70ce8d..a855d6cbe59 100644
--- a/apps/files/js/filelist.js
+++ b/apps/files/js/filelist.js
@@ -1,4 +1,16 @@
-var FileList={
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+/* global OC, t, n, FileList, FileActions, Files */
+/* global procesSelection, dragOptions, SVGSupport, replaceSVG */
+window.FileList={
useUndo:true,
postProcessList: function() {
$('#fileList tr').each(function() {
@@ -27,6 +39,9 @@ var FileList={
Files.setupDragAndDrop();
}
FileList.updateFileSummary();
+ procesSelection();
+
+ $(window).scrollTop(0);
$fileList.trigger(jQuery.Event("updated"));
},
createRow:function(type, name, iconurl, linktarget, size, lastModified, permissions) {
@@ -189,6 +204,7 @@ var FileList={
return OC.linkTo('files', 'index.php')+"?dir="+ encodeURIComponent(dir).replace(/%2F/g, '/');
},
setCurrentDir: function(targetDir, changeUrl) {
+ var url;
$('#dir').val(targetDir);
if (changeUrl !== false) {
if (window.history.pushState && changeUrl !== false) {
@@ -300,7 +316,10 @@ var FileList={
},
remove:function(name){
var fileEl = FileList.findFileEl(name);
- fileEl.find('td.filename').draggable('destroy');
+ if (fileEl.data('permissions') & OC.PERMISSION_DELETE) {
+ // file is only draggable when delete permissions are set
+ fileEl.find('td.filename').draggable('destroy');
+ }
fileEl.remove();
FileList.updateFileSummary();
if ( ! $('tr[data-file]').exists() ) {
@@ -389,7 +408,7 @@ var FileList={
}
return true;
};
-
+
form.submit(function(event) {
event.stopPropagation();
event.preventDefault();
@@ -416,10 +435,9 @@ var FileList={
tr.attr('data-file', newname);
var path = td.children('a.name').attr('href');
td.children('a.name').attr('href', path.replace(encodeURIComponent(oldname), encodeURIComponent(newname)));
+ var basename = newname;
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
- var basename=newname.substr(0,newname.lastIndexOf('.'));
- } else {
- var basename=newname;
+ basename = newname.substr(0,newname.lastIndexOf('.'));
}
td.find('a.name span.nametext').text(basename);
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
@@ -463,7 +481,7 @@ var FileList={
var basename = newname;
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
basename = newname.substr(0, newname.lastIndexOf('.'));
- }
+ }
td.find('a.name span.nametext').text(basename);
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
if ( ! td.find('a.name span.extension').exists() ) {
@@ -472,6 +490,7 @@ var FileList={
td.find('a.name span.extension').text(newname.substr(newname.lastIndexOf('.')));
}
form.remove();
+ FileActions.display( tr.find('td.filename'), true);
td.children('a.name').show();
} catch (error) {
input.attr('title', error);
@@ -524,10 +543,9 @@ var FileList={
td.children('a.name .span').text(newName);
var path = td.children('a.name').attr('href');
td.children('a.name').attr('href', path.replace(encodeURIComponent(oldName), encodeURIComponent(newName)));
+ var basename = newName;
if (newName.indexOf('.') > 0) {
- var basename = newName.substr(0, newName.lastIndexOf('.'));
- } else {
- var basename = newName;
+ basename = newName.substr(0, newName.lastIndexOf('.'));
}
td.children('a.name').empty();
var span = $('<span class="nametext"></span>');
@@ -775,6 +793,20 @@ var FileList={
$('#fileList tr.searchresult').each(function(i,e) {
$(e).removeClass("searchresult");
});
+ },
+
+ /**
+ * Returns the download URL of the given file
+ * @param filename file name of the file
+ * @param dir optional directory in which the file name is, defaults to the current directory
+ */
+ getDownloadUrl: function(filename, dir) {
+ var params = {
+ files: filename,
+ dir: dir || FileList.getCurrentDirectory(),
+ download: null
+ };
+ return OC.filePath('files', 'ajax', 'download.php') + '?' + OC.buildQueryString(params);
}
};
@@ -814,7 +846,7 @@ $(document).ready(function() {
{name: 'requesttoken', value: oc_requesttoken}
];
};
- }
+ }
});
file_upload_start.on('fileuploadadd', function(e, data) {
@@ -853,7 +885,7 @@ $(document).ready(function() {
*/
file_upload_start.on('fileuploaddone', function(e, data) {
OC.Upload.log('filelist handle fileuploaddone', e, data);
-
+
var response;
if (typeof data.result === 'string') {
response = data.result;
@@ -890,8 +922,8 @@ $(document).ready(function() {
data.context.find('td.filesize').text(humanFileSize(size));
} else {
- // only append new file if dragged onto current dir's crumb (last)
- if (data.context && data.context.hasClass('crumb') && !data.context.hasClass('last')) {
+ // only append new file if uploaded into the current folder
+ if (file.directory !== FileList.getCurrentDirectory()) {
return;
}
diff --git a/apps/files/js/files.js b/apps/files/js/files.js
index 1f12ade8d79..1ec4c4ec7ab 100644
--- a/apps/files/js/files.js
+++ b/apps/files/js/files.js
@@ -1,4 +1,16 @@
-Files={
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+/* global OC, t, n, FileList, FileActions */
+/* global getURLParameter, isPublic */
+var Files = {
// file space size sync
_updateStorageStatistics: function() {
Files._updateStorageStatisticsTimeout = null;
@@ -41,6 +53,7 @@ Files={
}
if (response.data !== undefined && response.data.uploadMaxFilesize !== undefined) {
$('#max_upload').val(response.data.uploadMaxFilesize);
+ $('#free_space').val(response.data.freeSpace);
$('#upload.button').attr('original-title', response.data.maxHumanFilesize);
$('#usedSpacePercent').val(response.data.usedSpacePercent);
Files.displayStorageWarnings();
@@ -67,17 +80,25 @@ Files={
return fileName;
},
- isFileNameValid:function (name) {
- if (name === '.') {
- throw t('files', '\'.\' is an invalid file name.');
- } else if (name.length === 0) {
+ /**
+ * Checks whether the given file name is valid.
+ * @param name file name to check
+ * @return true if the file name is valid.
+ * Throws a string exception with an error message if
+ * the file name is not valid
+ */
+ isFileNameValid: function (name) {
+ var trimmedName = name.trim();
+ if (trimmedName === '.' || trimmedName === '..') {
+ throw t('files', '"{name}" is an invalid file name.', {name: name});
+ } else if (trimmedName.length === 0) {
throw t('files', 'File name cannot be empty.');
}
-
// check for invalid characters
- var invalid_characters = ['\\', '/', '<', '>', ':', '"', '|', '?', '*'];
+ var invalid_characters =
+ ['\\', '/', '<', '>', ':', '"', '|', '?', '*', '\n'];
for (var i = 0; i < invalid_characters.length; i++) {
- if (name.indexOf(invalid_characters[i]) !== -1) {
+ if (trimmedName.indexOf(invalid_characters[i]) !== -1) {
throw t('files', "Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed.");
}
}
@@ -384,7 +405,7 @@ $(document).ready(function() {
Files.resizeBreadcrumbs(width, true);
// display storage warnings
- setTimeout ( "Files.displayStorageWarnings()", 100 );
+ setTimeout(Files.displayStorageWarnings, 100);
OC.Notification.setDefault(Files.displayStorageWarnings);
// only possible at the moment if user is logged in
@@ -493,7 +514,7 @@ var createDragShadow = function(event) {
var dir=$('#dir').val();
$(selectedFiles).each(function(i,elem) {
- var newtr = $('<tr/>').attr('data-dir', dir).attr('data-filename', elem.name);
+ var newtr = $('<tr/>').attr('data-dir', dir).attr('data-filename', elem.name).attr('data-origin', elem.origin);
newtr.append($('<td/>').addClass('filename').text(elem.name));
newtr.append($('<td/>').addClass('size').text(humanFileSize(elem.size)));
tbody.append(newtr);
@@ -511,13 +532,30 @@ var createDragShadow = function(event) {
};
//options for file drag/drop
+//start&stop handlers needs some cleaning up
var dragOptions={
revert: 'invalid', revertDuration: 300,
opacity: 0.7, zIndex: 100, appendTo: 'body', cursorAt: { left: 24, top: 18 },
helper: createDragShadow, cursor: 'move',
- stop: function(event, ui) {
- $('#fileList tr td.filename').addClass('ui-draggable');
- }
+ start: function(event, ui){
+ var $selectedFiles = $('td.filename input:checkbox:checked');
+ if($selectedFiles.length > 1){
+ $selectedFiles.parents('tr').fadeTo(250, 0.2);
+ }
+ else{
+ $(this).fadeTo(250, 0.2);
+ }
+ },
+ stop: function(event, ui) {
+ var $selectedFiles = $('td.filename input:checkbox:checked');
+ if($selectedFiles.length > 1){
+ $selectedFiles.parents('tr').fadeTo(250, 1);
+ }
+ else{
+ $(this).fadeTo(250, 1);
+ }
+ $('#fileList tr td.filename').addClass('ui-draggable');
+ }
};
// sane browsers support using the distance option
if ( $('html.ie').length === 0) {
@@ -525,6 +563,7 @@ if ( $('html.ie').length === 0) {
}
var folderDropOptions={
+ hoverClass: "canDrop",
drop: function( event, ui ) {
//don't allow moving a file into a selected folder
if ($(event.target).parents('tr').find('td input:first').prop('checked') === true) {
@@ -537,6 +576,11 @@ var folderDropOptions={
$(files).each(function(i,row) {
var dir = $(row).data('dir');
var file = $(row).data('filename');
+ //slapdash selector, tracking down our original element that the clone budded off of.
+ var origin = $('tr[data-id=' + $(row).data('origin') + ']');
+ var td = origin.children('td.filename');
+ var oldBackgroundImage = td.css('background-image');
+ td.css('background-image', 'url('+ OC.imagePath('core', 'loading.gif') + ')');
$.post(OC.filePath('files', 'ajax', 'move.php'), { dir: dir, file: file, target: dir+'/'+target }, function(result) {
if (result) {
if (result.status === 'success') {
@@ -559,6 +603,7 @@ var folderDropOptions={
} else {
OC.dialogs.alert(t('files', 'Error moving file'), t('files', 'Error'));
}
+ td.css('background-image', oldBackgroundImage);
});
});
},
@@ -583,6 +628,11 @@ var crumbDropOptions={
$(files).each(function(i,row) {
var dir = $(row).data('dir');
var file = $(row).data('filename');
+ //slapdash selector, tracking down our original element that the clone budded off of.
+ var origin = $('tr[data-id=' + $(row).data('origin') + ']');
+ var td = origin.children('td.filename');
+ var oldBackgroundImage = td.css('background-image');
+ td.css('background-image', 'url('+ OC.imagePath('core', 'loading.gif') + ')');
$.post(OC.filePath('files', 'ajax', 'move.php'), { dir: dir, file: file, target: target }, function(result) {
if (result) {
if (result.status === 'success') {
@@ -597,6 +647,7 @@ var crumbDropOptions={
} else {
OC.dialogs.alert(t('files', 'Error moving file'), t('files', 'Error'));
}
+ td.css('background-image', oldBackgroundImage);
});
});
},
@@ -612,21 +663,22 @@ function procesSelection() {
return el.type==='dir';
});
if (selectedFiles.length === 0 && selectedFolders.length === 0) {
- $('#headerName>span.name').text(t('files','Name'));
+ $('#headerName span.name').text(t('files','Name'));
$('#headerSize').text(t('files','Size'));
$('#modified').text(t('files','Modified'));
$('table').removeClass('multiselect');
$('.selectedActions').hide();
+ $('#select_all').removeAttr('checked');
}
else {
$('.selectedActions').show();
var totalSize = 0;
for(var i=0; i<selectedFiles.length; i++) {
totalSize+=selectedFiles[i].size;
- };
+ }
for(var i=0; i<selectedFolders.length; i++) {
totalSize+=selectedFolders[i].size;
- };
+ }
$('#headerSize').text(humanFileSize(totalSize));
var selection = '';
if (selectedFolders.length > 0) {
@@ -662,7 +714,8 @@ function getSelectedFilesTrash(property) {
mime:$(element).data('mime'),
type:$(element).data('type'),
size:$(element).data('size'),
- etag:$(element).data('etag')
+ etag:$(element).data('etag'),
+ origin: $(element).data('id')
};
if (property) {
files.push(file[property]);
@@ -719,7 +772,7 @@ Files.lazyLoadPreview = function(path, mime, ready, width, height, etag) {
console.warn('Files.lazyLoadPreview(): missing etag argument');
}
- if ( $('#publicUploadButtonMock').length ) {
+ if ( $('#isPublic').length ) {
urlSpec.t = $('#dirToken').val();
previewURL = OC.Router.generate('core_ajax_public_preview', urlSpec);
} else {
@@ -737,10 +790,11 @@ Files.lazyLoadPreview = function(path, mime, ready, width, height, etag) {
}
img.src = previewURL;
});
-}
+};
function getUniqueName(name) {
if (FileList.findFileEl(name).exists()) {
+ var numMatch;
var parts=name.split('.');
var extension = "";
if (parts.length > 1) {
@@ -774,7 +828,7 @@ function checkTrashStatus() {
function onClickBreadcrumb(e) {
var $el = $(e.target).closest('.crumb'),
- $targetDir = $el.data('dir');
+ $targetDir = $el.data('dir'),
isPublic = !!$('#isPublic').val();
if ($targetDir !== undefined && !isPublic) {
@@ -782,3 +836,4 @@ function onClickBreadcrumb(e) {
FileList.changeDirectory(decodeURIComponent($targetDir));
}
}
+
diff --git a/apps/files/js/upgrade.js b/apps/files/js/upgrade.js
index 02d57fc9e6c..714adf824a1 100644
--- a/apps/files/js/upgrade.js
+++ b/apps/files/js/upgrade.js
@@ -1,3 +1,14 @@
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+/* global OC */
$(document).ready(function () {
var eventSource, total, bar = $('#progressbar');
console.log('start');
diff --git a/apps/files/js/upload.js b/apps/files/js/upload.js
index 9d9f61f600e..617cf4b1c1d 100644
--- a/apps/files/js/upload.js
+++ b/apps/files/js/upload.js
@@ -1,3 +1,14 @@
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+/* global OC */
function Upload(fileSelector) {
if ($.support.xhrFileUpload) {
return new XHRUpload(fileSelector.target.files);
diff --git a/apps/files/lib/app.php b/apps/files/lib/app.php
index e04ac173d55..fea88faa92a 100644
--- a/apps/files/lib/app.php
+++ b/apps/files/lib/app.php
@@ -59,6 +59,13 @@ class App {
$result['data'] = array(
'message' => $this->l10n->t("Invalid folder name. Usage of 'Shared' is reserved.")
);
+ // rename to non-existing folder is denied
+ } else if (!$this->view->file_exists($dir)) {
+ $result['data'] = array('message' => (string)$this->l10n->t(
+ 'The target folder has been moved or deleted.',
+ array($dir)),
+ 'code' => 'targetnotfound'
+ );
// rename to existing file is denied
} else if ($this->view->file_exists($dir . '/' . $newname)) {
@@ -83,14 +90,17 @@ class App {
else {
$meta['type'] = 'file';
}
+ // these need to be set for determineIcon()
+ $meta['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($meta['mimetype']);
+ $meta['directory'] = $dir;
$fileinfo = array(
'id' => $meta['fileid'],
'mime' => $meta['mimetype'],
'size' => $meta['size'],
'etag' => $meta['etag'],
- 'directory' => $dir,
+ 'directory' => $meta['directory'],
'name' => $newname,
- 'isPreviewAvailable' => \OC::$server->getPreviewManager()->isMimeSupported($meta['mimetype']),
+ 'isPreviewAvailable' => $meta['isPreviewAvailable'],
'icon' => \OCA\Files\Helper::determineIcon($meta)
);
$result['success'] = true;
diff --git a/apps/files/lib/helper.php b/apps/files/lib/helper.php
index eaff28178ea..01fc65d76b7 100644
--- a/apps/files/lib/helper.php
+++ b/apps/files/lib/helper.php
@@ -5,16 +5,17 @@ namespace OCA\Files;
class Helper
{
public static function buildFileStorageStatistics($dir) {
+ // information about storage capacities
+ $storageInfo = \OC_Helper::getStorageInfo($dir);
+
$l = new \OC_L10N('files');
- $maxUploadFilesize = \OCP\Util::maxUploadFilesize($dir);
+ $maxUploadFilesize = \OCP\Util::maxUploadFilesize($dir, $storageInfo['free']);
$maxHumanFilesize = \OCP\Util::humanFileSize($maxUploadFilesize);
$maxHumanFilesize = $l->t('Upload') . ' max. ' . $maxHumanFilesize;
- // information about storage capacities
- $storageInfo = \OC_Helper::getStorageInfo($dir);
-
return array('uploadMaxFilesize' => $maxUploadFilesize,
'maxHumanFilesize' => $maxHumanFilesize,
+ 'freeSpace' => $storageInfo['free'],
'usedSpacePercent' => (int)$storageInfo['relative']);
}
diff --git a/apps/files/templates/admin.php b/apps/files/templates/admin.php
index 697fc52526a..a5afd55fbc3 100644
--- a/apps/files/templates/admin.php
+++ b/apps/files/templates/admin.php
@@ -5,7 +5,7 @@
<h2><?php p($l->t('File handling')); ?></h2>
<?php if($_['uploadChangable']):?>
<label for="maxUploadSize"><?php p($l->t( 'Maximum upload size' )); ?> </label>
- <input name='maxUploadSize' id="maxUploadSize" value='<?php p($_['uploadMaxFilesize']) ?>'/>
+ <input type="text" name='maxUploadSize' id="maxUploadSize" value='<?php p($_['uploadMaxFilesize']) ?>'/>
<?php if($_['displayMaxPossibleUploadSize']):?>
(<?php p($l->t('max. possible: ')); p($_['maxPossibleUploadSize']) ?>)
<?php endif;?>
diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php
index 00ec109621f..939043b2c9f 100644
--- a/apps/files/templates/index.php
+++ b/apps/files/templates/index.php
@@ -1,6 +1,7 @@
<div id="controls">
<?php print_unescaped($_['breadcrumb']); ?>
<div class="actions creatable <?php if (!$_['isCreatable']):?>hidden<?php endif; ?>">
+ <?php if(!isset($_['dirToken'])):?>
<div id="new" class="button">
<a><?php p($l->t('New'));?></a>
<ul>
@@ -12,21 +13,27 @@
data-type='web'><p><?php p($l->t('From link'));?></p></li>
</ul>
</div>
+ <?php endif;?>
<div id="upload" class="button"
title="<?php p($l->t('Upload') . ' max. '.$_['uploadMaxHumanFilesize']) ?>">
<?php if($_['uploadMaxFilesize'] >= 0):?>
- <input type="hidden" name="MAX_FILE_SIZE" id="max_upload"
- value="<?php p($_['uploadMaxFilesize']) ?>">
+ <input type="hidden" id="max_upload" name="MAX_FILE_SIZE" value="<?php p($_['uploadMaxFilesize']) ?>">
+ <?php endif;?>
+ <input type="hidden" id="upload_limit" value="<?php p($_['uploadLimit']) ?>">
+ <input type="hidden" id="free_space" value="<?php p($_['freeSpace']) ?>">
+ <?php if(isset($_['dirToken'])):?>
+ <input type="hidden" id="publicUploadRequestToken" name="requesttoken" value="<?php p($_['requesttoken']) ?>" />
+ <input type="hidden" id="dirToken" name="dirToken" value="<?php p($_['dirToken']) ?>" />
<?php endif;?>
<input type="hidden" class="max_human_file_size"
value="(max <?php p($_['uploadMaxHumanFilesize']); ?>)">
<input type="hidden" name="dir" value="<?php p($_['dir']) ?>" id="dir">
<input type="file" id="file_upload_start" name='files[]'
data-url="<?php print_unescaped(OCP\Util::linkTo('files', 'ajax/upload.php')); ?>" />
- <a href="#" class="svg"></a>
+ <a href="#" class="svg icon icon-upload"></a>
</div>
<?php if ($_['trash']): ?>
- <input id="trash" type="button" value="<?php p($l->t('Deleted files'));?>" class="button" <?php $_['trashEmpty'] ? p('disabled') : '' ?>></input>
+ <input id="trash" type="button" value="<?php p($l->t('Deleted files'));?>" class="button" <?php $_['trashEmpty'] ? p('disabled') : '' ?> />
<?php endif; ?>
<div id="uploadprogresswrapper">
<div id="uploadprogressbar"></div>
@@ -44,7 +51,7 @@
<div id="emptycontent" <?php if (!$_['emptyContent']):?>class="hidden"<?php endif; ?>><?php p($l->t('Nothing in here. Upload something!'))?></div>
-<input type="hidden" id="disableSharing" data-status="<?php p($_['disableSharing']); ?>"></input>
+<input type="hidden" id="disableSharing" data-status="<?php p($_['disableSharing']); ?>" />
<table id="filestable" data-allow-public-upload="<?php p($_['publicUploadEnabled'])?>" data-preview-x="36" data-preview-y="36">
<thead>
diff --git a/apps/files/templates/part.breadcrumb.php b/apps/files/templates/part.breadcrumb.php
index 90d07d4336c..2a0df622767 100644
--- a/apps/files/templates/part.breadcrumb.php
+++ b/apps/files/templates/part.breadcrumb.php
@@ -1,6 +1,10 @@
<div class="crumb <?php if(!count($_["breadcrumb"])) p('last');?>" data-dir=''>
<a href="<?php print_unescaped($_['baseURL']); ?>">
- <img src="<?php print_unescaped(OCP\image_path('core', 'places/home.svg'));?>" class="svg" />
+ <?php if(isset($_['rootBreadCrumb'])):
+ echo $_['rootBreadCrumb'];
+ else:?>
+ <img src="<?php print_unescaped(OCP\image_path('core', 'places/home.svg'));?>" class="svg" />
+ <?php endif;?>
</a>
</div>
<?php for($i=0; $i<count($_["breadcrumb"]); $i++):
diff --git a/apps/files/templates/part.list.php b/apps/files/templates/part.list.php
index 2f630e1f014..f4fb96a7a7c 100644
--- a/apps/files/templates/part.list.php
+++ b/apps/files/templates/part.list.php
@@ -18,7 +18,7 @@ $totalsize = 0; ?>
data-size="<?php p($file['size']);?>"
data-etag="<?php p($file['etag']);?>"
data-permissions="<?php p($file['permissions']); ?>">
- <?php if($file['isPreviewAvailable']): ?>
+ <?php if(isset($file['isPreviewAvailable']) and $file['isPreviewAvailable']): ?>
<td class="filename svg preview-icon"
<?php else: ?>
<td class="filename svg"
diff --git a/apps/files/tests/ajax_rename.php b/apps/files/tests/ajax_rename.php
index 350ff5d3687..a1a5c8983ba 100644
--- a/apps/files/tests/ajax_rename.php
+++ b/apps/files/tests/ajax_rename.php
@@ -38,7 +38,7 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase {
$l10nMock->expects($this->any())
->method('t')
->will($this->returnArgument(0));
- $viewMock = $this->getMock('\OC\Files\View', array('rename', 'normalizePath', 'getFileInfo'), array(), '', false);
+ $viewMock = $this->getMock('\OC\Files\View', array('rename', 'normalizePath', 'getFileInfo', 'file_exists'), array(), '', false);
$viewMock->expects($this->any())
->method('normalizePath')
->will($this->returnArgument(0));
@@ -63,6 +63,11 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase {
$oldname = 'Shared';
$newname = 'new_name';
+ $this->viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->with('/')
+ ->will($this->returnValue(true));
+
$result = $this->files->rename($dir, $oldname, $newname);
$expected = array(
'success' => false,
@@ -80,6 +85,11 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase {
$oldname = 'Shared';
$newname = 'new_name';
+ $this->viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->with('/test')
+ ->will($this->returnValue(true));
+
$this->viewMock->expects($this->any())
->method('getFileInfo')
->will($this->returnValue(array(
@@ -129,6 +139,11 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase {
$oldname = 'oldname';
$newname = 'newname';
+ $this->viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->with('/')
+ ->will($this->returnValue(true));
+
$this->viewMock->expects($this->any())
->method('getFileInfo')
->will($this->returnValue(array(
@@ -141,7 +156,6 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase {
'name' => 'new_name',
)));
-
$result = $this->files->rename($dir, $oldname, $newname);
$this->assertTrue($result['success']);
@@ -154,4 +168,35 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase {
$this->assertEquals(\OC_Helper::mimetypeIcon('dir'), $result['data']['icon']);
$this->assertFalse($result['data']['isPreviewAvailable']);
}
+
+ /**
+ * Test rename inside a folder that doesn't exist any more
+ */
+ function testRenameInNonExistingFolder() {
+ $dir = '/unexist';
+ $oldname = 'oldname';
+ $newname = 'newname';
+
+ $this->viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->with('/unexist')
+ ->will($this->returnValue(false));
+
+ $this->viewMock->expects($this->any())
+ ->method('getFileInfo')
+ ->will($this->returnValue(array(
+ 'fileid' => 123,
+ 'type' => 'dir',
+ 'mimetype' => 'httpd/unix-directory',
+ 'size' => 18,
+ 'etag' => 'abcdef',
+ 'directory' => '/unexist',
+ 'name' => 'new_name',
+ )));
+
+ $result = $this->files->rename($dir, $oldname, $newname);
+
+ $this->assertFalse($result['success']);
+ $this->assertEquals('targetnotfound', $result['data']['code']);
+ }
}
diff --git a/apps/files/tests/js/fileactionsSpec.js b/apps/files/tests/js/fileactionsSpec.js
new file mode 100644
index 00000000000..8bbc1d3d141
--- /dev/null
+++ b/apps/files/tests/js/fileactionsSpec.js
@@ -0,0 +1,75 @@
+/**
+* ownCloud
+*
+* @author Vincent Petry
+* @copyright 2014 Vincent Petry <pvince81@owncloud.com>
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+/* global OC, FileActions, FileList */
+describe('FileActions tests', function() {
+ var $filesTable;
+ beforeEach(function() {
+ // init horrible parameters
+ var $body = $('body');
+ $body.append('<input type="hidden" id="dir" value="/subdir"></input>');
+ $body.append('<input type="hidden" id="permissions" value="31"></input>');
+ // dummy files table
+ $filesTable = $body.append('<table id="filestable"></table>');
+ });
+ afterEach(function() {
+ $('#dir, #permissions, #filestable').remove();
+ });
+ it('calling display() sets file actions', function() {
+ // note: download_url is actually the link target, not the actual download URL...
+ var $tr = FileList.addFile('testName.txt', 1234, new Date(), false, false, {download_url: 'test/download/url'});
+
+ // no actions before call
+ expect($tr.find('.action[data-action=Download]').length).toEqual(0);
+ expect($tr.find('.action[data-action=Rename]').length).toEqual(0);
+ expect($tr.find('.action.delete').length).toEqual(0);
+
+ FileActions.display($tr.find('td.filename'), true);
+
+ // actions defined after cal
+ expect($tr.find('.action[data-action=Download]').length).toEqual(1);
+ expect($tr.find('.nametext .action[data-action=Rename]').length).toEqual(1);
+ expect($tr.find('.action.delete').length).toEqual(1);
+ });
+ it('calling display() twice correctly replaces file actions', function() {
+ var $tr = FileList.addFile('testName.txt', 1234, new Date(), false, false, {download_url: 'test/download/url'});
+
+ FileActions.display($tr.find('td.filename'), true);
+ FileActions.display($tr.find('td.filename'), true);
+
+ // actions defined after cal
+ expect($tr.find('.action[data-action=Download]').length).toEqual(1);
+ expect($tr.find('.nametext .action[data-action=Rename]').length).toEqual(1);
+ expect($tr.find('.action.delete').length).toEqual(1);
+ });
+ it('redirects to download URL when clicking download', function() {
+ var redirectStub = sinon.stub(OC, 'redirect');
+ // note: download_url is actually the link target, not the actual download URL...
+ var $tr = FileList.addFile('test download File.txt', 1234, new Date(), false, false, {download_url: 'test/download/url'});
+ FileActions.display($tr.find('td.filename'), true);
+
+ $tr.find('.action[data-action=Download]').click();
+
+ expect(redirectStub.calledOnce).toEqual(true);
+ expect(redirectStub.getCall(0).args[0]).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?files=test%20download%20File.txt&dir=%2Fsubdir&download');
+ redirectStub.restore();
+ });
+});
diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js
new file mode 100644
index 00000000000..c26e65fc4de
--- /dev/null
+++ b/apps/files/tests/js/filelistSpec.js
@@ -0,0 +1,65 @@
+/**
+* ownCloud
+*
+* @author Vincent Petry
+* @copyright 2014 Vincent Petry <pvince81@owncloud.com>
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+/* global OC, FileList */
+describe('FileList tests', function() {
+ beforeEach(function() {
+ // init horrible parameters
+ var $body = $('body');
+ $body.append('<input type="hidden" id="dir" value="/subdir"></input>');
+ $body.append('<input type="hidden" id="permissions" value="31"></input>');
+ // dummy files table
+ $body.append('<table id="filestable"></table>');
+ });
+ afterEach(function() {
+ $('#dir, #permissions, #filestable').remove();
+ });
+ it('generates file element with correct attributes when calling addFile', function() {
+ var lastMod = new Date(10000);
+ // note: download_url is actually the link target, not the actual download URL...
+ var $tr = FileList.addFile('testName.txt', 1234, lastMod, false, false, {download_url: 'test/download/url'});
+
+ expect($tr).toBeDefined();
+ expect($tr[0].tagName.toLowerCase()).toEqual('tr');
+ expect($tr.find('a:first').attr('href')).toEqual('test/download/url');
+ expect($tr.attr('data-type')).toEqual('file');
+ expect($tr.attr('data-file')).toEqual('testName.txt');
+ expect($tr.attr('data-size')).toEqual('1234');
+ expect($tr.attr('data-permissions')).toEqual('31');
+ //expect($tr.attr('data-mime')).toEqual('plain/text');
+ });
+ it('generates dir element with correct attributes when calling addDir', function() {
+ var lastMod = new Date(10000);
+ var $tr = FileList.addDir('testFolder', 1234, lastMod, false);
+
+ expect($tr).toBeDefined();
+ expect($tr[0].tagName.toLowerCase()).toEqual('tr');
+ expect($tr.attr('data-type')).toEqual('dir');
+ expect($tr.attr('data-file')).toEqual('testFolder');
+ expect($tr.attr('data-size')).toEqual('1234');
+ expect($tr.attr('data-permissions')).toEqual('31');
+ //expect($tr.attr('data-mime')).toEqual('httpd/unix-directory');
+ });
+ it('returns correct download URL', function() {
+ expect(FileList.getDownloadUrl('some file.txt')).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?files=some%20file.txt&dir=%2Fsubdir&download');
+ expect(FileList.getDownloadUrl('some file.txt', '/anotherpath/abc')).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?files=some%20file.txt&dir=%2Fanotherpath%2Fabc&download');
+ });
+});
diff --git a/apps/files/tests/js/filesSpec.js b/apps/files/tests/js/filesSpec.js
new file mode 100644
index 00000000000..018c8ef0f3c
--- /dev/null
+++ b/apps/files/tests/js/filesSpec.js
@@ -0,0 +1,85 @@
+/**
+* ownCloud
+*
+* @author Vincent Petry
+* @copyright 2014 Vincent Petry <pvince81@owncloud.com>
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+/* global Files */
+describe('Files tests', function() {
+ describe('File name validation', function() {
+ it('Validates correct file names', function() {
+ var fileNames = [
+ 'boringname',
+ 'something.with.extension',
+ 'now with spaces',
+ '.a',
+ '..a',
+ '.dotfile',
+ 'single\'quote',
+ ' spaces before',
+ 'spaces after ',
+ 'allowed chars including the crazy ones $%&_-^@!,()[]{}=;#',
+ '汉字也能用',
+ 'und Ümläüte sind auch willkommen'
+ ];
+ for ( var i = 0; i < fileNames.length; i++ ) {
+ var error = false;
+ try {
+ expect(Files.isFileNameValid(fileNames[i])).toEqual(true);
+ }
+ catch (e) {
+ error = e;
+ }
+ expect(error).toEqual(false);
+ }
+ });
+ it('Detects invalid file names', function() {
+ var fileNames = [
+ '',
+ ' ',
+ '.',
+ '..',
+ 'back\\slash',
+ 'sl/ash',
+ 'lt<lt',
+ 'gt>gt',
+ 'col:on',
+ 'double"quote',
+ 'pi|pe',
+ 'dont?ask?questions?',
+ 'super*star',
+ 'new\nline',
+ ' ..',
+ '.. ',
+ '. ',
+ ' .'
+ ];
+ for ( var i = 0; i < fileNames.length; i++ ) {
+ var threwException = false;
+ try {
+ Files.isFileNameValid(fileNames[i]);
+ console.error('Invalid file name not detected:', fileNames[i]);
+ }
+ catch (e) {
+ threwException = true;
+ }
+ expect(threwException).toEqual(true);
+ }
+ });
+ });
+});
diff --git a/apps/files/triggerupdate.php b/apps/files/triggerupdate.php
index 0e29edbba35..a37b9823add 100644
--- a/apps/files/triggerupdate.php
+++ b/apps/files/triggerupdate.php
@@ -6,6 +6,7 @@ if (OC::$CLI) {
if (count($argv) === 2) {
$file = $argv[1];
list(, $user) = explode('/', $file);
+ OCP\JSON::checkUserExists($owner);
OC_Util::setupFS($user);
$view = new \OC\Files\View('');
/**