Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: sync share on globalscale when adding new instance #878

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
['name' => 'Remote#test', 'url' => '/test', 'verb' => 'GET'],
['name' => 'Remote#event', 'url' => '/event/', 'verb' => 'POST'],
['name' => 'Remote#incoming', 'url' => '/incoming/', 'verb' => 'POST'],
['name' => 'Remote#forward', 'url' => '/forward/', 'verb' => 'POST'],
['name' => 'Remote#circles', 'url' => '/circles/', 'verb' => 'GET'],
['name' => 'Remote#circle', 'url' => '/circle/{circleId}/', 'verb' => 'GET'],
['name' => 'Remote#members', 'url' => '/members/{circleId}/', 'verb' => 'GET'],
Expand Down
15 changes: 10 additions & 5 deletions lib/Command/CirclesCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,10 @@ private function saveLoopback(InputInterface $input, OutputInterface $output, st
[$scheme, $cloudId, $path] = $this->parseAddress($loopback);

$question = new ConfirmationQuestion(
'- Do you want to save <info>' . $loopback
. '</info> as your <info>loopback</info> address ? (y/N) ', false, '/^(y|Y)/i'
'- Do you want to save <info>'
. $loopback
. '</info> as your <info>loopback</info> address ? (y/N) ',
false, '/^(y|Y)/i'
);

$helper = $this->getHelper('question');
Expand Down Expand Up @@ -463,7 +465,8 @@ private function checkInternal(InputInterface $input, OutputInterface $output, s
$fullInternal = rtrim($scheme . '://' . $cloudId . $path, '/');

$question = new ConfirmationQuestion(
'<comment>Do you want to check the validity of this internal address?</comment> (Y/n) ', true,
'<comment>Do you want to run a series of test to confirm the validity of this internal address?</comment> (Y/n) ',
true,
'/^(y|Y)/i'
);

Expand Down Expand Up @@ -573,8 +576,10 @@ private function saveInternal(InputInterface $input, OutputInterface $output, st

$output->writeln('');
$question = new ConfirmationQuestion(
'- Do you want to save <info>' . $internal
. '</info> as your <info>internal</info> address ? (y/N) ', false, '/^(y|Y)/i'
'- Do you want to save <info>'
. $internal
. '</info> as your <info>internal</info> address ? (y/N) ',
false, '/^(y|Y)/i'
);

$helper = $this->getHelper('question');
Expand Down
18 changes: 18 additions & 0 deletions lib/Command/CirclesMaintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@
use OC\Core\Command\Base;
use OCA\Circles\Db\CoreRequestBuilder;
use OCA\Circles\Exceptions\MaintenanceException;
use OCA\Circles\Service\CircleService;
use OCA\Circles\Service\FederatedUserService;
use OCA\Circles\Service\MaintenanceService;
use OCA\Circles\Service\OutputService;
use OCA\Circles\Service\ShareService;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -104,6 +107,21 @@ protected function configure() {
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output): int {


/** @var ShareService $shareService */
$shareService = \OC::$server->get(ShareService::class);
/** @var CircleService $circleService */
$circleService = \OC::$server->get(CircleService::class);
/** @var FederatedUserService $federatedUserService */
$federatedUserService = \OC::$server->get(FederatedUserService::class);
$federatedUserService->setLocalCurrentUserId('test3A');

$circle = $circleService->getCircle('T3yPBiOeEn7Tv1KJ1BOkroECmaWEeuu');
$shareService->syncRemoteShares($circle);


return 0;
$reset = $input->getOption('reset');
$uninstall = $input->getOption('uninstall');
$level = (int)$input->getOption('level');
Expand Down
26 changes: 26 additions & 0 deletions lib/Controller/RemoteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,32 @@ public function incoming(): DataResponse {
}


/**
* @PublicPage
* @NoCSRFRequired
*
* @return DataResponse
*/
public function forward(): DataResponse {
try {
$event = $this->extractEventFromRequest();
} catch (Exception $e) {
$this->e($e);

return $this->exceptionResponse($e, Http::STATUS_UNAUTHORIZED);
}

try {
$this->remoteDownstreamService->forwardedEvent($event);

return new DataResponse($this->serialize($event->getResult()));
} catch (Exception $e) {
return $this->exceptionResponse($e);
}
}



/**
* @PublicPage
* @NoCSRFRequired
Expand Down
2 changes: 1 addition & 1 deletion lib/Cron/GlobalSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class GlobalSync extends TimedJob {
* Cache constructor.
*/
public function __construct() {
$this->setInterval(10);
$this->setInterval(900);
}


Expand Down
2 changes: 1 addition & 1 deletion lib/Cron/Maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function __construct(
MaintenanceService $maintenanceService,
ConfigService $configService
) {
$this->setInterval(10);
$this->setInterval(900);

$this->maintenanceService = $maintenanceService;
$this->configService = $configService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @copyright 2021
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -32,30 +32,39 @@
namespace OCA\Circles\FederatedItems;

use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore;
use OCA\Circles\Exceptions\RequestBuilderException;
use OCA\Circles\IFederatedItem;
use OCA\Circles\IFederatedItemForwardResult;
use OCA\Circles\IFederatedItemHighSeverity;
use OCA\Circles\IFederatedItemLimitedToInstanceWithMembership;
use OCA\Circles\Model\Federated\FederatedEvent;
use OCA\Circles\Service\CircleEventService;
use OCA\Circles\Service\GlobalEventService;
use OCA\Circles\Service\ShareWrapperService;


/**
* Class SharesSync
*
* @package OCA\Circles\FederatedItems
*/
class SharedItemsSync implements
class SharedFilesSync implements
IFederatedItem,
IFederatedItemForwardResult,
IFederatedItemHighSeverity,
IFederatedItemLimitedToInstanceWithMembership {


// TODO: testing that IFederatedItemLimitedToInstanceWithMembership is working (since multi-instance)
// TODO: implements IFederatedItemInstanceMember to the check procedure
/** @var ShareWrapperService */
private $shareWrapperService;

/** @var CircleEventService */
private $circleEventService;
/** @var GlobalEventService */
private $globalEventService;


public function __construct(CircleEventService $circleEventService) {
$this->circleEventService = $circleEventService;
public function __construct(
ShareWrapperService $shareWrapperService,
GlobalEventService $globalEventService
) {
$this->shareWrapperService = $shareWrapperService;
$this->globalEventService = $globalEventService;
}


Expand All @@ -68,11 +77,16 @@ public function verify(FederatedEvent $event): void {

/**
* @param FederatedEvent $event
*
* @throws RequestBuilderException
*/
public function manage(FederatedEvent $event): void {
$this->circleEventService->onSharedItemsSyncRequested($event);
\OC::$server->getLogger()->log(3, '### MANAGE');
$this->globalEventService->onSharedItemsSyncRequested($event);
$circle = $event->getCircle();

$event->setResult(new SimpleDataStore(['shares' => 'ok']));
$wrappedShares = $this->shareWrapperService->getSharesToCircle($circle->getSingleId());
$event->setResult(new SimpleDataStore(['shares' => $wrappedShares]));
}


Expand All @@ -81,5 +95,6 @@ public function manage(FederatedEvent $event): void {
* @param array $results
*/
public function result(FederatedEvent $event, array $results): void {
\OC::$server->getLogger()->log(3, '### RESULT: ' . json_encode($results));
}
}
40 changes: 40 additions & 0 deletions lib/IFederatedItemForwardResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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 <maxence@artificial-owl.com>
* @copyright 2021
* @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;

/**
* Interface IFederatedItemForwardResult
*
* @package OCA\Circles
*/
interface IFederatedItemForwardResult {
}
2 changes: 1 addition & 1 deletion lib/IFederatedItemLimitedToInstanceWithMembership.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
namespace OCA\Circles;

/**
* Interface IFederatedItemInstanceMember
* Interface IFederatedItemLimitedToInstanceWithMembership
*
* @package OCA\Circles
*/
Expand Down
22 changes: 22 additions & 0 deletions lib/Model/Federated/FederatedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class FederatedEvent implements JsonSerializable {
/** @var bool */
private $dataRequestOnly = false;

/** @var bool */
private $forwardResult = false;

/** @var string */
private $sender = '';

Expand Down Expand Up @@ -222,6 +225,25 @@ public function setDataRequestOnly(bool $dataRequestOnly): self {
}


/**
* @param bool $forwardResult
*
* @return FederatedEvent
*/
public function setForwardResult(bool $forwardResult): self {
$this->forwardResult = $forwardResult;

return $this;
}

/**
* @return bool
*/
public function isForwardResult(): bool {
return $this->forwardResult;
}


/**
*
* Origin of the request
Expand Down
25 changes: 25 additions & 0 deletions lib/Model/Federated/RemoteInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class RemoteInstance extends NC22Signatory implements INC22QueryRow, JsonSeriali
public const TEST = 'test';
public const ALIASES = 'aliases';
public const INCOMING = 'incoming';
public const FORWARD = 'forward';
public const EVENT = 'event';
public const CIRCLES = 'circles';
public const CIRCLE = 'circle';
Expand Down Expand Up @@ -92,6 +93,9 @@ class RemoteInstance extends NC22Signatory implements INC22QueryRow, JsonSeriali
/** @var string */
private $incoming = '';

/** @var string */
private $forward = '';

/** @var string */
private $root = '';

Expand Down Expand Up @@ -221,6 +225,25 @@ public function setIncoming(string $incoming): self {
}


/**
* @param string $forward
*
* @return RemoteInstance
*/
public function setForward(string $forward): self {
$this->forward = $forward;

return $this;
}

/**
* @return string
*/
public function getForward(): string {
return $this->forward;
}


/**
* @return string
*/
Expand Down Expand Up @@ -486,6 +509,7 @@ public function import(array $data): NC22Signatory {
->setEvent($this->get(self::EVENT, $data))
->setRoot($this->get(self::ROOT, $data))
->setIncoming($this->get(self::INCOMING, $data))
->setForward($this->get(self::FORWARD, $data))
->setCircles($this->get(self::CIRCLES, $data))
->setCircle($this->get(self::CIRCLE, $data))
->setMembers($this->get(self::MEMBERS, $data))
Expand Down Expand Up @@ -516,6 +540,7 @@ public function jsonSerialize(): array {
self::ROOT => $this->getRoot(),
self::EVENT => $this->getEvent(),
self::INCOMING => $this->getIncoming(),
self::FORWARD => $this->getForward(),
self::TEST => $this->getTest(),
self::CIRCLES => $this->getCircles(),
self::CIRCLE => $this->getCircle(),
Expand Down
5 changes: 3 additions & 2 deletions lib/Search/LocalUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct(ICollaboratorSearch $search, ConfigService $configSe
/**
* {@inheritdoc}
*/
public function search($search) {
public function search($search): array {
$result = [];
$userManager = \OC::$server->getUserManager();

Expand All @@ -86,7 +86,8 @@ public function search($search) {
* @return array
*/
private function searchFromCollaborator($search): array {
[$temp, $hasMore] = $this->search->search($search, [IShare::TYPE_USER, IShare::TYPE_EMAIL], false, 50, 0);
[$temp, $hasMore] =
$this->search->search($search, [IShare::TYPE_USER, IShare::TYPE_EMAIL], false, 50, 0);

$result = array_merge($temp['exact']['users'], $temp['users']);
$parsed = [];
Expand Down
Loading