@@ -813,6 +813,61 @@ public function testGetShareById(): void {
813813 $ this ->assertEquals ($ share , $ this ->manager ->getShareById ('default:42 ' ));
814814 }
815815
816+ public function testGetShareByIdOfDisabledInitiatorAsShareOwner (): void {
817+ $ this ->config ->method ('getAppValue ' )
818+ ->willReturnMap ([
819+ ['files_sharing ' , 'hide_disabled_user_shares ' , 'yes ' , 'yes ' ],
820+ ]);
821+
822+ $ share = $ this ->manager ->newShare ();
823+ $ share ->setShareType (IShare::TYPE_USER )
824+ ->setShareOwner ('owner ' )
825+ ->setSharedBy ('initiator ' )
826+ ->setSharedWith ('recipient ' );
827+
828+ $ this ->userManager ->method ('get ' )->willReturnMap ([
829+ ['owner ' , $ this ->createEnabledUser (true )],
830+ ['initiator ' , $ this ->createEnabledUser (false )],
831+ ]);
832+
833+ $ this ->defaultProvider
834+ ->expects ($ this ->once ())
835+ ->method ('getShareById ' )
836+ ->with ('42 ' , 'owner ' )
837+ ->willReturn ($ share );
838+
839+ $ this ->assertSame ($ share , $ this ->manager ->getShareById ('default:42 ' , 'owner ' ));
840+ }
841+
842+ public function testGetShareByIdOfDisabledInitiatorAsOtherUser (): void {
843+ $ this ->expectException (ShareNotFound::class);
844+ $ this ->expectExceptionMessage ('The requested share does not exist anymore ' );
845+
846+ $ this ->config ->method ('getAppValue ' )
847+ ->willReturnMap ([
848+ ['files_sharing ' , 'hide_disabled_user_shares ' , 'yes ' , 'yes ' ],
849+ ]);
850+
851+ $ share = $ this ->manager ->newShare ();
852+ $ share ->setShareType (IShare::TYPE_USER )
853+ ->setShareOwner ('owner ' )
854+ ->setSharedBy ('initiator ' )
855+ ->setSharedWith ('recipient ' );
856+
857+ $ this ->userManager ->method ('get ' )->willReturnMap ([
858+ ['owner ' , $ this ->createEnabledUser (true )],
859+ ['initiator ' , $ this ->createEnabledUser (false )],
860+ ]);
861+
862+ $ this ->defaultProvider
863+ ->expects ($ this ->once ())
864+ ->method ('getShareById ' )
865+ ->with ('42 ' , 'recipient ' )
866+ ->willReturn ($ share );
867+
868+ $ this ->manager ->getShareById ('default:42 ' , 'recipient ' );
869+ }
870+
816871 public function testGetExpiredShareById (): void {
817872 $ this ->expectException (ShareNotFound::class);
818873
@@ -960,6 +1015,13 @@ public function createShare($id, int $type, ?Node $node, $sharedWith, $sharedBy,
9601015 return $ share ;
9611016 }
9621017
1018+ private function createEnabledUser (bool $ enabled ): IUser &MockObject {
1019+ $ user = $ this ->createMock (IUser::class);
1020+ $ user ->method ('isEnabled ' )->willReturn ($ enabled );
1021+
1022+ return $ user ;
1023+ }
1024+
9631025 public static function dataGeneralChecks (): array {
9641026 $ user0 = 'user0 ' ;
9651027 $ user2 = 'user1 ' ;
@@ -3261,6 +3323,83 @@ public function testCreateShareUser(): void {
32613323 $ manager ->createShare ($ share );
32623324 }
32633325
3326+ public function testCreateShareUserAlreadySharedReusesExistingShare (): void {
3327+ /** @var Manager&MockObject $manager */
3328+ $ manager = $ this ->createManagerMock ()
3329+ ->onlyMethods (['generalChecks ' , 'userCreateChecks ' , 'pathCreateChecks ' ])
3330+ ->getMock ();
3331+
3332+ $ shareOwner = $ this ->createMock (IUser::class);
3333+ $ shareOwner ->method ('getUID ' )->willReturn ('shareOwner ' );
3334+
3335+ $ path = $ this ->createMock (File::class);
3336+ $ path ->method ('getOwner ' )->willReturn ($ shareOwner );
3337+ $ path ->method ('getName ' )->willReturn ('target ' );
3338+ $ path ->method ('getStorage ' )->willReturn ($ this ->createMock (IStorage::class));
3339+
3340+ $ share = $ this ->createShare (null , IShare::TYPE_USER , $ path , 'sharedWith ' , 'sharedBy ' , null , Constants::PERMISSION_ALL );
3341+ $ existingShare = $ this ->createShare ('42 ' , IShare::TYPE_USER , $ path , 'sharedWith ' , 'shareOwner ' , 'shareOwner ' , Constants::PERMISSION_READ );
3342+
3343+ $ this ->config ->method ('getAppValue ' )
3344+ ->willReturnMap ([
3345+ ['files_sharing ' , 'hide_disabled_user_shares ' , 'yes ' , 'yes ' ],
3346+ ]);
3347+ $ this ->userManager ->method ('get ' )->willReturnMap ([
3348+ ['shareOwner ' , $ this ->createEnabledUser (true )],
3349+ ]);
3350+
3351+ $ manager ->method ('userCreateChecks ' )
3352+ ->willThrowException (new AlreadySharedException ('Already shared ' , $ existingShare ));
3353+
3354+ $ this ->defaultProvider ->expects ($ this ->never ())
3355+ ->method ('create ' );
3356+
3357+ $ existingShare ->expects ($ this ->once ())
3358+ ->method ('setNode ' )
3359+ ->with ($ path );
3360+
3361+ $ this ->assertSame ($ existingShare , $ manager ->createShare ($ share ));
3362+ }
3363+
3364+ public function testCreateShareUserAlreadySharedByDisabledInitiator (): void {
3365+ $ this ->expectException (AlreadySharedException::class);
3366+
3367+ /** @var Manager&MockObject $manager */
3368+ $ manager = $ this ->createManagerMock ()
3369+ ->onlyMethods (['generalChecks ' , 'userCreateChecks ' , 'pathCreateChecks ' ])
3370+ ->getMock ();
3371+
3372+ $ shareOwner = $ this ->createMock (IUser::class);
3373+ $ shareOwner ->method ('getUID ' )->willReturn ('shareOwner ' );
3374+
3375+ $ path = $ this ->createMock (File::class);
3376+ $ path ->method ('getOwner ' )->willReturn ($ shareOwner );
3377+ $ path ->method ('getName ' )->willReturn ('target ' );
3378+ $ path ->method ('getStorage ' )->willReturn ($ this ->createMock (IStorage::class));
3379+
3380+ $ share = $ this ->createShare (null , IShare::TYPE_USER , $ path , 'sharedWith ' , 'shareOwner ' , null , Constants::PERMISSION_ALL );
3381+ $ existingShare = $ this ->createShare ('42 ' , IShare::TYPE_USER , $ path , 'sharedWith ' , 'initiator ' , 'shareOwner ' , Constants::PERMISSION_READ );
3382+
3383+ $ this ->config ->method ('getAppValue ' )
3384+ ->willReturnMap ([
3385+ ['files_sharing ' , 'hide_disabled_user_shares ' , 'yes ' , 'yes ' ],
3386+ ]);
3387+ $ this ->userManager ->method ('get ' )->willReturnMap ([
3388+ ['shareOwner ' , $ this ->createEnabledUser (true )],
3389+ ['initiator ' , $ this ->createEnabledUser (false )],
3390+ ]);
3391+
3392+ $ manager ->method ('userCreateChecks ' )
3393+ ->willThrowException (new AlreadySharedException ('Already shared ' , $ existingShare ));
3394+
3395+ $ this ->defaultProvider ->expects ($ this ->never ())
3396+ ->method ('create ' );
3397+ $ this ->dispatcher ->expects ($ this ->never ())
3398+ ->method ('dispatchTyped ' );
3399+
3400+ $ manager ->createShare ($ share );
3401+ }
3402+
32643403 public function testCreateShareGroup (): void {
32653404 $ manager = $ this ->createManagerMock ()
32663405 ->onlyMethods (['generalChecks ' , 'groupCreateChecks ' , 'pathCreateChecks ' , 'validateExpirationDateInternal ' ])
@@ -3685,6 +3824,86 @@ public function testGetSharesByOwnerless(): void {
36853824 $ this ->assertSame ($ share , $ shares [0 ]);
36863825 }
36873826
3827+ public function testGetSharesByOfDisabledInitiatorAsShareOwner (): void {
3828+ $ this ->config ->method ('getAppValue ' )
3829+ ->willReturnMap ([
3830+ ['files_sharing ' , 'hide_disabled_user_shares ' , 'yes ' , 'yes ' ],
3831+ ]);
3832+
3833+ $ share = $ this ->manager ->newShare ();
3834+ $ share ->setShareType (IShare::TYPE_USER )
3835+ ->setShareOwner ('owner ' )
3836+ ->setSharedBy ('initiator ' )
3837+ ->setSharedWith ('recipient ' );
3838+
3839+ $ this ->userManager ->method ('get ' )->willReturnMap ([
3840+ ['owner ' , $ this ->createEnabledUser (true )],
3841+ ['initiator ' , $ this ->createEnabledUser (false )],
3842+ ]);
3843+
3844+ $ this ->defaultProvider ->expects ($ this ->once ())
3845+ ->method ('getSharesBy ' )
3846+ ->willReturn ([$ share ]);
3847+
3848+ $ shares = $ this ->manager ->getSharesBy ('owner ' , IShare::TYPE_USER , $ this ->createMock (Folder::class), true , -1 , 0 );
3849+
3850+ $ this ->assertCount (1 , $ shares );
3851+ $ this ->assertSame ($ share , $ shares [0 ]);
3852+ }
3853+
3854+ public function testGetSharesByOfDisabledInitiatorAsOtherUser (): void {
3855+ $ this ->config ->method ('getAppValue ' )
3856+ ->willReturnMap ([
3857+ ['files_sharing ' , 'hide_disabled_user_shares ' , 'yes ' , 'yes ' ],
3858+ ]);
3859+
3860+ $ share = $ this ->manager ->newShare ();
3861+ $ share ->setShareType (IShare::TYPE_USER )
3862+ ->setShareOwner ('owner ' )
3863+ ->setSharedBy ('initiator ' )
3864+ ->setSharedWith ('recipient ' );
3865+
3866+ $ this ->userManager ->method ('get ' )->willReturnMap ([
3867+ ['owner ' , $ this ->createEnabledUser (true )],
3868+ ['initiator ' , $ this ->createEnabledUser (false )],
3869+ ['resharer ' , $ this ->createEnabledUser (true )],
3870+ ]);
3871+
3872+ $ this ->defaultProvider ->expects ($ this ->once ())
3873+ ->method ('getSharesBy ' )
3874+ ->willReturn ([$ share ]);
3875+
3876+ $ shares = $ this ->manager ->getSharesBy ('resharer ' , IShare::TYPE_USER , $ this ->createMock (Folder::class), true , -1 , 0 );
3877+
3878+ $ this ->assertCount (0 , $ shares );
3879+ }
3880+
3881+ public function testGetSharedWithOfDisabledInitiator (): void {
3882+ $ this ->config ->method ('getAppValue ' )
3883+ ->willReturnMap ([
3884+ ['files_sharing ' , 'hide_disabled_user_shares ' , 'yes ' , 'yes ' ],
3885+ ]);
3886+
3887+ $ share = $ this ->manager ->newShare ();
3888+ $ share ->setShareType (IShare::TYPE_USER )
3889+ ->setShareOwner ('owner ' )
3890+ ->setSharedBy ('initiator ' )
3891+ ->setSharedWith ('recipient ' );
3892+
3893+ $ this ->userManager ->method ('get ' )->willReturnMap ([
3894+ ['owner ' , $ this ->createEnabledUser (true )],
3895+ ['initiator ' , $ this ->createEnabledUser (false )],
3896+ ]);
3897+
3898+ $ this ->defaultProvider ->expects ($ this ->once ())
3899+ ->method ('getSharedWith ' )
3900+ ->willReturn ([$ share ]);
3901+
3902+ $ shares = $ this ->manager ->getSharedWith ('recipient ' , IShare::TYPE_USER );
3903+
3904+ $ this ->assertCount (0 , $ shares );
3905+ }
3906+
36883907 /**
36893908 * Test to ensure we correctly remove expired link shares
36903909 *
0 commit comments