1414use OCA \FederatedFileSharing \FederatedShareProvider ;
1515use OCA \Federation \TrustedServers ;
1616use OCA \Files_Sharing \Activity \Providers \RemoteShares ;
17+ use OCA \Files_Sharing \External \ExternalShare ;
1718use OCA \Files_Sharing \External \Manager ;
1819use OCA \GlobalSiteSelector \Service \SlaveService ;
20+ use OCA \Polls \Db \Share ;
1921use OCP \Activity \IManager as IActivityManager ;
2022use OCP \App \IAppManager ;
2123use OCP \AppFramework \QueryException ;
4446use OCP \Share \IManager ;
4547use OCP \Share \IProviderFactory ;
4648use OCP \Share \IShare ;
49+ use OCP \Snowflake \IGenerator ;
4750use OCP \Util ;
4851use Psr \Log \LoggerInterface ;
4952use SensitiveParameter ;
@@ -72,6 +75,7 @@ public function __construct(
7275 private IFilenameValidator $ filenameValidator ,
7376 private readonly IProviderFactory $ shareProviderFactory ,
7477 private readonly SetupManager $ setupManager ,
78+ private readonly IGenerator $ snowflakeGenerator ,
7579 ) {
7680 }
7781
@@ -93,7 +97,7 @@ public function getShareType() {
9397 * @throws HintException
9498 * @since 14.0.0
9599 */
96- public function shareReceived (ICloudFederationShare $ share ) {
100+ public function shareReceived (ICloudFederationShare $ share ): string {
97101 if (!$ this ->isS2SEnabled (true )) {
98102 throw new ProviderCouldNotAddShareException ('Server does not support federated cloud sharing ' , '' , Http::STATUS_SERVICE_UNAVAILABLE );
99103 }
@@ -159,9 +163,18 @@ public function shareReceived(ICloudFederationShare $share) {
159163 }
160164 }
161165
166+ $ externalShare = new ExternalShare ();
167+ $ externalShare ->setId ($ this ->snowflakeGenerator ->nextId ());
168+ $ externalShare ->setRemote ($ remote );
169+ $ externalShare ->setRemoteId ($ remoteId );
170+ $ externalShare ->setShareToken ($ token );
171+ $ externalShare ->setPassword ('' );
172+ $ externalShare ->setName ($ name );
173+ $ externalShare ->setShareType ($ shareType );
174+ $ externalShare ->setAccepted (IShare::STATUS_PENDING );
175+
162176 try {
163- $ this ->externalShareManager ->addShare ($ remote , $ token , '' , $ name , $ owner , $ shareType , false , $ userOrGroup , $ remoteId );
164- $ shareId = Server::get (IDBConnection::class)->lastInsertId ('*PREFIX*share_external ' );
177+ $ this ->externalShareManager ->addShare ($ externalShare , $ userOrGroup );
165178
166179 // get DisplayName about the owner of the share
167180 $ ownerDisplayName = $ this ->getUserDisplayName ($ ownerFederatedId );
@@ -184,14 +197,14 @@ public function shareReceived(ICloudFederationShare $share) {
184197 ->setType ('remote_share ' )
185198 ->setSubject (RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED , [$ ownerFederatedId , trim ($ name , '/ ' ), $ ownerDisplayName ])
186199 ->setAffectedUser ($ shareWith )
187- ->setObject ('remote_share ' , $ shareId , $ name );
200+ ->setObject ('remote_share ' , $ externalShare -> getId () , $ name );
188201 Server::get (IActivityManager::class)->publish ($ event );
189- $ this ->notifyAboutNewShare ($ shareWith , $ shareId , $ ownerFederatedId , $ sharedByFederatedId , $ name , $ ownerDisplayName );
202+ $ this ->notifyAboutNewShare ($ shareWith , $ externalShare -> getId () , $ ownerFederatedId , $ sharedByFederatedId , $ name , $ ownerDisplayName );
190203
191204 // If auto-accept is enabled, accept the share
192205 if ($ this ->federatedShareProvider ->isFederatedTrustedShareAutoAccept () && $ trustedServers ?->isTrustedServer($ remote ) === true ) {
193206 /** @var IUser $userOrGroup */
194- $ this ->externalShareManager ->acceptShare ($ shareId , $ userOrGroup );
207+ $ this ->externalShareManager ->acceptShare ($ externalShare , $ userOrGroup );
195208 }
196209 } else {
197210 /** @var IGroup $userOrGroup */
@@ -202,18 +215,18 @@ public function shareReceived(ICloudFederationShare $share) {
202215 ->setType ('remote_share ' )
203216 ->setSubject (RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED , [$ ownerFederatedId , trim ($ name , '/ ' ), $ ownerDisplayName ])
204217 ->setAffectedUser ($ user ->getUID ())
205- ->setObject ('remote_share ' , $ shareId , $ name );
218+ ->setObject ('remote_share ' , $ externalShare -> getId () , $ name );
206219 Server::get (IActivityManager::class)->publish ($ event );
207- $ this ->notifyAboutNewShare ($ user ->getUID (), $ shareId , $ ownerFederatedId , $ sharedByFederatedId , $ name , $ ownerDisplayName );
220+ $ this ->notifyAboutNewShare ($ user ->getUID (), $ externalShare -> getId () , $ ownerFederatedId , $ sharedByFederatedId , $ name , $ ownerDisplayName );
208221
209222 // If auto-accept is enabled, accept the share
210223 if ($ this ->federatedShareProvider ->isFederatedTrustedShareAutoAccept () && $ trustedServers ?->isTrustedServer($ remote ) === true ) {
211- $ this ->externalShareManager ->acceptShare ($ shareId , $ user );
224+ $ this ->externalShareManager ->acceptShare ($ externalShare , $ user );
212225 }
213226 }
214227 }
215228
216- return $ shareId ;
229+ return $ externalShare -> getId () ;
217230 } catch (\Exception $ e ) {
218231 $ this ->logger ->error ('Server can not add remote share. ' , [
219232 'app ' => 'files_sharing ' ,
@@ -275,7 +288,7 @@ private function mapShareTypeToNextcloud($shareType) {
275288 return $ result ;
276289 }
277290
278- private function notifyAboutNewShare ($ shareWith , $ shareId , $ ownerFederatedId , $ sharedByFederatedId , $ name , $ displayName ): void {
291+ private function notifyAboutNewShare ($ shareWith , string $ shareId , $ ownerFederatedId , $ sharedByFederatedId , string $ name , string $ displayName ): void {
279292 $ notification = $ this ->notificationManager ->createNotification ();
280293 $ notification ->setApp ('files_sharing ' )
281294 ->setUser ($ shareWith )
@@ -813,7 +826,7 @@ public function getFederationIdFromSharedSecret(
813826 return '' ;
814827 }
815828
816- return $ share[ ' user ' ] . '@ ' . $ share[ ' remote ' ] ;
829+ return $ share-> getUser () . '@ ' . $ share-> getRemote () ;
817830 }
818831
819832 // if uid_owner is a local account, the request comes from the recipient
0 commit comments