11
11
use OC \Files \Node \Node ;
12
12
use OCA \Circles \CirclesManager ;
13
13
use OCA \Circles \Exceptions \CircleNotFoundException ;
14
+ use OCA \Circles \Model \Circle ;
15
+ use OCA \Circles \Model \Member ;
14
16
use OCA \Circles \Model \Probes \CircleProbe ;
15
17
use OCA \GroupFolders \Mount \GroupMountPoint ;
16
18
use OCA \GroupFolders \ResponseDefinitions ;
17
- use OCA \GroupFolders \Settings \Admin ;
18
19
use OCP \AutoloadNotAllowedException ;
19
20
use OCP \Constants ;
20
21
use OCP \DB \Exception ;
36
37
37
38
/**
38
39
* @psalm-import-type GroupFoldersGroup from ResponseDefinitions
40
+ * @psalm-import-type GroupFoldersCircle from ResponseDefinitions
39
41
* @psalm-import-type GroupFoldersUser from ResponseDefinitions
40
42
* @psalm-import-type GroupFoldersAclManage from ResponseDefinitions
41
43
* @psalm-import-type GroupFoldersApplicable from ResponseDefinitions
@@ -264,16 +266,33 @@ private function getManageAcl(array $mappings): array {
264
266
];
265
267
}
266
268
267
- $ group = Server::get (IGroupManager::class)->get ($ entry ['mapping_id ' ]);
268
- if ($ group === null ) {
269
- return null ;
269
+ if ($ entry ['mapping_type ' ] === 'group ' ) {
270
+ $ group = Server::get (IGroupManager::class)->get ($ entry ['mapping_id ' ]);
271
+ if ($ group === null ) {
272
+ return null ;
273
+ }
274
+
275
+ return [
276
+ 'type ' => 'group ' ,
277
+ 'id ' => $ group ->getGID (),
278
+ 'displayname ' => $ group ->getDisplayName ()
279
+ ];
270
280
}
271
281
272
- return [
273
- 'type ' => 'group ' ,
274
- 'id ' => $ group ->getGID (),
275
- 'displayname ' => $ group ->getDisplayName ()
276
- ];
282
+ if ($ entry ['mapping_type ' ] === 'circle ' ) {
283
+ $ circle = $ this ->getCircle ($ entry ['mapping_id ' ]);
284
+ if ($ circle === null ) {
285
+ return null ;
286
+ }
287
+
288
+ return [
289
+ 'type ' => 'circle ' ,
290
+ 'id ' => $ circle ->getSingleId (),
291
+ 'displayname ' => $ circle ->getDisplayName ()
292
+ ];
293
+ }
294
+
295
+ return null ;
277
296
}, $ mappings )));
278
297
}
279
298
@@ -401,6 +420,20 @@ private function getGroups(int $id): array {
401
420
], array_values (array_filter ($ groups )));
402
421
}
403
422
423
+ /**
424
+ * @throws Exception
425
+ * @return list<GroupFoldersCircle>
426
+ */
427
+ private function getCircles (int $ id ): array {
428
+ $ circles = $ this ->getAllApplicable ()[$ id ] ?? [];
429
+ $ circles = array_map (fn (string $ singleId ): ?Circle => $ this ->getCircle ($ singleId ), array_keys ($ circles ));
430
+
431
+ return array_map (fn (Circle $ circle ): array => [
432
+ 'sid ' => $ circle ->getSingleId (),
433
+ 'displayname ' => $ circle ->getDisplayName ()
434
+ ], array_values (array_filter ($ circles )));
435
+ }
436
+
404
437
/**
405
438
* Check if the user is able to configure the advanced folder permissions. This
406
439
* is the case if the user is an admin, has admin permissions for the group folder
@@ -460,6 +493,19 @@ public function searchGroups(int $id, string $search = ''): array {
460
493
return array_values (array_filter ($ groups , fn (array $ group ): bool => (stripos ($ group ['gid ' ], $ search ) !== false ) || (stripos ($ group ['displayname ' ], $ search ) !== false )));
461
494
}
462
495
496
+ /**
497
+ * @throws Exception
498
+ * @return list<GroupFoldersCircle>
499
+ */
500
+ public function searchCircles (int $ id , string $ search = '' ): array {
501
+ $ circles = $ this ->getCircles ($ id );
502
+ if ($ search === '' ) {
503
+ return $ circles ;
504
+ }
505
+
506
+ return array_values (array_filter ($ circles , fn (array $ circle ): bool => (stripos ($ circle ['displayname ' ], $ search ) !== false )));
507
+ }
508
+
463
509
/**
464
510
* @throws Exception
465
511
* @return list<GroupFoldersUser>
@@ -482,6 +528,27 @@ public function searchUsers(int $id, string $search = '', int $limit = 10, int $
482
528
}
483
529
}
484
530
531
+ foreach ($ this ->getCircles ($ id ) as $ circleData ) {
532
+ $ circle = $ this ->getCircle ($ circleData ['sid ' ]);
533
+ if ($ circle === null ) {
534
+ continue ;
535
+ }
536
+
537
+ foreach ($ circle ->getInheritedMembers (false ) as $ member ) {
538
+ if ($ member ->getUserType () !== Member::TYPE_USER ) {
539
+ continue ;
540
+ }
541
+
542
+ $ uid = $ member ->getUserId ();
543
+ if (!isset ($ users [$ uid ])) {
544
+ $ users [$ uid ] = [
545
+ 'uid ' => $ uid ,
546
+ 'displayname ' => $ member ->getDisplayName ()
547
+ ];
548
+ }
549
+ }
550
+ }
551
+
485
552
return array_values ($ users );
486
553
}
487
554
@@ -918,27 +985,32 @@ public function getFolderPermissionsForUser(IUser $user, int $folderId): int {
918
985
* returns if the groupId is in fact the singleId of an existing Circle
919
986
*/
920
987
public function isACircle (string $ groupId ): bool {
988
+ return ($ this ->getCircle ($ groupId ) !== null );
989
+ }
990
+
991
+ /**
992
+ * returns the Circle from its single Id, or NULL if not available
993
+ */
994
+ public function getCircle (string $ groupId ): ?Circle {
921
995
$ circlesManager = $ this ->getCirclesManager ();
922
996
if ($ circlesManager === null ) {
923
- return false ;
997
+ return null ;
924
998
}
925
999
926
1000
$ circlesManager ->startSuperSession ();
927
1001
$ probe = new CircleProbe ();
928
1002
$ probe ->includeSystemCircles ();
929
1003
$ probe ->includeSingleCircles ();
930
1004
try {
931
- $ circlesManager ->getCircle ($ groupId , $ probe );
932
-
933
- return true ;
1005
+ return $ circlesManager ->getCircle ($ groupId , $ probe );
934
1006
} catch (CircleNotFoundException ) {
935
1007
} catch (\Exception $ e ) {
936
1008
$ this ->logger ->warning ('' , ['exception ' => $ e ]);
937
1009
} finally {
938
1010
$ circlesManager ->stopSession ();
939
1011
}
940
1012
941
- return false ;
1013
+ return null ;
942
1014
}
943
1015
944
1016
public function getCirclesManager (): ?CirclesManager {
0 commit comments