]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix mount type root detection
authorVincent Petry <pvince81@owncloud.com>
Mon, 14 Dec 2015 09:44:47 +0000 (10:44 +0100)
committerVincent Petry <pvince81@owncloud.com>
Mon, 14 Dec 2015 09:44:47 +0000 (10:44 +0100)
Since Webdav doesn't contain that information, we need to rely on the
parent folder's mount type to find out whether a child item is a
shared/external root or not.

Fixed the mount type detection logic and added unit test.

Also added a fix that ignores detection if no parent folder exists (ex:
shared file list, favorites, etc)

apps/files/js/filelist.js
apps/files/tests/js/filelistSpec.js

index 672c39a8bb16f440982d758d64cb362ed151a6e3..7e1329d1155336951c5a1f01b6c08f0ccf057ad1 100644 (file)
                        }
 
                        if (fileData.mountType) {
-                               // FIXME: HACK: detect shared-root
-                               if (fileData.mountType === 'shared' && this.dirInfo.mountType !== 'shared') {
-                                       // if parent folder isn't share, assume the displayed folder is a share root
-                                       fileData.mountType = 'shared-root';
-                               } else if (fileData.mountType === 'external' && this.dirInfo.mountType !== 'external') {
-                                       // if parent folder isn't external, assume the displayed folder is the external storage root
-                                       fileData.mountType = 'external-root';
+                               // dirInfo (parent) only exist for the "real" file list
+                               if (this.dirInfo.id) {
+                                       // FIXME: HACK: detect shared-root
+                                       if (fileData.mountType === 'shared' && this.dirInfo.mountType !== 'shared' && this.dirInfo.mountType !== 'shared-root') {
+                                               // if parent folder isn't share, assume the displayed folder is a share root
+                                               fileData.mountType = 'shared-root';
+                                       } else if (fileData.mountType === 'external' && this.dirInfo.mountType !== 'external' && this.dirInfo.mountType !== 'external-root') {
+                                               // if parent folder isn't external, assume the displayed folder is the external storage root
+                                               fileData.mountType = 'external-root';
+                                       }
                                }
                                tr.attr('data-mounttype', fileData.mountType);
                        }
index 9f7ad50bc608716b00c421b5608051826b9a636a..3542a5cee8f999cee76fa6c3c938d3e655e99a41 100644 (file)
@@ -2534,4 +2534,34 @@ describe('OCA.Files.FileList tests', function() {
                        expect(newFileMenuStub.notCalled).toEqual(true);
                });
        });
+       describe('mount type detection', function() {
+               function testMountType(dirInfoId, dirInfoMountType, inputMountType, expectedMountType) {
+                       var $tr;
+                       fileList.dirInfo.id = dirInfoId;
+                       fileList.dirInfo.mountType = dirInfoMountType;
+                       $tr = fileList.add({
+                               type: 'dir',
+                               mimetype: 'httpd/unix-directory',
+                               name: 'test dir',
+                               mountType: inputMountType
+                       });
+
+                       expect($tr.attr('data-mounttype')).toEqual(expectedMountType);
+               }
+
+               it('leaves mount type as is if no parent exists', function() {
+                       testMountType(null, null, 'external', 'external');
+                       testMountType(null, null, 'shared', 'shared');
+               });
+               it('detects share root if parent exists', function() {
+                       testMountType(123, null, 'shared', 'shared-root');
+                       testMountType(123, 'shared', 'shared', 'shared');
+                       testMountType(123, 'shared-root', 'shared', 'shared');
+               });
+               it('detects external storage root if parent exists', function() {
+                       testMountType(123, null, 'external', 'external-root');
+                       testMountType(123, 'external', 'external', 'external');
+                       testMountType(123, 'external-root', 'external', 'external');
+               });
+       });
 });