99use NCU \Federation \ISignedCloudFederationProvider ;
1010use OC \AppFramework \Http ;
1111use OC \Files \Filesystem ;
12+ use OC \Files \SetupManager ;
1213use OCA \FederatedFileSharing \AddressHandler ;
1314use OCA \FederatedFileSharing \FederatedShareProvider ;
1415use OCA \Federation \TrustedServers ;
3435use OCP \IDBConnection ;
3536use OCP \IGroupManager ;
3637use OCP \IURLGenerator ;
38+ use OCP \IUser ;
3739use OCP \IUserManager ;
3840use OCP \Notification \IManager as INotificationManager ;
3941use OCP \Server ;
@@ -68,6 +70,7 @@ public function __construct(
6870 private LoggerInterface $ logger ,
6971 private IFilenameValidator $ filenameValidator ,
7072 private readonly IProviderFactory $ shareProviderFactory ,
73+ private readonly SetupManager $ setupManager ,
7174 ) {
7275 }
7376
@@ -128,6 +131,8 @@ public function shareReceived(ICloudFederationShare $share) {
128131 throw new ProviderCouldNotAddShareException ('The mountpoint name contains invalid characters. ' , '' , Http::STATUS_BAD_REQUEST );
129132 }
130133
134+ $ userOrGroup = null ;
135+
131136 // FIXME this should be a method in the user management instead
132137 if ($ shareType === IShare::TYPE_USER ) {
133138 $ this ->logger ->debug ('shareWith before, ' . $ shareWith , ['app ' => 'files_sharing ' ]);
@@ -138,19 +143,23 @@ public function shareReceived(ICloudFederationShare $share) {
138143 );
139144 $ this ->logger ->debug ('shareWith after, ' . $ shareWith , ['app ' => 'files_sharing ' ]);
140145
141- if (!$ this ->userManager ->userExists ($ shareWith )) {
146+ $ userOrGroup = $ this ->userManager ->get ($ shareWith );
147+ if ($ userOrGroup === null ) {
142148 throw new ProviderCouldNotAddShareException ('User does not exists ' , '' , Http::STATUS_BAD_REQUEST );
143149 }
144150
145- \OC_Util:: setupFS ( $ shareWith );
151+ $ this -> setupManager -> setupForUser ( $ userOrGroup );
146152 }
147153
148- if ($ shareType === IShare::TYPE_GROUP && !$ this ->groupManager ->groupExists ($ shareWith )) {
149- throw new ProviderCouldNotAddShareException ('Group does not exists ' , '' , Http::STATUS_BAD_REQUEST );
154+ if ($ shareType === IShare::TYPE_GROUP ) {
155+ $ userOrGroup = $ this ->groupManager ->get ($ shareWith );
156+ if ($ userOrGroup === null ) {
157+ throw new ProviderCouldNotAddShareException ('Group does not exists ' , '' , Http::STATUS_BAD_REQUEST );
158+ }
150159 }
151160
152161 try {
153- $ this ->externalShareManager ->addShare ($ remote , $ token , '' , $ name , $ owner , $ shareType , false , $ shareWith , $ remoteId );
162+ $ this ->externalShareManager ->addShare ($ remote , $ token , '' , $ name , $ owner , $ shareType , false , $ userOrGroup , $ remoteId );
154163 $ shareId = Server::get (IDBConnection::class)->lastInsertId ('*PREFIX*share_external ' );
155164
156165 // get DisplayName about the owner of the share
@@ -179,7 +188,8 @@ public function shareReceived(ICloudFederationShare $share) {
179188
180189 // If auto-accept is enabled, accept the share
181190 if ($ this ->federatedShareProvider ->isFederatedTrustedShareAutoAccept () && $ trustedServers ?->isTrustedServer($ remote ) === true ) {
182- $ this ->externalShareManager ->acceptShare ($ shareId , $ shareWith );
191+ /** @var IUser $userOrGroup */
192+ $ this ->externalShareManager ->acceptShare ($ shareId , $ userOrGroup );
183193 }
184194 } else {
185195 $ groupMembers = $ this ->groupManager ->get ($ shareWith )->getUsers ();
@@ -195,7 +205,7 @@ public function shareReceived(ICloudFederationShare $share) {
195205
196206 // If auto-accept is enabled, accept the share
197207 if ($ this ->federatedShareProvider ->isFederatedTrustedShareAutoAccept () && $ trustedServers ?->isTrustedServer($ remote ) === true ) {
198- $ this ->externalShareManager ->acceptShare ($ shareId , $ user-> getUID () );
208+ $ this ->externalShareManager ->acceptShare ($ shareId , $ user );
199209 }
200210 }
201211 }
0 commit comments