]> source.dussan.org Git - nextcloud-server.git/commitdiff
Added permission check for drag and drop
authorVincent Petry <pvince81@owncloud.com>
Thu, 4 Sep 2014 17:58:49 +0000 (19:58 +0200)
committerVincent Petry <pvince81@owncloud.com>
Thu, 4 Sep 2014 18:18:24 +0000 (20:18 +0200)
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
apps/files/js/files.js
apps/files/tests/js/filelistSpec.js

index 037e04db21c42f7f2d9d2abb3b7e29c682d4ca19..4a9c56e6bf5c129d7298280fd80341bc26734263 100644 (file)
                        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
                 */
                                        // 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) {
                                        // cancel uploads to current dir if no permission
                                        var isCreatable = (self.getDirectoryPermissions() & OC.PERMISSION_CREATE) !== 0;
                                        if (!isCreatable) {
+                                               self._showPermissionDeniedNotification();
                                                return false;
                                        }
                                }
index df0c40a4405763b737185a380646bac8224a8494..5fcf99d24af3a02591992bf02b84027a2099c19b 100644 (file)
@@ -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) {
index cad564323b4aaf4a7aafe674d104438fc933d255..65a89ef85cd0f5ac7d4c7c346d00a4396fc62f09 100644 (file)
@@ -1835,7 +1835,6 @@ describe('OCA.Files.FileList tests', function() {
                        // but it makes it possible to simulate the event triggering to
                        // test the response of the handlers
                        $uploader = $('#file_upload_start');
-                       fileList.setupUploadEvents();
                        fileList.setFiles(testFiles);
                });
 
@@ -1912,6 +1911,16 @@ describe('OCA.Files.FileList tests', function() {
                                ev = dropOn(fileList.$fileList.find('th:first'));
 
                                expect(ev.result).toEqual(false);
+                               expect(notificationStub.calledOnce).toEqual(true);
+                       });
+                       it('drop on an folder does not trigger upload if no upload permission on that folder', function() {
+                               var $tr = fileList.findFileEl('somedir');
+                               var ev;
+                               $tr.data('permissions', OC.PERMISSION_READ);
+                               ev = dropOn($tr);
+
+                               expect(ev.result).toEqual(false);
+                               expect(notificationStub.calledOnce).toEqual(true);
                        });
                        it('drop on a file row inside the table triggers upload to current folder', function() {
                                var ev;