diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2015-08-12 17:05:20 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2015-08-26 11:54:24 +0200 |
commit | c6ed40c9f891454d8f9ceeb67c45ff3d8ce22537 (patch) | |
tree | 566af906922513157a8332161829ddd3668a281b /apps/files_sharing/api/sharees.php | |
parent | 068a81897e0a307b7823aeab48595ed7b6f613b0 (diff) | |
download | nextcloud-server-c6ed40c9f891454d8f9ceeb67c45ff3d8ce22537.tar.gz nextcloud-server-c6ed40c9f891454d8f9ceeb67c45ff3d8ce22537.zip |
Make shareType an array
Diffstat (limited to 'apps/files_sharing/api/sharees.php')
-rw-r--r-- | apps/files_sharing/api/sharees.php | 57 |
1 files changed, 44 insertions, 13 deletions
diff --git a/apps/files_sharing/api/sharees.php b/apps/files_sharing/api/sharees.php index bfde21deb2a..de5f9c8cbf4 100644 --- a/apps/files_sharing/api/sharees.php +++ b/apps/files_sharing/api/sharees.php @@ -184,13 +184,46 @@ class Sharees { $search = isset($_GET['search']) ? (string) $_GET['search'] : ''; $itemType = isset($_GET['itemType']) ? (string) $_GET['itemType'] : null; $existingShares = isset($_GET['existingShares']) ? (array) $_GET['existingShares'] : []; - $shareType = isset($_GET['shareType']) && is_numeric($_GET['shareType']) ? (int) $_GET['shareType'] : null; - $page = !empty($_GET['page']) ? (int) $_GET['page'] : 1; - $perPage = !empty($_GET['limit']) ? (int) $_GET['limit'] : 200; + $page = !empty($_GET['page']) ? max(1, (int) $_GET['page']) : 1; + $perPage = !empty($_GET['limit']) ? max(1, (int) $_GET['limit']) : 200; + + $shareTypes = [ + \OCP\Share::SHARE_TYPE_USER, + \OCP\Share::SHARE_TYPE_GROUP, + \OCP\Share::SHARE_TYPE_REMOTE, + ]; + if (isset($_GET['shareType']) && is_array($_GET['shareType'])) { + $shareTypes = array_intersect($shareTypes, $_GET['shareType']); + sort($shareTypes); + + } else if (isset($_GET['shareType']) && is_numeric($_GET['shareType'])) { + $shareTypes = array_intersect($shareTypes, [(int) $_GET['shareType']]); + sort($shareTypes); + } + + if (in_array(\OCP\Share::SHARE_TYPE_REMOTE, $shareTypes) && !$this->isRemoteSharingAllowed($itemType)) { + // Remove remote shares from type array, because it is not allowed. + $shareTypes = array_diff($shareTypes, [\OCP\Share::SHARE_TYPE_REMOTE]); + } $shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; - return $this->searchSharees($search, $itemType, $existingShares, $shareType, $page, $perPage, $shareWithGroupOnly); + return $this->searchSharees($search, $itemType, $existingShares, $shareTypes, $page, $perPage, $shareWithGroupOnly); + } + + /** + * Method to get out the static call for better testing + * + * @param string $itemType + * @return bool + */ + protected function isRemoteSharingAllowed($itemType) { + try { + $backend = \OCP\Share::getBackend($itemType); + return $backend->isShareTypeAllowed(\OCP\Share::SHARE_TYPE_REMOTE); + } catch (\Exception $e) { + return false; + } } /** @@ -199,13 +232,13 @@ class Sharees { * @param string $search * @param string $itemType * @param array $existingShares - * @param int $shareType + * @param array $shareTypes * @param int $page * @param int $perPage * @param bool $shareWithGroupOnly * @return \OC_OCS_Result */ - protected function searchSharees($search, $itemType, array $existingShares, $shareType, $page, $perPage, $shareWithGroupOnly) { + protected function searchSharees($search, $itemType, array $existingShares, array $shareTypes, $page, $perPage, $shareWithGroupOnly) { $sharedUsers = $sharedGroups = []; if (!empty($existingShares)) { @@ -227,20 +260,19 @@ class Sharees { $sharees = []; // Get users - if ($shareType === null || $shareType === \OCP\Share::SHARE_TYPE_USER) { + if (in_array(\OCP\Share::SHARE_TYPE_USER, $shareTypes)) { $potentialSharees = $this->getUsers($search, $shareWithGroupOnly); $sharees = array_merge($sharees, $this->filterSharees($potentialSharees, $sharedUsers)); } // Get groups - if ($shareType === null || $shareType === \OCP\Share::SHARE_TYPE_GROUP) { + if (in_array(\OCP\Share::SHARE_TYPE_GROUP, $shareTypes)) { $potentialSharees = $this->getGroups($search, $shareWithGroupOnly); $sharees = array_merge($sharees, $this->filterSharees($potentialSharees, $sharedGroups)); } // Get remote - if (($shareType === null || $shareType === \OCP\Share::SHARE_TYPE_REMOTE) && - \OCP\Share::getBackend($itemType)->isShareTypeAllowed(\OCP\Share::SHARE_TYPE_REMOTE)) { + if (in_array(\OCP\Share::SHARE_TYPE_REMOTE, $shareTypes)) { $sharees = array_merge($sharees, $this->getRemote($search)); } @@ -267,12 +299,11 @@ class Sharees { 'search' => $search, 'itemType' => $itemType, 'existingShares' => $existingShares, + 'shareType' => $shareTypes, 'page' => $page + 1, 'limit' => $perPage, ]; - if ($shareType !== null) { - $params['shareType'] = $shareType; - } + $url = $this->urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/sharees') . '?' . http_build_query($params); $response->addHeader('Link', '<' . $url . '> rel="next"'); } |