Skip to content
Closed
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
+bypass_circle_types
Signed-off-by: Maxence Lange <[email protected]>
  • Loading branch information
ArtificialOwl committed Mar 25, 2022
commit 47187d20dde9a939e46435081dec05f10930227a
8 changes: 8 additions & 0 deletions lib/Command/CirclesConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int

if (strtolower($input->getOption('output')) === 'json') {
$output->writeln(json_encode($outcome, JSON_PRETTY_PRINT));
} elseif (strtolower($input->getOption('output')) !== 'none') {
$circle = $this->circleService->getCircle($circleId);
$output->writeln(
json_encode(
Circle::getCircleFlags($circle, Circle::FLAGS_LONG),
JSON_PRETTY_PRINT
)
);
}

return 0;
Expand Down
4 changes: 3 additions & 1 deletion lib/FederatedItems/CircleConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function __construct(CircleRequest $circleRequest, ConfigService $configS
* @param FederatedEvent $event
*
* @throws FederatedItemException
* @throws \OCA\Circles\Exceptions\RequestBuilderException
*/
public function verify(FederatedEvent $event): void {
$circle = $event->getCircle();
Expand Down Expand Up @@ -141,7 +142,8 @@ public function verify(FederatedEvent $event): void {

$new = clone $circle;
$new->setConfig($config);
$this->configService->confirmAllowedCircleTypes($new);

$this->configService->confirmAllowedCircleTypes($new, $circle);

$event->getData()->sInt('config', $new->getConfig());

Expand Down
4 changes: 3 additions & 1 deletion lib/Model/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,9 @@ public function getMemberships(): array {
* @throws RequestBuilderException
*/
public function getLink(string $singleId, bool $detailed = false): Membership {
$this->getManager()->getLink($this, $singleId, $detailed);
if ($singleId !== '') {
return $this->getManager()->getLink($this, $singleId, $detailed);
}

throw new MembershipNotFoundException();
}
Expand Down
73 changes: 63 additions & 10 deletions lib/Service/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@

namespace OCA\Circles\Service;

use OCA\Circles\Tools\Model\NCRequest;
use OCA\Circles\Tools\Traits\TNCLogger;
use OCA\Circles\Tools\Traits\TArrayTools;
use OCA\Circles\Tools\Traits\TStringTools;
use OC;
use OCA\Circles\AppInfo\Application;
use OCA\Circles\Exceptions\GSStatusException;
use OCA\Circles\Exceptions\MembershipNotFoundException;
use OCA\Circles\Exceptions\RequestBuilderException;
use OCA\Circles\IFederatedUser;
use OCA\Circles\Model\Circle;
use OCA\Circles\Model\Member;
use OCA\Circles\Tools\Model\NCRequest;
use OCA\Circles\Tools\Traits\TArrayTools;
use OCA\Circles\Tools\Traits\TNCLogger;
use OCA\Circles\Tools\Traits\TStringTools;
use OCP\IConfig;
use OCP\IURLGenerator;

Expand Down Expand Up @@ -106,6 +108,9 @@ class ConfigService {
public const ALLOWED_TYPES = 'allowed_types';
public const CIRCLE_TYPES_FORCE = 'circle_types_force';
public const CIRCLE_TYPES_BLOCK = 'circle_types_block';

public const BYPASS_CIRCLE_TYPES = 'bypass_circle_types';

public const MIGRATION_BYPASS = 'migration_bypass';
public const MIGRATION_22 = 'migration_22';
public const MIGRATION_22_1 = 'migration_22_1';
Expand Down Expand Up @@ -182,6 +187,7 @@ class ConfigService {
self::ALLOWED_TYPES => Member::ALLOWING_ALL_TYPES,
self::CIRCLE_TYPES_FORCE => '0',
self::CIRCLE_TYPES_BLOCK => '0',
self::BYPASS_CIRCLE_TYPES => '',

self::MIGRATION_BYPASS => '0',
self::MIGRATION_22 => '0',
Expand Down Expand Up @@ -343,7 +349,7 @@ public function sendPasswordByMail(Circle $circle): bool {
}

return (!$this->getBool('password_single_enabled', $circle->getSettings(), false)
|| $this->get('password_single', $circle->getSettings()) === '');
|| $this->get('password_single', $circle->getSettings()) === '');
}


Expand Down Expand Up @@ -757,13 +763,60 @@ public function linkToRoute(string $route, array $args): string {
* Enforce or Block circle's config/type
*
* @param Circle $circle
* @param Circle|null $previous
*
* @throws RequestBuilderException
*/
public function confirmAllowedCircleTypes(Circle $circle): void {
public function confirmAllowedCircleTypes(Circle $circle, ?Circle $previous = null): void {
try {
if (!$circle->hasInitiator()) {
throw new MembershipNotFoundException();
}

$circle->getInitiator()->getLink($this->getAppValue(self::BYPASS_CIRCLE_TYPES));

return;
} catch (MembershipNotFoundException $e) {
}

$config = $circle->getConfig();
$config |= $this->getAppValueInt(ConfigService::CIRCLE_TYPES_FORCE);
$block = $this->getAppValueInt(ConfigService::CIRCLE_TYPES_BLOCK);
$config |= $block;
$config -= $block;
$force = $this->getAppValueInt(self::CIRCLE_TYPES_FORCE);
$block = $this->getAppValueInt(self::CIRCLE_TYPES_BLOCK);

if (is_null($previous)) {
$config |= $force;
$config &= ~$block;
} else {
// if we have a previous entry, we compare old and new config.
foreach (array_merge($this->extractBitwise($force), $this->extractBitwise($block)) as $bit) {
if ($previous->isConfig($bit)) {
$config |= $bit;
} else {
$config &= ~$bit;
}
}
}

$circle->setConfig($config);
}


/**
* @param int $bitwise
*
* @return array
*/
public function extractBitwise(int $bitwise): array {
$values = [];
$b = 1;
while ($b <= $bitwise) {
if (($bitwise & $b) !== 0) {
$values[] = $b;
}

$b = $b << 1;
}

return $values;
}
}
4 changes: 2 additions & 2 deletions lib/Service/MembershipService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@

namespace OCA\Circles\Service;

use OCA\Circles\Tools\Exceptions\ItemNotFoundException;
use OCA\Circles\Tools\Traits\TNCLogger;
use OCA\Circles\Db\CircleRequest;
use OCA\Circles\Db\MemberRequest;
use OCA\Circles\Db\MembershipRequest;
Expand All @@ -44,6 +42,8 @@
use OCA\Circles\Model\FederatedUser;
use OCA\Circles\Model\Member;
use OCA\Circles\Model\Membership;
use OCA\Circles\Tools\Exceptions\ItemNotFoundException;
use OCA\Circles\Tools\Traits\TNCLogger;

/**
* Class MembershipService
Expand Down