Browse Source

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>
tags/v14.0.0beta1
Daniel Calviño Sánchez 6 years ago
parent
commit
2c073dc53d
1 changed files with 10 additions and 2 deletions
  1. 10
    2
      apps/files_sharing/lib/Controller/ShareAPIController.php

+ 10
- 2
apps/files_sharing/lib/Controller/ShareAPIController.php View File

@@ -207,8 +207,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);
}



Loading…
Cancel
Save