Skip to content

Commit 82f050a

Browse files
committed
fix(external-share): move ExternalShareScanJob creation deeper
Signed-off-by: Maxence Lange <maxence@artificial-owl.com> d
1 parent 3bf5565 commit 82f050a

4 files changed

Lines changed: 8 additions & 11 deletions

File tree

‎apps/files_sharing/lib/Controller/ExternalSharesController.php‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88

99
namespace OCA\Files_Sharing\Controller;
1010

11-
use OCA\Files_Sharing\BackgroundJob\ExternalShareScanJob;
1211
use OCA\Files_Sharing\External\Manager;
1312
use OCP\AppFramework\Controller;
1413
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
1514
use OCP\AppFramework\Http\JSONResponse;
16-
use OCP\BackgroundJob\IJobList;
1715
use OCP\IRequest;
1816

1917
/**
@@ -26,7 +24,6 @@ public function __construct(
2624
string $appName,
2725
IRequest $request,
2826
private readonly Manager $externalManager,
29-
private IJobList $jobList,
3027
) {
3128
parent::__construct($appName, $request);
3229
}
@@ -47,7 +44,6 @@ public function create(string $id): JSONResponse {
4744
$externalShare = $this->externalManager->getShare($id);
4845
if ($externalShare !== false) {
4946
$this->externalManager->acceptShare($externalShare);
50-
$this->jobList->add(ExternalShareScanJob::class, [$externalShare->getUser(), $externalShare->getMountpoint()]);
5147
}
5248
return new JSONResponse();
5349
}

‎apps/files_sharing/lib/External/Manager.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010

1111
use OC\Files\Filesystem;
1212
use OCA\FederatedFileSharing\Events\FederatedShareAddedEvent;
13+
use OCA\Files_Sharing\BackgroundJob\ExternalShareScanJob;
1314
use OCA\Files_Sharing\Helper;
1415
use OCP\AppFramework\Db\DoesNotExistException;
16+
use OCP\BackgroundJob\IJobList;
1517
use OCP\DB\Exception;
1618
use OCP\EventDispatcher\IEventDispatcher;
1719
use OCP\Federation\ICloudFederationFactory;
@@ -58,6 +60,7 @@ public function __construct(
5860
private ICertificateManager $certificateManager,
5961
private ExternalShareMapper $externalShareMapper,
6062
private IConfig $config,
63+
private readonly IJobList $jobList,
6164
) {
6265
$this->user = $userSession->getUser();
6366
}
@@ -249,6 +252,7 @@ public function acceptShare(ExternalShare $externalShare, ?IUser $user = null):
249252
$externalShare->setMountpoint($mountPoint);
250253
$this->externalShareMapper->update($externalShare);
251254
$userShareAccepted = true;
255+
$this->jobList->add(ExternalShareScanJob::class, [$externalShare->getUser(), $externalShare->getMountpoint()]);
252256
}
253257
} else {
254258
try {

‎apps/files_sharing/tests/Controller/ExternalShareControllerTest.php‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use OCA\Files_Sharing\External\ExternalShare;
1313
use OCA\Files_Sharing\External\Manager;
1414
use OCP\AppFramework\Http\JSONResponse;
15-
use OCP\BackgroundJob\IJobList;
1615
use OCP\IRequest;
1716
use PHPUnit\Framework\MockObject\MockObject;
1817

@@ -24,21 +23,18 @@
2423
class ExternalShareControllerTest extends \Test\TestCase {
2524
private IRequest&MockObject $request;
2625
private Manager&MockObject $externalManager;
27-
private IJobList&MockObject $jobList;
2826

2927
protected function setUp(): void {
3028
parent::setUp();
3129
$this->request = $this->createMock(IRequest::class);
3230
$this->externalManager = $this->createMock(Manager::class);
33-
$this->jobList = $this->createMock(IJobList::class);
3431
}
3532

3633
public function getExternalShareController(): ExternalSharesController {
3734
return new ExternalSharesController(
3835
'files_sharing',
3936
$this->request,
4037
$this->externalManager,
41-
$this->jobList,
4238
);
4339
}
4440

@@ -62,9 +58,6 @@ public function testCreate(): void {
6258
->expects($this->once())
6359
->method('acceptShare')
6460
->with($share);
65-
$this->jobList
66-
->expects($this->once())
67-
->method('add');
6861

6962
$this->assertEquals(new JSONResponse(), $this->getExternalShareController()->create('4'));
7063
}

‎apps/files_sharing/tests/External/ManagerTest.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use OCA\Files_Sharing\External\Manager;
1919
use OCA\Files_Sharing\External\MountProvider;
2020
use OCA\Files_Sharing\Tests\TestCase;
21+
use OCP\BackgroundJob\IJobList;
2122
use OCP\Contacts\IManager;
2223
use OCP\EventDispatcher\IEventDispatcher;
2324
use OCP\Federation\ICloudFederationFactory;
@@ -77,6 +78,7 @@ class ManagerTest extends TestCase {
7778
private IOCMDiscoveryService&MockObject $ocmDiscoveryService;
7879
private ExternalShareMapper $externalShareMapper;
7980
private IConfig $config;
81+
private IJobList&MockObject $jobList;
8082

8183
protected function setUp(): void {
8284
parent::setUp();
@@ -93,6 +95,7 @@ protected function setUp(): void {
9395
$this->cloudFederationProviderManager = $this->createMock(ICloudFederationProviderManager::class);
9496
$this->cloudFederationFactory = $this->createMock(ICloudFederationFactory::class);
9597
$this->config = $this->createMock(IConfig::class);
98+
$this->jobList = $this->createMock(IJobList::class);
9699
$this->groupManager = $this->createMock(IGroupManager::class);
97100
$this->userManager = $this->createMock(IUserManager::class);
98101
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
@@ -182,6 +185,7 @@ private function createManagerForUser(IUser $user): Manager&MockObject {
182185
$this->certificateManager,
183186
$this->externalShareMapper,
184187
$this->config,
188+
$this->jobList,
185189
]
186190
)->onlyMethods(['tryOCMEndPoint'])->getMock();
187191
}

0 commit comments

Comments
 (0)