Skip to content

Commit c2b8926

Browse files
Merge pull request #2289 from nextcloud/feat/share-access-update-event
2 parents d2a7e8c + 81eeebe commit c2b8926

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+457
-811
lines changed

lib/Service/CircleService.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
use OCA\Circles\Tools\Traits\TDeserialize;
5252
use OCA\Circles\Tools\Traits\TNCLogger;
5353
use OCA\Circles\Tools\Traits\TStringTools;
54+
use OCA\Files_Sharing\Event\UserShareAccessUpdatedEvent;
55+
use OCP\EventDispatcher\IEventDispatcher;
5456
use OCP\ICache;
5557
use OCP\ICacheFactory;
5658
use OCP\IL10N;
@@ -124,6 +126,7 @@ public function __construct(
124126
MemberService $memberService,
125127
PermissionService $permissionService,
126128
ConfigService $configService,
129+
private readonly IEventDispatcher $eventDispatcher,
127130
) {
128131
$this->l10n = $l10n;
129132
$this->hasher = $hasher;
@@ -422,14 +425,16 @@ public function updateDescription(string $circleId, string $description): array
422425
*/
423426
public function circleJoin(string $circleId): array {
424427
$this->federatedUserService->mustHaveCurrentUser();
428+
/** @var FederatedUser $currentUser */
429+
$currentUser = $this->federatedUserService->getCurrentUser();
425430

426431
$probe = new CircleProbe();
427432
$probe->includeNonVisibleCircles()
428433
->emulateVisitor();
429434

430435
$circle = $this->circleRequest->getCircle(
431436
$circleId,
432-
$this->federatedUserService->getCurrentUser(),
437+
$currentUser,
433438
$probe
434439
);
435440

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

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

450+
$this->eventDispatcher->dispatchTyped(new UserShareAccessUpdatedEvent($this->memberService->collectShareAccessUpdateUsers($currentUser)));
451+
445452
return $event->getOutcome();
446453
}
447454

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

469478
$probe = new CircleProbe();
470479
$probe->includeNonVisibleCircles()
471480
->emulateVisitor();
472481

473482
$circle = $this->circleRequest->getCircle(
474483
$circleId,
475-
$this->federatedUserService->getCurrentUser(),
484+
$currentUser,
476485
$probe
477486
);
478487

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

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

494+
$this->eventDispatcher->dispatchTyped(new UserShareAccessUpdatedEvent($this->memberService->collectShareAccessUpdateUsers($currentUser)));
495+
485496
return $event->getOutcome();
486497
}
487498

488-
489499
/**
490500
* @param string $circleId
491501
* @param CircleProbe|null $probe

lib/Service/MemberService.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
use OCA\Circles\Tools\Traits\TArrayTools;
4545
use OCA\Circles\Tools\Traits\TNCLogger;
4646
use OCA\Circles\Tools\Traits\TStringTools;
47+
use OCA\Files_Sharing\Event\UserShareAccessUpdatedEvent;
48+
use OCP\EventDispatcher\IEventDispatcher;
49+
use OCP\IUser;
50+
use OCP\IUserManager;
4751

4852
/**
4953
* Class MemberService
@@ -91,6 +95,8 @@ public function __construct(
9195
MembershipService $membershipService,
9296
FederatedEventService $federatedEventService,
9397
RemoteStreamService $remoteStreamService,
98+
private readonly IEventDispatcher $eventDispatcher,
99+
private readonly IUserManager $userManager,
94100
) {
95101
$this->circleRequest = $circleRequest;
96102
$this->memberRequest = $memberRequest;
@@ -209,6 +215,8 @@ public function addMember(string $circleId, FederatedUser $federatedUser, bool $
209215

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

218+
$this->eventDispatcher->dispatchTyped(new UserShareAccessUpdatedEvent($this->collectShareAccessUpdateUsers($member)));
219+
212220
return $event->getOutcome();
213221
}
214222

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

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

268+
$this->eventDispatcher->dispatchTyped(new UserShareAccessUpdatedEvent(array_merge(...array_map(fn (Member $member) => $this->collectShareAccessUpdateUsers($member), array_values($members)))));
269+
260270
return $event->getOutcome();
261271
}
262272

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

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

304+
$this->eventDispatcher->dispatchTyped(new UserShareAccessUpdatedEvent($this->collectShareAccessUpdateUsers($member)));
305+
294306
return $event->getOutcome();
295307
}
296308

309+
310+
/**
311+
* @return list<IUser>
312+
*/
313+
public function collectShareAccessUpdateUsers(Member|FederatedUser $member): array {
314+
if ($member->getUserType() === Member::TYPE_USER) {
315+
return [$this->userManager->getExistingUser($member->getUserId())];
316+
}
317+
318+
if ($member->getUserType() === Member::TYPE_CIRCLE) {
319+
$circle = $this->circleRequest->getCircle($member->getSingleId());
320+
$members = $circle->getInheritedMembers();
321+
$userMembers = array_filter($members, static fn (Member $inheritedMember) => $inheritedMember->getUserType() === Member::TYPE_USER);
322+
return array_map(fn (Member $inheritedMember) => $this->userManager->getExistingUser($inheritedMember->getUserId()), $userMembers);
323+
}
324+
325+
return [];
326+
}
327+
297328
/**
298329
* @param string $memberId
299330
* @param int $level

psalm.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@
5959
<file name="tests/stubs/oc_user_manager.php" />
6060
<file name="tests/stubs/oc_user_nouserexception.php" />
6161
<file name="tests/stubs/oc_user_user.php" />
62-
<file name="tests/stubs/oca_user_ldap_mapping_abstractmapping.php" />
63-
<file name="tests/stubs/oca_user_ldap_mapping_usermapping.php" />
6462
<file name="tests/stubs/oca_dav_carddav_contactsmanager.php" />
6563
<file name="tests/stubs/oca_federatedfilesharing_notifications.php" />
64+
<file name="tests/stubs/oca_files_sharing_event_usershareaccessupdatedevent.php" />
6665
<file name="tests/stubs/oca_files_sharing_external_manager.php" />
66+
<file name="tests/stubs/oca_user_ldap_mapping_abstractmapping.php" />
67+
<file name="tests/stubs/oca_user_ldap_mapping_usermapping.php" />
6768
<file name="tests/stubs/stecman_component_symfony_console_bashcompletion_completion_completionawareinterface.php" />
6869
<file name="tests/stubs/symfony_component_console_command_command.php" />
6970
<file name="tests/stubs/symfony_component_console_helper_helper.php" />

tests/stubs/doctrine_dbal_connection.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@
99
use Doctrine\DBAL\Cache\QueryCacheProfile;
1010
use Doctrine\DBAL\Driver\API\ExceptionConverter;
1111
use Doctrine\DBAL\Driver\Connection as DriverConnection;
12+
use Doctrine\DBAL\Driver\Exception as TheDriverException;
1213
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
1314
use Doctrine\DBAL\Driver\Statement as DriverStatement;
1415
use Doctrine\DBAL\Event\TransactionBeginEventArgs;
1516
use Doctrine\DBAL\Event\TransactionCommitEventArgs;
1617
use Doctrine\DBAL\Event\TransactionRollBackEventArgs;
1718
use Doctrine\DBAL\Exception\ConnectionLost;
19+
use Doctrine\DBAL\Exception\DeadlockException;
1820
use Doctrine\DBAL\Exception\DriverException;
21+
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
1922
use Doctrine\DBAL\Exception\InvalidArgumentException;
23+
use Doctrine\DBAL\Exception\TransactionRolledBack;
24+
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
2025
use Doctrine\DBAL\Platforms\AbstractPlatform;
2126
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
2227
use Doctrine\DBAL\Query\QueryBuilder;
@@ -48,8 +53,8 @@
4853
* A database abstraction-level connection that implements features like events, transaction isolation levels,
4954
* configuration, emulated transaction nesting, lazy connecting and more.
5055
*
51-
* @psalm-import-type Params from DriverManager
52-
* @psalm-consistent-constructor
56+
* @phpstan-import-type Params from DriverManager
57+
* @phpstan-consistent-constructor
5358
*/
5459
class Connection
5560
{
@@ -130,7 +135,7 @@ class Connection
130135
* @param Driver $driver The driver to use.
131136
* @param Configuration|null $config The configuration, optional.
132137
* @param EventManager|null $eventManager The event manager, optional.
133-
* @psalm-param Params $params
138+
* @phpstan-param Params $params
134139
*
135140
* @throws Exception
136141
*/
@@ -145,7 +150,7 @@ public function __construct(#[SensitiveParameter]
145150
* @internal
146151
*
147152
* @return array<string,mixed>
148-
* @psalm-return Params
153+
* @phpstan-return Params
149154
*/
150155
public function getParams()
151156
{
@@ -232,7 +237,7 @@ public function getExpressionBuilder()
232237
*
233238
* @throws Exception
234239
*
235-
* @psalm-assert !null $this->_conn
240+
* @phpstan-assert !null $this->_conn
236241
*/
237242
public function connect()
238243
{

tests/stubs/doctrine_dbal_connections_primaryreadreplicaconnection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
*
6060
* Instantiation through the DriverManager looks like:
6161
*
62-
* @psalm-import-type Params from DriverManager
62+
* @phpstan-import-type Params from DriverManager
6363
* @example
6464
*
6565
* $conn = DriverManager::getConnection(array(
@@ -98,7 +98,7 @@ class PrimaryReadReplicaConnection extends Connection
9898
* @internal The connection can be only instantiated by the driver manager.
9999
*
100100
* @param array<string,mixed> $params
101-
* @psalm-param Params $params
101+
* @phpstan-param Params $params
102102
*
103103
* @throws Exception
104104
* @throws InvalidArgumentException

tests/stubs/doctrine_dbal_driver_exception.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Throwable;
88

9-
/** @psalm-immutable */
109
interface Exception extends Throwable
1110
{
1211
/**

tests/stubs/doctrine_dbal_exception.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use function spl_object_hash;
1414
use function sprintf;
1515

16-
/** @psalm-immutable */
1716
class Exception extends \Exception
1817
{
1918
public static function notSupported(string $method): self

tests/stubs/doctrine_dbal_exception_constraintviolationexception.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
/**
66
* Base class for all constraint violation related errors detected in the driver.
7-
*
8-
* @psalm-immutable
97
*/
108
class ConstraintViolationException extends ServerException
119
{

tests/stubs/doctrine_dbal_exception_driverexception.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
/**
1212
* Base class for all errors detected in the driver.
13-
*
14-
* @psalm-immutable
1513
*/
1614
class DriverException extends Exception implements TheDriverException
1715
{

tests/stubs/doctrine_dbal_exception_serverexception.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
/**
66
* Base class for all server related errors detected in the driver.
7-
*
8-
* @psalm-immutable
97
*/
108
class ServerException extends DriverException
119
{

0 commit comments

Comments
 (0)