1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Circles - Bring cloud-users closer together. |
4
|
|
|
* |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. See the COPYING file. |
7
|
|
|
* |
8
|
|
|
* @author Maxence Lange <[email protected]> |
9
|
|
|
* @author Vinicius Cubas Brand <[email protected]> |
10
|
|
|
* @author Daniel Tygel <[email protected]> |
11
|
|
|
* |
12
|
|
|
* @copyright 2017 |
13
|
|
|
* @license GNU AGPL version 3 or any later version |
14
|
|
|
* |
15
|
|
|
* This program is free software: you can redistribute it and/or modify |
16
|
|
|
* it under the terms of the GNU Affero General Public License as |
17
|
|
|
* published by the Free Software Foundation, either version 3 of the |
18
|
|
|
* License, or (at your option) any later version. |
19
|
|
|
* |
20
|
|
|
* This program is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU Affero General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* You should have received a copy of the GNU Affero General Public License |
26
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
27
|
|
|
* |
28
|
|
|
*/ |
29
|
|
|
|
30
|
|
|
namespace OCA\Circles\Service; |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
use daita\MySmallPhpTools\Traits\TArrayTools; |
34
|
|
|
use Exception; |
35
|
|
|
use OC; |
36
|
|
|
use OCA\Circles\AppInfo\Application; |
37
|
|
|
use OCA\Circles\Db\CircleProviderRequest; |
38
|
|
|
use OCA\Circles\Db\DeprecatedCirclesRequest; |
39
|
|
|
use OCA\Circles\Db\DeprecatedMembersRequest; |
40
|
|
|
use OCA\Circles\Db\FederatedLinksRequest; |
41
|
|
|
use OCA\Circles\Db\FileSharesRequest; |
42
|
|
|
use OCA\Circles\Db\TokensRequest; |
43
|
|
|
use OCA\Circles\Exceptions\CircleAlreadyExistsException; |
44
|
|
|
use OCA\Circles\Exceptions\CircleDoesNotExistException; |
45
|
|
|
use OCA\Circles\Exceptions\CircleTypeDisabledException; |
46
|
|
|
use OCA\Circles\Exceptions\ConfigNoCircleAvailableException; |
47
|
|
|
use OCA\Circles\Exceptions\FederatedCircleNotAllowedException; |
48
|
|
|
use OCA\Circles\Exceptions\GSStatusException; |
49
|
|
|
use OCA\Circles\Exceptions\MemberIsNotOwnerException; |
50
|
|
|
use OCA\Circles\Exceptions\MembersLimitException; |
51
|
|
|
use OCA\Circles\Model\DeprecatedCircle; |
52
|
|
|
use OCA\Circles\Model\DeprecatedMember; |
53
|
|
|
use OCA\Circles\Model\GlobalScale\GSEvent; |
54
|
|
|
use OCP\IGroupManager; |
55
|
|
|
use OCP\IL10N; |
56
|
|
|
use OCP\IUserSession; |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Class CirclesService |
61
|
|
|
* |
62
|
|
|
* @deprecated |
63
|
|
|
* @package OCA\Circles\Service |
64
|
|
|
*/ |
65
|
|
|
class CirclesService { |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
use TArrayTools; |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
/** @var string */ |
72
|
|
|
private $userId; |
73
|
|
|
|
74
|
|
|
/** @var IL10N */ |
75
|
|
|
private $l10n; |
76
|
|
|
|
77
|
|
|
/** @var IGroupManager */ |
78
|
|
|
private $groupManager; |
79
|
|
|
|
80
|
|
|
/** @var MembersService */ |
81
|
|
|
private $membersService; |
82
|
|
|
|
83
|
|
|
/** @var ConfigService */ |
84
|
|
|
private $configService; |
85
|
|
|
|
86
|
|
|
/** @var DeprecatedCirclesRequest */ |
87
|
|
|
private $circlesRequest; |
88
|
|
|
|
89
|
|
|
/** @var DeprecatedMembersRequest */ |
90
|
|
|
private $membersRequest; |
91
|
|
|
|
92
|
|
|
/** @var TokensRequest */ |
93
|
|
|
private $tokensRequest; |
94
|
|
|
|
95
|
|
|
/** @var FileSharesRequest */ |
96
|
|
|
private $fileSharesRequest; |
97
|
|
|
|
98
|
|
|
/** @var FederatedLinksRequest */ |
99
|
|
|
private $federatedLinksRequest; |
100
|
|
|
|
101
|
|
|
/** @var GSUpstreamService */ |
102
|
|
|
private $gsUpstreamService; |
103
|
|
|
|
104
|
|
|
/** @var EventsService */ |
105
|
|
|
private $eventsService; |
106
|
|
|
|
107
|
|
|
/** @var CircleProviderRequest */ |
108
|
|
|
private $circleProviderRequest; |
109
|
|
|
|
110
|
|
|
/** @var MiscService */ |
111
|
|
|
private $miscService; |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* CirclesService constructor. |
116
|
|
|
* |
117
|
|
|
* @param string $userId |
118
|
|
|
* @param IL10N $l10n |
119
|
|
|
* @param IUserSession $userSession |
120
|
|
|
* @param IGroupManager $groupManager |
121
|
|
|
* @param MembersService $membersService |
122
|
|
|
* @param ConfigService $configService |
123
|
|
|
* @param DeprecatedCirclesRequest $circlesRequest |
124
|
|
|
* @param DeprecatedMembersRequest $membersRequest |
125
|
|
|
* @param TokensRequest $tokensRequest |
126
|
|
|
* @param FileSharesRequest $fileSharesRequest |
127
|
|
|
* @param FederatedLinksRequest $federatedLinksRequest |
128
|
|
|
* @param GSUpstreamService $gsUpstreamService |
129
|
|
|
* @param EventsService $eventsService |
130
|
|
|
* @param CircleProviderRequest $circleProviderRequest |
131
|
|
|
* @param MiscService $miscService |
132
|
|
|
*/ |
133
|
|
|
public function __construct( |
134
|
|
|
$userId, |
135
|
|
|
IL10N $l10n, |
136
|
|
|
IUserSession $userSession, |
137
|
|
|
IGroupManager $groupManager, |
138
|
|
|
MembersService $membersService, |
139
|
|
|
ConfigService $configService, |
140
|
|
|
DeprecatedCirclesRequest $circlesRequest, |
141
|
|
|
DeprecatedMembersRequest $membersRequest, |
142
|
|
|
TokensRequest $tokensRequest, |
143
|
|
|
FileSharesRequest $fileSharesRequest, |
144
|
|
|
FederatedLinksRequest $federatedLinksRequest, |
145
|
|
|
GSUpstreamService $gsUpstreamService, |
146
|
|
|
EventsService $eventsService, |
147
|
|
|
CircleProviderRequest $circleProviderRequest, |
148
|
|
|
MiscService $miscService |
149
|
|
|
) { |
150
|
|
|
|
151
|
|
View Code Duplication |
if ($userId === null) { |
|
|
|
|
152
|
|
|
$user = $userSession->getUser(); |
153
|
|
|
if ($user !== null) { |
154
|
|
|
$userId = $user->getUID(); |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
$this->userId = $userId; |
159
|
|
|
$this->l10n = $l10n; |
160
|
|
|
$this->groupManager = $groupManager; |
161
|
|
|
$this->membersService = $membersService; |
162
|
|
|
$this->configService = $configService; |
163
|
|
|
$this->circlesRequest = $circlesRequest; |
164
|
|
|
$this->membersRequest = $membersRequest; |
165
|
|
|
$this->tokensRequest = $tokensRequest; |
166
|
|
|
$this->fileSharesRequest = $fileSharesRequest; |
167
|
|
|
$this->federatedLinksRequest = $federatedLinksRequest; |
168
|
|
|
$this->gsUpstreamService = $gsUpstreamService; |
169
|
|
|
$this->eventsService = $eventsService; |
170
|
|
|
$this->circleProviderRequest = $circleProviderRequest; |
171
|
|
|
$this->miscService = $miscService; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Create circle using this->userId as owner |
177
|
|
|
* |
178
|
|
|
* @param int|string $type |
179
|
|
|
* @param string $name |
180
|
|
|
* |
181
|
|
|
* @param string $ownerId |
182
|
|
|
* |
183
|
|
|
* @return DeprecatedCircle |
184
|
|
|
* @throws CircleAlreadyExistsException |
185
|
|
|
* @throws CircleTypeDisabledException |
186
|
|
|
* @throws Exception |
187
|
|
|
*/ |
188
|
|
|
public function createCircle($type, $name, string $ownerId = '') { |
189
|
|
|
$type = $this->convertTypeStringToBitValue($type); |
190
|
|
|
$type = (int)$type; |
191
|
|
|
|
192
|
|
|
if ($type === '') { |
|
|
|
|
193
|
|
|
throw new CircleTypeDisabledException( |
194
|
|
|
$this->l10n->t('You need a specify a type of circle') |
195
|
|
|
); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
// if (!$this->configService->isCircleAllowed($type)) { |
199
|
|
|
// throw new CircleTypeDisabledException( |
200
|
|
|
// $this->l10n->t('You cannot create this type of circle') |
201
|
|
|
// ); |
202
|
|
|
// } |
203
|
|
|
|
204
|
|
|
$circle = new DeprecatedCircle($type, $name); |
205
|
|
|
if ($ownerId === '') { |
206
|
|
|
$ownerId = $this->userId; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
if (!$this->circlesRequest->isCircleUnique($circle, $ownerId)) { |
210
|
|
|
throw new CircleAlreadyExistsException( |
211
|
|
|
$this->l10n->t('A circle with that name exists') |
212
|
|
|
); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
$circle->generateUniqueId(); |
216
|
|
|
|
217
|
|
|
$owner = new DeprecatedMember($ownerId, DeprecatedMember::TYPE_USER); |
218
|
|
|
$owner->setCircleId($circle->getUniqueId()) |
219
|
|
|
->setLevel(DeprecatedMember::LEVEL_OWNER) |
220
|
|
|
->setStatus(DeprecatedMember::STATUS_MEMBER); |
221
|
|
|
$this->membersService->updateCachedName($owner); |
222
|
|
|
|
223
|
|
|
$circle->setOwner($owner) |
224
|
|
|
->setViewer($owner); |
225
|
|
|
|
226
|
|
|
$event = new GSEvent(GSEvent::CIRCLE_CREATE, true); |
227
|
|
|
$event->setDeprecatedCircle($circle); |
|
|
|
|
228
|
|
|
$this->gsUpstreamService->newEvent($event); |
229
|
|
|
|
230
|
|
|
return $circle; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* list Circles depends on type (or all) and name (parts) and minimum level. |
236
|
|
|
* |
237
|
|
|
* @param string $userId |
238
|
|
|
* @param mixed $type |
239
|
|
|
* @param string $name |
240
|
|
|
* @param int $level |
241
|
|
|
* |
242
|
|
|
* @param bool $forceAll |
243
|
|
|
* |
244
|
|
|
* @return DeprecatedCircle[] |
245
|
|
|
* @throws CircleTypeDisabledException |
246
|
|
|
* @throws Exception |
247
|
|
|
*/ |
248
|
|
|
public function listCircles($userId, $type, $name = '', $level = 0, $forceAll = false) { |
249
|
|
|
$type = $this->convertTypeStringToBitValue($type); |
250
|
|
|
|
251
|
|
|
if ($userId === '') { |
252
|
|
|
throw new Exception('UserID cannot be null'); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
// if (!$this->configService->isCircleAllowed((int)$type)) { |
256
|
|
|
// throw new CircleTypeDisabledException( |
257
|
|
|
// $this->l10n->t('You cannot display this type of circle') |
258
|
|
|
// ); |
259
|
|
|
// } |
260
|
|
|
|
261
|
|
|
$data = []; |
262
|
|
|
$result = $this->circlesRequest->getCircles($userId, $type, $name, $level, $forceAll); |
263
|
|
|
foreach ($result as $item) { |
264
|
|
|
$data[] = $item; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
return $data; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* returns details on circle and its members if this->userId is a member itself. |
273
|
|
|
* |
274
|
|
|
* @param string $circleUniqueId |
275
|
|
|
* @param bool $forceAll |
276
|
|
|
* |
277
|
|
|
* @return DeprecatedCircle |
278
|
|
|
* @throws Exception |
279
|
|
|
*/ |
280
|
|
|
public function detailsCircle($circleUniqueId, $forceAll = false) { |
281
|
|
|
|
282
|
|
|
try { |
283
|
|
|
if (!$forceAll) { |
284
|
|
|
$circle = $this->circlesRequest->getCircle( |
285
|
|
|
$circleUniqueId, $this->userId, Member::TYPE_USER, '', $forceAll |
286
|
|
|
); |
287
|
|
|
} else { |
288
|
|
|
$circle = $this->circlesRequest->getCircleFromUniqueId($circleUniqueId); |
289
|
|
|
} |
290
|
|
|
if ($forceAll === true || $this->viewerIsAdmin() |
291
|
|
|
|| $circle->getHigherViewer() |
292
|
|
|
->isLevel(Member::LEVEL_MEMBER) |
293
|
|
|
) { |
294
|
|
|
$this->detailsCircleMembers($circle, $forceAll); |
|
|
|
|
295
|
|
|
$this->detailsCircleLinkedGroups($circle); |
|
|
|
|
296
|
|
|
$this->detailsCircleFederatedCircles($circle); |
297
|
|
|
} |
298
|
|
|
} catch (Exception $e) { |
299
|
|
|
throw $e; |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
return $circle; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* get the Members list and add the result to the Circle. |
308
|
|
|
* |
309
|
|
|
* @param DeprecatedCircle $circle |
310
|
|
|
* |
311
|
|
|
* @throws Exception |
312
|
|
|
*/ |
313
|
|
|
private function detailsCircleMembers(Circle $circle, $forceAll = false) { |
314
|
|
|
if ($forceAll || $this->viewerIsAdmin()) { |
315
|
|
|
$members = $this->membersRequest->forceGetMembers($circle->getUniqueId(), 0); |
316
|
|
|
} else { |
317
|
|
|
$members = $this->membersRequest->getMembers( |
318
|
|
|
$circle->getUniqueId(), $circle->getHigherViewer() |
319
|
|
|
); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
$circle->setMembers($members); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* // TODO - check this on GS setup |
328
|
|
|
* get the Linked Group list and add the result to the Circle. |
329
|
|
|
* |
330
|
|
|
* @param DeprecatedCircle $circle |
331
|
|
|
* |
332
|
|
|
* @throws GSStatusException |
333
|
|
|
*/ |
334
|
|
|
private function detailsCircleLinkedGroups(DeprecatedCircle $circle) { |
|
|
|
|
335
|
|
|
// $groups = []; |
336
|
|
|
// if ($this->configService->isLinkedGroupsAllowed()) { |
337
|
|
|
// $groups = |
338
|
|
|
// $this->membersRequest->getGroupsFromCircle( |
339
|
|
|
// $circle->getUniqueId(), $circle->getHigherViewer() |
340
|
|
|
// ); |
341
|
|
|
// } |
342
|
|
|
// |
343
|
|
|
// $circle->setGroups($groups); |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* get the Federated Circles list and add the result to the Circle. |
349
|
|
|
* |
350
|
|
|
* @param DeprecatedCircle $circle |
351
|
|
|
*/ |
352
|
|
|
private function detailsCircleFederatedCircles(DeprecatedCircle $circle) { |
353
|
|
|
$links = []; |
354
|
|
|
|
355
|
|
|
try { |
356
|
|
|
if ($this->configService->isFederatedCirclesAllowed()) { |
|
|
|
|
357
|
|
|
$circle->hasToBeFederated(); |
358
|
|
|
$links = $this->federatedLinksRequest->getLinksFromCircle($circle->getUniqueId()); |
359
|
|
|
} |
360
|
|
|
} catch (FederatedCircleNotAllowedException $e) { |
|
|
|
|
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
$circle->setLinks($links); |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* save new settings if current user is admin. |
369
|
|
|
* |
370
|
|
|
* @param string $circleUniqueId |
371
|
|
|
* @param array $settings |
372
|
|
|
* |
373
|
|
|
* @return DeprecatedCircle |
374
|
|
|
* @throws Exception |
375
|
|
|
*/ |
376
|
|
|
public function settingsCircle(string $circleUniqueId, array $settings) { |
377
|
|
|
$circle = $this->circlesRequest->getCircle($circleUniqueId, $this->userId); |
378
|
|
|
$this->hasToBeOwner($circle->getHigherViewer()); |
379
|
|
|
|
380
|
|
|
if (!$this->viewerIsAdmin()) { |
381
|
|
|
$settings['members_limit'] = $circle->getSetting('members_limit'); |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
if ($this->get('password_single', $settings) === '' |
385
|
|
|
&& $circle->getSetting('password_single_enabled') === 'false') { |
386
|
|
|
$settings['password_single_enabled'] = false; |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
// can only be run from the instance of the circle's owner. |
390
|
|
|
$event = new GSEvent(GSEvent::CIRCLE_UPDATE); |
391
|
|
|
$event->setDeprecatedCircle($circle); |
|
|
|
|
392
|
|
|
$event->getData() |
393
|
|
|
->sBool('local_admin', $this->viewerIsAdmin()) |
394
|
|
|
->sArray('settings', $settings); |
395
|
|
|
|
396
|
|
|
if ($this->getBool('password_enforcement', $settings) === true |
397
|
|
|
&& $this->getBool('password_single_enabled', $settings) === true |
398
|
|
|
&& $this->get('password_single', $settings) !== '' |
399
|
|
|
) { |
400
|
|
|
$event->getData() |
401
|
|
|
->sBool('password_changed', true); |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
$this->gsUpstreamService->newEvent($event); |
405
|
|
|
|
406
|
|
|
$circle->setSettings($settings); |
407
|
|
|
|
408
|
|
|
return $circle; |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
|
412
|
|
|
/** |
413
|
|
|
* @param DeprecatedCircle $circle |
414
|
|
|
*/ |
415
|
|
|
public function updatePasswordOnShares(DeprecatedCircle $circle) { |
416
|
|
|
$this->tokensRequest->updateSinglePassword($circle->getUniqueId(), $circle->getPasswordSingle()); |
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
|
420
|
|
|
/** |
421
|
|
|
* Join a circle. |
422
|
|
|
* |
423
|
|
|
* @param string $circleUniqueId |
424
|
|
|
* |
425
|
|
|
* @return null|DeprecatedMember |
426
|
|
|
* @throws Exception |
427
|
|
|
*/ |
428
|
|
|
public function joinCircle($circleUniqueId): DeprecatedMember { |
429
|
|
|
try { |
430
|
|
|
$circle = $this->circlesRequest->getCircle($circleUniqueId, $this->userId); |
431
|
|
|
$member = $this->membersRequest->getFreshNewMember( |
432
|
|
|
$circleUniqueId, $this->userId, DeprecatedMember::TYPE_USER, '' |
433
|
|
|
); |
434
|
|
|
|
435
|
|
|
$this->membersService->updateCachedName($member); |
436
|
|
|
|
437
|
|
|
$event = new GSEvent(GSEvent::MEMBER_JOIN); |
438
|
|
|
$event->setDeprecatedCircle($circle); |
|
|
|
|
439
|
|
|
$event->setMember($member); |
440
|
|
|
$this->gsUpstreamService->newEvent($event); |
441
|
|
|
} catch (Exception $e) { |
442
|
|
|
throw $e; |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
return $member; |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
|
449
|
|
|
/** |
450
|
|
|
* Leave a circle. |
451
|
|
|
* |
452
|
|
|
* @param string $circleUniqueId |
453
|
|
|
* |
454
|
|
|
* @return null|DeprecatedMember |
455
|
|
|
* @throws Exception |
456
|
|
|
*/ |
457
|
|
|
public function leaveCircle($circleUniqueId) { |
458
|
|
|
$circle = $this->circlesRequest->getCircle($circleUniqueId, $this->userId); |
459
|
|
|
$member = $circle->getViewer(); |
460
|
|
|
|
461
|
|
|
$event = new GSEvent(GSEvent::MEMBER_LEAVE); |
462
|
|
|
$event->setDeprecatedCircle($circle); |
|
|
|
|
463
|
|
|
$event->setMember($member); |
464
|
|
|
$this->gsUpstreamService->newEvent($event); |
465
|
|
|
|
466
|
|
|
return $member; |
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
|
470
|
|
|
/** |
471
|
|
|
* destroy a circle. |
472
|
|
|
* |
473
|
|
|
* @param string $circleUniqueId |
474
|
|
|
* |
475
|
|
|
* @param bool $force |
476
|
|
|
* |
477
|
|
|
* @throws CircleDoesNotExistException |
478
|
|
|
* @throws MemberIsNotOwnerException |
479
|
|
|
* @throws ConfigNoCircleAvailableException |
480
|
|
|
* @throws Exception |
481
|
|
|
*/ |
482
|
|
|
public function removeCircle($circleUniqueId, bool $force = false) { |
483
|
|
|
if ($force) { |
484
|
|
|
$circle = $this->circlesRequest->forceGetCircle($circleUniqueId); |
485
|
|
|
} else { |
486
|
|
|
$circle = $this->circlesRequest->getCircle($circleUniqueId, $this->userId); |
487
|
|
|
$this->hasToBeOwner($circle->getHigherViewer()); |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
// removing a Circle is done only by owner, so can already be done by local user, or admin, or occ |
491
|
|
|
// at this point, we already know that all condition are filled. we can force it. |
492
|
|
|
$event = new GSEvent(GSEvent::CIRCLE_DESTROY, false, true); |
493
|
|
|
$event->setDeprecatedCircle($circle); |
|
|
|
|
494
|
|
|
|
495
|
|
|
$this->gsUpstreamService->newEvent($event); |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
|
499
|
|
|
/** |
500
|
|
|
* @return DeprecatedCircle[] |
501
|
|
|
*/ |
502
|
|
|
public function getCirclesToSync(): array { |
503
|
|
|
$circles = $this->circlesRequest->forceGetCircles(); |
504
|
|
|
|
505
|
|
|
$sync = []; |
506
|
|
|
foreach ($circles as $circle) { |
507
|
|
|
if ($circle->getOwner() |
508
|
|
|
->getInstance() !== '' |
509
|
|
|
// || $circle->getType() === Circle::CIRCLES_PERSONAL |
510
|
|
|
) { |
511
|
|
|
continue; |
512
|
|
|
} |
513
|
|
|
|
514
|
|
|
$members = $this->membersRequest->forceGetMembers($circle->getUniqueId()); |
515
|
|
|
$circle->setMembers($members); |
516
|
|
|
|
517
|
|
|
$sync[] = $circle; |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
return $sync; |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
|
524
|
|
|
/** |
525
|
|
|
* @param $circleName |
526
|
|
|
* |
527
|
|
|
* @return DeprecatedCircle|null |
528
|
|
|
* @throws CircleDoesNotExistException |
529
|
|
|
*/ |
530
|
|
|
public function infoCircleByName($circleName) { |
531
|
|
|
return $this->circlesRequest->forceGetCircleByName($circleName); |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
|
535
|
|
|
/** |
536
|
|
|
* Convert a Type in String to its Bit Value |
537
|
|
|
* |
538
|
|
|
* @param string $type |
539
|
|
|
* |
540
|
|
|
* @return int|mixed |
541
|
|
|
*/ |
542
|
|
|
public function convertTypeStringToBitValue($type) { |
543
|
|
|
$strings = [ |
544
|
|
|
'personal' => DeprecatedCircle::CIRCLES_PERSONAL, |
545
|
|
|
'secret' => DeprecatedCircle::CIRCLES_SECRET, |
546
|
|
|
'closed' => DeprecatedCircle::CIRCLES_CLOSED, |
547
|
|
|
'public' => DeprecatedCircle::CIRCLES_PUBLIC, |
548
|
|
|
'all' => DeprecatedCircle::CIRCLES_ALL |
549
|
|
|
]; |
550
|
|
|
|
551
|
|
|
if (!key_exists(strtolower($type), $strings)) { |
552
|
|
|
return $type; |
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
return $strings[strtolower($type)]; |
556
|
|
|
} |
557
|
|
|
|
558
|
|
|
|
559
|
|
|
/** |
560
|
|
|
* getCircleIcon() |
561
|
|
|
* |
562
|
|
|
* Return the right imagePath for a type of circle. |
563
|
|
|
* |
564
|
|
|
* @param string $type |
565
|
|
|
* @param bool $png |
566
|
|
|
* |
567
|
|
|
* @return string |
568
|
|
|
*/ |
569
|
|
|
public static function getCircleIcon($type, $png = false) { |
570
|
|
|
|
571
|
|
|
$ext = '.svg'; |
572
|
|
|
if ($png === true) { |
573
|
|
|
$ext = '.png'; |
574
|
|
|
} |
575
|
|
|
|
576
|
|
|
$urlGen = OC::$server->getURLGenerator(); |
577
|
|
|
switch ($type) { |
578
|
|
|
case DeprecatedCircle::CIRCLES_PERSONAL: |
579
|
|
|
return $urlGen->getAbsoluteURL( |
580
|
|
|
$urlGen->imagePath(Application::APP_ID, 'personal' . $ext) |
581
|
|
|
); |
582
|
|
|
case DeprecatedCircle::CIRCLES_CLOSED: |
583
|
|
|
return $urlGen->getAbsoluteURL( |
584
|
|
|
$urlGen->imagePath(Application::APP_ID, 'closed' . $ext) |
585
|
|
|
); |
586
|
|
|
case DeprecatedCircle::CIRCLES_SECRET: |
587
|
|
|
return $urlGen->getAbsoluteURL( |
588
|
|
|
$urlGen->imagePath(Application::APP_ID, 'secret' . $ext) |
589
|
|
|
); |
590
|
|
|
case DeprecatedCircle::CIRCLES_PUBLIC: |
591
|
|
|
return $urlGen->getAbsoluteURL( |
592
|
|
|
$urlGen->imagePath(Application::APP_ID, 'black_circle' . $ext) |
593
|
|
|
); |
594
|
|
|
} |
595
|
|
|
|
596
|
|
|
return $urlGen->getAbsoluteURL( |
597
|
|
|
$urlGen->imagePath(Application::APP_ID, 'black_circle' . $ext) |
598
|
|
|
); |
599
|
|
|
} |
600
|
|
|
|
601
|
|
|
|
602
|
|
|
/** |
603
|
|
|
* @param string $circleUniqueIds |
604
|
|
|
* @param int $limit |
605
|
|
|
* @param int $offset |
606
|
|
|
* |
607
|
|
|
* @return array |
608
|
|
|
* @throws GSStatusException |
609
|
|
|
*/ |
610
|
|
|
public function getFilesForCircles($circleUniqueIds, $limit = -1, $offset = 0) { |
611
|
|
|
if (!is_array($circleUniqueIds)) { |
612
|
|
|
$circleUniqueIds = [$circleUniqueIds]; |
613
|
|
|
} |
614
|
|
|
|
615
|
|
|
return $this->circleProviderRequest->getFilesForCircles( |
616
|
|
|
$this->userId, $circleUniqueIds, $limit, $offset |
617
|
|
|
); |
618
|
|
|
} |
619
|
|
|
|
620
|
|
|
|
621
|
|
|
/** |
622
|
|
|
* @param DeprecatedCircle $circle |
623
|
|
|
* |
624
|
|
|
* @throws MembersLimitException |
625
|
|
|
*/ |
626
|
|
|
public function checkThatCircleIsNotFull(DeprecatedCircle $circle) { |
627
|
|
|
$members = |
628
|
|
|
$this->membersRequest->forceGetMembers( |
629
|
|
|
$circle->getUniqueId(), DeprecatedMember::LEVEL_MEMBER, 0, true |
630
|
|
|
); |
631
|
|
|
|
632
|
|
|
$limit = (int)$circle->getSetting('members_limit'); |
633
|
|
|
if ($limit === -1) { |
634
|
|
|
return; |
635
|
|
|
} |
636
|
|
|
if ($limit === 0) { |
637
|
|
|
$limit = $this->configService->getAppValue(ConfigService::MEMBERS_LIMIT); |
638
|
|
|
} |
639
|
|
|
|
640
|
|
|
if (sizeof($members) >= $limit) { |
641
|
|
|
throw new MembersLimitException( |
642
|
|
|
'This circle already reach its limit on the number of members' |
643
|
|
|
); |
644
|
|
|
} |
645
|
|
|
|
646
|
|
|
} |
647
|
|
|
|
648
|
|
|
/** |
649
|
|
|
* @return bool |
650
|
|
|
*/ |
651
|
|
|
public function viewerIsAdmin(): bool { |
652
|
|
|
if ($this->userId === '') { |
653
|
|
|
return false; |
654
|
|
|
} |
655
|
|
|
|
656
|
|
|
return ($this->groupManager->isAdmin($this->userId)); |
657
|
|
|
} |
658
|
|
|
|
659
|
|
|
|
660
|
|
|
/** |
661
|
|
|
* should be moved. |
662
|
|
|
* |
663
|
|
|
* @param DeprecatedMember $member |
664
|
|
|
* |
665
|
|
|
* @throws MemberIsNotOwnerException |
666
|
|
|
*/ |
667
|
|
View Code Duplication |
public function hasToBeOwner(DeprecatedMember $member) { |
|
|
|
|
668
|
|
|
if (!$this->groupManager->isAdmin($this->userId) |
669
|
|
|
&& $member->getLevel() < DeprecatedMember::LEVEL_OWNER) { |
670
|
|
|
throw new MemberIsNotOwnerException( |
671
|
|
|
$this->l10n->t('This member is not the owner of the circle') |
672
|
|
|
); |
673
|
|
|
} |
674
|
|
|
} |
675
|
|
|
|
676
|
|
|
|
677
|
|
|
/** |
678
|
|
|
* should be moved. |
679
|
|
|
* |
680
|
|
|
* @param DeprecatedMember $member |
681
|
|
|
* |
682
|
|
|
* @throws MemberIsNotOwnerException |
683
|
|
|
*/ |
684
|
|
View Code Duplication |
public function hasToBeAdmin(DeprecatedMember $member) { |
|
|
|
|
685
|
|
|
if (!$this->groupManager->isAdmin($member->getUserId()) |
686
|
|
|
&& $member->getLevel() < DeprecatedMember::LEVEL_ADMIN) { |
687
|
|
|
throw new MemberIsNotOwnerException( |
688
|
|
|
$this->l10n->t('This member is not an admin of the circle') |
689
|
|
|
); |
690
|
|
|
} |
691
|
|
|
} |
692
|
|
|
|
693
|
|
|
} |
694
|
|
|
|
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.