2018-07-02 12:29:03 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
2020-08-24 15:54:25 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
|
2018-07-02 12:29:03 +03:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-07-02 12:29:03 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OC\Collaboration\Collaborators;
|
|
|
|
|
|
|
|
use OCP\Collaboration\Collaborators\ISearchPlugin;
|
|
|
|
use OCP\Collaboration\Collaborators\ISearchResult;
|
|
|
|
use OCP\Collaboration\Collaborators\SearchResultType;
|
|
|
|
use OCP\Federation\ICloudFederationProviderManager;
|
|
|
|
use OCP\Federation\ICloudIdManager;
|
|
|
|
use OCP\Share;
|
2020-06-24 17:49:16 +03:00
|
|
|
use OCP\Share\IShare;
|
2018-07-02 12:29:03 +03:00
|
|
|
|
|
|
|
class RemoteGroupPlugin implements ISearchPlugin {
|
|
|
|
protected $shareeEnumeration;
|
|
|
|
|
|
|
|
/** @var ICloudIdManager */
|
|
|
|
private $cloudIdManager;
|
|
|
|
/** @var bool */
|
|
|
|
private $enabled = false;
|
|
|
|
|
|
|
|
public function __construct(ICloudFederationProviderManager $cloudFederationProviderManager, ICloudIdManager $cloudIdManager) {
|
|
|
|
try {
|
|
|
|
$fileSharingProvider = $cloudFederationProviderManager->getCloudFederationProvider('file');
|
|
|
|
$supportedShareTypes = $fileSharingProvider->getSupportedShareTypes();
|
|
|
|
if (in_array('group', $supportedShareTypes)) {
|
|
|
|
$this->enabled = true;
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
// do nothing, just don't enable federated group shares
|
|
|
|
}
|
|
|
|
$this->cloudIdManager = $cloudIdManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function search($search, $limit, $offset, ISearchResult $searchResult) {
|
|
|
|
$result = ['wide' => [], 'exact' => []];
|
|
|
|
$resultType = new SearchResultType('remote_groups');
|
|
|
|
|
|
|
|
if ($this->enabled && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) {
|
2021-01-12 12:15:48 +03:00
|
|
|
[$remoteGroup, $serverUrl] = $this->splitGroupRemote($search);
|
2018-07-02 12:29:03 +03:00
|
|
|
$result['exact'][] = [
|
2019-05-23 18:03:04 +03:00
|
|
|
'label' => $remoteGroup . " ($serverUrl)",
|
|
|
|
'guid' => $remoteGroup,
|
|
|
|
'name' => $remoteGroup,
|
2018-07-02 12:29:03 +03:00
|
|
|
'value' => [
|
2020-06-24 17:49:16 +03:00
|
|
|
'shareType' => IShare::TYPE_REMOTE_GROUP,
|
2018-07-02 12:29:03 +03:00
|
|
|
'shareWith' => $search,
|
2019-05-23 18:03:04 +03:00
|
|
|
'server' => $serverUrl,
|
2018-07-02 12:29:03 +03:00
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
$searchResult->addResultSet($resultType, $result['wide'], $result['exact']);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-23 18:03:04 +03:00
|
|
|
/**
|
|
|
|
* split group and remote from federated cloud id
|
|
|
|
*
|
|
|
|
* @param string $address federated share address
|
|
|
|
* @return array [user, remoteURL]
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function splitGroupRemote($address) {
|
|
|
|
try {
|
|
|
|
$cloudId = $this->cloudIdManager->resolveCloudId($address);
|
|
|
|
return [$cloudId->getUser(), $cloudId->getRemote()];
|
|
|
|
} catch (\InvalidArgumentException $e) {
|
|
|
|
throw new \InvalidArgumentException('Invalid Federated Cloud ID', 0, $e);
|
|
|
|
}
|
|
|
|
}
|
2018-07-02 12:29:03 +03:00
|
|
|
}
|