Skip to content

Commit 7a461a8

Browse files
committed
fix: Revert change to the cloud integration
This might fixes the test. Signed-off-by: Carl Schwan <[email protected]>
1 parent 46c8632 commit 7a461a8

File tree

3 files changed

+12
-29
lines changed

3 files changed

+12
-29
lines changed

apps/files_sharing/lib/External/Manager.php

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use OCA\FederatedFileSharing\Events\FederatedShareAddedEvent;
1515
use OCA\Files_Sharing\Helper;
1616
use OCA\Files_Sharing\ResponseDefinitions;
17-
use OCP\AppFramework\Http;
1817
use OCP\DB\Exception;
1918
use OCP\DB\QueryBuilder\IQueryBuilder;
2019
use OCP\EventDispatcher\IEventDispatcher;
@@ -34,7 +33,6 @@
3433
use OCP\IUser;
3534
use OCP\IUserSession;
3635
use OCP\Notification\IManager;
37-
use OCP\OCM\Exceptions\OCMProviderException;
3836
use OCP\OCS\IDiscoveryService;
3937
use OCP\Server;
4038
use OCP\Share;
@@ -56,8 +54,7 @@
5654
* accepted: bool,
5755
* share_type:int,
5856
* password: string,
59-
* mountpoint_hash:
60-
* string
57+
* mountpoint_hash: string
6158
* }
6259
*/
6360
class Manager {
@@ -80,6 +77,7 @@ public function __construct(
8077
private LoggerInterface $logger,
8178
private IRootFolder $rootFolder,
8279
private SetupManager $setupManager,
80+
private ICertificateManager $certificateManager,
8381
) {
8482
$this->user = $userSession->getUser();
8583
}
@@ -524,7 +522,6 @@ private function sendFeedbackToRemote(string $remote, string $token, string $rem
524522
* @return array|false
525523
*/
526524
protected function tryOCMEndPoint(string $remoteDomain, string $token, string $remoteId, string $feedback) {
527-
$response = null;
528525
switch ($feedback) {
529526
case 'accept':
530527
$notification = $this->cloudFederationFactory->getCloudFederationNotification();
@@ -538,11 +535,7 @@ protected function tryOCMEndPoint(string $remoteDomain, string $token, string $r
538535
]
539536

540537
);
541-
try {
542-
$response = $this->cloudFederationProviderManager->sendCloudNotification($remoteDomain, $notification);
543-
} catch (OCMProviderException) {
544-
}
545-
break;
538+
return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification);
546539
case 'decline':
547540
$notification = $this->cloudFederationFactory->getCloudFederationNotification();
548541
$notification->setMessage(
@@ -553,26 +546,9 @@ protected function tryOCMEndPoint(string $remoteDomain, string $token, string $r
553546
'sharedSecret' => $token,
554547
'message' => 'Recipient declined the share'
555548
]
556-
557549
);
558-
try {
559-
$response = $this->cloudFederationProviderManager->sendCloudNotification($remoteDomain, $notification);
560-
} catch (OCMProviderException) {
561-
}
562-
break;
563-
default:
564-
throw new \RuntimeException('Unknown feedback');
550+
return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification);
565551
}
566-
567-
if ($response !== null && $response->getStatusCode() === Http::STATUS_CREATED) {
568-
$result = json_decode($response->getBody(), true);
569-
if (is_array($result)) {
570-
return $result;
571-
} else {
572-
return [];
573-
}
574-
}
575-
576552
return false;
577553
}
578554

@@ -589,7 +565,7 @@ public function getMount(array $data, ?IUser $user = null) {
589565
$data['manager'] = $this;
590566
$mountPoint = '/' . $user->getUID() . '/files' . $data['mountpoint'];
591567
$data['mountpoint'] = $mountPoint;
592-
$data['certificateManager'] = Server::get(ICertificateManager::class);
568+
$data['certificateManager'] = $this->certificateManager;
593569
return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader);
594570
}
595571

apps/files_sharing/tests/External/ManagerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use OCP\Http\Client\IClient;
2727
use OCP\Http\Client\IClientService;
2828
use OCP\Http\Client\IResponse;
29+
use OCP\ICertificateManager;
2930
use OCP\ICacheFactory;
3031
use OCP\IDBConnection;
3132
use OCP\IGroup;
@@ -66,6 +67,7 @@ class ManagerTest extends TestCase {
6667
protected IGroupManager&MockObject $groupManager;
6768
protected IUserManager&MockObject $userManager;
6869
protected SetupManager&MockObject $setupManager;
70+
protected ICertificateManager&MockObject $certificateManager;
6971

7072
protected function setUp(): void {
7173
parent::setUp();
@@ -97,6 +99,8 @@ protected function setUp(): void {
9799
->method('search')
98100
->willReturn([]);
99101

102+
$this->certificateManager = $this->createMock(ICertificateManager::class);
103+
100104
$this->logger = $this->createMock(LoggerInterface::class);
101105
$this->logger->expects($this->never())->method('emergency');
102106

@@ -158,6 +162,7 @@ private function createManagerForUser(IUser $user): Manager&MockObject {
158162
$this->logger,
159163
$this->rootFolder,
160164
$this->setupManager,
165+
$this->certificateManager,
161166
]
162167
)->onlyMethods(['tryOCMEndPoint'])->getMock();
163168
}

build/psalm-baseline.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,8 @@
15201520
<file src="apps/files_sharing/lib/External/Manager.php">
15211521
<DeprecatedMethod>
15221522
<code><![CDATA[insertIfNotExist]]></code>
1523+
<code><![CDATA[sendNotification]]></code>
1524+
<code><![CDATA[sendNotification]]></code>
15231525
</DeprecatedMethod>
15241526
<LessSpecificReturnStatement>
15251527
<code><![CDATA[$mount]]></code>

0 commit comments

Comments
 (0)