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 ;
23
24
use OCP \Files \FileInfo ;
24
25
use OCP \Files \IMimeTypeLoader ;
25
26
use OCP \Files \IRootFolder ;
26
- use OCP \IConfig ;
27
+ use OCP \IConfig ;m
27
28
use OCP \IDBConnection ;
28
29
use OCP \IGroup ;
29
30
use OCP \IGroupManager ;
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,15 @@ 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
+ public function searchCircles (int $ id , string $ search = '' ): array {
497
+ $ circles = $ this ->getCircles ($ id );
498
+ if ($ search === '' ) {
499
+ return $ circles ;
500
+ }
501
+
502
+ return array_values (array_filter ($ circles , fn (array $ circle ): bool => (stripos ($ circle ['displayname ' ], $ search ) !== false )));
503
+ }
504
+
463
505
/**
464
506
* @throws Exception
465
507
* @return list<GroupFoldersUser>
@@ -482,6 +524,27 @@ public function searchUsers(int $id, string $search = '', int $limit = 10, int $
482
524
}
483
525
}
484
526
527
+ foreach ($ this ->getCircles ($ id ) as $ circleData ) {
528
+ $ circle = $ this ->getCircle ($ circleData ['sid ' ]);
529
+ if ($ circle === null ) {
530
+ continue ;
531
+ }
532
+
533
+ foreach ($ circle ->getInheritedMembers (false ) as $ member ) {
534
+ if ($ member ->getUserType () !== Member::TYPE_USER ) {
535
+ continue ;
536
+ }
537
+
538
+ $ uid = $ member ->getUserId ();
539
+ if (!isset ($ users [$ uid ])) {
540
+ $ users [$ uid ] = [
541
+ 'uid ' => $ uid ,
542
+ 'displayname ' => $ member ->getDisplayName ()
543
+ ];
544
+ }
545
+ }
546
+ }
547
+
485
548
return array_values ($ users );
486
549
}
487
550
@@ -918,27 +981,32 @@ public function getFolderPermissionsForUser(IUser $user, int $folderId): int {
918
981
* returns if the groupId is in fact the singleId of an existing Circle
919
982
*/
920
983
public function isACircle (string $ groupId ): bool {
984
+ return ($ this ->getCircle ($ groupId ) !== null );
985
+ }
986
+
987
+ /**
988
+ * returns the Circle from its single Id, or NULL if not available
989
+ */
990
+ public function getCircle (string $ groupId ): ?Circle {
921
991
$ circlesManager = $ this ->getCirclesManager ();
922
992
if ($ circlesManager === null ) {
923
- return false ;
993
+ return null ;
924
994
}
925
995
926
996
$ circlesManager ->startSuperSession ();
927
997
$ probe = new CircleProbe ();
928
998
$ probe ->includeSystemCircles ();
929
999
$ probe ->includeSingleCircles ();
930
1000
try {
931
- $ circlesManager ->getCircle ($ groupId , $ probe );
932
-
933
- return true ;
1001
+ return $ circlesManager ->getCircle ($ groupId , $ probe );
934
1002
} catch (CircleNotFoundException ) {
935
1003
} catch (\Exception $ e ) {
936
1004
$ this ->logger ->warning ('' , ['exception ' => $ e ]);
937
1005
} finally {
938
1006
$ circlesManager ->stopSession ();
939
1007
}
940
1008
941
- return false ;
1009
+ return null ;
942
1010
}
943
1011
944
1012
public function getCirclesManager (): ?CirclesManager {
0 commit comments