|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2017 Arthur Schiwon <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @author Arthur Schiwon <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @license GNU AGPL version 3 or any later version |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
12
|
|
|
* License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
namespace OC\Collaboration\Collaborators; |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
use OCP\Collaboration\Collaborators\ISearchPlugin; |
|
28
|
|
|
use OCP\Collaboration\Collaborators\ISearchResult; |
|
29
|
|
|
use OCP\Collaboration\Collaborators\SearchResultType; |
|
30
|
|
|
use OCP\Federation\ICloudFederationProviderManager; |
|
31
|
|
|
use OCP\Federation\ICloudIdManager; |
|
32
|
|
|
use OCP\Share; |
|
33
|
|
|
|
|
34
|
|
|
class RemoteGroupPlugin implements ISearchPlugin { |
|
35
|
|
|
protected $shareeEnumeration; |
|
36
|
|
|
|
|
37
|
|
|
/** @var ICloudIdManager */ |
|
38
|
|
|
private $cloudIdManager; |
|
39
|
|
|
/** @var bool */ |
|
40
|
|
|
private $enabled = false; |
|
41
|
|
|
|
|
42
|
|
|
public function __construct(ICloudFederationProviderManager $cloudFederationProviderManager, ICloudIdManager $cloudIdManager) { |
|
43
|
|
|
try { |
|
44
|
|
|
$fileSharingProvider = $cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
45
|
|
|
$supportedShareTypes = $fileSharingProvider->getSupportedShareTypes(); |
|
46
|
|
|
if (in_array('group', $supportedShareTypes)) { |
|
47
|
|
|
$this->enabled = true; |
|
48
|
|
|
} |
|
49
|
|
|
} catch (\Exception $e) { |
|
50
|
|
|
// do nothing, just don't enable federated group shares |
|
51
|
|
|
} |
|
52
|
|
|
$this->cloudIdManager = $cloudIdManager; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
56
|
|
|
$result = ['wide' => [], 'exact' => []]; |
|
57
|
|
|
$resultType = new SearchResultType('remote_groups'); |
|
58
|
|
|
|
|
59
|
|
|
if ($this->enabled && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) { |
|
60
|
|
|
list($remoteGroup, $serverUrl) = $this->splitGroupRemote($search); |
|
61
|
|
|
$result['exact'][] = [ |
|
62
|
|
|
'label' => $remoteGroup . " ($serverUrl)", |
|
63
|
|
|
'guid' => $remoteGroup, |
|
64
|
|
|
'name' => $remoteGroup, |
|
65
|
|
|
'value' => [ |
|
66
|
|
|
'shareType' => Share::SHARE_TYPE_REMOTE_GROUP, |
|
|
|
|
|
|
67
|
|
|
'shareWith' => $search, |
|
68
|
|
|
'server' => $serverUrl, |
|
69
|
|
|
], |
|
70
|
|
|
]; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$searchResult->addResultSet($resultType, $result['wide'], $result['exact']); |
|
74
|
|
|
|
|
75
|
|
|
return true; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* split group and remote from federated cloud id |
|
80
|
|
|
* |
|
81
|
|
|
* @param string $address federated share address |
|
82
|
|
|
* @return array [user, remoteURL] |
|
83
|
|
|
* @throws \InvalidArgumentException |
|
84
|
|
|
*/ |
|
85
|
|
|
public function splitGroupRemote($address) { |
|
86
|
|
|
try { |
|
87
|
|
|
$cloudId = $this->cloudIdManager->resolveCloudId($address); |
|
88
|
|
|
return [$cloudId->getUser(), $cloudId->getRemote()]; |
|
89
|
|
|
} catch (\InvalidArgumentException $e) { |
|
90
|
|
|
throw new \InvalidArgumentException('Invalid Federated Cloud ID', 0, $e); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|
This class constant has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.