From f1bfe35cda2f11d1b38726cf2d4f879427b2c8d5 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 4 Sep 2014 19:58:49 +0200 Subject: Added permission check for drag and drop When dropping files onto a read-only folder, a notification is now shown instead of attempting to upload. This for both the drag for upload and drag from inside the file list cases. --- apps/files/js/filelist.js | 19 +++++++++++++++++++ apps/files/js/files.js | 7 ++++++- 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'apps/files/js') diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 037e04db21c..4a9c56e6bf5 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -1631,6 +1631,18 @@ return name; }, + /** + * Shows a "permission denied" notification + */ + _showPermissionDeniedNotification: function() { + var message = t('core', 'You don’t have permission to upload or create files here'); + OC.Notification.show(message); + //hide notification after 10 sec + setTimeout(function() { + OC.Notification.hide(); + }, 5000); + }, + /** * Setup file upload events related to the file-upload plugin */ @@ -1662,6 +1674,12 @@ // remember as context data.context = dropTarget; + // if permissions are specified, only allow if create permission is there + var permissions = dropTarget.data('permissions'); + if (!_.isUndefined(permissions) && (permissions & OC.PERMISSION_CREATE) === 0) { + self._showPermissionDeniedNotification(); + return false; + } var dir = dropTarget.data('file'); // if from file list, need to prepend parent dir if (dir) { @@ -1686,6 +1704,7 @@ // cancel uploads to current dir if no permission var isCreatable = (self.getDirectoryPermissions() & OC.PERMISSION_CREATE) !== 0; if (!isCreatable) { + self._showPermissionDeniedNotification(); return false; } } diff --git a/apps/files/js/files.js b/apps/files/js/files.js index df0c40a4405..5fcf99d24af 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -433,7 +433,12 @@ var folderDropOptions = { return false; } - var targetPath = FileList.getCurrentDirectory() + '/' + $(this).closest('tr').data('file'); + var $tr = $(this).closest('tr'); + if (($tr.data('permissions') & OC.PERMISSION_CREATE) === 0) { + FileList._showPermissionDeniedNotification(); + return false; + } + var targetPath = FileList.getCurrentDirectory() + '/' + $tr.data('file'); var files = FileList.getSelectedFiles(); if (files.length === 0) { -- cgit v1.2.3