Skip to content
Merged
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
16 changes: 13 additions & 3 deletions lib/Service/CircleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
use OCA\Circles\Tools\Traits\TDeserialize;
use OCA\Circles\Tools\Traits\TNCLogger;
use OCA\Circles\Tools\Traits\TStringTools;
use OCA\Files_Sharing\Event\UserShareAccessUpdatedEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IL10N;
Expand Down Expand Up @@ -124,6 +126,7 @@ public function __construct(
MemberService $memberService,
PermissionService $permissionService,
ConfigService $configService,
private readonly IEventDispatcher $eventDispatcher,
) {
$this->l10n = $l10n;
$this->hasher = $hasher;
Expand Down Expand Up @@ -422,14 +425,16 @@ public function updateDescription(string $circleId, string $description): array
*/
public function circleJoin(string $circleId): array {
$this->federatedUserService->mustHaveCurrentUser();
/** @var FederatedUser $currentUser */
$currentUser = $this->federatedUserService->getCurrentUser();

$probe = new CircleProbe();
$probe->includeNonVisibleCircles()
->emulateVisitor();

$circle = $this->circleRequest->getCircle(
$circleId,
$this->federatedUserService->getCurrentUser(),
$currentUser,
$probe
);

Expand All @@ -442,6 +447,8 @@ public function circleJoin(string $circleId): array {

$this->federatedEventService->newEvent($event);

$this->eventDispatcher->dispatchTyped(new UserShareAccessUpdatedEvent($this->memberService->collectShareAccessUpdateUsers($currentUser)));

return $event->getOutcome();
}

Expand All @@ -465,14 +472,16 @@ public function circleJoin(string $circleId): array {
*/
public function circleLeave(string $circleId, bool $force = false): array {
$this->federatedUserService->mustHaveCurrentUser();
/** @var FederatedUser $currentUser */
$currentUser = $this->federatedUserService->getCurrentUser();

$probe = new CircleProbe();
$probe->includeNonVisibleCircles()
->emulateVisitor();

$circle = $this->circleRequest->getCircle(
$circleId,
$this->federatedUserService->getCurrentUser(),
$currentUser,
$probe
);

Expand All @@ -482,10 +491,11 @@ public function circleLeave(string $circleId, bool $force = false): array {

$this->federatedEventService->newEvent($event);

$this->eventDispatcher->dispatchTyped(new UserShareAccessUpdatedEvent($this->memberService->collectShareAccessUpdateUsers($currentUser)));

return $event->getOutcome();
}


/**
* @param string $circleId
* @param CircleProbe|null $probe
Expand Down
31 changes: 31 additions & 0 deletions lib/Service/MemberService.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
use OCA\Circles\Tools\Traits\TArrayTools;
use OCA\Circles\Tools\Traits\TNCLogger;
use OCA\Circles\Tools\Traits\TStringTools;
use OCA\Files_Sharing\Event\UserShareAccessUpdatedEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUser;
use OCP\IUserManager;

/**
* Class MemberService
Expand Down Expand Up @@ -91,6 +95,8 @@ public function __construct(
MembershipService $membershipService,
FederatedEventService $federatedEventService,
RemoteStreamService $remoteStreamService,
private readonly IEventDispatcher $eventDispatcher,
private readonly IUserManager $userManager,
) {
$this->circleRequest = $circleRequest;
$this->memberRequest = $memberRequest;
Expand Down Expand Up @@ -209,6 +215,8 @@ public function addMember(string $circleId, FederatedUser $federatedUser, bool $

$this->federatedEventService->newEvent($event);

$this->eventDispatcher->dispatchTyped(new UserShareAccessUpdatedEvent($this->collectShareAccessUpdateUsers($member)));

return $event->getOutcome();
}

Expand Down Expand Up @@ -257,6 +265,8 @@ function (FederatedUser $federatedUser) use ($patron) {

$this->federatedEventService->newEvent($event);

$this->eventDispatcher->dispatchTyped(new UserShareAccessUpdatedEvent(array_merge(...array_map(fn (Member $member) => $this->collectShareAccessUpdateUsers($member), array_values($members)))));

return $event->getOutcome();
}

Expand Down Expand Up @@ -291,9 +301,30 @@ public function removeMember(string $memberId, bool $forceSync = false): array {

$this->federatedEventService->newEvent($event);

$this->eventDispatcher->dispatchTyped(new UserShareAccessUpdatedEvent($this->collectShareAccessUpdateUsers($member)));

return $event->getOutcome();
}


/**
* @return list<IUser>
*/
public function collectShareAccessUpdateUsers(Member|FederatedUser $member): array {
if ($member->getUserType() === Member::TYPE_USER) {
return [$this->userManager->getExistingUser($member->getUserId())];
}

if ($member->getUserType() === Member::TYPE_CIRCLE) {
$circle = $this->circleRequest->getCircle($member->getSingleId());
$members = $circle->getInheritedMembers();
$userMembers = array_filter($members, static fn (Member $inheritedMember) => $inheritedMember->getUserType() === Member::TYPE_USER);
return array_map(fn (Member $inheritedMember) => $this->userManager->getExistingUser($inheritedMember->getUserId()), $userMembers);
}

return [];
}

/**
* @param string $memberId
* @param int $level
Expand Down
5 changes: 3 additions & 2 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@
<file name="tests/stubs/oc_user_manager.php" />
<file name="tests/stubs/oc_user_nouserexception.php" />
<file name="tests/stubs/oc_user_user.php" />
<file name="tests/stubs/oca_user_ldap_mapping_abstractmapping.php" />
<file name="tests/stubs/oca_user_ldap_mapping_usermapping.php" />
<file name="tests/stubs/oca_dav_carddav_contactsmanager.php" />
<file name="tests/stubs/oca_federatedfilesharing_notifications.php" />
<file name="tests/stubs/oca_files_sharing_event_usershareaccessupdatedevent.php" />
<file name="tests/stubs/oca_files_sharing_external_manager.php" />
<file name="tests/stubs/oca_user_ldap_mapping_abstractmapping.php" />
<file name="tests/stubs/oca_user_ldap_mapping_usermapping.php" />
<file name="tests/stubs/stecman_component_symfony_console_bashcompletion_completion_completionawareinterface.php" />
<file name="tests/stubs/symfony_component_console_command_command.php" />
<file name="tests/stubs/symfony_component_console_helper_helper.php" />
Expand Down
15 changes: 10 additions & 5 deletions tests/stubs/doctrine_dbal_connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@
use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Driver\Exception as TheDriverException;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\Driver\Statement as DriverStatement;
use Doctrine\DBAL\Event\TransactionBeginEventArgs;
use Doctrine\DBAL\Event\TransactionCommitEventArgs;
use Doctrine\DBAL\Event\TransactionRollBackEventArgs;
use Doctrine\DBAL\Exception\ConnectionLost;
use Doctrine\DBAL\Exception\DeadlockException;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
use Doctrine\DBAL\Exception\InvalidArgumentException;
use Doctrine\DBAL\Exception\TransactionRolledBack;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use Doctrine\DBAL\Query\QueryBuilder;
Expand Down Expand Up @@ -48,8 +53,8 @@
* A database abstraction-level connection that implements features like events, transaction isolation levels,
* configuration, emulated transaction nesting, lazy connecting and more.
*
* @psalm-import-type Params from DriverManager
* @psalm-consistent-constructor
* @phpstan-import-type Params from DriverManager
* @phpstan-consistent-constructor
*/
class Connection
{
Expand Down Expand Up @@ -130,7 +135,7 @@ class Connection
* @param Driver $driver The driver to use.
* @param Configuration|null $config The configuration, optional.
* @param EventManager|null $eventManager The event manager, optional.
* @psalm-param Params $params
* @phpstan-param Params $params
*
* @throws Exception
*/
Expand All @@ -145,7 +150,7 @@ public function __construct(#[SensitiveParameter]
* @internal
*
* @return array<string,mixed>
* @psalm-return Params
* @phpstan-return Params
*/
public function getParams()
{
Expand Down Expand Up @@ -232,7 +237,7 @@ public function getExpressionBuilder()
*
* @throws Exception
*
* @psalm-assert !null $this->_conn
* @phpstan-assert !null $this->_conn
*/
public function connect()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
*
* Instantiation through the DriverManager looks like:
*
* @psalm-import-type Params from DriverManager
* @phpstan-import-type Params from DriverManager
* @example
*
* $conn = DriverManager::getConnection(array(
Expand Down Expand Up @@ -98,7 +98,7 @@ class PrimaryReadReplicaConnection extends Connection
* @internal The connection can be only instantiated by the driver manager.
*
* @param array<string,mixed> $params
* @psalm-param Params $params
* @phpstan-param Params $params
*
* @throws Exception
* @throws InvalidArgumentException
Expand Down
1 change: 0 additions & 1 deletion tests/stubs/doctrine_dbal_driver_exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Throwable;

/** @psalm-immutable */
interface Exception extends Throwable
{
/**
Expand Down
1 change: 0 additions & 1 deletion tests/stubs/doctrine_dbal_exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use function spl_object_hash;
use function sprintf;

/** @psalm-immutable */
class Exception extends \Exception
{
public static function notSupported(string $method): self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

/**
* Base class for all constraint violation related errors detected in the driver.
*
* @psalm-immutable
*/
class ConstraintViolationException extends ServerException
{
Expand Down
2 changes: 0 additions & 2 deletions tests/stubs/doctrine_dbal_exception_driverexception.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

/**
* Base class for all errors detected in the driver.
*
* @psalm-immutable
*/
class DriverException extends Exception implements TheDriverException
{
Expand Down
2 changes: 0 additions & 2 deletions tests/stubs/doctrine_dbal_exception_serverexception.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

/**
* Base class for all server related errors detected in the driver.
*
* @psalm-immutable
*/
class ServerException extends DriverException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

/**
* Exception for a unique constraint violation detected in the driver.
*
* @psalm-immutable
*/
class UniqueConstraintViolationException extends ConstraintViolationException
{
Expand Down
2 changes: 1 addition & 1 deletion tests/stubs/doctrine_dbal_query_querybuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function getConnection()
* @deprecated The builder state is an internal concern.
*
* @return int Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN.
* @psalm-return self::STATE_*
* @phpstan-return self::STATE_*
*/
public function getState()
{
Expand Down
1 change: 0 additions & 1 deletion tests/stubs/doctrine_dbal_schema_schemaexception.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

use function sprintf;

/** @psalm-immutable */
class SchemaException extends Exception
{
/** @deprecated Use {@see TableDoesNotExist} instead. */
Expand Down
25 changes: 13 additions & 12 deletions tests/stubs/oc.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,29 @@
* SPDX-FileCopyrightText: 2013-2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
use OC\Encryption\HookManager;

use OC\Profiler\BuiltInProfiler;
use OC\Share20\GroupDeletedListener;
use OC\Share20\Hooks;
use OC\Share20\UserDeletedListener;
use OC\Share20\UserRemovedListener;
use OC\User\DisabledUserException;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Events\BeforeFileSystemSetupEvent;
use OCP\Group\Events\GroupDeletedEvent;
use OCP\Group\Events\UserRemovedEvent;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IInitialStateService;
use OCP\ILogger;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\Security\Bruteforce\IThrottler;
use OCP\Server;
use OCP\Share;
use OCP\Template\ITemplateManager;
use OCP\User\Events\UserChangedEvent;
use OCP\User\Events\UserDeletedEvent;
use OCP\Util;
use Psr\Log\LoggerInterface;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
Expand All @@ -29,10 +40,6 @@
* OC_autoload!
*/
class OC {
/**
* Associative array for autoloading. classname => filename
*/
public static array $CLASSPATH = [];
/**
* The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud)
*/
Expand All @@ -59,8 +66,6 @@ class OC {
*/
public static bool $CLI = false;

public static \OC\Autoloader $loader;

public static \Composer\Autoload\ClassLoader $composerAutoloader;

public static \OC\Server $server;
Expand Down Expand Up @@ -119,10 +124,6 @@ public static function registerCleanupHooks(\OC\SystemConfig $systemConfig): voi
*/
public static function registerShareHooks(\OC\SystemConfig $systemConfig): void
{
}

protected static function registerAutoloaderCache(\OC\SystemConfig $systemConfig): void
{
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/stubs/oc_appframework_bootstrap_coordinator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IServerContainer;
use Psr\Container\ContainerExceptionInterface;
use Psr\Log\LoggerInterface;
use Throwable;
use function class_exists;
Expand Down
Loading
Loading