Merge pull request #8564 from nextcloud/files_external_read_only

Make it possible to make external storages read only
This commit is contained in:
Morris Jobke 2018-05-01 23:39:30 +02:00 committed by GitHub
commit e9c6ec4b22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 7 deletions

View file

@ -272,7 +272,7 @@ abstract class Node implements \Sabre\DAV\INode {
$mountpointpath = substr($mountpointpath, 0, -1);
}
if ($mountpointpath === $this->info->getPath()) {
if (!$mountpoint->getOption('readonly', false) && $mountpointpath === $this->info->getPath()) {
$permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE;
}
}

View file

@ -48,6 +48,12 @@ var MOUNT_OPTIONS_DROPDOWN_TEMPLATE =
' <label for="mountOptionsEncoding">{{mountOptionsEncodingLabel}}</label>'+
' </span>'+
' </li>'+
' <li class="optionRow">' +
' <span class="menuitem">' +
' <input id="mountOptionsReadOnly" class="checkbox" name="readonly" type="checkbox" value="true"/>' +
' <label for="mountOptionsReadOnly">{{t "files_external" "Read only"}}</label>' +
' </span>' +
' </li>' +
' </ul>'+
'</div>';
@ -916,7 +922,8 @@ MountConfigListView.prototype = _.extend({
'previews': true,
'enable_sharing': false,
'filesystem_check_changes': 1,
'encoding_compatibility': false
'encoding_compatibility': false,
'readonly': false,
}));
}
@ -1303,7 +1310,8 @@ MountConfigListView.prototype = _.extend({
'previews',
'filesystem_check_changes',
'enable_sharing',
'encoding_compatibility'
'encoding_compatibility',
'readonly'
];
if (this._encryptionEnabled) {
visibleOptions.push('encrypt');

View file

@ -192,7 +192,8 @@ class ListCommand extends Base {
'previews' => true,
'filesystem_check_changes' => 1,
'enable_sharing' => false,
'encoding_compatibility' => false
'encoding_compatibility' => false,
'readonly' => false,
];
$rows = array_map(function (StorageConfig $config) use ($userId, $defaultMountOptions, $full) {
$storageConfig = $config->getBackendOptions();

View file

@ -12,6 +12,7 @@
$l->t("Check for changes");
$l->t("Never");
$l->t("Once every direct access");
$l->t('Read only');
script('files_external', 'settings');
style('files_external', 'settings');

View file

@ -376,7 +376,8 @@ describe('OCA.External.Settings tests', function() {
previews: true,
enable_sharing: false,
filesystem_check_changes: 0,
encoding_compatibility: false
encoding_compatibility: false,
readonly: false
});
});
});

View file

@ -727,7 +727,8 @@ describe('OCA.Sharing.FileList tests', function() {
etag: 'abc',
shareOwner: 'User One',
recipients: 'User Two',
mountType: 'external-root'
mountType: 'external-root',
sharePermissions: OC.PERMISSION_READ,
}]);
$tr = fileList.$el.find('tr:first');
@ -749,7 +750,8 @@ describe('OCA.Sharing.FileList tests', function() {
etag: 'abc',
shareOwner: 'User One',
recipients: 'User Two',
mountType: 'external-root'
mountType: 'external-root',
sharePermissions: OC.PERMISSION_READ | OC.PERMISSION_SHARE,
}]);
$tr = fileList.$el.find('tr:first');

View file

@ -259,6 +259,23 @@ class OC_Util {
return $storage;
});
\OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) {
/*
* Do not allow any operations that modify the storage
*/
if ($mount->getOption('readonly', false)) {
return new \OC\Files\Storage\Wrapper\PermissionsMask([
'storage' => $storage,
'mask' => \OCP\Constants::PERMISSION_ALL & ~(
\OCP\Constants::PERMISSION_UPDATE |
\OCP\Constants::PERMISSION_CREATE |
\OCP\Constants::PERMISSION_DELETE
),
]);
}
return $storage;
});
OC_Hook::emit('OC_Filesystem', 'preSetup', array('user' => $user));
\OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(true);