diff --git a/apps/files_sharing/lib/Controller/ExternalSharesController.php b/apps/files_sharing/lib/Controller/ExternalSharesController.php index 16450974ad97a..12675e1f5c134 100644 --- a/apps/files_sharing/lib/Controller/ExternalSharesController.php +++ b/apps/files_sharing/lib/Controller/ExternalSharesController.php @@ -7,12 +7,10 @@ */ namespace OCA\Files_Sharing\Controller; -use OCA\Files_Sharing\BackgroundJob\ExternalShareScanJob; use OCA\Files_Sharing\External\Manager; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\JSONResponse; -use OCP\BackgroundJob\IJobList; use OCP\IRequest; use OCP\IUser; use OCP\IUserSession; @@ -28,7 +26,6 @@ public function __construct( string $appName, IRequest $request, private readonly Manager $externalManager, - private readonly IJobList $jobList, private readonly IUserSession $userSession, ) { parent::__construct($appName, $request); @@ -58,7 +55,6 @@ public function create(string $id): JSONResponse { $externalShare = $this->externalManager->getShare($id, $this->getUser()); if ($externalShare !== false) { $this->externalManager->acceptShare($externalShare, $this->getUser()); - $this->jobList->add(ExternalShareScanJob::class, [$externalShare->getUser(), $externalShare->getMountpoint()]); } return new JSONResponse(); } diff --git a/apps/files_sharing/lib/External/Manager.php b/apps/files_sharing/lib/External/Manager.php index 7988ccd76d377..fe883c900202d 100644 --- a/apps/files_sharing/lib/External/Manager.php +++ b/apps/files_sharing/lib/External/Manager.php @@ -11,8 +11,10 @@ use OC\Files\Filesystem; use OC\User\NoUserException; use OCA\FederatedFileSharing\Events\FederatedShareAddedEvent; +use OCA\Files_Sharing\BackgroundJob\ExternalShareScanJob; use OCA\Files_Sharing\Helper; use OCP\AppFramework\Db\DoesNotExistException; +use OCP\BackgroundJob\IJobList; use OCP\DB\Exception; use OCP\EventDispatcher\IEventDispatcher; use OCP\Federation\ICloudFederationFactory; @@ -48,6 +50,7 @@ public function __construct( private readonly IRootFolder $rootFolder, private readonly ISetupManager $setupManager, private readonly ExternalShareMapper $externalShareMapper, + private readonly IJobList $jobList, ) { } @@ -199,6 +202,7 @@ public function acceptShare(ExternalShare $externalShare, IUser $user): bool { $externalShare->setMountpoint($mountPoint); $this->externalShareMapper->update($externalShare); $userShareAccepted = true; + $this->jobList->add(ExternalShareScanJob::class, [$externalShare->getUser(), $externalShare->getMountpoint()]); } } else { try { diff --git a/apps/files_sharing/tests/Controller/ExternalShareControllerTest.php b/apps/files_sharing/tests/Controller/ExternalShareControllerTest.php index c0bfc424c4366..5bd95c82cebed 100644 --- a/apps/files_sharing/tests/Controller/ExternalShareControllerTest.php +++ b/apps/files_sharing/tests/Controller/ExternalShareControllerTest.php @@ -11,7 +11,6 @@ use OCA\Files_Sharing\External\ExternalShare; use OCA\Files_Sharing\External\Manager; use OCP\AppFramework\Http\JSONResponse; -use OCP\BackgroundJob\IJobList; use OCP\IRequest; use OCP\IUser; use OCP\IUserSession; @@ -25,14 +24,12 @@ class ExternalShareControllerTest extends \Test\TestCase { private IRequest&MockObject $request; private Manager&MockObject $externalManager; - private IJobList&MockObject $jobList; private IUser $user; protected function setUp(): void { parent::setUp(); $this->request = $this->createMock(IRequest::class); $this->externalManager = $this->createMock(Manager::class); - $this->jobList = $this->createMock(IJobList::class); $this->user = $this->createMock(IUser::class); $this->user->method('getUID')->willReturn('user'); } @@ -45,7 +42,6 @@ public function getExternalShareController(): ExternalSharesController { 'files_sharing', $this->request, $this->externalManager, - $this->jobList, $session, ); } @@ -70,9 +66,6 @@ public function testCreate(): void { ->expects($this->once()) ->method('acceptShare') ->with($share, $this->user); - $this->jobList - ->expects($this->once()) - ->method('add'); $this->assertEquals(new JSONResponse(), $this->getExternalShareController()->create('4')); } diff --git a/apps/files_sharing/tests/External/ManagerTest.php b/apps/files_sharing/tests/External/ManagerTest.php index 0fa8d3485296a..f1dc9c617cc16 100644 --- a/apps/files_sharing/tests/External/ManagerTest.php +++ b/apps/files_sharing/tests/External/ManagerTest.php @@ -17,6 +17,7 @@ use OCA\Files_Sharing\External\Manager; use OCA\Files_Sharing\External\MountProvider; use OCA\Files_Sharing\Tests\TestCase; +use OCP\BackgroundJob\IJobList; use OCP\Contacts\IManager; use OCP\EventDispatcher\IEventDispatcher; use OCP\Federation\ICloudFederationFactory; @@ -72,6 +73,7 @@ class ManagerTest extends TestCase { protected ICertificateManager&MockObject $certificateManager; private ExternalShareMapper $externalShareMapper; private IConfig $config; + private IJobList&MockObject $jobList; protected function setUp(): void { parent::setUp(); @@ -83,6 +85,7 @@ protected function setUp(): void { $this->cloudFederationProviderManager = $this->createMock(ICloudFederationProviderManager::class); $this->cloudFederationFactory = $this->createMock(ICloudFederationFactory::class); $this->config = $this->createMock(IConfig::class); + $this->jobList = $this->createMock(IJobList::class); $this->groupManager = $this->createMock(IGroupManager::class); $this->userManager = $this->createMock(IUserManager::class); $this->eventDispatcher = $this->createMock(IEventDispatcher::class); @@ -164,6 +167,7 @@ private function createManager(): Manager&MockObject { $this->rootFolder, $this->setupManager, $this->externalShareMapper, + $this->jobList, ] )->onlyMethods(['tryOCMEndPoint'])->getMock(); }