diff options
author | Maxence Lange <maxence@nextcloud.com> | 2017-03-17 18:48:33 -0100 |
---|---|---|
committer | Maxence Lange <maxence@nextcloud.com> | 2017-03-17 18:48:33 -0100 |
commit | 69694012ab0eca1ec1f3dc0d2b10a3b1728b0927 (patch) | |
tree | f79ec80ba1eefb73884c723718d8fa5c76cbf203 /apps/files_sharing/lib | |
parent | 3c66ad64e626cb602685a640c235d472f0777a53 (diff) | |
download | nextcloud-server-69694012ab0eca1ec1f3dc0d2b10a3b1728b0927.tar.gz nextcloud-server-69694012ab0eca1ec1f3dc0d2b10a3b1728b0927.zip |
shares-circles
Signed-off-by: Maxence Lange <maxence@nextcloud.com>
Diffstat (limited to 'apps/files_sharing/lib')
-rw-r--r-- | apps/files_sharing/lib/Controller/ShareAPIController.php | 44 | ||||
-rw-r--r-- | apps/files_sharing/lib/Controller/ShareesAPIController.php | 29 | ||||
-rw-r--r-- | apps/files_sharing/lib/MountProvider.php | 3 |
3 files changed, 74 insertions, 2 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 6181cde6fe6..711970d0c84 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -192,8 +192,12 @@ class ShareAPIController extends OCSController { $result['share_with'] = $share->getSharedWith(); $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]; } + $result['mail_send'] = $share->getMailSend() ? 1 : 0; return $result; @@ -443,6 +447,19 @@ class ShareAPIController extends OCSController { \OCP\Constants::PERMISSION_DELETE); } $share->setSharedWith($shareWith); + } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { + if (!\OCP\App::isEnabled('circles')) { + throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled')); + } + + $circle = \OCA\Circles\Api\Circles::detailsCircle($shareWith); + + // Valid circle is required to share + if ($circle === null) { + throw new OCSNotFoundException($this->l->t('Please specify a valid circle')); + } + $share->setSharedWith($shareWith); + $share->setPermissions($permissions); } else { throw new OCSBadRequestException($this->l->t('Unknown share type')); } @@ -469,10 +486,12 @@ class ShareAPIController extends OCSController { * @return DataResponse */ private function getSharedWithMe($node = null) { + $userShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, -1, 0); $groupShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0); + $circleShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $node, -1, 0); - $shares = array_merge($userShares, $groupShares); + $shares = array_merge($userShares, $groupShares, $circleShares); $shares = array_filter($shares, function (IShare $share) { return $share->getShareOwner() !== $this->currentUser; @@ -592,7 +611,13 @@ class ShareAPIController extends OCSController { } else { $mailShares = []; } - $shares = array_merge($userShares, $groupShares, $linkShares, $mailShares); + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { + $circleShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $path, $reshares, -1, 0); + } else { + $circleShares = []; + } + + $shares = array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares); if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { $federatedShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0); @@ -784,6 +809,11 @@ class ShareAPIController extends OCSController { } } + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { + // TODO: have a sanity check like above? + return true; + } + return false; } @@ -832,6 +862,16 @@ class ShareAPIController extends OCSController { // Do nothing, just try the other share type } + + try { + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { + $share = $this->shareManager->getShareById('ocCircleShare:' . $id); + return $share; + } + } catch (ShareNotFound $e) { + // Do nothing, just try the other share type + } + try { if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { $share = $this->shareManager->getShareById('ocMailShare:' . $id); diff --git a/apps/files_sharing/lib/Controller/ShareesAPIController.php b/apps/files_sharing/lib/Controller/ShareesAPIController.php index e4b5b0ce19c..eb65727c770 100644 --- a/apps/files_sharing/lib/Controller/ShareesAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareesAPIController.php @@ -92,12 +92,14 @@ class ShareesAPIController extends OCSController { 'groups' => [], 'remotes' => [], 'emails' => [], + 'circles' => [], ], 'users' => [], 'groups' => [], 'remotes' => [], 'emails' => [], 'lookup' => [], + 'circles' => [], ]; protected $reachedEndFor = []; @@ -294,6 +296,23 @@ class ShareesAPIController extends OCSController { } } + + /** + * @param string $search + */ + protected function getCircles($search) { + $this->result['circles'] = $this->result['exact']['circles'] = []; + + $result = \OCA\Circles\Api\Sharees::search($search, $this->limit, $this->offset); + if (array_key_exists('circles', $result['exact'])) { + $this->result['exact']['circles'] = $result['exact']['circles']; + } + if (array_key_exists('circles', $result)) { + $this->result['circles'] = $result['circles']; + } + } + + /** * @param string $search * @return array @@ -453,6 +472,10 @@ class ShareesAPIController extends OCSController { $shareTypes[] = Share::SHARE_TYPE_EMAIL; } + if (\OCP\App::isEnabled('circles')) { + $shareTypes[] = Share::SHARE_TYPE_CIRCLE; + } + if (isset($_GET['shareType']) && is_array($_GET['shareType'])) { $shareTypes = array_intersect($shareTypes, $_GET['shareType']); sort($shareTypes); @@ -512,6 +535,12 @@ class ShareesAPIController extends OCSController { $this->getGroups($search); } + // Get circles + if (in_array(Share::SHARE_TYPE_CIRCLE, $shareTypes)) { + $this->getCircles($search); + } + + // Get remote $remoteResults = ['results' => [], 'exact' => [], 'exactIdMatch' => false]; if (in_array(Share::SHARE_TYPE_REMOTE, $shareTypes)) { diff --git a/apps/files_sharing/lib/MountProvider.php b/apps/files_sharing/lib/MountProvider.php index 5c5d57057b2..f474190fc98 100644 --- a/apps/files_sharing/lib/MountProvider.php +++ b/apps/files_sharing/lib/MountProvider.php @@ -68,8 +68,11 @@ class MountProvider implements IMountProvider { * @return \OCP\Files\Mount\IMountPoint[] */ public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) { + $shares = $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_USER, null, -1); $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_GROUP, null, -1)); + $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_CIRCLE, null, -1)); + // filter out excluded shares and group shares that includes self $shares = array_filter($shares, function (\OCP\Share\IShare $share) use ($user) { return $share->getPermissions() > 0 && $share->getShareOwner() !== $user->getUID(); |