-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Maxence Lange <[email protected]>
- Loading branch information
1 parent
323c8c4
commit fb59325
Showing
52 changed files
with
5,878 additions
and
479 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,242 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
/** | ||
* Circles - Bring cloud-users closer together. | ||
* | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. See the COPYING file. | ||
* | ||
* @author Maxence Lange <[email protected]> | ||
* @copyright 2022 | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
|
||
namespace OCA\Circles; | ||
|
||
use Exception; | ||
use OCA\Circles\Exceptions\CircleSharesManagerException; | ||
use OCA\Circles\Model\Probes\CircleProbe; | ||
use OCA\Circles\Service\CircleService; | ||
use OCA\Circles\Service\ConfigService; | ||
use OCA\Circles\Service\DebugService; | ||
use OCA\Circles\Service\FederatedSyncItemService; | ||
use OCA\Circles\Service\FederatedSyncService; | ||
use OCA\Circles\Service\FederatedSyncShareService; | ||
use Psr\Container\ContainerExceptionInterface; | ||
use Psr\Container\NotFoundExceptionInterface; | ||
|
||
/** | ||
* Class CircleSharesManager | ||
* | ||
* @package OCA\Circles | ||
*/ | ||
class CircleSharesManager implements ICircleSharesManager { | ||
|
||
|
||
private CircleService $circleService; | ||
private FederatedSyncService $federatedSyncService; | ||
private FederatedSyncItemService $federatedSyncItemService; | ||
private FederatedSyncShareService $federatedSyncShareService; | ||
private ConfigService $configService; | ||
private DebugService $debugService; | ||
|
||
private string $originAppId = ''; | ||
private string $originItemType = ''; | ||
|
||
|
||
/** | ||
* @param CircleService $circleService | ||
* @param FederatedSyncItemService $federatedSyncItemService | ||
* @param FederatedSyncShareService $federatedSyncShareService | ||
* @param ConfigService $configService | ||
*/ | ||
public function __construct( | ||
CircleService $circleService, | ||
FederatedSyncService $federatedSyncService, | ||
FederatedSyncItemService $federatedSyncItemService, | ||
FederatedSyncShareService $federatedSyncShareService, | ||
ConfigService $configService, | ||
DebugService $debugService | ||
) { | ||
$this->circleService = $circleService; | ||
$this->federatedSyncService = $federatedSyncService; | ||
$this->federatedSyncItemService = $federatedSyncItemService; | ||
$this->federatedSyncShareService = $federatedSyncShareService; | ||
$this->configService = $configService; | ||
$this->debugService = $debugService; | ||
} | ||
|
||
|
||
/** | ||
* @param string $syncManager | ||
* | ||
* @throws ContainerExceptionInterface | ||
* @throws NotFoundExceptionInterface | ||
*/ | ||
public function registerFederatedSyncManager(string $syncManager): void { | ||
if ($this->originAppId !== '' || $this->originItemType !== '') { | ||
return; | ||
} | ||
|
||
$federatedSyncManager = \OC::$server->get($syncManager); | ||
if (!($federatedSyncManager instanceof IFederatedSyncManager)) { | ||
// log something | ||
return; | ||
} | ||
|
||
$this->federatedSyncService->addFederatedSyncManager($federatedSyncManager); | ||
} | ||
|
||
|
||
/** | ||
* @param string $itemId | ||
* @param string $circleId | ||
* @param array $extraData | ||
* | ||
* @throws CircleSharesManagerException | ||
* @throws Exceptions\CircleNotFoundException | ||
* @throws Exceptions\FederatedSyncConflictException | ||
* @throws Exceptions\FederatedSyncManagerNotFoundException | ||
* @throws Exceptions\InitiatorNotFoundException | ||
* @throws Exceptions\RequestBuilderException | ||
* @throws Exceptions\SyncedSharedAlreadyExistException | ||
*/ | ||
public function createShare( | ||
string $itemId, | ||
string $circleId, | ||
array $extraData = [] | ||
): void { | ||
$this->debugService->setDebugType('federated_sync'); | ||
$this->debugService->info('New request to create a share', $circleId, [ | ||
'appId' => $this->originAppId, | ||
'itemType' => $this->originItemType, | ||
'itemId' => $itemId, | ||
'extraData' => $extraData | ||
]); | ||
|
||
try { | ||
$this->mustHaveOrigin(); | ||
|
||
// TODO: verify rules that apply when sharing to a circle | ||
$probe = new CircleProbe(); | ||
$probe->includeSystemCircles() | ||
->mustBeMember(); | ||
|
||
$circle = $this->circleService->getCircle($circleId, $probe); | ||
|
||
// get valid SyncedItem based on appId, itemType, itemId | ||
$syncedItem = $this->federatedSyncItemService->getSyncedItem( | ||
$this->originAppId, | ||
$this->originItemType, | ||
$itemId | ||
); | ||
|
||
$this->debugService->info( | ||
'Initiating the process of sharing {syncedItem.singleId} to {circle.id}', | ||
$circleId, [ | ||
'circle' => $circle, | ||
'syncedItem' => $syncedItem, | ||
'extraData' => $extraData | ||
] | ||
); | ||
|
||
// confirm item is local | ||
if (!$syncedItem->isLocal()) { | ||
// TODO: sharing a remote item | ||
return; | ||
} | ||
|
||
$this->federatedSyncShareService->createShare($syncedItem, $circle, $extraData); | ||
} catch (Exception $e) { | ||
$this->debugService->exception($e, $circleId); | ||
throw $e; | ||
} | ||
// this->$this->federatedItemService->getSharedItem | ||
} | ||
|
||
/** | ||
* @param string $itemId | ||
* @param string $circleId | ||
* @param array $extraData | ||
* | ||
* @throws CircleSharesManagerException | ||
*/ | ||
public function updateShare( | ||
string $itemId, | ||
string $circleId, | ||
array $extraData = [] | ||
): void { | ||
$this->mustHaveOrigin(); | ||
} | ||
|
||
/** | ||
* @param string $itemId | ||
* @param string $circleId | ||
* | ||
* @throws CircleSharesManagerException | ||
*/ | ||
public function deleteShare(string $itemId, string $circleId): void { | ||
$this->mustHaveOrigin(); | ||
} | ||
|
||
/** | ||
* @param string $itemId | ||
* @param array $serializedData | ||
*/ | ||
public function updateItem( | ||
string $itemId, | ||
array $serializedData | ||
): void { | ||
$this->mustHaveOrigin(); | ||
} | ||
|
||
/** | ||
* @param string $itemId | ||
* | ||
* @throws CircleSharesManagerException | ||
*/ | ||
public function deleteItem(string $itemId): void { | ||
$this->mustHaveOrigin(); | ||
} | ||
|
||
|
||
/** | ||
* @param string $appId | ||
* @param string $itemType | ||
*/ | ||
public function setOrigin(string $appId, string $itemType) { | ||
$this->originAppId = $appId; | ||
$this->originItemType = $itemType; | ||
} | ||
|
||
/** | ||
* @throws CircleSharesManagerException | ||
*/ | ||
private function mustHaveOrigin(): void { | ||
if ($this->originAppId !== '' && $this->originItemType !== '') { | ||
return; | ||
} | ||
|
||
throw new CircleSharesManagerException( | ||
'ICirclesManager::getShareManager(appId, itemType) used empty params' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.