2222use OCP \Files \ISetupManager ;
2323use OCP \Files \NotFoundException ;
2424use OCP \Files \NotPermittedException ;
25- use OCP \Files \Storage \IStorageFactory ;
2625use OCP \Http \Client \IClientService ;
27- use OCP \ICertificateManager ;
28- use OCP \IConfig ;
2926use OCP \IDBConnection ;
3027use OCP \IGroup ;
3128use OCP \IGroupManager ;
3229use OCP \IUser ;
33- use OCP \IUserSession ;
3430use OCP \Notification \IManager ;
3531use OCP \OCS \IDiscoveryService ;
3632use OCP \Share \IShare ;
3733use OCP \User \Exceptions \UserNotFoundException ;
3834use Psr \Log \LoggerInterface ;
3935
4036class Manager {
41- private ?IUser $ user ;
42-
4337 public function __construct (
44- private IDBConnection $ connection ,
45- private \OC \Files \Mount \Manager $ mountManager ,
46- private IStorageFactory $ storageLoader ,
47- private IClientService $ clientService ,
48- private IManager $ notificationManager ,
49- private IDiscoveryService $ discoveryService ,
50- private ICloudFederationProviderManager $ cloudFederationProviderManager ,
51- private ICloudFederationFactory $ cloudFederationFactory ,
52- private IGroupManager $ groupManager ,
53- IUserSession $ userSession ,
54- private IEventDispatcher $ eventDispatcher ,
55- private LoggerInterface $ logger ,
56- private IRootFolder $ rootFolder ,
57- private ISetupManager $ setupManager ,
58- private ICertificateManager $ certificateManager ,
59- private ExternalShareMapper $ externalShareMapper ,
38+ private readonly IDBConnection $ connection ,
39+ private readonly \OC \Files \Mount \Manager $ mountManager ,
40+ private readonly IClientService $ clientService ,
41+ private readonly IManager $ notificationManager ,
42+ private readonly IDiscoveryService $ discoveryService ,
43+ private readonly ICloudFederationProviderManager $ cloudFederationProviderManager ,
44+ private readonly ICloudFederationFactory $ cloudFederationFactory ,
45+ private readonly IGroupManager $ groupManager ,
46+ private readonly IEventDispatcher $ eventDispatcher ,
47+ private readonly LoggerInterface $ logger ,
48+ private readonly IRootFolder $ rootFolder ,
49+ private readonly ISetupManager $ setupManager ,
50+ private readonly ExternalShareMapper $ externalShareMapper ,
6051 ) {
61- $ this ->user = $ userSession ->getUser ();
6252 }
6353
6454 /**
@@ -93,8 +83,7 @@ public function addShare(ExternalShare $externalShare, IUser|IGroup $shareWith):
9383 }
9484 }
9585
96- public function getShare (string $ id , ?IUser $ user = null ): ExternalShare |false {
97- $ user = $ user ?? $ this ->user ;
86+ public function getShare (string $ id , IUser $ user ): ExternalShare |false {
9887 try {
9988 $ externalShare = $ this ->externalShareMapper ->getById ($ id );
10089 } catch (DoesNotExistException $ e ) {
@@ -193,16 +182,7 @@ private function updateSubShare(ExternalShare $externalShare, IUser $user, ?stri
193182 *
194183 * @return bool True if the share could be accepted, false otherwise
195184 */
196- public function acceptShare (ExternalShare $ externalShare , ?IUser $ user = null ): bool {
197- // If we're auto-accepting a share, we need to know the user id
198- // as there is no session available while processing the share
199- // from the remote server request.
200- $ user = $ user ?? $ this ->user ;
201- if ($ user === null ) {
202- $ this ->logger ->error ('No user specified for accepting share ' );
203- return false ;
204- }
205-
185+ public function acceptShare (ExternalShare $ externalShare , IUser $ user ): bool {
206186 $ result = false ;
207187 $ this ->setupManager ->setupForUser ($ user );
208188 $ folder = $ this ->rootFolder ->getUserFolder ($ user ->getUID ());
@@ -250,13 +230,7 @@ public function acceptShare(ExternalShare $externalShare, ?IUser $user = null):
250230 *
251231 * @return bool True if the share could be declined, false otherwise
252232 */
253- public function declineShare (ExternalShare $ externalShare , ?Iuser $ user = null ): bool {
254- $ user = $ user ?? $ this ->user ;
255- if ($ user === null ) {
256- $ this ->logger ->error ('No user specified for declining share ' );
257- return false ;
258- }
259-
233+ public function declineShare (ExternalShare $ externalShare , Iuser $ user ): bool {
260234 $ result = false ;
261235
262236 if ($ externalShare ->getShareType () === IShare::TYPE_USER ) {
@@ -282,13 +256,7 @@ public function declineShare(ExternalShare $externalShare, ?Iuser $user = null):
282256 return $ result ;
283257 }
284258
285- public function processNotification (ExternalShare $ remoteShare , ?IUser $ user = null ): void {
286- $ user = $ user ?? $ this ->user ;
287- if ($ user === null ) {
288- $ this ->logger ->error ('No user specified for processing notification ' );
289- return ;
290- }
291-
259+ public function processNotification (ExternalShare $ remoteShare , IUser $ user ): void {
292260 $ filter = $ this ->notificationManager ->createNotification ();
293261 $ filter ->setApp ('files_sharing ' )
294262 ->setUser ($ user ->getUID ())
@@ -371,33 +339,18 @@ protected function tryOCMEndPoint(ExternalShare $externalShare, string $feedback
371339 /**
372340 * remove '/user/files' from the path and trailing slashes
373341 */
374- protected function stripPath (string $ path ): string {
375- $ prefix = '/ ' . $ this -> user ->getUID () . '/files ' ;
342+ protected function stripPath (IUser $ user , string $ path ): string {
343+ $ prefix = '/ ' . $ user ->getUID () . '/files ' ;
376344 return rtrim (substr ($ path , strlen ($ prefix )), '/ ' );
377345 }
378346
379- public function getMount (array $ data , ?IUser $ user = null ): Mount {
380- $ user = $ user ?? $ this ->user ;
381- $ data ['manager ' ] = $ this ;
382- $ mountPoint = '/ ' . $ user ->getUID () . '/files ' . $ data ['mountpoint ' ];
383- $ data ['mountpoint ' ] = $ mountPoint ;
384- $ data ['certificateManager ' ] = $ this ->certificateManager ;
385- return new Mount (Storage::class, $ mountPoint , $ data , $ this , $ this ->storageLoader );
386- }
387-
388- protected function mountShare (array $ data , ?IUser $ user = null ): Mount {
389- $ mount = $ this ->getMount ($ data , $ user );
390- $ this ->mountManager ->addMount ($ mount );
391- return $ mount ;
392- }
393-
394347 public function getMountManager (): \OC \Files \Mount \Manager {
395348 return $ this ->mountManager ;
396349 }
397350
398- public function setMountPoint (string $ source , string $ target ): bool {
399- $ source = $ this ->stripPath ($ source );
400- $ target = $ this ->stripPath ($ target );
351+ public function setMountPoint (IUser $ user , string $ source , string $ target ): bool {
352+ $ source = $ this ->stripPath ($ user , $ source );
353+ $ target = $ this ->stripPath ($ user , $ target );
401354 $ sourceHash = md5 ($ source );
402355 $ targetHash = md5 ($ target );
403356
@@ -406,16 +359,16 @@ public function setMountPoint(string $source, string $target): bool {
406359 ->set ('mountpoint ' , $ qb ->createNamedParameter ($ target ))
407360 ->set ('mountpoint_hash ' , $ qb ->createNamedParameter ($ targetHash ))
408361 ->where ($ qb ->expr ()->eq ('mountpoint_hash ' , $ qb ->createNamedParameter ($ sourceHash )))
409- ->andWhere ($ qb ->expr ()->eq ('user ' , $ qb ->createNamedParameter ($ this -> user ->getUID ())));
362+ ->andWhere ($ qb ->expr ()->eq ('user ' , $ qb ->createNamedParameter ($ user ->getUID ())));
410363
411364 $ result = (bool )$ qb ->executeStatement ();
412365
413- $ this ->eventDispatcher ->dispatchTyped (new InvalidateMountCacheEvent ($ this -> user ));
366+ $ this ->eventDispatcher ->dispatchTyped (new InvalidateMountCacheEvent ($ user ));
414367
415368 return $ result ;
416369 }
417370
418- public function removeShare (string $ mountPoint ): bool {
371+ public function removeShare (IUser $ user , string $ mountPoint ): bool {
419372 try {
420373 $ mountPointObj = $ this ->mountManager ->find ($ mountPoint );
421374 } catch (NotFoundException $ e ) {
@@ -428,11 +381,11 @@ public function removeShare(string $mountPoint): bool {
428381 }
429382 $ id = $ mountPointObj ->getStorage ()->getCache ()->getId ('' );
430383
431- $ mountPoint = $ this ->stripPath ($ mountPoint );
384+ $ mountPoint = $ this ->stripPath ($ user , $ mountPoint );
432385
433386 try {
434387 try {
435- $ externalShare = $ this ->externalShareMapper ->getByMountPointAndUser ($ mountPoint , $ this -> user );
388+ $ externalShare = $ this ->externalShareMapper ->getByMountPointAndUser ($ mountPoint , $ user );
436389 } catch (DoesNotExistException $ e ) {
437390 // ignore
438391 $ this ->removeReShares ((string )$ id );
@@ -517,9 +470,9 @@ public function removeGroupShares(IGroup $group): bool {
517470 *
518471 * @return list<ExternalShare> list of open server-to-server shares
519472 */
520- public function getOpenShares (): array {
473+ public function getOpenShares (IUser $ user ): array {
521474 try {
522- return $ this ->externalShareMapper ->getShares ($ this -> user , IShare::STATUS_PENDING );
475+ return $ this ->externalShareMapper ->getShares ($ user , IShare::STATUS_PENDING );
523476 } catch (Exception $ e ) {
524477 $ this ->logger ->emergency ('Error when retrieving shares ' , ['exception ' => $ e ]);
525478 return [];
@@ -531,9 +484,9 @@ public function getOpenShares(): array {
531484 *
532485 * @return list<ExternalShare> list of accepted server-to-server shares
533486 */
534- public function getAcceptedShares (): array {
487+ public function getAcceptedShares (IUser $ user ): array {
535488 try {
536- return $ this ->externalShareMapper ->getShares ($ this -> user , IShare::STATUS_ACCEPTED );
489+ return $ this ->externalShareMapper ->getShares ($ user , IShare::STATUS_ACCEPTED );
537490 } catch (Exception $ e ) {
538491 $ this ->logger ->emergency ('Error when retrieving shares ' , ['exception ' => $ e ]);
539492 return [];
0 commit comments