1515use OCP \EventDispatcher \IEventListener ;
1616use OCP \Files \Config \ICachedMountInfo ;
1717use OCP \Files \Config \IUserMountCache ;
18+ use OCP \Files \Storage \IStorageFactory ;
1819use OCP \Group \Events \UserAddedEvent ;
1920use OCP \Group \Events \UserRemovedEvent ;
2021use OCP \IUser ;
@@ -36,50 +37,64 @@ public function __construct(
3637 private readonly IUserMountCache $ userMountCache ,
3738 private readonly MountProvider $ shareMountProvider ,
3839 private readonly ShareTargetValidator $ shareTargetValidator ,
40+ private readonly IStorageFactory $ storageFactory ,
3941 ) {
4042 }
4143 public function handle (Event $ event ): void {
4244 if ($ event instanceof UserShareAccessUpdatedEvent) {
4345 foreach ($ event ->getUsers () as $ user ) {
44- $ this ->updateForUser ($ user );
46+ $ this ->updateForUser ($ user, true );
4547 }
4648 }
4749 if ($ event instanceof UserAddedEvent || $ event instanceof UserRemovedEvent) {
48- $ this ->updateForUser ($ event ->getUser ());
50+ $ this ->updateForUser ($ event ->getUser (), true );
4951 }
5052 if (
5153 $ event instanceof ShareCreatedEvent
52- || $ event instanceof BeforeShareDeletedEvent
5354 || $ event instanceof ShareTransferredEvent
5455 ) {
5556 foreach ($ this ->shareManager ->getUsersForShare ($ event ->getShare ()) as $ user ) {
56- $ this ->updateForUser ($ user );
57+ $ this ->updateForUser ($ user , true );
58+ }
59+ }
60+ if ($ event instanceof BeforeShareDeletedEvent) {
61+ foreach ($ this ->shareManager ->getUsersForShare ($ event ->getShare ()) as $ user ) {
62+ $ this ->updateForUser ($ user , false , [$ event ->getShare ()]);
5763 }
5864 }
5965 }
6066
61- private function updateForUser (IUser $ user ): void {
67+ private function updateForUser (IUser $ user, bool $ verifyMountPoints , array $ ignoreShares = [] ): void {
6268 // prevent recursion
6369 if (isset ($ this ->inUpdate [$ user ->getUID ()])) {
6470 return ;
6571 }
6672 $ this ->inUpdate [$ user ->getUID ()] = true ;
67-
6873 $ cachedMounts = $ this ->userMountCache ->getMountsForUser ($ user );
74+ $ shareMounts = array_filter ($ cachedMounts , fn (ICachedMountInfo $ mount ) => $ mount ->getMountProvider () === MountProvider::class);
6975 $ mountPoints = array_map (fn (ICachedMountInfo $ mount ) => $ mount ->getMountPoint (), $ cachedMounts );
7076 $ mountsByPath = array_combine ($ mountPoints , $ cachedMounts );
7177
72- $ shares = $ this ->shareMountProvider ->getSuperSharesForUser ($ user );
78+ $ shares = $ this ->shareMountProvider ->getSuperSharesForUser ($ user, $ ignoreShares );
7379
80+ $ mountsChanged = count ($ shares ) !== count ($ shareMounts );
7481 foreach ($ shares as &$ share ) {
7582 [$ parentShare , $ groupedShares ] = $ share ;
7683 $ mountPoint = '/ ' . $ user ->getUID () . '/files/ ' . trim ($ parentShare ->getTarget (), '/ ' ) . '/ ' ;
7784 $ mountKey = $ parentShare ->getNodeId () . ':: ' . $ mountPoint ;
7885 if (!isset ($ cachedMounts [$ mountKey ])) {
79- $ this ->shareTargetValidator ->verifyMountPoint ($ user , $ parentShare , $ mountsByPath , $ groupedShares );
86+ $ mountsChanged = true ;
87+ if ($ verifyMountPoints ) {
88+ $ this ->shareTargetValidator ->verifyMountPoint ($ user , $ parentShare , $ mountsByPath , $ groupedShares );
89+ }
8090 }
8191 }
8292
93+ if ($ mountsChanged ) {
94+ $ newMounts = $ this ->shareMountProvider ->getMountsFromSuperShares ($ user , $ shares , $ this ->storageFactory );
95+ $ this ->userMountCache ->registerMounts ($ user , $ newMounts , [MountProvider::class]);
96+ }
97+
8398 unset($ this ->inUpdate [$ user ->getUID ()]);
8499 }
85100}
0 commit comments