aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/files/ajax/newfile.php9
-rw-r--r--apps/files/ajax/newfolder.php9
-rw-r--r--apps/files/ajax/upload.php6
-rw-r--r--apps/files/css/files.css34
-rw-r--r--apps/files/index.php6
-rw-r--r--apps/files/js/admin.js12
-rw-r--r--apps/files/js/file-upload.js37
-rw-r--r--apps/files/js/fileactions.js48
-rw-r--r--apps/files/js/filelist.js27
-rw-r--r--apps/files/js/files.js48
-rw-r--r--apps/files/js/upgrade.js11
-rw-r--r--apps/files/js/upload.js11
-rw-r--r--apps/files/lib/app.php7
-rw-r--r--apps/files/lib/helper.php1
-rw-r--r--apps/files/templates/index.php15
-rw-r--r--apps/files/tests/ajax_rename.php49
-rw-r--r--apps/files/tests/js/fileactionsSpec.js16
-rw-r--r--apps/files/tests/js/filelistSpec.js2
-rw-r--r--apps/files/tests/js/filesSpec.js8
-rw-r--r--apps/files_encryption/hooks/hooks.php64
-rwxr-xr-xapps/files_encryption/lib/helper.php2
-rwxr-xr-xapps/files_encryption/lib/keymanager.php55
-rw-r--r--apps/files_encryption/lib/proxy.php41
-rw-r--r--apps/files_encryption/lib/util.php2
-rw-r--r--apps/files_encryption/tests/hooks.php271
-rw-r--r--apps/files_encryption/tests/keymanager.php20
-rw-r--r--apps/files_encryption/tests/proxy.php50
-rwxr-xr-xapps/files_encryption/tests/share.php44
-rw-r--r--apps/files_sharing/css/mobile.css49
-rw-r--r--apps/files_sharing/css/public.css70
-rw-r--r--apps/files_sharing/js/public.js24
-rw-r--r--apps/files_sharing/lib/api.php3
-rw-r--r--apps/files_sharing/lib/cache.php39
-rw-r--r--apps/files_sharing/public.php15
-rw-r--r--apps/files_sharing/templates/public.php83
-rw-r--r--apps/files_sharing/tests/cache.php134
-rw-r--r--apps/files_trashbin/ajax/preview.php14
-rw-r--r--apps/user_ldap/lib/connection.php2
38 files changed, 1018 insertions, 320 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 bdaf6a77d14..8f6c42d6620 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'])) {
@@ -125,7 +126,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'],
@@ -177,5 +179,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/css/files.css b/apps/files/css/files.css
index 16ee2b9bca0..5526abaf6e2 100644
--- a/apps/files/css/files.css
+++ b/apps/files/css/files.css
@@ -65,10 +65,15 @@
top: 44px;
width: 100%;
}
-#filestable tbody tr { background-color:#fff; height:40px; }
-#filestable, #controls {
- min-width: 680px;
+/* make sure there's enough room for the file actions */
+#body-user #filestable {
+ min-width: 750px;
+}
+#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);
}
@@ -98,7 +103,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 {
@@ -114,7 +119,9 @@ table th#headerDate, table td.date {
-moz-box-sizing: border-box;
box-sizing: border-box;
position: relative;
+ /* this can not be just width, both need to be set … table styling */
min-width: 176px;
+ max-width: 176px;
}
/* Multiselect bar */
@@ -140,7 +147,7 @@ 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:32px; text-align:center; }
table td.filename a.name {
@@ -169,6 +176,15 @@ table td.filename .nametext, .uploadtext, .modified { float:left; padding:14px 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) */
@@ -242,7 +258,7 @@ table td.filename form { font-size:14px; margin-left:48px; margin-right:48px; }
#fileList tr td.filename a.name label {
position: absolute;
- width: 100%;
+ width: 80%;
height: 50px;
}
@@ -253,6 +269,7 @@ table td.filename form { font-size:14px; margin-left:48px; margin-right:48px; }
position: absolute;
top: 14px;
right: 0;
+ font-size: 11px;
}
#fileList img.move2trash { display:inline; margin:-8px 0; padding:16px 8px 16px 8px !important; float:right; }
@@ -261,6 +278,7 @@ table td.filename form { font-size:14px; margin-left:48px; margin-right:48px; }
right: 0;
padding: 28px 14px 19px !important;
}
+
a.action>img { max-height:16px; max-width:16px; vertical-align:text-bottom; }
/* Actions for selected files */
@@ -290,6 +308,10 @@ a.action>img { max-height:16px; max-width:16px; vertical-align:text-bottom; }
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/index.php b/apps/files/index.php
index 2ce8fdb065f..dd63f29bc28 100644
--- a/apps/files/index.php
+++ b/apps/files/index.php
@@ -101,6 +101,8 @@ 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');
// if the encryption app is disabled, than everything is fine (INIT_SUCCESSFUL status code)
@@ -132,8 +134,10 @@ 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);
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 eb59e71a030..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,10 +188,11 @@ 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) {
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js
index 63fd0f4ce05..f538af10362 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() {
@@ -28,7 +40,8 @@ var FileList={
}
FileList.updateFileSummary();
procesSelection();
-
+
+ $(window).scrollTop(0);
$fileList.trigger(jQuery.Event("updated"));
},
createRow:function(type, name, iconurl, linktarget, size, lastModified, permissions) {
@@ -191,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) {
@@ -394,7 +408,7 @@ var FileList={
}
return true;
};
-
+
form.submit(function(event) {
event.stopPropagation();
event.preventDefault();
@@ -468,7 +482,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() ) {
@@ -477,6 +491,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);
@@ -833,7 +848,7 @@ $(document).ready(function() {
{name: 'requesttoken', value: oc_requesttoken}
];
};
- }
+ }
});
file_upload_start.on('fileuploadadd', function(e, data) {
@@ -872,7 +887,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;
diff --git a/apps/files/js/files.js b/apps/files/js/files.js
index 2fe4ab464c8..a535700c1b3 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.");
}
}
@@ -654,10 +675,10 @@ function procesSelection() {
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) {
@@ -751,7 +772,7 @@ Files.lazyLoadPreview = function(path, mime, ready, width, height, etag) {
console.warn('Files.lazyLoadPreview(): missing etag argument');
}
- if ( $('#public_upload').length ) {
+ if ( $('#isPublic').length ) {
urlSpec.t = $('#dirToken').val();
previewURL = OC.Router.generate('core_ajax_public_preview', urlSpec);
} else {
@@ -769,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) {
@@ -806,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) {
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 1ac266073db..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)) {
diff --git a/apps/files/lib/helper.php b/apps/files/lib/helper.php
index eaff28178ea..21d1f50e587 100644
--- a/apps/files/lib/helper.php
+++ b/apps/files/lib/helper.php
@@ -15,6 +15,7 @@ class Helper
return array('uploadMaxFilesize' => $maxUploadFilesize,
'maxHumanFilesize' => $maxHumanFilesize,
+ 'freeSpace' => $storageInfo['free'],
'usedSpacePercent' => (int)$storageInfo['relative']);
}
diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php
index 5ed1ee0c7a0..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,11 +13,17 @@
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']); ?>)">
@@ -26,7 +33,7 @@
<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/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
index 23f7b58dcd9..8bbc1d3d141 100644
--- a/apps/files/tests/js/fileactionsSpec.js
+++ b/apps/files/tests/js/fileactionsSpec.js
@@ -18,7 +18,10 @@
* 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');
@@ -43,7 +46,18 @@ describe('FileActions tests', function() {
// actions defined after cal
expect($tr.find('.action[data-action=Download]').length).toEqual(1);
- expect($tr.find('.action[data-action=Rename]').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() {
diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js
index 61e026c0725..c26e65fc4de 100644
--- a/apps/files/tests/js/filelistSpec.js
+++ b/apps/files/tests/js/filelistSpec.js
@@ -18,6 +18,8 @@
* 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
diff --git a/apps/files/tests/js/filesSpec.js b/apps/files/tests/js/filesSpec.js
index 9d0a2e4f9d7..018c8ef0f3c 100644
--- a/apps/files/tests/js/filesSpec.js
+++ b/apps/files/tests/js/filesSpec.js
@@ -18,6 +18,8 @@
* 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() {
@@ -36,12 +38,14 @@ describe('Files tests', function() {
'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) {
- fail();
+ error = e;
}
+ expect(error).toEqual(false);
}
});
it('Detects invalid file names', function() {
@@ -69,7 +73,7 @@ describe('Files tests', function() {
var threwException = false;
try {
Files.isFileNameValid(fileNames[i]);
- fail();
+ console.error('Invalid file name not detected:', fileNames[i]);
}
catch (e) {
threwException = true;
diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php
index 09d5687e226..4c4b3f2040f 100644
--- a/apps/files_encryption/hooks/hooks.php
+++ b/apps/files_encryption/hooks/hooks.php
@@ -32,6 +32,8 @@ class Hooks {
// file for which we want to rename the keys after the rename operation was successful
private static $renamedFiles = array();
+ // file for which we want to delete the keys after the delete operation was successful
+ private static $deleteFiles = array();
/**
* @brief Startup encryption backend upon user login
@@ -630,4 +632,66 @@ class Hooks {
}
}
+ /**
+ * @brief if the file was really deleted we remove the encryption keys
+ * @param array $params
+ * @return boolean
+ */
+ public static function postDelete($params) {
+
+ if (!isset(self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]])) {
+ return true;
+ }
+
+ $deletedFile = self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]];
+ $path = $deletedFile['path'];
+ $user = $deletedFile['uid'];
+
+ // we don't need to remember the file any longer
+ unset(self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]]);
+
+ $view = new \OC\Files\View('/');
+
+ // return if the file still exists and wasn't deleted correctly
+ if ($view->file_exists('/' . $user . '/files/' . $path)) {
+ return true;
+ }
+
+ // Disable encryption proxy to prevent recursive calls
+ $proxyStatus = \OC_FileProxy::$enabled;
+ \OC_FileProxy::$enabled = false;
+
+ // Delete keyfile & shareKey so it isn't orphaned
+ if (!Keymanager::deleteFileKey($view, $path, $user)) {
+ \OCP\Util::writeLog('Encryption library',
+ 'Keyfile or shareKey could not be deleted for file "' . $user.'/files/'.$path . '"', \OCP\Util::ERROR);
+ }
+
+ Keymanager::delAllShareKeys($view, $user, $path);
+
+ \OC_FileProxy::$enabled = $proxyStatus;
+ }
+
+ /**
+ * @brief remember the file which should be deleted and it's owner
+ * @param array $params
+ * @return boolean
+ */
+ public static function preDelete($params) {
+ $path = $params[\OC\Files\Filesystem::signal_param_path];
+
+ // skip this method if the trash bin is enabled or if we delete a file
+ // outside of /data/user/files
+ if (\OCP\App::isEnabled('files_trashbin')) {
+ return true;
+ }
+
+ $util = new Util(new \OC_FilesystemView('/'), \OCP\USER::getUser());
+ list($owner, $ownerPath) = $util->getUidAndFilename($path);
+
+ self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]] = array(
+ 'uid' => $owner,
+ 'path' => $ownerPath);
+ }
+
}
diff --git a/apps/files_encryption/lib/helper.php b/apps/files_encryption/lib/helper.php
index 5dcb05fa196..bb06a57c714 100755
--- a/apps/files_encryption/lib/helper.php
+++ b/apps/files_encryption/lib/helper.php
@@ -63,6 +63,8 @@ class Helper {
\OCP\Util::connectHook('OC_Filesystem', 'rename', 'OCA\Encryption\Hooks', 'preRename');
\OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OCA\Encryption\Hooks', 'postRename');
+ \OCP\Util::connectHook('OC_Filesystem', 'post_delete', 'OCA\Encryption\Hooks', 'postDelete');
+ \OCP\Util::connectHook('OC_Filesystem', 'delete', 'OCA\Encryption\Hooks', 'preDelete');
}
/**
diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php
index b2c756894b4..7abc565f609 100755
--- a/apps/files_encryption/lib/keymanager.php
+++ b/apps/files_encryption/lib/keymanager.php
@@ -214,15 +214,24 @@ class Keymanager {
*
* @param \OC_FilesystemView $view
* @param string $path path of the file the key belongs to
+ * @param string $userId the user to whom the file belongs
* @return bool Outcome of unlink operation
* @note $path must be relative to data/user/files. e.g. mydoc.txt NOT
* /data/admin/files/mydoc.txt
*/
- public static function deleteFileKey(\OC_FilesystemView $view, $path) {
+ public static function deleteFileKey($view, $path, $userId=null) {
$trimmed = ltrim($path, '/');
- $userId = Helper::getUser($path);
+ if ($trimmed === '') {
+ \OCP\Util::writeLog('Encryption library',
+ 'Can\'t delete file-key empty path given!', \OCP\Util::ERROR);
+ return false;
+ }
+
+ if ($userId === null) {
+ $userId = Helper::getUser($path);
+ }
$util = new Util($view, $userId);
if($util->isSystemWideMountPoint($path)) {
@@ -402,7 +411,15 @@ class Keymanager {
* @param string $userId owner of the file
* @param string $filePath path to the file, relative to the owners file dir
*/
- public static function delAllShareKeys(\OC_FilesystemView $view, $userId, $filePath) {
+ public static function delAllShareKeys($view, $userId, $filePath) {
+
+ $filePath = ltrim($filePath, '/');
+
+ if ($filePath === '') {
+ \OCP\Util::writeLog('Encryption library',
+ 'Can\'t delete share-keys empty path given!', \OCP\Util::ERROR);
+ return false;
+ }
$util = new util($view, $userId);
@@ -413,17 +430,15 @@ class Keymanager {
}
- if ($view->is_dir($userId . '/files/' . $filePath)) {
+ if ($view->is_dir($baseDir . $filePath)) {
$view->unlink($baseDir . $filePath);
} else {
- $localKeyPath = $view->getLocalFile($baseDir . $filePath);
- $escapedPath = Helper::escapeGlobPattern($localKeyPath);
- $matches = glob($escapedPath . '*.shareKey');
- foreach ($matches as $ma) {
- $result = unlink($ma);
- if (!$result) {
- \OCP\Util::writeLog('Encryption library',
- 'Keyfile or shareKey could not be deleted for file "' . $filePath . '"', \OCP\Util::ERROR);
+ $parentDir = dirname($baseDir . $filePath);
+ $filename = pathinfo($filePath, PATHINFO_BASENAME);
+ foreach($view->getDirectoryContent($parentDir) as $content) {
+ $path = $content['path'];
+ if (self::getFilenameFromShareKey($content['name']) === $filename) {
+ $view->unlink('/' . $userId . '/' . $path);
}
}
}
@@ -523,4 +538,20 @@ class Keymanager {
return $targetPath;
}
+
+ /**
+ * @brief extract filename from share key name
+ * @param string $shareKey (filename.userid.sharekey)
+ * @return mixed filename or false
+ */
+ protected static function getFilenameFromShareKey($shareKey) {
+ $parts = explode('.', $shareKey);
+
+ $filename = false;
+ if(count($parts) > 2) {
+ $filename = implode('.', array_slice($parts, 0, count($parts)-2));
+ }
+
+ return $filename;
+ }
}
diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php
index 4e71ab1dd5d..11048005969 100644
--- a/apps/files_encryption/lib/proxy.php
+++ b/apps/files_encryption/lib/proxy.php
@@ -204,47 +204,6 @@ class Proxy extends \OC_FileProxy {
}
/**
- * @brief When a file is deleted, remove its keyfile also
- */
- public function preUnlink($path) {
-
- $relPath = Helper::stripUserFilesPath($path);
-
- // skip this method if the trash bin is enabled or if we delete a file
- // outside of /data/user/files
- if (\OCP\App::isEnabled('files_trashbin') || $relPath === false) {
- return true;
- }
-
- // Disable encryption proxy to prevent recursive calls
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
-
- $view = new \OC_FilesystemView('/');
-
- $userId = \OCP\USER::getUser();
-
- $util = new Util($view, $userId);
-
- list($owner, $ownerPath) = $util->getUidAndFilename($relPath);
-
- // Delete keyfile & shareKey so it isn't orphaned
- if (!Keymanager::deleteFileKey($view, $ownerPath)) {
- \OCP\Util::writeLog('Encryption library',
- 'Keyfile or shareKey could not be deleted for file "' . $ownerPath . '"', \OCP\Util::ERROR);
- }
-
- Keymanager::delAllShareKeys($view, $owner, $ownerPath);
-
- \OC_FileProxy::$enabled = $proxyStatus;
-
- // If we don't return true then file delete will fail; better
- // to leave orphaned keyfiles than to disallow file deletion
- return true;
-
- }
-
- /**
* @param $path
* @return bool
*/
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index 8816d4d649a..ae3e2a2e15a 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -57,7 +57,7 @@ class Util {
* @param $userId
* @param bool $client
*/
- public function __construct(\OC_FilesystemView $view, $userId, $client = false) {
+ public function __construct($view, $userId, $client = false) {
$this->view = $view;
$this->client = $client;
diff --git a/apps/files_encryption/tests/hooks.php b/apps/files_encryption/tests/hooks.php
new file mode 100644
index 00000000000..c26cba6406d
--- /dev/null
+++ b/apps/files_encryption/tests/hooks.php
@@ -0,0 +1,271 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @author Bjoern Schiessle
+ * @copyright 2014 Bjoern Schiessle <schiessle@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/>.
+ *
+ */
+
+require_once __DIR__ . '/../../../lib/base.php';
+require_once __DIR__ . '/../lib/crypt.php';
+require_once __DIR__ . '/../lib/keymanager.php';
+require_once __DIR__ . '/../lib/stream.php';
+require_once __DIR__ . '/../lib/util.php';
+require_once __DIR__ . '/../appinfo/app.php';
+require_once __DIR__ . '/util.php';
+
+use OCA\Encryption;
+
+/**
+ * Class Test_Encryption_Hooks
+ * @brief this class provide basic hook app tests
+ */
+class Test_Encryption_Hooks extends \PHPUnit_Framework_TestCase {
+
+ const TEST_ENCRYPTION_HOOKS_USER1 = "test-proxy-user1";
+ const TEST_ENCRYPTION_HOOKS_USER2 = "test-proxy-user2";
+
+ /**
+ * @var \OC_FilesystemView
+ */
+ public $user1View; // view on /data/user1/files
+ public $user2View; // view on /data/user2/files
+ public $rootView; // view on /data/user
+ public $data;
+ public $filename;
+
+ public static function setUpBeforeClass() {
+ // reset backend
+ \OC_User::clearBackends();
+ \OC_User::useBackend('database');
+
+ \OC_Hook::clear('OC_Filesystem');
+ \OC_Hook::clear('OC_User');
+
+ // clear share hooks
+ \OC_Hook::clear('OCP\\Share');
+ \OC::registerShareHooks();
+ \OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup');
+
+ // Filesystem related hooks
+ \OCA\Encryption\Helper::registerFilesystemHooks();
+
+ // Sharing related hooks
+ \OCA\Encryption\Helper::registerShareHooks();
+
+ // clear and register proxies
+ \OC_FileProxy::clearProxies();
+ \OC_FileProxy::register(new OCA\Encryption\Proxy());
+
+ // create test user
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1, true);
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2, true);
+ }
+
+ function setUp() {
+ // set user id
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
+ \OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
+
+ // init filesystem view
+ $this->user1View = new \OC_FilesystemView('/'. \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '/files');
+ $this->user2View = new \OC_FilesystemView('/'. \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '/files');
+ $this->rootView = new \OC_FilesystemView('/');
+
+ // init short data
+ $this->data = 'hats';
+ $this->filename = 'enc_hooks_tests-' . uniqid() . '.txt';
+
+ }
+
+ public static function tearDownAfterClass() {
+ // cleanup test user
+ \OC_User::deleteUser(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
+ \OC_User::deleteUser(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
+ }
+
+ function testDeleteHooks() {
+
+ // remember files_trashbin state
+ $stateFilesTrashbin = OC_App::isEnabled('files_trashbin');
+
+ // we want to tests with app files_trashbin disabled
+ \OC_App::disable('files_trashbin');
+
+ // make sure that the trash bin is disabled
+ $this->assertFalse(\OC_APP::isEnabled('files_trashbin'));
+
+ $this->user1View->file_put_contents($this->filename, $this->data);
+
+ // check if all keys are generated
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+
+
+ \Test_Encryption_Util::logoutHelper();
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
+ \OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
+
+
+ $this->user2View->file_put_contents($this->filename, $this->data);
+
+ // check if all keys are generated
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+
+
+ // create a dummy file that we can delete something outside of data/user/files
+ // in this case no share or file keys should be deleted
+ $this->rootView->file_put_contents(self::TEST_ENCRYPTION_HOOKS_USER2 . "/" . $this->filename, $this->data);
+
+ // delete dummy file outside of data/user/files
+ $this->rootView->unlink(self::TEST_ENCRYPTION_HOOKS_USER2 . "/" . $this->filename);
+
+ // all keys should still exist
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+
+
+ // delete the file in data/user/files
+ // now the correspondig share and file keys from user2 should be deleted
+ $this->user2View->unlink($this->filename);
+
+ // check if keys from user2 are really deleted
+ $this->assertFalse($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
+ $this->assertFalse($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+
+ // but user1 keys should still exist
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+
+ if ($stateFilesTrashbin) {
+ OC_App::enable('files_trashbin');
+ }
+ else {
+ OC_App::disable('files_trashbin');
+ }
+ }
+
+ function testDeleteHooksForSharedFiles() {
+
+ \Test_Encryption_Util::logoutHelper();
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
+ \OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
+
+ // remember files_trashbin state
+ $stateFilesTrashbin = OC_App::isEnabled('files_trashbin');
+
+ // we want to tests with app files_trashbin disabled
+ \OC_App::disable('files_trashbin');
+
+ // make sure that the trash bin is disabled
+ $this->assertFalse(\OC_APP::isEnabled('files_trashbin'));
+
+ $this->user1View->file_put_contents($this->filename, $this->data);
+
+ // check if all keys are generated
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+
+ // get the file info from previous created file
+ $fileInfo = $this->user1View->getFileInfo($this->filename);
+
+ // check if we have a valid file info
+ $this->assertTrue(is_array($fileInfo));
+
+ // share the file with user2
+ \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_HOOKS_USER2, OCP\PERMISSION_ALL);
+
+ // check if new share key exists
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
+
+ \Test_Encryption_Util::logoutHelper();
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
+ \OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
+
+ // user2 has a local file with the same name
+ $this->user2View->file_put_contents($this->filename, $this->data);
+
+ // check if all keys are generated
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+
+ // delete the Shared file from user1 in data/user2/files/Shared
+ $this->user2View->unlink('/Shared/' . $this->filename);
+
+ // now keys from user1s home should be gone
+ $this->assertFalse($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
+ $this->assertFalse($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
+ $this->assertFalse($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+
+ // but user2 keys should still exist
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+
+ // cleanup
+
+ $this->user2View->unlink($this->filename);
+
+ \Test_Encryption_Util::logoutHelper();
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
+ \OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
+
+ // unshare the file
+ \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_HOOKS_USER2);
+
+ $this->user1View->unlink($this->filename);
+
+ if ($stateFilesTrashbin) {
+ OC_App::enable('files_trashbin');
+ }
+ else {
+ OC_App::disable('files_trashbin');
+ }
+ }
+
+}
diff --git a/apps/files_encryption/tests/keymanager.php b/apps/files_encryption/tests/keymanager.php
index 58a57ee5af4..6f32c50743c 100644
--- a/apps/files_encryption/tests/keymanager.php
+++ b/apps/files_encryption/tests/keymanager.php
@@ -137,6 +137,17 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase {
}
/**
+ * @small
+ */
+ function testGetFilenameFromShareKey() {
+ $this->assertEquals("file",
+ \TestProtectedKeymanagerMethods::testGetFilenameFromShareKey("file.user.shareKey"));
+ $this->assertEquals("file.name.with.dots",
+ \TestProtectedKeymanagerMethods::testGetFilenameFromShareKey("file.name.with.dots.user.shareKey"));
+ $this->assertFalse(\TestProtectedKeymanagerMethods::testGetFilenameFromShareKey("file.txt"));
+ }
+
+ /**
* @medium
*/
function testSetFileKey() {
@@ -234,3 +245,12 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase {
\OC_FileProxy::$enabled = $proxyStatus;
}
}
+
+/**
+ * dummy class to access protected methods of \OCA\Encryption\Keymanager for testing
+ */
+class TestProtectedKeymanagerMethods extends \OCA\Encryption\Keymanager {
+ public static function testGetFilenameFromShareKey($sharekey) {
+ return self::getFilenameFromShareKey($sharekey);
+ }
+} \ No newline at end of file
diff --git a/apps/files_encryption/tests/proxy.php b/apps/files_encryption/tests/proxy.php
index c3006274d6d..51cc0b795e3 100644
--- a/apps/files_encryption/tests/proxy.php
+++ b/apps/files_encryption/tests/proxy.php
@@ -112,54 +112,4 @@ class Test_Encryption_Proxy extends \PHPUnit_Framework_TestCase {
}
- function testPreUnlinkWithoutTrash() {
-
- // remember files_trashbin state
- $stateFilesTrashbin = OC_App::isEnabled('files_trashbin');
-
- // we want to tests with app files_trashbin enabled
- \OC_App::disable('files_trashbin');
-
- $this->view->file_put_contents($this->filename, $this->data);
-
- // create a dummy file that we can delete something outside of data/user/files
- $this->rootView->file_put_contents("dummy.txt", $this->data);
-
- // check if all keys are generated
- $this->assertTrue($this->rootView->file_exists(
- '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '.shareKey'));
- $this->assertTrue($this->rootView->file_exists(
- '/files_encryption/keyfiles/' . $this->filename . '.key'));
-
-
- // delete dummy file outside of data/user/files
- $this->rootView->unlink("dummy.txt");
-
- // all keys should still exist
- $this->assertTrue($this->rootView->file_exists(
- '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '.shareKey'));
- $this->assertTrue($this->rootView->file_exists(
- '/files_encryption/keyfiles/' . $this->filename . '.key'));
-
-
- // delete the file in data/user/files
- $this->view->unlink($this->filename);
-
- // now also the keys should be gone
- $this->assertFalse($this->rootView->file_exists(
- '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '.shareKey'));
- $this->assertFalse($this->rootView->file_exists(
- '/files_encryption/keyfiles/' . $this->filename . '.key'));
-
- if ($stateFilesTrashbin) {
- OC_App::enable('files_trashbin');
- }
- else {
- OC_App::disable('files_trashbin');
- }
- }
-
}
diff --git a/apps/files_encryption/tests/share.php b/apps/files_encryption/tests/share.php
index e55427620a6..acf408a07f0 100755
--- a/apps/files_encryption/tests/share.php
+++ b/apps/files_encryption/tests/share.php
@@ -194,8 +194,9 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
. $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// cleanup
- $this->view->unlink(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
+ $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/');
+ $this->view->unlink($this->filename);
+ $this->view->chroot('/');
// check if share key not exists
$this->assertFalse($this->view->file_exists(
@@ -265,8 +266,9 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
. $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// cleanup
- $this->view->unlink(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
+ $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/');
+ $this->view->unlink($this->filename);
+ $this->view->chroot('/');
// check if share key not exists
$this->assertFalse($this->view->file_exists(
@@ -352,7 +354,9 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
. $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// cleanup
- $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1);
+ $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files');
+ $this->view->unlink($this->folder1);
+ $this->view->chroot('/');
// check if share key not exists
$this->assertFalse($this->view->file_exists(
@@ -482,9 +486,9 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
. $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// cleanup
- $this->view->unlink(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1 . $this->subfolder
- . $this->subsubfolder . '/' . $this->filename);
+ $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files');
+ $this->view->unlink($this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename);
+ $this->view->chroot('/');
// check if share key not exists
$this->assertFalse($this->view->file_exists(
@@ -559,7 +563,9 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
. $this->filename . '.' . $publicShareKeyId . '.shareKey'));
// cleanup
- $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
+ $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/');
+ $this->view->unlink($this->filename);
+ $this->view->chroot('/');
// check if share key not exists
$this->assertFalse($this->view->file_exists(
@@ -636,7 +642,9 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
. $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey'));
// cleanup
- $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
+ $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/');
+ $this->view->unlink($this->filename);
+ $this->view->chroot('/');
// check if share key not exists
$this->assertFalse($this->view->file_exists(
@@ -731,8 +739,10 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
. $this->filename . '.' . $recoveryKeyId . '.shareKey'));
// cleanup
- $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
- $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->folder1);
+ $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/');
+ $this->view->unlink($this->filename);
+ $this->view->unlink($this->folder1);
+ $this->view->chroot('/');
// check if share key for recovery not exists
$this->assertFalse($this->view->file_exists(
@@ -828,8 +838,10 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
$this->assertEquals($this->dataShort, $retrievedCryptedFile2);
// cleanup
- $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1);
- $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename);
+ $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/');
+ $this->view->unlink($this->folder1);
+ $this->view->unlink($this->filename);
+ $this->view->chroot('/');
// check if share key for user and recovery exists
$this->assertFalse($this->view->file_exists(
@@ -930,7 +942,9 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
. $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
// cleanup
- $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
+ $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/');
+ $this->view->unlink($this->filename);
+ $this->view->chroot('/');
}
}
diff --git a/apps/files_sharing/css/mobile.css b/apps/files_sharing/css/mobile.css
new file mode 100644
index 00000000000..7d2116d190d
--- /dev/null
+++ b/apps/files_sharing/css/mobile.css
@@ -0,0 +1,49 @@
+@media only screen and (max-width: 600px) {
+
+/* make header scroll up for single shares, more view of content on small screens */
+#header.share-file {
+ position: absolute !important;
+}
+
+/* hide size and date columns */
+table th#headerSize,
+table td.filesize,
+table th#headerDate,
+table td.date {
+ display: none;
+}
+
+/* restrict length of displayed filename to prevent overflow */
+table td.filename .nametext {
+ max-width: 75% !important;
+}
+
+/* on mobile, show single shared image at full width without margin */
+#imgframe {
+ width: 100%;
+ padding: 0;
+ margin-bottom: 35px;
+}
+/* some margin for the file type icon */
+#imgframe .publicpreview {
+ margin-top: 32px;
+}
+
+/* always show actions on mobile */
+#fileList a.action {
+ -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=20)" !important;
+ filter: alpha(opacity=20) !important;
+ opacity: .2 !important;
+ display: inline !important;
+}
+/* some padding for better clickability */
+#fileList a.action img {
+ padding: 0 6px 0 12px;
+}
+/* hide text of the actions on mobile */
+#fileList a.action span {
+ display: none;
+}
+
+
+}
diff --git a/apps/files_sharing/css/public.css b/apps/files_sharing/css/public.css
index 6e0c6eb75b9..21f0c82b829 100644
--- a/apps/files_sharing/css/public.css
+++ b/apps/files_sharing/css/public.css
@@ -14,39 +14,17 @@ body {
padding:7px;
}
-#details {
- color:#fff;
- float: left;
-}
-
-#public_upload,
-#download {
- font-weight:700;
- margin: 0 0 0 6px;
- padding: 0 5px;
- height: 32px;
- float: left;
-
-}
-
-.header-right #details {
- margin-right: 28px;
-}
-
.header-right {
padding: 0;
height: 32px;
}
-#public_upload {
- margin-left: 5px;
-}
-
-#public_upload img,
-#download img {
- padding-left:2px;
- padding-right:5px;
- vertical-align:text-bottom;
+#details {
+ color:#fff;
+ -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
+ filter: alpha(opacity=50);
+ opacity: .5;
+ padding-right: 5px;
}
#controls {
@@ -71,9 +49,8 @@ footer {
p.info {
color: #777;
text-align: center;
- width: 352px;
margin: 0 auto;
- padding: 20px;
+ padding: 20px 0;
}
p.info a {
@@ -94,9 +71,13 @@ p.info a {
max-width:100%;
}
-thead{
- background-color: white;
- padding-left:0 !important; /* fixes multiselect bar offset on shared page */
+/* some margin for the file type icon */
+#imgframe .publicpreview {
+ margin-top: 10%;
+}
+
+thead {
+ padding-left: 0 !important; /* fixes multiselect bar offset on shared page */
}
#data-upload-form {
@@ -110,27 +91,20 @@ thead{
margin: 0;
}
-#file_upload_start {
- -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
- filter: alpha(opacity=0);
- opacity: 0;
- z-index: 20;
- position: absolute !important;
- top: 0;
- left: 0;
- width: 100% !important;
-}
-
+.directDownload,
.directLink {
margin-bottom: 20px;
}
+.directDownload .button img {
+ vertical-align: text-bottom;
+}
.directLink label {
font-weight: normal;
+ -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
+ filter: alpha(opacity=50);
+ opacity: .5;
}
.directLink input {
- margin-left: 10px;
+ margin-left: 5px;
width: 300px;
}
-.public_actions {
- padding: 4px;
-}
diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js
index 79c15623c0c..c1b7eee3fb7 100644
--- a/apps/files_sharing/js/public.js
+++ b/apps/files_sharing/js/public.js
@@ -9,22 +9,13 @@ function fileDownloadPath(dir, file) {
$(document).ready(function() {
- $('#data-upload-form').tipsy({gravity:'ne', fade:true});
-
if (typeof FileActions !== 'undefined') {
var mimetype = $('#mimetype').val();
// Show file preview if previewer is available, images are already handled by the template
if (mimetype.substr(0, mimetype.indexOf('/')) != 'image' && $('.publicpreview').length === 0) {
// Trigger default action if not download TODO
var action = FileActions.getDefault(mimetype, 'file', OC.PERMISSION_READ);
- if (typeof action === 'undefined') {
- $('#noPreview').show();
- if (mimetype != 'httpd/unix-directory') {
- // NOTE: Remove when a better file previewer solution exists
- $('#content').remove();
- $('table').remove();
- }
- } else {
+ if (typeof action !== 'undefined') {
action($('#filename').val());
}
}
@@ -56,16 +47,9 @@ $(document).ready(function() {
};
});
- // Add Uploadprogress Wrapper to controls bar
- $('#controls').append($('#controls .actions div#uploadprogresswrapper'));
- $('#uploadprogresswrapper').addClass('public_actions');
-
- // Cancel upload trigger
- $('#cancel_upload_button').click(function() {
- OC.Upload.cancelUploads();
- procesSelection();
+ $(document).on('click', '#directLink', function() {
+ $(this).focus();
+ $(this).select();
});
- $('#directLink').focus();
-
});
diff --git a/apps/files_sharing/lib/api.php b/apps/files_sharing/lib/api.php
index f828a4e840d..061e60ad8ed 100644
--- a/apps/files_sharing/lib/api.php
+++ b/apps/files_sharing/lib/api.php
@@ -178,8 +178,7 @@ class Api {
$share['received_from_displayname'] = \OCP\User::getDisplayName($receivedFrom['uid_owner']);
}
if ($share) {
- $share['filename'] = $file['name'];
- $result[] = $share;
+ $result = array_merge($result, $share);
}
}
diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php
index 425d51113b1..86e324409fe 100644
--- a/apps/files_sharing/lib/cache.php
+++ b/apps/files_sharing/lib/cache.php
@@ -259,17 +259,38 @@ class Shared_Cache extends Cache {
* @return array
*/
public function searchByMime($mimetype) {
-
- if (strpos($mimetype, '/')) {
- $where = '`mimetype` = ? AND ';
- } else {
- $where = '`mimepart` = ? AND ';
+ $mimepart = null;
+ if (strpos($mimetype, '/') === false) {
+ $mimepart = $mimetype;
+ $mimetype = null;
}
- $value = $this->getMimetypeId($mimetype);
-
- return $this->searchWithWhere($where, $value);
-
+ // note: searchWithWhere is currently broken as it doesn't
+ // recurse into subdirs nor returns the correct
+ // file paths, so using getFolderContents() for now
+
+ $result = array();
+ $exploreDirs = array('');
+ while (count($exploreDirs) > 0) {
+ $dir = array_pop($exploreDirs);
+ $files = $this->getFolderContents($dir);
+ // no results?
+ if (!$files) {
+ continue;
+ }
+ foreach ($files as $file) {
+ if ($file['mimetype'] === 'httpd/unix-directory') {
+ $exploreDirs[] = ltrim($dir . '/' . $file['name'], '/');
+ }
+ else if (($mimepart && $file['mimepart'] === $mimepart) || ($mimetype && $file['mimetype'] === $mimetype)) {
+ // usersPath not reliable
+ //$file['path'] = $file['usersPath'];
+ $file['path'] = ltrim($dir . '/' . $file['name'], '/');
+ $result[] = $file;
+ }
+ }
+ }
+ return $result;
}
/**
diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php
index 4a81e482970..f03ac7205a3 100644
--- a/apps/files_sharing/public.php
+++ b/apps/files_sharing/public.php
@@ -137,21 +137,19 @@ if (isset($path)) {
} else {
OCP\Util::addScript('files', 'file-upload');
OCP\Util::addStyle('files_sharing', 'public');
+ OCP\Util::addStyle('files_sharing', 'mobile');
OCP\Util::addScript('files_sharing', 'public');
OCP\Util::addScript('files', 'fileactions');
OCP\Util::addScript('files', 'jquery.iframe-transport');
OCP\Util::addScript('files', 'jquery.fileupload');
$maxUploadFilesize=OCP\Util::maxUploadFilesize($path);
$tmpl = new OCP\Template('files_sharing', 'public', 'base');
- $tmpl->assign('uidOwner', $shareOwner);
$tmpl->assign('displayName', \OCP\User::getDisplayName($shareOwner));
$tmpl->assign('filename', $file);
$tmpl->assign('directory_path', $linkItem['file_target']);
$tmpl->assign('mimetype', \OC\Files\Filesystem::getMimeType($path));
- $tmpl->assign('fileTarget', basename($linkItem['file_target']));
$tmpl->assign('dirToken', $linkItem['token']);
$tmpl->assign('sharingToken', $token);
- $tmpl->assign('disableSharing', true);
$allowPublicUploadEnabled = (bool) ($linkItem['permissions'] & OCP\PERMISSION_CREATE);
if (OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes') === 'no') {
$allowPublicUploadEnabled = false;
@@ -159,9 +157,6 @@ if (isset($path)) {
if ($linkItem['item_type'] !== 'folder') {
$allowPublicUploadEnabled = false;
}
- $tmpl->assign('allowPublicUploadEnabled', $allowPublicUploadEnabled);
- $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize);
- $tmpl->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
$urlLinkIdentifiers= (isset($token)?'&t='.$token:'')
.(isset($_GET['dir'])?'&dir='.$_GET['dir']:'')
@@ -222,17 +217,23 @@ if (isset($path)) {
$maxUploadFilesize=OCP\Util::maxUploadFilesize($path);
$fileHeader = (!isset($files) or count($files) > 0);
$emptyContent = ($allowPublicUploadEnabled and !$fileHeader);
+
+ $freeSpace=OCP\Util::freeSpace($path);
+ $uploadLimit=OCP\Util::uploadLimit();
$folder = new OCP\Template('files', 'index', '');
$folder->assign('fileList', $list->fetchPage());
$folder->assign('breadcrumb', $breadcrumbNav->fetchPage());
$folder->assign('dir', $getPath);
- $folder->assign('isCreatable', false);
+ $folder->assign('isCreatable', $allowPublicUploadEnabled);
+ $folder->assign('dirToken', $linkItem['token']);
$folder->assign('permissions', OCP\PERMISSION_READ);
$folder->assign('isPublic',true);
$folder->assign('publicUploadEnabled', 'no');
$folder->assign('files', $files);
$folder->assign('uploadMaxFilesize', $maxUploadFilesize);
$folder->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
+ $folder->assign('freeSpace', $freeSpace);
+ $folder->assign('uploadLimit', $uploadLimit); // PHP upload limit
$folder->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
$folder->assign('usedSpacePercent', 0);
$folder->assign('fileHeader', $fileHeader);
diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php
index e1132142eff..3ddaf4446df 100644
--- a/apps/files_sharing/templates/public.php
+++ b/apps/files_sharing/templates/public.php
@@ -9,54 +9,14 @@
<input type="hidden" name="sharingToken" value="<?php p($_['sharingToken']) ?>" id="sharingToken">
<input type="hidden" name="filename" value="<?php p($_['filename']) ?>" id="filename">
<input type="hidden" name="mimetype" value="<?php p($_['mimetype']) ?>" id="mimetype">
-<header><div id="header" class="icon icon-noise">
+<header><div id="header" class="icon icon-noise <?php p((isset($_['folder']) ? 'share-folder' : 'share-file')) ?>">
<a href="<?php print_unescaped(link_to('', 'index.php')); ?>" title="" id="owncloud"><img class="svg"
src="<?php print_unescaped(image_path('', 'logo-wide.svg')); ?>" alt="<?php p($theme->getName()); ?>" /></a>
<div id="logo-claim" style="display:none;"><?php p($theme->getLogoClaim()); ?></div>
<div class="header-right">
- <?php if (isset($_['folder'])): ?>
- <span id="details"><?php p($l->t('%s shared the folder %s with you',
- array($_['displayName'], $_['filename']))) ?></span>
- <?php else: ?>
- <span id="details"><?php p($l->t('%s shared the file %s with you',
- array($_['displayName'], $_['filename']))) ?></span>
- <?php endif; ?>
-
-
- <?php if (!isset($_['folder']) || $_['allowZipDownload']): ?>
- <a href="<?php p($_['downloadURL']); ?>" class="button" id="download">
- <img class="svg" alt="Download" src="<?php print_unescaped(OCP\image_path("core", "actions/download.svg")); ?>" />
- <span><?php p($l->t('Download'))?></span>
- </a>
- <?php endif; ?>
-
- <?php if ($_['allowPublicUploadEnabled']):?>
-
-
- <input type="hidden" id="publicUploadRequestToken" name="requesttoken" value="<?php p($_['requesttoken']) ?>" />
- <input type="hidden" id="dirToken" name="dirToken" value="<?php p($_['dirToken']) ?>" />
- <input type="hidden" id="uploadMaxFilesize" name="uploadMaxFilesize" value="<?php p($_['uploadMaxFilesize']) ?>" />
- <input type="hidden" id="uploadMaxHumanFilesize" name="uploadMaxHumanFilesize" value="<?php p($_['uploadMaxHumanFilesize']) ?>" />
- <input type="hidden" id="directory_path" name="directory_path" value="<?php p($_['directory_path']) ?>" />
- <?php if($_['uploadMaxFilesize'] >= 0):?>
- <input type="hidden" name="MAX_FILE_SIZE" id="max_upload"
- value="<?php p($_['uploadMaxFilesize']) ?>">
- <?php endif;?>
-
-
- <div id="data-upload-form" title="<?php p($l->t('Upload') . ' max. '.$_['uploadMaxHumanFilesize']) ?>">
- <input id="file_upload_start" type="file" name="files[]" data-url="<?php print_unescaped(OCP\Util::linkTo('files', 'ajax/upload.php')); ?>" multiple>
- <a href="#" id="public_upload" class="button">
- <img class="svg" alt="Upload" src="<?php print_unescaped(OCP\image_path("core", "actions/upload.svg")); ?>" />
- <span><?php p($l->t('Upload'))?></span>
- </a>
- </div>
-
- </div>
- <div>
- <?php endif; ?>
+ <span id="details"><?php p($l->t('shared by %s', array($_['displayName']))) ?></span>
</div>
- </div></header>
+</div></header>
<div id="content">
<div id="preview">
<?php if (isset($_['folder'])): ?>
@@ -72,25 +32,28 @@
<source src="<?php p($_['downloadURL']); ?>" type="<?php p($_['mimetype']); ?>" />
</video>
</div>
- <?php elseif (\OC\Preview::isMimeSupported($_['mimetype'])): ?>
+ <?php else: ?>
<div id="imgframe">
- <img src="<?php p(OCP\Util::linkToRoute( 'core_ajax_public_preview', array('x' => 500, 'y' => 500, 'file' => urlencode($_['directory_path']), 't' => $_['dirToken']))); ?>" class="publicpreview"/>
+ <?php $size = \OC\Preview::isMimeSupported($_['mimetype']) ? 500 : 128 ?>
+ <img src="<?php p(OCP\Util::linkToRoute( 'core_ajax_public_preview', array('x' => $size, 'y' => $size, 'file' => urlencode($_['directory_path']), 't' => $_['dirToken']))); ?>" class="publicpreview"/>
</div>
- <?php else: ?>
- <ul id="noPreview">
- <li class="error">
- <?php p($l->t('No preview available for').' '.$_['filename']); ?><br />
- <a href="<?php p($_['downloadURL']); ?>" id="download"><img class="svg" alt="Download"
- src="<?php print_unescaped(OCP\image_path("core", "actions/download.svg")); ?>"
- /><?php p($l->t('Download'))?></a>
- </li>
- </ul>
<?php endif; ?>
- <div class="directLink"><label for="directLink"><?php p($l->t('Direct link')) ?></label><input id="directLink" type="text" readonly value="<?php p($_['downloadURL']); ?>"></input></div>
+ <div class="directDownload">
+ <a href="<?php p($_['downloadURL']); ?>" id="download" class="button">
+ <img class="svg" alt="" src="<?php print_unescaped(OCP\image_path("core", "actions/download.svg")); ?>"/>
+ <?php p($l->t('Download %s', array($_['filename'])))?>
+ </a>
+ </div>
+ <div class="directLink">
+ <label for="directLink"><?php p($l->t('Direct link')) ?></label>
+ <input id="directLink" type="text" readonly value="<?php p($_['downloadURL']); ?>">
+ </div>
<?php endif; ?>
</div>
- <footer>
- <p class="info">
- <?php print_unescaped($theme->getLongFooter()); ?>
- </p>
- </footer>
+
+</div>
+<footer>
+ <p class="info">
+ <?php print_unescaped($theme->getLongFooter()); ?>
+ </p>
+</footer>
diff --git a/apps/files_sharing/tests/cache.php b/apps/files_sharing/tests/cache.php
new file mode 100644
index 00000000000..56a51c83f6b
--- /dev/null
+++ b/apps/files_sharing/tests/cache.php
@@ -0,0 +1,134 @@
+<?php
+/**
+ * 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/>.
+ *
+ */
+require_once __DIR__ . '/base.php';
+
+class Test_Files_Sharing_Cache extends Test_Files_Sharing_Base {
+
+ function setUp() {
+ parent::setUp();
+
+ self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
+
+ // prepare user1's dir structure
+ $textData = "dummy file data\n";
+ $this->view->mkdir('container');
+ $this->view->mkdir('container/shareddir');
+ $this->view->mkdir('container/shareddir/subdir');
+ $this->view->mkdir('container/shareddir/emptydir');
+
+ $textData = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ $this->view->file_put_contents('container/not shared.txt', $textData);
+ $this->view->file_put_contents('container/shared single file.txt', $textData);
+ $this->view->file_put_contents('container/shareddir/bar.txt', $textData);
+ $this->view->file_put_contents('container/shareddir/subdir/another.txt', $textData);
+ $this->view->file_put_contents('container/shareddir/subdir/another too.txt', $textData);
+ $this->view->file_put_contents('container/shareddir/subdir/not a text file.xml', '<xml></xml>');
+
+ list($this->ownerStorage, $internalPath) = $this->view->resolvePath('');
+ $this->ownerCache = $this->ownerStorage->getCache();
+ $this->ownerStorage->getScanner()->scan('');
+
+ // share "shareddir" with user2
+ $fileinfo = $this->view->getFileInfo('container/shareddir');
+ \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
+ self::TEST_FILES_SHARING_API_USER2, 31);
+
+ $fileinfo = $this->view->getFileInfo('container/shared single file.txt');
+ \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
+ self::TEST_FILES_SHARING_API_USER2, 31);
+
+ // login as user2
+ self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
+
+ // retrieve the shared storage
+ $secondView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2);
+ list($this->sharedStorage, $internalPath) = $secondView->resolvePath('files/Shared/shareddir');
+ $this->sharedCache = $this->sharedStorage->getCache();
+ }
+
+ function tearDown() {
+ $this->sharedCache->clear();
+
+ self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
+
+ $fileinfo = $this->view->getFileInfo('container/shareddir');
+ \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
+ self::TEST_FILES_SHARING_API_USER2);
+
+ $fileinfo = $this->view->getFileInfo('container/shared single file.txt');
+ \OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
+ self::TEST_FILES_SHARING_API_USER2);
+
+ $this->view->deleteAll('container');
+
+ $this->ownerCache->clear();
+
+ parent::tearDown();
+ }
+
+ /**
+ * Test searching by mime type
+ */
+ function testSearchByMime() {
+ $results = $this->sharedStorage->getCache()->searchByMime('text');
+ $check = array(
+ array(
+ 'name' => 'shared single file.txt',
+ 'path' => 'shared single file.txt'
+ ),
+ array(
+ 'name' => 'bar.txt',
+ 'path' => 'shareddir/bar.txt'
+ ),
+ array(
+ 'name' => 'another too.txt',
+ 'path' => 'shareddir/subdir/another too.txt'
+ ),
+ array(
+ 'name' => 'another.txt',
+ 'path' => 'shareddir/subdir/another.txt'
+ ),
+ );
+ $this->verifyFiles($check, $results);
+
+ $results2 = $this->sharedStorage->getCache()->searchByMime('text/plain');
+
+ $this->verifyFiles($check, $results);
+ }
+
+ /**
+ * Checks that all provided attributes exist in the files list,
+ * only the values provided in $examples will be used to check against
+ * the file list. The files order also needs to be the same.
+ *
+ * @param array $examples array of example files
+ * @param array $files array of files
+ */
+ private function verifyFiles($examples, $files) {
+ $this->assertEquals(count($examples), count($files));
+ foreach ($files as $i => $file) {
+ foreach ($examples[$i] as $key => $value) {
+ $this->assertEquals($value, $file[$key]);
+ }
+ }
+ }
+}
diff --git a/apps/files_trashbin/ajax/preview.php b/apps/files_trashbin/ajax/preview.php
index ce432f4d14e..44738734b19 100644
--- a/apps/files_trashbin/ajax/preview.php
+++ b/apps/files_trashbin/ajax/preview.php
@@ -34,7 +34,17 @@ try{
if ($view->is_dir($file)) {
$mimetype = 'httpd/unix-directory';
} else {
- $mimetype = \OC_Helper::getFileNameMimeType(pathinfo($file, PATHINFO_FILENAME));
+ $pathInfo = pathinfo($file);
+ $fileName = $pathInfo['basename'];
+ // if in root dir
+ if ($pathInfo['dirname'] === '.') {
+ // cut off the .d* suffix
+ $i = strrpos($fileName, '.');
+ if ($i !== false) {
+ $fileName = substr($fileName, 0, $i);
+ }
+ }
+ $mimetype = \OC_Helper::getFileNameMimeType($fileName);
}
$preview->setMimetype($mimetype);
$preview->setMaxX($maxX);
@@ -45,4 +55,4 @@ try{
}catch(\Exception $e) {
\OC_Response::setStatus(500);
\OC_Log::write('core', $e->getmessage(), \OC_Log::DEBUG);
-} \ No newline at end of file
+}
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php
index c4e4efd0483..7fbabda7106 100644
--- a/apps/user_ldap/lib/connection.php
+++ b/apps/user_ldap/lib/connection.php
@@ -52,7 +52,7 @@ class Connection extends LDAPUtility {
$this->configID = $configID;
$this->configuration = new Configuration($configPrefix,
!is_null($configID));
- $memcache = new \OC\Memcache\Factory();
+ $memcache = \OC::$server->getMemCacheFactory();
if($memcache->isAvailable()) {
$this->cache = $memcache->create();
} else {