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 CirclesQueryHelper */ |
70
|
|
|
private $circlesQueryHelper; |
71
|
|
|
|
72
|
|
|
/** @var FederatedUserService */ |
73
|
|
|
private $federatedUserService; |
74
|
|
|
|
75
|
|
|
/** @var CircleService */ |
76
|
|
|
private $circleService; |
77
|
|
|
|
78
|
|
|
/** @var MemberService */ |
79
|
|
|
private $memberService; |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* CirclesManager constructor. |
84
|
|
|
* |
85
|
|
|
* @param IUserSession $userSession |
86
|
|
|
* @param FederatedUserService $federatedUserService |
87
|
|
|
* @param CircleService $circleService |
88
|
|
|
* @param MemberService $memberService |
89
|
|
|
* @param CirclesQueryHelper $circlesQueryHelper |
90
|
|
|
*/ |
91
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
92
|
|
|
IUserSession $userSession, |
93
|
|
|
FederatedUserService $federatedUserService, |
94
|
|
|
CircleService $circleService, |
95
|
|
|
MemberService $memberService, |
96
|
|
|
CirclesQueryHelper $circlesQueryHelper |
97
|
|
|
) { |
98
|
|
|
$this->userSession = $userSession; |
99
|
|
|
$this->federatedUserService = $federatedUserService; |
100
|
|
|
$this->circleService = $circleService; |
101
|
|
|
$this->memberService = $memberService; |
102
|
|
|
$this->circlesQueryHelper = $circlesQueryHelper; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* WIP |
108
|
|
|
* |
109
|
|
|
* @return Circle |
110
|
|
|
*/ |
111
|
|
|
// public function create(): Circle { |
112
|
|
|
// } |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* WIP |
117
|
|
|
* |
118
|
|
|
* returns Circles available to Current User |
119
|
|
|
* |
120
|
|
|
* @return Circle[] |
121
|
|
|
* @throws InitiatorNotFoundException |
122
|
|
|
* @throws FederatedUserException |
123
|
|
|
* @throws FederatedUserNotFoundException |
124
|
|
|
* @throws InvalidIdException |
125
|
|
|
* @throws RequestBuilderException |
126
|
|
|
* @throws SingleCircleNotFoundException |
127
|
|
|
*/ |
128
|
|
|
// public function getCircles(bool $asMember = false): array { |
129
|
|
|
// $this->federatedUserService->initCurrentUser(); |
130
|
|
|
// $this->circleService->getCircles(); |
131
|
|
|
// } |
132
|
|
|
|
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* WIP |
136
|
|
|
* |
137
|
|
|
* @return Circle[] |
138
|
|
|
* @throws InitiatorNotFoundException |
139
|
|
|
* @throws RequestBuilderException |
140
|
|
|
*/ |
141
|
|
|
// public function getAllCircles(): array { |
142
|
|
|
// $this->federatedUserService->bypassCurrentUserCondition(true); |
143
|
|
|
// $this->circleService->getCircles(); |
144
|
|
|
// } |
145
|
|
|
|
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* WIP |
149
|
|
|
* |
150
|
|
|
* @param string $singleId |
151
|
|
|
* |
152
|
|
|
* @return Circle |
153
|
|
|
*/ |
154
|
|
|
// public function getCircle(string $singleId): Circle { |
155
|
|
|
// |
156
|
|
|
// } |
157
|
|
|
|
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* WIP |
161
|
|
|
* |
162
|
|
|
* @param string $circleId |
163
|
|
|
* @param string $singleId |
164
|
|
|
* |
165
|
|
|
* @return Member |
166
|
|
|
* @throws InitiatorNotFoundException |
167
|
|
|
* @throws MemberNotFoundException |
168
|
|
|
* @throws RequestBuilderException |
169
|
|
|
*/ |
170
|
|
|
// public function getMember(string $circleId, string $singleId): Member { |
171
|
|
|
// $this->federatedUserService->bypassCurrentUserCondition(true); |
172
|
|
|
// $this->memberService->getMemberById($circleId, $singleId); |
173
|
|
|
// } |
174
|
|
|
|
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* WIP |
178
|
|
|
* |
179
|
|
|
* @param string $memberId |
180
|
|
|
* |
181
|
|
|
* @return Member |
182
|
|
|
*/ |
183
|
|
|
// public function getMemberById(string $memberId): Member { |
184
|
|
|
// } |
185
|
|
|
|
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @return IFederatedUser |
189
|
|
|
* @throws FederatedUserException |
190
|
|
|
* @throws FederatedUserNotFoundException |
191
|
|
|
* @throws InvalidIdException |
192
|
|
|
* @throws RequestBuilderException |
193
|
|
|
* @throws SingleCircleNotFoundException |
194
|
|
|
*/ |
195
|
|
|
public function getCurrentFederatedUser(): IFederatedUser { |
196
|
|
|
$user = $this->userSession->getUser(); |
197
|
|
|
if ($user === null) { |
198
|
|
|
throw new FederatedUserNotFoundException('current user session not found'); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
return $this->federatedUserService->getLocalFederatedUser($user->getUID()); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @param string $federatedId |
207
|
|
|
* @param int $type |
208
|
|
|
* |
209
|
|
|
* @return IFederatedUser |
210
|
|
|
* @throws CircleNotFoundException |
211
|
|
|
* @throws FederatedItemException |
212
|
|
|
* @throws FederatedUserException |
213
|
|
|
* @throws FederatedUserNotFoundException |
214
|
|
|
* @throws InvalidIdException |
215
|
|
|
* @throws MemberNotFoundException |
216
|
|
|
* @throws OwnerNotFoundException |
217
|
|
|
* @throws RemoteInstanceException |
218
|
|
|
* @throws RemoteNotFoundException |
219
|
|
|
* @throws RemoteResourceNotFoundException |
220
|
|
|
* @throws RequestBuilderException |
221
|
|
|
* @throws SingleCircleNotFoundException |
222
|
|
|
* @throws UnknownRemoteException |
223
|
|
|
* @throws UserTypeNotFoundException |
224
|
|
|
*/ |
225
|
|
|
public function getFederatedUser(string $federatedId, int $type = Member::TYPE_SINGLE): IFederatedUser { |
226
|
|
|
return $this->federatedUserService->getFederatedUser($federatedId, $type); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @return CirclesQueryHelper |
232
|
|
|
*/ |
233
|
|
|
public function getQueryHelper(): CirclesQueryHelper { |
234
|
|
|
return $this->circlesQueryHelper; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @param array $data |
240
|
|
|
* @param string $prefix |
241
|
|
|
* |
242
|
|
|
* @return Circle |
243
|
|
|
* @throws CircleNotFoundException |
244
|
|
|
*/ |
245
|
|
|
public function extractCircle(array $data, string $prefix = ''): Circle { |
246
|
|
|
$circle = new Circle(); |
247
|
|
|
$circle->importFromDatabase($data, $prefix); |
248
|
|
|
|
249
|
|
|
return $circle; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.