From ab9a36e872173b34be2e678de0c452885e3b48d8 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 26 Apr 2017 14:53:11 +0200 Subject: [PATCH] allow apps to set custom mount types Signed-off-by: Robin Appelman --- apps/dav/lib/Connector/Sabre/FilesPlugin.php | 6 ++++ apps/files/js/filelist.js | 2 ++ apps/files/lib/Helper.php | 9 ++---- .../lib/Config/ExternalMountPoint.php | 30 +++++++++++++++++++ apps/files_sharing/lib/SharedMount.php | 4 +++ core/js/files/client.js | 11 ++++++- lib/private/Files/Mount/MountPoint.php | 4 +++ lib/public/Files/Mount/IMountPoint.php | 9 ++++++ 8 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 apps/files_external/lib/Config/ExternalMountPoint.php diff --git a/apps/dav/lib/Connector/Sabre/FilesPlugin.php b/apps/dav/lib/Connector/Sabre/FilesPlugin.php index a4f3f363a5..4c426dd105 100644 --- a/apps/dav/lib/Connector/Sabre/FilesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesPlugin.php @@ -65,6 +65,7 @@ class FilesPlugin extends ServerPlugin { const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums'; const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint'; const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview'; + const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type'; /** * Reference to main server object @@ -159,6 +160,7 @@ class FilesPlugin extends ServerPlugin { $server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME; $server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME; $server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME; + $server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME; // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH $allowedProperties = ['{DAV:}getetag']; @@ -381,6 +383,10 @@ class FilesPlugin extends ServerPlugin { return $node->getSize(); }); } + + $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { + return $node->getFileInfo()->getMountPoint()->getMountType(); + }); } /** diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 6b5b5a2dae..047131f3d7 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -1069,6 +1069,8 @@ return OC.MimeType.getIconUrl('dir-shared'); } else if (fileInfo.mountType === 'external-root') { return OC.MimeType.getIconUrl('dir-external'); + } else if (fileInfo.mountType !== '') { + return OC.MimeType.getIconUrl('dir-' + fileInfo.mountType); } return OC.MimeType.getIconUrl('dir'); } diff --git a/apps/files/lib/Helper.php b/apps/files/lib/Helper.php index c3d8095791..d2cebce5dd 100644 --- a/apps/files/lib/Helper.php +++ b/apps/files/lib/Helper.php @@ -157,12 +157,9 @@ class Helper { $entry['isShareMountPoint'] = $i['is_share_mount_point']; } $mountType = null; - if ($i->isShared()) { - $mountType = 'shared'; - } else if ($i->isMounted()) { - $mountType = 'external'; - } - if ($mountType !== null) { + $mount = $i->getMountPoint(); + $mountType = $mount->getMountType(); + if ($mountType !== '') { if ($i->getInternalPath() === '') { $mountType .= '-root'; } diff --git a/apps/files_external/lib/Config/ExternalMountPoint.php b/apps/files_external/lib/Config/ExternalMountPoint.php new file mode 100644 index 0000000000..76a090b7ec --- /dev/null +++ b/apps/files_external/lib/Config/ExternalMountPoint.php @@ -0,0 +1,30 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Files_External\Config; + +use OC\Files\Mount\MountPoint; + +class ExternalMountPoint extends MountPoint { + public function getMountType() { + return 'external'; + } +} diff --git a/apps/files_sharing/lib/SharedMount.php b/apps/files_sharing/lib/SharedMount.php index d5ae303390..b42682ab2a 100644 --- a/apps/files_sharing/lib/SharedMount.php +++ b/apps/files_sharing/lib/SharedMount.php @@ -258,4 +258,8 @@ class SharedMount extends MountPoint implements MoveableMount { return -1; } } + + public function getMountType() { + return 'shared'; + } } diff --git a/core/js/files/client.js b/core/js/files/client.js index cde3afde9d..e8cf5b9bdb 100644 --- a/core/js/files/client.js +++ b/core/js/files/client.js @@ -114,7 +114,11 @@ /** * Preview availability */ - [Client.NS_NEXTCLOUD, 'has-preview'] + [Client.NS_NEXTCLOUD, 'has-preview'], + /** + * Mount type + */ + [Client.NS_NEXTCLOUD, 'mount-type'], ]; /** @@ -361,6 +365,11 @@ } } + var mounTypeProp = props['{' + Client.NS_NEXTCLOUD + '}mount-type']; + if (!_.isUndefined(mounTypeProp)) { + data.mountType = mounTypeProp; + } + // extend the parsed data using the custom parsers _.each(this._fileInfoParsers, function(parserFunction) { _.extend(data, parserFunction(response) || {}); diff --git a/lib/private/Files/Mount/MountPoint.php b/lib/private/Files/Mount/MountPoint.php index 42b79596c9..e7a37e382f 100644 --- a/lib/private/Files/Mount/MountPoint.php +++ b/lib/private/Files/Mount/MountPoint.php @@ -274,4 +274,8 @@ class MountPoint implements IMountPoint { public function getMountId() { return $this->mountId; } + + public function getMountType() { + return ''; + } } diff --git a/lib/public/Files/Mount/IMountPoint.php b/lib/public/Files/Mount/IMountPoint.php index 0876d8b11d..47830c68ff 100644 --- a/lib/public/Files/Mount/IMountPoint.php +++ b/lib/public/Files/Mount/IMountPoint.php @@ -119,4 +119,13 @@ interface IMountPoint { * @since 9.1.0 */ public function getMountId(); + + /** + * Get the type of mount point, used to distinguish things like shares and external storages + * in the web interface + * + * @return string + * @since 12.0.0 + */ + public function getMountType(); }