1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Circles - Bring cloud-users closer together. |
8
|
|
|
* |
9
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
10
|
|
|
* later. See the COPYING file. |
11
|
|
|
* |
12
|
|
|
* @author Maxence Lange <[email protected]> |
13
|
|
|
* @copyright 2021 |
14
|
|
|
* @license GNU AGPL version 3 or any later version |
15
|
|
|
* |
16
|
|
|
* This program is free software: you can redistribute it and/or modify |
17
|
|
|
* it under the terms of the GNU Affero General Public License as |
18
|
|
|
* published by the Free Software Foundation, either version 3 of the |
19
|
|
|
* License, or (at your option) any later version. |
20
|
|
|
* |
21
|
|
|
* This program is distributed in the hope that it will be useful, |
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24
|
|
|
* GNU Affero General Public License for more details. |
25
|
|
|
* |
26
|
|
|
* You should have received a copy of the GNU Affero General Public License |
27
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
28
|
|
|
* |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
namespace OCA\Circles; |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
use OCA\Circles\Exceptions\CircleNotFoundException; |
36
|
|
|
use OCA\Circles\Exceptions\FederatedItemException; |
37
|
|
|
use OCA\Circles\Exceptions\FederatedUserException; |
38
|
|
|
use OCA\Circles\Exceptions\FederatedUserNotFoundException; |
39
|
|
|
use OCA\Circles\Exceptions\InitiatorNotFoundException; |
40
|
|
|
use OCA\Circles\Exceptions\InvalidIdException; |
41
|
|
|
use OCA\Circles\Exceptions\MemberNotFoundException; |
42
|
|
|
use OCA\Circles\Exceptions\OwnerNotFoundException; |
43
|
|
|
use OCA\Circles\Exceptions\RemoteInstanceException; |
44
|
|
|
use OCA\Circles\Exceptions\RemoteNotFoundException; |
45
|
|
|
use OCA\Circles\Exceptions\RemoteResourceNotFoundException; |
46
|
|
|
use OCA\Circles\Exceptions\RequestBuilderException; |
47
|
|
|
use OCA\Circles\Exceptions\SingleCircleNotFoundException; |
48
|
|
|
use OCA\Circles\Exceptions\UnknownRemoteException; |
49
|
|
|
use OCA\Circles\Exceptions\UserTypeNotFoundException; |
50
|
|
|
use OCA\Circles\Model\Circle; |
51
|
|
|
use OCA\Circles\Model\Member; |
52
|
|
|
use OCA\Circles\Service\CircleService; |
53
|
|
|
use OCA\Circles\Service\FederatedUserService; |
54
|
|
|
use OCA\Circles\Service\MemberService; |
55
|
|
|
use OCP\IUserSession; |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Class CirclesManager |
60
|
|
|
* |
61
|
|
|
* @package OCA\Circles |
62
|
|
|
*/ |
63
|
|
|
class CirclesManager { |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** @var IUserSession */ |
67
|
|
|
private $userSession; |
68
|
|
|
|
69
|
|
|
/** @var FederatedUserService */ |
70
|
|
|
private $federatedUserService; |
71
|
|
|
|
72
|
|
|
/** @var CircleService */ |
73
|
|
|
private $circleService; |
74
|
|
|
|
75
|
|
|
/** @var MemberService */ |
76
|
|
|
private $memberService; |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* CirclesManager constructor. |
81
|
|
|
* |
82
|
|
|
* @param IUserSession $userSession |
83
|
|
|
* @param FederatedUserService $federatedUserService |
84
|
|
|
* @param CircleService $circleService |
85
|
|
|
* @param MemberService $memberService |
86
|
|
|
*/ |
87
|
|
|
public function __construct( |
88
|
|
|
IUserSession $userSession, |
89
|
|
|
FederatedUserService $federatedUserService, |
90
|
|
|
CircleService $circleService, |
91
|
|
|
MemberService $memberService |
92
|
|
|
) { |
93
|
|
|
$this->userSession = $userSession; |
94
|
|
|
$this->federatedUserService = $federatedUserService; |
95
|
|
|
$this->circleService = $circleService; |
96
|
|
|
$this->memberService = $memberService; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* WIP |
102
|
|
|
* |
103
|
|
|
* @return Circle |
104
|
|
|
*/ |
105
|
|
|
// public function create(): Circle { |
106
|
|
|
// } |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* WIP |
111
|
|
|
* |
112
|
|
|
* returns Circles available to Current User |
113
|
|
|
* |
114
|
|
|
* @return Circle[] |
115
|
|
|
* @throws InitiatorNotFoundException |
116
|
|
|
* @throws FederatedUserException |
117
|
|
|
* @throws FederatedUserNotFoundException |
118
|
|
|
* @throws InvalidIdException |
119
|
|
|
* @throws RequestBuilderException |
120
|
|
|
* @throws SingleCircleNotFoundException |
121
|
|
|
*/ |
122
|
|
|
// public function getCircles(bool $asMember = false): array { |
123
|
|
|
// $this->federatedUserService->initCurrentUser(); |
124
|
|
|
// $this->circleService->getCircles(); |
125
|
|
|
// } |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* WIP |
130
|
|
|
* |
131
|
|
|
* @return Circle[] |
132
|
|
|
* @throws InitiatorNotFoundException |
133
|
|
|
* @throws RequestBuilderException |
134
|
|
|
*/ |
135
|
|
|
// public function getAllCircles(): array { |
136
|
|
|
// $this->federatedUserService->bypassCurrentUserCondition(true); |
137
|
|
|
// $this->circleService->getCircles(); |
138
|
|
|
// } |
139
|
|
|
|
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* WIP |
143
|
|
|
* |
144
|
|
|
* @param string $singleId |
145
|
|
|
* |
146
|
|
|
* @return Circle |
147
|
|
|
*/ |
148
|
|
|
// public function getCircle(string $singleId): Circle { |
149
|
|
|
// |
150
|
|
|
// } |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* WIP |
155
|
|
|
* |
156
|
|
|
* @param string $circleId |
157
|
|
|
* @param string $singleId |
158
|
|
|
* |
159
|
|
|
* @return Member |
160
|
|
|
* @throws InitiatorNotFoundException |
161
|
|
|
* @throws MemberNotFoundException |
162
|
|
|
* @throws RequestBuilderException |
163
|
|
|
*/ |
164
|
|
|
// public function getMember(string $circleId, string $singleId): Member { |
165
|
|
|
// $this->federatedUserService->bypassCurrentUserCondition(true); |
166
|
|
|
// $this->memberService->getMemberById($circleId, $singleId); |
167
|
|
|
// } |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* WIP |
172
|
|
|
* |
173
|
|
|
* @param string $memberId |
174
|
|
|
* |
175
|
|
|
* @return Member |
176
|
|
|
*/ |
177
|
|
|
// public function getMemberById(string $memberId): Member { |
178
|
|
|
// } |
179
|
|
|
|
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* WIP |
183
|
|
|
* |
184
|
|
|
* @return IFederatedUser |
185
|
|
|
* @throws FederatedUserException |
186
|
|
|
* @throws FederatedUserNotFoundException |
187
|
|
|
* @throws InvalidIdException |
188
|
|
|
* @throws RequestBuilderException |
189
|
|
|
* @throws SingleCircleNotFoundException |
190
|
|
|
*/ |
191
|
|
|
// public function getCurrentFederatedUser(): IFederatedUser { |
192
|
|
|
// $user = $this->userSession->getUser(); |
193
|
|
|
// if ($user === null) { |
194
|
|
|
// throw new FederatedUserNotFoundException('current user session not found'); |
195
|
|
|
// } |
196
|
|
|
// |
197
|
|
|
// return $this->federatedUserService->getLocalFederatedUser($user->getUID()); |
198
|
|
|
// } |
199
|
|
|
|
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @param string $federatedId |
203
|
|
|
* @param int $type |
204
|
|
|
* |
205
|
|
|
* @return IFederatedUser |
206
|
|
|
* @throws CircleNotFoundException |
207
|
|
|
* @throws FederatedItemException |
208
|
|
|
* @throws FederatedUserException |
209
|
|
|
* @throws FederatedUserNotFoundException |
210
|
|
|
* @throws InvalidIdException |
211
|
|
|
* @throws MemberNotFoundException |
212
|
|
|
* @throws OwnerNotFoundException |
213
|
|
|
* @throws RemoteInstanceException |
214
|
|
|
* @throws RemoteNotFoundException |
215
|
|
|
* @throws RemoteResourceNotFoundException |
216
|
|
|
* @throws RequestBuilderException |
217
|
|
|
* @throws SingleCircleNotFoundException |
218
|
|
|
* @throws UnknownRemoteException |
219
|
|
|
* @throws UserTypeNotFoundException |
220
|
|
|
*/ |
221
|
|
|
public function getFederatedUser(string $federatedId, int $type = Member::TYPE_SINGLE): IFederatedUser { |
222
|
|
|
return $this->federatedUserService->getFederatedUser($federatedId, $type); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
|