1717use OCP \Files \Config \ICachedMountInfo ;
1818use OCP \Files \Config \IUserMountCache ;
1919use OCP \Files \Events \Node \FilesystemTornDownEvent ;
20+ use OCP \Files \Storage \IStorageFactory ;
2021use OCP \Group \Events \UserAddedEvent ;
2122use OCP \Group \Events \UserRemovedEvent ;
2223use OCP \IUser ;
@@ -37,6 +38,7 @@ public function __construct(
3738 private readonly IUserMountCache $ userMountCache ,
3839 private readonly MountProvider $ shareMountProvider ,
3940 private readonly ShareTargetValidator $ shareTargetValidator ,
41+ private readonly IStorageFactory $ storageFactory ,
4042 ) {
4143 $ this ->updatedUsers = new CappedMemoryCache ();
4244 }
@@ -46,38 +48,52 @@ public function handle(Event $event): void {
4648 }
4749 if ($ event instanceof UserShareAccessUpdatedEvent) {
4850 foreach ($ event ->getUsers () as $ user ) {
49- $ this ->updateForUser ($ user );
51+ $ this ->updateForUser ($ user, true );
5052 }
5153 }
5254 if ($ event instanceof UserAddedEvent || $ event instanceof UserRemovedEvent) {
53- $ this ->updateForUser ($ event ->getUser ());
55+ $ this ->updateForUser ($ event ->getUser (), true );
5456 }
55- if ($ event instanceof ShareCreatedEvent || $ event instanceof BeforeShareDeletedEvent ) {
57+ if ($ event instanceof ShareCreatedEvent) {
5658 foreach ($ this ->shareManager ->getUsersForShare ($ event ->getShare ()) as $ user ) {
57- $ this ->updateForUser ($ user );
59+ $ this ->updateForUser ($ user , true );
60+ }
61+ }
62+ if ($ event instanceof BeforeShareDeletedEvent) {
63+ foreach ($ this ->shareManager ->getUsersForShare ($ event ->getShare ()) as $ user ) {
64+ $ this ->updateForUser ($ user , false , [$ event ->getShare ()]);
5865 }
5966 }
6067 }
6168
62- private function updateForUser (IUser $ user ): void {
69+ private function updateForUser (IUser $ user, bool $ verifyMountPoints , array $ ignoreShares = [] ): void {
6370 if (isset ($ this ->updatedUsers [$ user ->getUID ()])) {
6471 return ;
6572 }
6673 $ this ->updatedUsers [$ user ->getUID ()] = true ;
67-
6874 $ cachedMounts = $ this ->userMountCache ->getMountsForUser ($ user );
75+ $ shareMounts = array_filter ($ cachedMounts , fn (ICachedMountInfo $ mount ) => $ mount ->getMountProvider () === MountProvider::class);
6976 $ mountPoints = array_map (fn (ICachedMountInfo $ mount ) => $ mount ->getMountPoint (), $ cachedMounts );
7077 $ mountsByPath = array_combine ($ mountPoints , $ cachedMounts );
7178
72- $ shares = $ this ->shareMountProvider ->getSuperSharesForUser ($ user );
79+ $ shares = $ this ->shareMountProvider ->getSuperSharesForUser ($ user, $ ignoreShares );
7380
81+ $ mountsChanged = count ($ shares ) !== count ($ shareMounts );
7482 foreach ($ shares as &$ share ) {
7583 [$ parentShare , $ groupedShares ] = $ share ;
7684 $ mountPoint = '/ ' . $ user ->getUID () . '/files/ ' . trim ($ parentShare ->getTarget (), '/ ' ) . '/ ' ;
7785 $ mountKey = $ parentShare ->getNodeId () . ':: ' . $ mountPoint ;
7886 if (!isset ($ cachedMounts [$ mountKey ])) {
79- $ this ->shareTargetValidator ->verifyMountPoint ($ user , $ parentShare , $ mountsByPath , $ groupedShares );
87+ $ mountsChanged = true ;
88+ if ($ verifyMountPoints ) {
89+ $ this ->shareTargetValidator ->verifyMountPoint ($ user , $ parentShare , $ mountsByPath , $ groupedShares );
90+ }
8091 }
8192 }
93+
94+ if ($ mountsChanged ) {
95+ $ newMounts = $ this ->shareMountProvider ->getMountsFromSuperShares ($ user , $ shares , $ this ->storageFactory );
96+ $ this ->userMountCache ->registerMounts ($ user , $ newMounts , [MountProvider::class]);
97+ }
8298 }
8399}
0 commit comments