summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2018-03-16 04:23:46 +0100
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2018-03-20 19:42:27 +0100
commitdf5cd18394dea317b51432f7a214d4f88f5ba2e4 (patch)
tree637877df3d8d269dc2be14a5762ac3821a1c261f /apps/files_sharing
parenta6f1721c2d1fa13a6f2cd48556392327fee64151 (diff)
downloadnextcloud-server-df5cd18394dea317b51432f7a214d4f88f5ba2e4.tar.gz
nextcloud-server-df5cd18394dea317b51432f7a214d4f88f5ba2e4.zip
Set "share_with" field to the ID of the circle
When a share is shared with a circle the "share_with" field returned by the API endpoint was always set to the name of the circle. However, the name is not enough to identify a circle. The Circles app now provides the ID of the circle in the "shared with" field of a Share, so this commit modifies the API endpoint to set the "share_with" field to the ID of the circle when provided by the Circles app. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php12
1 files changed, 10 insertions, 2 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index 10876e16568..82a93c446e2 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -200,8 +200,16 @@ class ShareAPIController extends OCSController {
$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL');
$result['token'] = $share->getToken();
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) {
- $result['share_with_displayname'] = $share->getSharedWith();
- $result['share_with'] = explode(' ', $share->getSharedWith(), 2)[0];
+ // getSharedWith() returns either "name (type, owner)" or
+ // "name (type, owner) [id]", depending on the Circles app version.
+ $hasCircleId = (substr($share->getSharedWith(), -1) === ']');
+
+ $displayNameLength = ($hasCircleId? strrpos($share->getSharedWith(), ' '): strlen($share->getSharedWith()));
+ $result['share_with_displayname'] = substr($share->getSharedWith(), 0, $displayNameLength);
+
+ $shareWithStart = ($hasCircleId? strrpos($share->getSharedWith(), '[') + 1: 0);
+ $shareWithLength = ($hasCircleId? -1: strpos($share->getSharedWith(), ' '));
+ $result['share_with'] = substr($share->getSharedWith(), $shareWithStart, $shareWithLength);
}