Example app for creating virtual folders
Example app for creating virtual folders
Requires https://github.com/nextcloud/server/pull/29886
The app in its base form allows the admin to setup virtual folders using occ commands.
Once a folder is configured it will show up at the configured mount point for the target user as a folder containing the provided files. The virtual folder itself will be read only while the configured files contained inside will have the full permissions from the source user.
occ virtualfolder:create <target user> <name> [<file ids>...]
occ virtualfolder:list
occ virtualfolder:delete <folder id>
occ virtualfolder:move <folder id> <new mount point>
Note that the provided mountpoint is absolute.
The app is setup to be easily adaptable into apps that create virtual folders for specific use cases.
Custom logic for configuring virtual folders can be setup in lib/Folder/FolderConfigManager.php
by adding your own logic to the getFoldersForUser
method.
All other methods in that class are only used by unit tests and the management command and can thus be removed
if you remove the management commands.
Permissions of files in the virtual folder can be restricted by changing getStorageForSourceFile
in lib/Mount/VirtualFolderMountProvider
to wrap the created Jail
storage wrapper into a PermissionsMask
wrapper
to apply a mask to the permissions for the files in the virtual folder.
virtual folders are exposed trough webdav under the virtualfolder
endpoint.
curl -u user:password -X MKCOL 'https://cloud.example.com/dav/virtualfolder/user/my_folder_name
Note: virtual folders created trough webdav will within the users hidden directory and thus will not be visible in the normal files UI.
It can still be accessed through the normal filesystem and dav apis at /.hidden_<instance_id>/my_folder_name/
.
curl -u user:password -X PROPFIND 'https://cloud.example.com/dav/virtualfolder/user
curl -X COPY -u user:password -H 'Destination: https://cloud.example.com/dav/virtualfolder/user/my_folder_name/file.txt' 'https://cloud.example.com/remote.php/dav/files/user/file.txt'
curl -u user:password -X PROPFIND 'https://cloud.example.com/dav/virtualfolder/user/my_folder_name
When listing a folder you can request the {http://nextcloud.org/ns}canonical-path
property to get the path to the file in the hidden user folder, this path can be used through the normal dav apis.
curl -u user:password -X DELETE 'https://cloud.example.com/dav/virtualfolder/user/my_folder_name/file.txt
AppInfo
Application
: setup the app by registering the mount providedCommand/*
: commands to allow the admin to configure virtual mountsFolder
FolderConfig
: data class to store information for a configured folderFolderConfigManager
: manage configured virtual foldersSourceFile
: holds the data of each source file in the virtual folder and allows access to the source storageVirtualFolder
: data class for virtual folders and source file informationVirtualFolderFactory
: get folder and source file info from folder configurationMigration
: database migration script for storing admin configured virtual foldersMount
VirtualFolderMount
: MountPoint
subclass to allow setting a custom folder iconVirtualFolderMountProvider
: mount provider that setups up all mounts required for the virtual folderStorage
EmptyStorage
: an empty readonly storage for use as the virtual folder rootLazyWrapper
: a storage wrapper that allows delaying setup of the source storage until the storage is usedLazeCacheWrapper
: same as LazyWrapper
but then for the source cache