Merge pull request #7047 from nextcloud/add-support-for-files-with-no-permissions

Add support for files with no permissions
This commit is contained in:
Björn Schießle 2017-11-20 16:15:52 +01:00 committed by GitHub
commit f347e2e4a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 61 additions and 52 deletions

View File

@ -300,6 +300,9 @@ abstract class Node implements \Sabre\DAV\INode {
if ($this->info->isMounted()) { if ($this->info->isMounted()) {
$p .= 'M'; $p .= 'M';
} }
if ($this->info->isReadable()) {
$p .= 'G';
}
if ($this->info->isDeletable()) { if ($this->info->isDeletable()) {
$p .= 'D'; $p .= 'D';
} }

View File

@ -42,15 +42,17 @@ use OCP\Share\IShare;
class NodeTest extends \Test\TestCase { class NodeTest extends \Test\TestCase {
public function davPermissionsProvider() { public function davPermissionsProvider() {
return array( return array(
array(\OCP\Constants::PERMISSION_ALL, 'file', false, false, 'RDNVW'), array(\OCP\Constants::PERMISSION_ALL, 'file', false, false, 'RGDNVW'),
array(\OCP\Constants::PERMISSION_ALL, 'dir', false, false, 'RDNVCK'), array(\OCP\Constants::PERMISSION_ALL, 'dir', false, false, 'RGDNVCK'),
array(\OCP\Constants::PERMISSION_ALL, 'file', true, false, 'SRDNVW'), array(\OCP\Constants::PERMISSION_ALL, 'file', true, false, 'SRGDNVW'),
array(\OCP\Constants::PERMISSION_ALL, 'file', true, true, 'SRMDNVW'), array(\OCP\Constants::PERMISSION_ALL, 'file', true, true, 'SRMGDNVW'),
array(\OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE, 'file', true, false, 'SDNVW'), array(\OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE, 'file', true, false, 'SGDNVW'),
array(\OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_UPDATE, 'file', false, false, 'RD'), array(\OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_UPDATE, 'file', false, false, 'RGD'),
array(\OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_DELETE, 'file', false, false, 'RNVW'), array(\OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_DELETE, 'file', false, false, 'RGNVW'),
array(\OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_CREATE, 'file', false, false, 'RDNVW'), array(\OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_CREATE, 'file', false, false, 'RGDNVW'),
array(\OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_CREATE, 'dir', false, false, 'RDNV'), array(\OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_READ, 'file', false, false, 'RDNVW'),
array(\OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_CREATE, 'dir', false, false, 'RGDNV'),
array(\OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_READ, 'dir', false, false, 'RDNVCK'),
); );
} }

View File

@ -235,7 +235,7 @@
} }
var filteredActions = {}; var filteredActions = {};
$.each(actions, function (name, action) { $.each(actions, function (name, action) {
if (action.permissions & permissions) { if ((action.permissions === OC.PERMISSION_NONE) || (action.permissions & permissions)) {
filteredActions[name] = action; filteredActions[name] = action;
} }
}); });

View File

@ -408,7 +408,7 @@
mime: 'all', mime: 'all',
order: -50, order: -50,
iconClass: 'icon-details', iconClass: 'icon-details',
permissions: OC.PERMISSION_READ, permissions: OC.PERMISSION_NONE,
actionHandler: function(fileName, context) { actionHandler: function(fileName, context) {
self._updateDetailsView(fileName); self._updateDetailsView(fileName);
} }
@ -1161,6 +1161,11 @@
} }
} }
var permissions = fileData.permissions;
if (permissions === undefined || permissions === null) {
permissions = this.getDirectoryPermissions();
}
//containing tr //containing tr
var tr = $('<tr></tr>').attr({ var tr = $('<tr></tr>').attr({
"data-id" : fileData.id, "data-id" : fileData.id,
@ -1170,7 +1175,7 @@
"data-mime": mime, "data-mime": mime,
"data-mtime": mtime, "data-mtime": mtime,
"data-etag": fileData.etag, "data-etag": fileData.etag,
"data-permissions": fileData.permissions || this.getDirectoryPermissions(), "data-permissions": permissions,
"data-has-preview": fileData.hasPreview !== false "data-has-preview": fileData.hasPreview !== false
}); });

View File

@ -104,7 +104,7 @@
}, },
mime: 'all', mime: 'all',
order: -100, order: -100,
permissions: OC.PERMISSION_READ, permissions: OC.PERMISSION_NONE,
iconClass: function(fileName, context) { iconClass: function(fileName, context) {
var $file = context.$file; var $file = context.$file;
var isFavorite = $file.data('favorite') === true; var isFavorite = $file.data('favorite') === true;

View File

@ -297,6 +297,15 @@ describe('OCA.Files.FileList tests', function() {
expect($tr.find('.filesize').text()).toEqual('Pending'); expect($tr.find('.filesize').text()).toEqual('Pending');
expect($tr.find('.date').text()).not.toEqual('?'); expect($tr.find('.date').text()).not.toEqual('?');
}); });
it('generates file element with no permissions when permissions are explicitly none', function() {
var fileData = {
type: 'dir',
name: 'testFolder',
permissions: OC.PERMISSION_NONE
};
var $tr = fileList.add(fileData);
expect($tr.attr('data-permissions')).toEqual('0');
});
it('generates file element with zero size when size is explicitly zero', function() { it('generates file element with zero size when size is explicitly zero', function() {
var fileData = { var fileData = {
type: 'dir', type: 'dir',

View File

@ -167,7 +167,7 @@ Feature: sharing
And folder "/merge-test-outside-perms" of user "user0" is shared with user "user1" with permissions 31 And folder "/merge-test-outside-perms" of user "user0" is shared with user "user1" with permissions 31
Then as "user1" gets properties of folder "/merge-test-outside-perms" with Then as "user1" gets properties of folder "/merge-test-outside-perms" with
|{http://owncloud.org/ns}permissions| |{http://owncloud.org/ns}permissions|
And the single response should contain a property "{http://owncloud.org/ns}permissions" with value "SRDNVCK" And the single response should contain a property "{http://owncloud.org/ns}permissions" with value "SRGDNVCK"
And as "user1" the folder "/merge-test-outside-perms (2)" does not exist And as "user1" the folder "/merge-test-outside-perms (2)" does not exist
Scenario: Merging shares for recipient when shared from outside with two groups Scenario: Merging shares for recipient when shared from outside with two groups
@ -197,7 +197,7 @@ Feature: sharing
And folder "/merge-test-outside-twogroups-perms" of user "user0" is shared with group "group2" with permissions 31 And folder "/merge-test-outside-twogroups-perms" of user "user0" is shared with group "group2" with permissions 31
Then as "user1" gets properties of folder "/merge-test-outside-twogroups-perms" with Then as "user1" gets properties of folder "/merge-test-outside-twogroups-perms" with
|{http://owncloud.org/ns}permissions| |{http://owncloud.org/ns}permissions|
And the single response should contain a property "{http://owncloud.org/ns}permissions" with value "SRDNVCK" And the single response should contain a property "{http://owncloud.org/ns}permissions" with value "SRGDNVCK"
And as "user1" the folder "/merge-test-outside-twogroups-perms (2)" does not exist And as "user1" the folder "/merge-test-outside-twogroups-perms (2)" does not exist
Scenario: Merging shares for recipient when shared from outside with two groups and member Scenario: Merging shares for recipient when shared from outside with two groups and member
@ -214,7 +214,7 @@ Feature: sharing
And folder "/merge-test-outside-twogroups-member-perms" of user "user0" is shared with user "user1" with permissions 1 And folder "/merge-test-outside-twogroups-member-perms" of user "user0" is shared with user "user1" with permissions 1
Then as "user1" gets properties of folder "/merge-test-outside-twogroups-member-perms" with Then as "user1" gets properties of folder "/merge-test-outside-twogroups-member-perms" with
|{http://owncloud.org/ns}permissions| |{http://owncloud.org/ns}permissions|
And the single response should contain a property "{http://owncloud.org/ns}permissions" with value "SRDNVCK" And the single response should contain a property "{http://owncloud.org/ns}permissions" with value "SRGDNVCK"
And as "user1" the folder "/merge-test-outside-twogroups-member-perms (2)" does not exist And as "user1" the folder "/merge-test-outside-twogroups-member-perms (2)" does not exist
Scenario: Merging shares for recipient when shared from inside with group Scenario: Merging shares for recipient when shared from inside with group
@ -253,7 +253,7 @@ Feature: sharing
And folder "/merge-test-inside-twogroups-perms" of user "user0" is shared with group "group2" And folder "/merge-test-inside-twogroups-perms" of user "user0" is shared with group "group2"
Then as "user0" gets properties of folder "/merge-test-inside-twogroups-perms" with Then as "user0" gets properties of folder "/merge-test-inside-twogroups-perms" with
|{http://owncloud.org/ns}permissions| |{http://owncloud.org/ns}permissions|
And the single response should contain a property "{http://owncloud.org/ns}permissions" with value "RDNVCK" And the single response should contain a property "{http://owncloud.org/ns}permissions" with value "RGDNVCK"
And as "user0" the folder "/merge-test-inside-twogroups-perms (2)" does not exist And as "user0" the folder "/merge-test-inside-twogroups-perms (2)" does not exist
And as "user0" the folder "/merge-test-inside-twogroups-perms (3)" does not exist And as "user0" the folder "/merge-test-inside-twogroups-perms (3)" does not exist
@ -270,7 +270,7 @@ Feature: sharing
And folder "/merge-test-outside-groups-renamebeforesecondshare" of user "user0" is shared with user "user1" And folder "/merge-test-outside-groups-renamebeforesecondshare" of user "user0" is shared with user "user1"
Then as "user1" gets properties of folder "/merge-test-outside-groups-renamebeforesecondshare-renamed" with Then as "user1" gets properties of folder "/merge-test-outside-groups-renamebeforesecondshare-renamed" with
|{http://owncloud.org/ns}permissions| |{http://owncloud.org/ns}permissions|
And the single response should contain a property "{http://owncloud.org/ns}permissions" with value "SRDNVCK" And the single response should contain a property "{http://owncloud.org/ns}permissions" with value "SRGDNVCK"
And as "user1" the folder "/merge-test-outside-groups-renamebeforesecondshare" does not exist And as "user1" the folder "/merge-test-outside-groups-renamebeforesecondshare" does not exist
Scenario: Merging shares for recipient when shared from outside with user then group and recipient renames in between Scenario: Merging shares for recipient when shared from outside with user then group and recipient renames in between
@ -287,7 +287,7 @@ Feature: sharing
And folder "/merge-test-outside-groups-renamebeforesecondshare" of user "user0" is shared with group "group1" And folder "/merge-test-outside-groups-renamebeforesecondshare" of user "user0" is shared with group "group1"
Then as "user1" gets properties of folder "/merge-test-outside-groups-renamebeforesecondshare-renamed" with Then as "user1" gets properties of folder "/merge-test-outside-groups-renamebeforesecondshare-renamed" with
|{http://owncloud.org/ns}permissions| |{http://owncloud.org/ns}permissions|
And the single response should contain a property "{http://owncloud.org/ns}permissions" with value "SRDNVCK" And the single response should contain a property "{http://owncloud.org/ns}permissions" with value "SRGDNVCK"
And as "user1" the folder "/merge-test-outside-groups-renamebeforesecondshare" does not exist And as "user1" the folder "/merge-test-outside-groups-renamebeforesecondshare" does not exist
Scenario: Empting trashbin Scenario: Empting trashbin

View File

@ -320,7 +320,7 @@
} }
} }
data.permissions = OC.PERMISSION_READ; data.permissions = OC.PERMISSION_NONE;
var permissionProp = props[Client.PROPERTY_PERMISSIONS]; var permissionProp = props[Client.PROPERTY_PERMISSIONS];
if (!_.isUndefined(permissionProp)) { if (!_.isUndefined(permissionProp)) {
var permString = permissionProp || ''; var permString = permissionProp || '';
@ -333,6 +333,9 @@
case 'K': case 'K':
data.permissions |= OC.PERMISSION_CREATE; data.permissions |= OC.PERMISSION_CREATE;
break; break;
case 'G':
data.permissions |= OC.PERMISSION_READ;
break;
case 'W': case 'W':
case 'N': case 'N':
case 'V': case 'V':

View File

@ -60,6 +60,7 @@ function fileDownloadPath(dir, file) {
/** @namespace */ /** @namespace */
var OCP = {}, var OCP = {},
OC = { OC = {
PERMISSION_NONE:0,
PERMISSION_CREATE:4, PERMISSION_CREATE:4,
PERMISSION_READ:1, PERMISSION_READ:1,
PERMISSION_UPDATE:2, PERMISSION_UPDATE:2,

View File

@ -164,7 +164,7 @@ describe('OC.Files.Client tests', function() {
'd:resourcetype': '<d:collection/>', 'd:resourcetype': '<d:collection/>',
'oc:id': '00000011oc2d13a6a068', 'oc:id': '00000011oc2d13a6a068',
'oc:fileid': '11', 'oc:fileid': '11',
'oc:permissions': 'RDNVCK', 'oc:permissions': 'GRDNVCK',
'oc:size': '120' 'oc:size': '120'
}, },
[ [
@ -196,7 +196,7 @@ describe('OC.Files.Client tests', function() {
'd:resourcetype': '<d:collection/>', 'd:resourcetype': '<d:collection/>',
'oc:id': '00000015oc2d13a6a068', 'oc:id': '00000015oc2d13a6a068',
'oc:fileid': '15', 'oc:fileid': '15',
'oc:permissions': 'RDNVCK', 'oc:permissions': 'GRDNVCK',
'oc:size': '100' 'oc:size': '100'
}, },
[ [
@ -257,7 +257,7 @@ describe('OC.Files.Client tests', function() {
expect(info.id).toEqual(51); expect(info.id).toEqual(51);
expect(info.path).toEqual('/path/to space/文件夹'); expect(info.path).toEqual('/path/to space/文件夹');
expect(info.name).toEqual('One.txt'); expect(info.name).toEqual('One.txt');
expect(info.permissions).toEqual(27); expect(info.permissions).toEqual(26);
expect(info.size).toEqual(250); expect(info.size).toEqual(250);
expect(info.mtime).toEqual(1436535485000); expect(info.mtime).toEqual(1436535485000);
expect(info.mimetype).toEqual('text/plain'); expect(info.mimetype).toEqual('text/plain');
@ -482,7 +482,7 @@ describe('OC.Files.Client tests', function() {
'd:resourcetype': '<d:collection/>', 'd:resourcetype': '<d:collection/>',
'oc:id': '00000011oc2d13a6a068', 'oc:id': '00000011oc2d13a6a068',
'oc:fileid': '11', 'oc:fileid': '11',
'oc:permissions': 'RDNVCK', 'oc:permissions': 'GRDNVCK',
'oc:size': '120' 'oc:size': '120'
}, },
[ [
@ -549,7 +549,7 @@ describe('OC.Files.Client tests', function() {
'd:resourcetype': '<d:collection/>', 'd:resourcetype': '<d:collection/>',
'oc:id': '00000011oc2d13a6a068', 'oc:id': '00000011oc2d13a6a068',
'oc:fileid': '11', 'oc:fileid': '11',
'oc:permissions': 'RDNVCK', 'oc:permissions': 'GRDNVCK',
'oc:size': '120' 'oc:size': '120'
}, },
[ [
@ -640,14 +640,14 @@ describe('OC.Files.Client tests', function() {
function testPermission(permission, isFile, expectedPermissions) { function testPermission(permission, isFile, expectedPermissions) {
var promise = getFileInfoWithPermission(permission, isFile); var promise = getFileInfoWithPermission(permission, isFile);
promise.then(function(result) { promise.then(function(status, result) {
expect(result.permissions).toEqual(expectedPermissions); expect(result.permissions).toEqual(expectedPermissions);
}); });
} }
function testMountType(permission, isFile, expectedMountType) { function testMountType(permission, isFile, expectedMountType) {
var promise = getFileInfoWithPermission(permission, isFile); var promise = getFileInfoWithPermission(permission, isFile);
promise.then(function(result) { promise.then(function(status, result) {
expect(result.mountType).toEqual(expectedMountType); expect(result.mountType).toEqual(expectedMountType);
}); });
} }
@ -655,43 +655,29 @@ describe('OC.Files.Client tests', function() {
it('properly parses file permissions', function() { it('properly parses file permissions', function() {
// permission, isFile, expectedPermissions // permission, isFile, expectedPermissions
var testCases = [ var testCases = [
['', true, OC.PERMISSION_READ], ['', true, OC.PERMISSION_NONE],
['C', true, OC.PERMISSION_READ | OC.PERMISSION_CREATE], ['C', true, OC.PERMISSION_CREATE],
['K', true, OC.PERMISSION_READ | OC.PERMISSION_CREATE], ['K', true, OC.PERMISSION_CREATE],
['W', true, OC.PERMISSION_READ | OC.PERMISSION_CREATE | OC.PERMISSION_UPDATE], ['G', true, OC.PERMISSION_READ],
['D', true, OC.PERMISSION_READ | OC.PERMISSION_DELETE], ['W', true, OC.PERMISSION_UPDATE],
['R', true, OC.PERMISSION_READ | OC.PERMISSION_SHARE], ['D', true, OC.PERMISSION_DELETE],
['CKWDR', true, OC.PERMISSION_ALL] ['R', true, OC.PERMISSION_SHARE],
['CKGWDR', true, OC.PERMISSION_ALL]
]; ];
_.each(testCases, function(testCase) { _.each(testCases, function(testCase) {
return testPermission.apply(testCase); return testPermission.apply(this, testCase);
});
});
it('properly parses folder permissions', function() {
var testCases = [
['', false, OC.PERMISSION_READ],
['C', false, OC.PERMISSION_READ | OC.PERMISSION_CREATE | OC.PERMISSION_UPDATE],
['K', false, OC.PERMISSION_READ | OC.PERMISSION_CREATE | OC.PERMISSION_UPDATE],
['W', false, OC.PERMISSION_READ | OC.PERMISSION_UPDATE],
['D', false, OC.PERMISSION_READ | OC.PERMISSION_DELETE],
['R', false, OC.PERMISSION_READ | OC.PERMISSION_SHARE],
['CKWDR', false, OC.PERMISSION_ALL]
];
_.each(testCases, function(testCase) {
return testPermission.apply(testCase);
}); });
}); });
it('properly parses mount types', function() { it('properly parses mount types', function() {
var testCases = [ var testCases = [
['CKWDR', false, null], ['CKGWDR', false, null],
['M', false, 'external'], ['M', false, 'external'],
['S', false, 'shared'], ['S', false, 'shared'],
['SM', false, 'shared'] ['SM', false, 'shared']
]; ];
_.each(testCases, function(testCase) { _.each(testCases, function(testCase) {
return testMountType.apply(testCase); return testMountType.apply(this, testCase);
}); });
}); });
}); });