2015-08-08 22:15:12 +02:00
|
|
|
<?php
|
2019-12-03 19:57:53 +01:00
|
|
|
|
2018-04-23 22:05:21 +02:00
|
|
|
declare(strict_types=1);
|
2015-08-08 22:15:12 +02:00
|
|
|
/**
|
2024-06-06 19:48:28 +02:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-08-08 22:15:12 +02:00
|
|
|
*/
|
2016-08-26 10:52:06 +02:00
|
|
|
namespace OCA\Files_Sharing\Controller;
|
2015-08-08 22:15:12 +02:00
|
|
|
|
2019-02-13 17:16:01 +01:00
|
|
|
use Generator;
|
|
|
|
use OC\Collaboration\Collaborators\SearchResult;
|
2024-10-10 12:40:31 +02:00
|
|
|
use OC\Share\Share;
|
2023-02-15 19:22:09 +01:00
|
|
|
use OCA\Files_Sharing\ResponseDefinitions;
|
|
|
|
use OCP\AppFramework\Http;
|
2024-07-25 13:14:46 +02:00
|
|
|
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
|
2017-02-21 17:24:40 -06:00
|
|
|
use OCP\AppFramework\Http\DataResponse;
|
2016-08-26 10:52:06 +02:00
|
|
|
use OCP\AppFramework\OCS\OCSBadRequestException;
|
|
|
|
use OCP\AppFramework\OCSController;
|
2017-08-31 22:47:02 +02:00
|
|
|
use OCP\Collaboration\Collaborators\ISearch;
|
2019-02-13 17:16:01 +01:00
|
|
|
use OCP\Collaboration\Collaborators\ISearchResult;
|
|
|
|
use OCP\Collaboration\Collaborators\SearchResultType;
|
2020-12-12 00:25:10 +01:00
|
|
|
use OCP\Constants;
|
2025-03-10 16:24:26 +01:00
|
|
|
use OCP\GlobalScale\IConfig as GlobalScaleIConfig;
|
2015-08-12 14:23:48 +02:00
|
|
|
use OCP\IConfig;
|
2019-11-22 20:52:10 +01:00
|
|
|
use OCP\IRequest;
|
2015-08-08 22:15:12 +02:00
|
|
|
use OCP\IURLGenerator;
|
2017-08-31 22:47:02 +02:00
|
|
|
use OCP\Share\IManager;
|
2020-04-21 08:42:28 +02:00
|
|
|
use OCP\Share\IShare;
|
2019-02-13 17:16:01 +01:00
|
|
|
use function array_slice;
|
|
|
|
use function array_values;
|
|
|
|
use function usort;
|
2015-08-08 22:15:12 +02:00
|
|
|
|
2023-02-15 19:22:09 +01:00
|
|
|
/**
|
2023-10-23 16:47:38 +02:00
|
|
|
* @psalm-import-type Files_SharingShareesSearchResult from ResponseDefinitions
|
|
|
|
* @psalm-import-type Files_SharingShareesRecommendedResult from ResponseDefinitions
|
2023-02-15 19:22:09 +01:00
|
|
|
*/
|
2016-08-26 10:52:06 +02:00
|
|
|
class ShareesAPIController extends OCSController {
|
2019-02-13 17:16:01 +01:00
|
|
|
|
2015-08-26 09:40:20 +02:00
|
|
|
/** @var int */
|
|
|
|
protected $offset = 0;
|
|
|
|
|
|
|
|
/** @var int */
|
|
|
|
protected $limit = 10;
|
|
|
|
|
2023-10-23 16:47:38 +02:00
|
|
|
/** @var Files_SharingShareesSearchResult */
|
2015-08-26 09:40:20 +02:00
|
|
|
protected $result = [
|
|
|
|
'exact' => [
|
|
|
|
'users' => [],
|
|
|
|
'groups' => [],
|
|
|
|
'remotes' => [],
|
2018-07-02 11:29:03 +02:00
|
|
|
'remote_groups' => [],
|
2016-10-24 13:16:05 +02:00
|
|
|
'emails' => [],
|
2017-03-17 18:48:33 -01:00
|
|
|
'circles' => [],
|
2018-07-16 03:48:50 +02:00
|
|
|
'rooms' => [],
|
2015-08-26 09:40:20 +02:00
|
|
|
],
|
|
|
|
'users' => [],
|
|
|
|
'groups' => [],
|
|
|
|
'remotes' => [],
|
2018-07-02 11:29:03 +02:00
|
|
|
'remote_groups' => [],
|
2016-10-24 13:16:05 +02:00
|
|
|
'emails' => [],
|
2016-11-18 14:08:42 +01:00
|
|
|
'lookup' => [],
|
2017-03-17 18:48:33 -01:00
|
|
|
'circles' => [],
|
2018-07-16 03:48:50 +02:00
|
|
|
'rooms' => [],
|
2019-02-21 21:36:14 +01:00
|
|
|
'lookupEnabled' => false,
|
2015-08-26 09:40:20 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
protected $reachedEndFor = [];
|
2015-08-13 10:13:23 +02:00
|
|
|
|
2017-08-31 22:47:02 +02:00
|
|
|
public function __construct(
|
2018-04-23 22:05:21 +02:00
|
|
|
string $appName,
|
2017-08-31 22:47:02 +02:00
|
|
|
IRequest $request,
|
2025-01-06 12:46:19 +01:00
|
|
|
protected ?string $userId,
|
2024-03-15 15:51:15 +01:00
|
|
|
protected IConfig $config,
|
|
|
|
protected IURLGenerator $urlGenerator,
|
|
|
|
protected IManager $shareManager,
|
|
|
|
protected ISearch $collaboratorSearch,
|
2017-01-27 12:52:17 +01:00
|
|
|
) {
|
2016-08-26 10:52:06 +02:00
|
|
|
parent::__construct($appName, $request);
|
2016-02-12 15:27:39 +01:00
|
|
|
}
|
|
|
|
|
2015-08-12 14:19:34 +02:00
|
|
|
/**
|
2023-02-15 19:22:09 +01:00
|
|
|
* Search for sharees
|
|
|
|
*
|
|
|
|
* @param string $search Text to search for
|
|
|
|
* @param string|null $itemType Limit to specific item types
|
|
|
|
* @param int $page Page offset for searching
|
|
|
|
* @param int $perPage Limit amount of search results per page
|
2024-09-24 15:53:13 +02:00
|
|
|
* @param int|list<int>|null $shareType Limit to specific share types
|
2023-02-15 19:22:09 +01:00
|
|
|
* @param bool $lookup If a global lookup should be performed too
|
2023-10-23 16:47:38 +02:00
|
|
|
* @return DataResponse<Http::STATUS_OK, Files_SharingShareesSearchResult, array{Link?: string}>
|
2023-02-15 19:22:09 +01:00
|
|
|
* @throws OCSBadRequestException Invalid search parameters
|
|
|
|
*
|
|
|
|
* 200: Sharees search result returned
|
2015-08-12 14:19:34 +02:00
|
|
|
*/
|
2024-07-25 13:14:46 +02:00
|
|
|
#[NoAdminRequired]
|
2024-03-28 16:13:19 +01:00
|
|
|
public function search(string $search = '', ?string $itemType = null, int $page = 1, int $perPage = 200, $shareType = null, bool $lookup = false): DataResponse {
|
2017-02-21 18:10:38 +01:00
|
|
|
|
|
|
|
// only search for string larger than a given threshold
|
2021-04-12 22:53:34 +02:00
|
|
|
$threshold = $this->config->getSystemValueInt('sharing.minSearchStringLength', 0);
|
2017-02-21 18:10:38 +01:00
|
|
|
if (strlen($search) < $threshold) {
|
2017-02-21 17:24:40 -06:00
|
|
|
return new DataResponse($this->result);
|
2017-02-21 18:10:38 +01:00
|
|
|
}
|
|
|
|
|
2024-03-15 15:51:15 +01:00
|
|
|
if ($this->shareManager->sharingDisabledForUser($this->userId)) {
|
|
|
|
return new DataResponse($this->result);
|
|
|
|
}
|
|
|
|
|
2017-02-21 18:10:38 +01:00
|
|
|
// never return more than the max. number of results configured in the config.php
|
2020-12-12 00:25:10 +01:00
|
|
|
$maxResults = $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT);
|
2017-02-21 18:10:38 +01:00
|
|
|
if ($maxResults > 0) {
|
|
|
|
$perPage = min($perPage, $maxResults);
|
|
|
|
}
|
2015-09-15 12:37:09 +02:00
|
|
|
if ($perPage <= 0) {
|
2016-08-26 10:52:06 +02:00
|
|
|
throw new OCSBadRequestException('Invalid perPage argument');
|
2015-09-15 12:37:09 +02:00
|
|
|
}
|
|
|
|
if ($page <= 0) {
|
2016-08-26 10:52:06 +02:00
|
|
|
throw new OCSBadRequestException('Invalid page');
|
2015-09-15 12:37:09 +02:00
|
|
|
}
|
2015-08-12 17:05:20 +02:00
|
|
|
|
|
|
|
$shareTypes = [
|
2020-04-21 08:42:28 +02:00
|
|
|
IShare::TYPE_USER,
|
2015-08-12 17:05:20 +02:00
|
|
|
];
|
2016-03-18 16:39:03 +01:00
|
|
|
|
2017-08-31 22:47:02 +02:00
|
|
|
if ($itemType === null) {
|
|
|
|
throw new OCSBadRequestException('Missing itemType');
|
|
|
|
} elseif ($itemType === 'file' || $itemType === 'folder') {
|
2016-11-10 14:16:35 +01:00
|
|
|
if ($this->shareManager->allowGroupSharing()) {
|
2020-04-21 08:42:28 +02:00
|
|
|
$shareTypes[] = IShare::TYPE_GROUP;
|
2016-11-10 14:16:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->isRemoteSharingAllowed($itemType)) {
|
2020-04-21 08:42:28 +02:00
|
|
|
$shareTypes[] = IShare::TYPE_REMOTE;
|
2016-11-10 14:16:35 +01:00
|
|
|
}
|
|
|
|
|
2018-07-02 11:29:03 +02:00
|
|
|
if ($this->isRemoteGroupSharingAllowed($itemType)) {
|
2020-04-21 08:42:28 +02:00
|
|
|
$shareTypes[] = IShare::TYPE_REMOTE_GROUP;
|
2018-07-02 11:29:03 +02:00
|
|
|
}
|
|
|
|
|
2020-04-21 08:42:28 +02:00
|
|
|
if ($this->shareManager->shareProviderExists(IShare::TYPE_EMAIL)) {
|
|
|
|
$shareTypes[] = IShare::TYPE_EMAIL;
|
2016-11-10 14:16:35 +01:00
|
|
|
}
|
2018-07-16 03:48:50 +02:00
|
|
|
|
2020-04-21 08:42:28 +02:00
|
|
|
if ($this->shareManager->shareProviderExists(IShare::TYPE_ROOM)) {
|
|
|
|
$shareTypes[] = IShare::TYPE_ROOM;
|
2018-07-16 03:48:50 +02:00
|
|
|
}
|
2023-02-20 09:50:31 +00:00
|
|
|
|
|
|
|
if ($this->shareManager->shareProviderExists(IShare::TYPE_SCIENCEMESH)) {
|
|
|
|
$shareTypes[] = IShare::TYPE_SCIENCEMESH;
|
|
|
|
}
|
2016-11-10 14:16:35 +01:00
|
|
|
} else {
|
2021-01-29 15:59:41 +01:00
|
|
|
if ($this->shareManager->allowGroupSharing()) {
|
|
|
|
$shareTypes[] = IShare::TYPE_GROUP;
|
|
|
|
}
|
2020-04-21 08:42:28 +02:00
|
|
|
$shareTypes[] = IShare::TYPE_EMAIL;
|
2016-03-18 16:39:03 +01:00
|
|
|
}
|
|
|
|
|
2017-09-13 16:21:23 +02:00
|
|
|
// FIXME: DI
|
2017-07-11 13:21:24 +02:00
|
|
|
if (\OC::$server->getAppManager()->isEnabledForUser('circles') && class_exists('\OCA\Circles\ShareByCircleProvider')) {
|
2020-04-21 08:42:28 +02:00
|
|
|
$shareTypes[] = IShare::TYPE_CIRCLE;
|
2017-03-17 18:48:33 -01:00
|
|
|
}
|
|
|
|
|
2023-02-20 09:50:31 +00:00
|
|
|
if ($this->shareManager->shareProviderExists(IShare::TYPE_SCIENCEMESH)) {
|
|
|
|
$shareTypes[] = IShare::TYPE_SCIENCEMESH;
|
|
|
|
}
|
|
|
|
|
2020-01-05 15:51:16 +01:00
|
|
|
if ($shareType !== null && is_array($shareType)) {
|
|
|
|
$shareTypes = array_intersect($shareTypes, $shareType);
|
2020-04-10 10:35:09 +02:00
|
|
|
} elseif (is_numeric($shareType)) {
|
2016-08-26 10:52:06 +02:00
|
|
|
$shareTypes = array_intersect($shareTypes, [(int)$shareType]);
|
2015-08-12 17:05:20 +02:00
|
|
|
}
|
2020-01-05 15:51:16 +01:00
|
|
|
sort($shareTypes);
|
2015-08-12 17:05:20 +02:00
|
|
|
|
2021-01-11 12:57:03 +01:00
|
|
|
$this->limit = $perPage;
|
2015-08-26 09:40:20 +02:00
|
|
|
$this->offset = $perPage * ($page - 1);
|
2015-08-12 14:19:34 +02:00
|
|
|
|
2025-03-10 16:24:26 +01:00
|
|
|
// In global scale mode we always search the lookup server
|
|
|
|
$this->result['lookupEnabled'] = \OCP\Server::get(GlobalScaleIConfig::class)->isGlobalScaleEnabled();
|
|
|
|
// TODO: Reconsider using lookup server for non-global-scale federation
|
2019-11-28 10:48:06 +01:00
|
|
|
|
2025-03-10 16:24:26 +01:00
|
|
|
[$result, $hasMoreResults] = $this->collaboratorSearch->search($search, $shareTypes, $this->result['lookupEnabled'], $this->limit, $this->offset);
|
2017-03-17 18:48:33 -01:00
|
|
|
|
2017-09-06 22:51:18 +02:00
|
|
|
// extra treatment for 'exact' subarray, with a single merge expected keys might be lost
|
2017-09-13 12:32:47 +02:00
|
|
|
if (isset($result['exact'])) {
|
|
|
|
$result['exact'] = array_merge($this->result['exact'], $result['exact']);
|
|
|
|
}
|
2017-09-06 16:09:29 +02:00
|
|
|
$this->result = array_merge($this->result, $result);
|
|
|
|
$response = new DataResponse($this->result);
|
2017-03-17 18:48:33 -01:00
|
|
|
|
2017-08-31 22:47:02 +02:00
|
|
|
if ($hasMoreResults) {
|
2023-02-15 19:22:09 +01:00
|
|
|
$response->setHeaders(['Link' => $this->getPaginationLink($page, [
|
2015-08-26 09:40:20 +02:00
|
|
|
'search' => $search,
|
|
|
|
'itemType' => $itemType,
|
|
|
|
'shareType' => $shareTypes,
|
2015-09-15 12:14:14 +02:00
|
|
|
'perPage' => $perPage,
|
2023-02-15 19:22:09 +01:00
|
|
|
])]);
|
2015-08-08 22:15:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
2015-08-11 18:03:07 +02:00
|
|
|
|
2019-02-13 17:16:01 +01:00
|
|
|
/**
|
|
|
|
* @param string $user
|
|
|
|
* @param int $shareType
|
|
|
|
*
|
|
|
|
* @return Generator<array<string>>
|
|
|
|
*/
|
|
|
|
private function getAllShareesByType(string $user, int $shareType): Generator {
|
|
|
|
$offset = 0;
|
|
|
|
$pageSize = 50;
|
|
|
|
|
|
|
|
while (count($page = $this->shareManager->getSharesBy(
|
|
|
|
$user,
|
|
|
|
$shareType,
|
|
|
|
null,
|
|
|
|
false,
|
|
|
|
$pageSize,
|
|
|
|
$offset
|
|
|
|
))) {
|
|
|
|
foreach ($page as $share) {
|
|
|
|
yield [$share->getSharedWith(), $share->getSharedWithDisplayName() ?? $share->getSharedWith()];
|
|
|
|
}
|
|
|
|
|
|
|
|
$offset += $pageSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function sortShareesByFrequency(array $sharees): array {
|
2022-10-09 21:41:18 +02:00
|
|
|
usort($sharees, function (array $s1, array $s2): int {
|
2019-02-13 17:16:01 +01:00
|
|
|
return $s2['count'] - $s1['count'];
|
|
|
|
});
|
|
|
|
return $sharees;
|
|
|
|
}
|
|
|
|
|
|
|
|
private $searchResultTypeMap = [
|
2020-04-21 08:42:28 +02:00
|
|
|
IShare::TYPE_USER => 'users',
|
|
|
|
IShare::TYPE_GROUP => 'groups',
|
|
|
|
IShare::TYPE_REMOTE => 'remotes',
|
|
|
|
IShare::TYPE_REMOTE_GROUP => 'remote_groups',
|
|
|
|
IShare::TYPE_EMAIL => 'emails',
|
2019-02-13 17:16:01 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
private function getAllSharees(string $user, array $shareTypes): ISearchResult {
|
|
|
|
$result = [];
|
|
|
|
foreach ($shareTypes as $shareType) {
|
|
|
|
$sharees = $this->getAllShareesByType($user, $shareType);
|
|
|
|
$shareTypeResults = [];
|
2021-01-12 09:15:48 +00:00
|
|
|
foreach ($sharees as [$sharee, $displayname]) {
|
2024-07-31 17:29:46 +02:00
|
|
|
if (!isset($this->searchResultTypeMap[$shareType]) || trim($sharee) === '') {
|
2019-02-13 17:16:01 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($shareTypeResults[$sharee])) {
|
|
|
|
$shareTypeResults[$sharee] = [
|
|
|
|
'count' => 1,
|
|
|
|
'label' => $displayname,
|
|
|
|
'value' => [
|
|
|
|
'shareType' => $shareType,
|
|
|
|
'shareWith' => $sharee,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
$shareTypeResults[$sharee]['count']++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$result = array_merge($result, array_values($shareTypeResults));
|
|
|
|
}
|
|
|
|
|
|
|
|
$top5 = array_slice(
|
|
|
|
$this->sortShareesByFrequency($result),
|
|
|
|
0,
|
|
|
|
5
|
|
|
|
);
|
|
|
|
|
|
|
|
$searchResult = new SearchResult();
|
|
|
|
foreach ($this->searchResultTypeMap as $int => $str) {
|
|
|
|
$searchResult->addResultSet(new SearchResultType($str), [], []);
|
|
|
|
foreach ($top5 as $x) {
|
|
|
|
if ($x['value']['shareType'] === $int) {
|
|
|
|
$searchResult->addResultSet(new SearchResultType($str), [], [$x]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $searchResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-02-15 19:22:09 +01:00
|
|
|
* Find recommended sharees
|
|
|
|
*
|
|
|
|
* @param string $itemType Limit to specific item types
|
2024-09-24 15:53:13 +02:00
|
|
|
* @param int|list<int>|null $shareType Limit to specific share types
|
2023-10-23 16:47:38 +02:00
|
|
|
* @return DataResponse<Http::STATUS_OK, Files_SharingShareesRecommendedResult, array{}>
|
2023-09-19 14:12:17 +02:00
|
|
|
*
|
|
|
|
* 200: Recommended sharees returned
|
2019-02-13 17:16:01 +01:00
|
|
|
*/
|
2024-07-25 13:14:46 +02:00
|
|
|
#[NoAdminRequired]
|
2023-02-15 19:22:09 +01:00
|
|
|
public function findRecommended(string $itemType, $shareType = null): DataResponse {
|
2019-02-13 17:16:01 +01:00
|
|
|
$shareTypes = [
|
2020-04-21 08:42:28 +02:00
|
|
|
IShare::TYPE_USER,
|
2019-02-13 17:16:01 +01:00
|
|
|
];
|
|
|
|
|
2023-02-15 19:22:09 +01:00
|
|
|
if ($itemType === 'file' || $itemType === 'folder') {
|
2019-02-13 17:16:01 +01:00
|
|
|
if ($this->shareManager->allowGroupSharing()) {
|
2020-04-21 08:42:28 +02:00
|
|
|
$shareTypes[] = IShare::TYPE_GROUP;
|
2019-02-13 17:16:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->isRemoteSharingAllowed($itemType)) {
|
2020-04-21 08:42:28 +02:00
|
|
|
$shareTypes[] = IShare::TYPE_REMOTE;
|
2019-02-13 17:16:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->isRemoteGroupSharingAllowed($itemType)) {
|
2020-04-21 08:42:28 +02:00
|
|
|
$shareTypes[] = IShare::TYPE_REMOTE_GROUP;
|
2019-02-13 17:16:01 +01:00
|
|
|
}
|
|
|
|
|
2020-04-21 08:42:28 +02:00
|
|
|
if ($this->shareManager->shareProviderExists(IShare::TYPE_EMAIL)) {
|
|
|
|
$shareTypes[] = IShare::TYPE_EMAIL;
|
2019-02-13 17:16:01 +01:00
|
|
|
}
|
|
|
|
|
2020-04-21 08:42:28 +02:00
|
|
|
if ($this->shareManager->shareProviderExists(IShare::TYPE_ROOM)) {
|
|
|
|
$shareTypes[] = IShare::TYPE_ROOM;
|
2019-02-13 17:16:01 +01:00
|
|
|
}
|
|
|
|
} else {
|
2020-04-21 08:42:28 +02:00
|
|
|
$shareTypes[] = IShare::TYPE_GROUP;
|
|
|
|
$shareTypes[] = IShare::TYPE_EMAIL;
|
2019-02-13 17:16:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: DI
|
|
|
|
if (\OC::$server->getAppManager()->isEnabledForUser('circles') && class_exists('\OCA\Circles\ShareByCircleProvider')) {
|
2020-04-21 08:42:28 +02:00
|
|
|
$shareTypes[] = IShare::TYPE_CIRCLE;
|
2019-02-13 17:16:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_GET['shareType']) && is_array($_GET['shareType'])) {
|
|
|
|
$shareTypes = array_intersect($shareTypes, $_GET['shareType']);
|
|
|
|
sort($shareTypes);
|
2020-04-10 10:35:09 +02:00
|
|
|
} elseif (is_numeric($shareType)) {
|
2019-02-13 17:16:01 +01:00
|
|
|
$shareTypes = array_intersect($shareTypes, [(int)$shareType]);
|
|
|
|
sort($shareTypes);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new DataResponse(
|
|
|
|
$this->getAllSharees($this->userId, $shareTypes)->asArray()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-07-29 15:37:08 +02:00
|
|
|
/**
|
2017-08-31 22:47:02 +02:00
|
|
|
* Method to get out the static call for better testing
|
2017-06-14 15:07:21 +02:00
|
|
|
*
|
2017-08-31 22:47:02 +02:00
|
|
|
* @param string $itemType
|
2017-06-14 15:07:21 +02:00
|
|
|
* @return bool
|
|
|
|
*/
|
2018-04-23 22:05:21 +02:00
|
|
|
protected function isRemoteSharingAllowed(string $itemType): bool {
|
2017-08-31 22:47:02 +02:00
|
|
|
try {
|
2017-09-13 12:32:47 +02:00
|
|
|
// FIXME: static foo makes unit testing unnecessarily difficult
|
2024-10-10 12:40:31 +02:00
|
|
|
$backend = Share::getBackend($itemType);
|
2020-04-21 08:42:28 +02:00
|
|
|
return $backend->isShareTypeAllowed(IShare::TYPE_REMOTE);
|
2017-08-31 22:47:02 +02:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
return false;
|
2017-06-14 15:07:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 11:29:03 +02:00
|
|
|
protected function isRemoteGroupSharingAllowed(string $itemType): bool {
|
2018-07-04 10:39:13 +02:00
|
|
|
try {
|
|
|
|
// FIXME: static foo makes unit testing unnecessarily difficult
|
2024-10-10 12:40:31 +02:00
|
|
|
$backend = Share::getBackend($itemType);
|
2020-04-21 08:42:28 +02:00
|
|
|
return $backend->isShareTypeAllowed(IShare::TYPE_REMOTE_GROUP);
|
2018-07-04 10:39:13 +02:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-02 11:29:03 +02:00
|
|
|
}
|
|
|
|
|
2017-08-31 22:47:02 +02:00
|
|
|
|
2015-08-11 18:03:07 +02:00
|
|
|
/**
|
2015-08-26 09:40:20 +02:00
|
|
|
* Generates a bunch of pagination links for the current page
|
2015-08-13 10:13:23 +02:00
|
|
|
*
|
2015-08-26 09:40:20 +02:00
|
|
|
* @param int $page Current page
|
|
|
|
* @param array $params Parameters for the URL
|
|
|
|
* @return string
|
2015-08-13 10:13:23 +02:00
|
|
|
*/
|
2018-04-23 22:05:21 +02:00
|
|
|
protected function getPaginationLink(int $page, array $params): string {
|
2015-08-26 09:40:20 +02:00
|
|
|
if ($this->isV2()) {
|
|
|
|
$url = $this->urlGenerator->getAbsoluteURL('/ocs/v2.php/apps/files_sharing/api/v1/sharees') . '?';
|
|
|
|
} else {
|
|
|
|
$url = $this->urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/sharees') . '?';
|
2015-08-13 10:13:23 +02:00
|
|
|
}
|
2015-08-26 09:40:20 +02:00
|
|
|
$params['page'] = $page + 1;
|
2018-01-26 00:02:03 +01:00
|
|
|
return '<' . $url . http_build_query($params) . '>; rel="next"';
|
2015-08-13 10:13:23 +02:00
|
|
|
}
|
|
|
|
|
2015-08-13 10:57:08 +02:00
|
|
|
/**
|
2015-08-26 09:40:20 +02:00
|
|
|
* @return bool
|
2015-08-13 10:57:08 +02:00
|
|
|
*/
|
2018-04-23 22:05:21 +02:00
|
|
|
protected function isV2(): bool {
|
2015-08-26 09:40:20 +02:00
|
|
|
return $this->request->getScriptName() === '/ocs/v2.php';
|
2015-08-11 18:03:07 +02:00
|
|
|
}
|
2015-08-08 22:15:12 +02:00
|
|
|
}
|