2323use OCP \Share \Events \BeforeShareDeletedEvent ;
2424use OCP \Share \Events \ShareCreatedEvent ;
2525use OCP \Share \IManager ;
26+ use OCP \Share \IShare ;
2627
2728/**
2829 * Listen to various events that can change what shares a user has access to
@@ -52,9 +53,9 @@ public function handle(Event $event): void {
5253 if ($ event instanceof UserAddedEvent || $ event instanceof UserRemovedEvent) {
5354 $ this ->updateForUser ($ event ->getUser ());
5455 }
55- if ($ event instanceof ShareCreatedEvent || $ event instanceof BeforeShareDeletedEvent ) {
56+ if ($ event instanceof ShareCreatedEvent) {
5657 foreach ($ this ->shareManager ->getUsersForShare ($ event ->getShare ()) as $ user ) {
57- $ this ->updateForUser ($ user );
58+ $ this ->updateForShare ($ user, $ event -> getShare () );
5859 }
5960 }
6061 }
@@ -80,4 +81,21 @@ private function updateForUser(IUser $user): void {
8081 }
8182 }
8283 }
84+
85+ private function updateForShare (IUser $ user , IShare $ share ): void {
86+ if (isset ($ this ->updatedUsers [$ user ->getUID ()])) {
87+ return ;
88+ }
89+ $ this ->updatedUsers [$ user ->getUID ()] = true ;
90+
91+ $ cachedMounts = $ this ->userMountCache ->getMountsForUser ($ user );
92+ $ mountPoints = array_map (fn (ICachedMountInfo $ mount ) => $ mount ->getMountPoint (), $ cachedMounts );
93+ $ mountsByPath = array_combine ($ mountPoints , $ cachedMounts );
94+
95+ $ mountPoint = '/ ' . $ user ->getUID () . '/files/ ' . trim ($ share ->getTarget (), '/ ' ) . '/ ' ;
96+ $ mountKey = $ share ->getNodeId () . ':: ' . $ mountPoint ;
97+ if (!isset ($ cachedMounts [$ mountKey ])) {
98+ $ this ->shareTargetValidator ->verifyMountPoint ($ user , $ share , $ mountsByPath , []);
99+ }
100+ }
83101}
0 commit comments