1818use OCA \Tables \Db \ViewMapper ;
1919use OCA \Tables \Errors \InternalError ;
2020use OCA \Tables \Errors \NotFoundError ;
21+ use OCA \Tables \Helper \CircleHelper ;
2122use OCA \Tables \Helper \ConversionHelper ;
2223use OCA \Tables \Helper \UserHelper ;
2324use OCA \Tables \Model \Permissions ;
2425use OCP \AppFramework \Db \DoesNotExistException ;
2526use OCP \AppFramework \Db \MultipleObjectsReturnedException ;
2627use OCP \DB \Exception ;
2728use Psr \Log \LoggerInterface ;
29+ use Throwable ;
2830
2931class PermissionsService {
3032 private TableMapper $ tableMapper ;
@@ -35,11 +37,14 @@ class PermissionsService {
3537
3638 private UserHelper $ userHelper ;
3739
40+ private CircleHelper $ circleHelper ;
41+
3842 protected LoggerInterface $ logger ;
3943
4044 protected ?string $ userId = null ;
4145
4246 protected bool $ isCli = false ;
47+
4348 private ContextMapper $ contextMapper ;
4449
4550 public function __construct (
@@ -50,6 +55,7 @@ public function __construct(
5055 ShareMapper $ shareMapper ,
5156 ContextMapper $ contextMapper ,
5257 UserHelper $ userHelper ,
58+ CircleHelper $ circleHelper ,
5359 bool $ isCLI
5460 ) {
5561 $ this ->tableMapper = $ tableMapper ;
@@ -60,6 +66,7 @@ public function __construct(
6066 $ this ->userId = $ userId ;
6167 $ this ->isCli = $ isCLI ;
6268 $ this ->contextMapper = $ contextMapper ;
69+ $ this ->circleHelper = $ circleHelper ;
6370 }
6471
6572
@@ -420,6 +427,7 @@ public function canReadShare(Share $share, ?string $userId = null): bool {
420427 * @param int $elementId
421428 * @param 'table'|'view' $elementType
422429 * @param string $userId
430+ * @return Permissions
423431 * @throws NotFoundError
424432 */
425433 public function getSharedPermissionsIfSharedWithMe (int $ elementId , string $ elementType , string $ userId ): Permissions {
@@ -436,16 +444,40 @@ public function getSharedPermissionsIfSharedWithMe(int $elementId, string $eleme
436444 $ this ->logger ->warning ('Exception occurred: ' .$ e ->getMessage ().' Permission denied. ' );
437445 return new Permissions ();
438446 }
439- $ additionalShares = [];
447+ $ groupShares = [];
440448 foreach ($ userGroups as $ userGroup ) {
441449 try {
442- $ additionalShares [] = $ this ->shareMapper ->findAllSharesForNodeFor ($ elementType , $ elementId , $ userGroup ->getGid (), 'group ' );
450+ $ groupShares [] = $ this ->shareMapper ->findAllSharesForNodeFor ($ elementType , $ elementId , $ userGroup ->getGid (), 'group ' );
443451 } catch (Exception $ e ) {
444452 $ this ->logger ->warning ('Exception occurred: ' .$ e ->getMessage ().' Permission denied. ' );
445453 return new Permissions ();
446454 }
447455 }
448- $ shares = array_merge ($ shares , ...$ additionalShares );
456+
457+ $ shares = array_merge ($ shares , ...$ groupShares );
458+
459+ if ($ this ->circleHelper ->isCirclesEnabled ()) {
460+ $ circleShares = [];
461+
462+ try {
463+ $ userCircles = $ this ->circleHelper ->getUserCircles ($ userId );
464+ } catch (Throwable $ e ) {
465+ $ this ->logger ->warning ('Exception occurred: ' . $ e ->getMessage () . ' Permission denied. ' );
466+ return new Permissions ();
467+ }
468+
469+ foreach ($ userCircles as $ userCircle ) {
470+ try {
471+ $ circleShares [] = $ this ->shareMapper ->findAllSharesForNodeFor ($ elementType , $ elementId , $ userCircle ->getSingleId (), 'circle ' );
472+ } catch (Exception $ e ) {
473+ $ this ->logger ->warning ('Exception occurred: ' . $ e ->getMessage () . ' Permission denied. ' );
474+ return new Permissions ();
475+ }
476+ }
477+
478+ $ shares = array_merge ($ shares , ...$ circleShares );
479+ }
480+
449481 if (count ($ shares ) > 0 ) {
450482 $ read = array_reduce ($ shares , function ($ carry , $ share ) {
451483 return $ carry || ($ share ->getPermissionRead ());
@@ -520,7 +552,7 @@ private function hasPermission(int $existingPermissions, string $permissionName)
520552 $ constantName = 'PERMISSION_ ' . strtoupper ($ permissionName );
521553 try {
522554 $ permissionBit = constant (Application::class . ":: $ constantName " );
523- } catch (\ Throwable $ t ) {
555+ } catch (Throwable $ t ) {
524556 $ this ->logger ->error ('Unexpected permission string {permission} ' , [
525557 'app ' => Application::APP_ID ,
526558 'permission ' => $ permissionName ,
0 commit comments