@@ -259,14 +259,23 @@ public function updateShareUserStatus(ShareAccessContext $accessContext, Share $
259259
260260 #[\Override]
261261 public function addShareSource (ShareAccessContext $ accessContext , Share $ share , ShareSource $ source ): Share {
262+ if ($ share ->owner ->instance !== null ) {
263+ throw new ShareOperationForbiddenException ();
264+ }
265+
262266 // only the owner can add sources, otherwise a user could add sources others don't have access to, which would remove their access
263267 $ this ->validateShareEditPermissions ($ accessContext , $ share , true );
264268
265269 if (($ sourceType = $ this ->registry ->getSourceTypes ()[$ source ->class ] ?? null ) === null ) {
266270 throw new RuntimeException ('The source type is not registered: ' . $ source ->class );
267271 }
268272
269- if (!$ sourceType ->validateSource ($ source ->value )) {
273+ $ ownerUser = $ this ->userManager ->get ($ share ->owner ->userId );
274+ if (!$ ownerUser instanceof IUser) {
275+ throw new RuntimeException ('Owner does not exist. ' );
276+ }
277+
278+ if (!$ sourceType ->validateSource ($ ownerUser , $ source ->value )) {
270279 throw new ShareInvalidException ('Invalid source: ' . $ source ->value . ' ' . $ source ->class , $ this ->l10n ->t ('The source does not exist. ' ));
271280 }
272281
@@ -870,11 +879,17 @@ private function validateInteraction(ShareAccessContext $accessContext, Share $s
870879 null , array_values (array_map (static fn (SharePermission $ permission ): string => $ permission ->class , $ share ->getEffectiveEnabledPermissions ($ accessContext )))
871880 );
872881
873- $ usersToCheck = [];
874- if ($ share ->owner ->instance === null && ($ ownerUser = $ this ->userManager ->get ($ share ->owner ->userId )) instanceof IUser) {
875- $ usersToCheck [] = $ ownerUser ;
882+ if ($ share ->owner ->instance !== null ) {
883+ throw new ShareOperationForbiddenException ();
884+ }
885+
886+ $ ownerUser = $ this ->userManager ->get ($ share ->owner ->userId );
887+ if (!$ ownerUser instanceof IUser) {
888+ throw new RuntimeException ('Owner does not exist. ' );
876889 }
877890
891+ $ usersToCheck = [$ ownerUser ];
892+
878893 if ($ accessContext ->currentUser instanceof IUser && !$ share ->owner ->isCurrentUser ($ accessContext )) {
879894 $ usersToCheck [] = $ accessContext ->currentUser ;
880895 }
@@ -902,7 +917,7 @@ private function validateInteraction(ShareAccessContext $accessContext, Share $s
902917 throw new RuntimeException ('The source type is not registered: ' . $ source ->class );
903918 }
904919
905- if (!$ sourceType ->validateSource ($ source ->value )) {
920+ if (!$ sourceType ->validateSource ($ ownerUser , $ source ->value )) {
906921 continue ;
907922 }
908923
0 commit comments