Browse Source

Add a listener for the events

Signed-off-by: Joas Schilling <coding@schilljs.com>
tags/v16.0.0alpha1
Joas Schilling 5 years ago
parent
commit
752276fd89
No account linked to committer's email address
2 changed files with 71 additions and 0 deletions
  1. 5
    0
      lib/base.php
  2. 66
    0
      lib/private/Collaboration/Resources/Listener.php

+ 5
- 0
lib/base.php View File

@@ -716,6 +716,7 @@ class OC {
self::registerEncryptionWrapper();
self::registerEncryptionHooks();
self::registerAccountHooks();
self::registerResourceCollectionHooks();

// Make sure that the application class is not loaded before the database is setup
if ($systemConfig->getValue("installed", false)) {
@@ -847,6 +848,10 @@ class OC {
\OCP\Util::connectHook('OC_User', 'changeUser', $hookHandler, 'changeUserHook');
}

private static function registerResourceCollectionHooks() {
\OC\Collaboration\Resources\Listener::register(\OC::$server->getEventDispatcher());
}

/**
* register hooks for the filesystem
*/

+ 66
- 0
lib/private/Collaboration/Resources/Listener.php View File

@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2019 Joas Schilling <coding@schilljs.com>
*
* @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 OC\Collaboration\Resources;


use OCP\Collaboration\Resources\IManager;
use OCP\IGroup;
use OCP\IUser;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;

class Listener {

public static function register(EventDispatcherInterface $dispatcher): void {
$listener = function(GenericEvent $event) {
/** @var IUser $user */
$user = $event->getArgument('user');
/** @var IManager $resourceManager */
$resourceManager = \OC::$server->query(IManager::class);

$resourceManager->invalidateAccessCacheForUser($user);
};
$dispatcher->addListener(IGroup::class . '::postAddUser', $listener);
$dispatcher->addListener(IGroup::class . '::postRemoveUser', $listener);

$dispatcher->addListener(IGroup::class . '::postDelete', function(GenericEvent $event) {
/** @var IUser $user */
$user = $event->getSubject();
/** @var IManager $resourceManager */
$resourceManager = \OC::$server->query(IManager::class);

$resourceManager->invalidateAccessCacheForUser($user);
});

$dispatcher->addListener(IGroup::class . '::preDelete', function(GenericEvent $event) {
/** @var IGroup $group */
$group = $event->getSubject();
/** @var IManager $resourceManager */
$resourceManager = \OC::$server->query(IManager::class);

foreach ($group->getUsers() as $user) {
$resourceManager->invalidateAccessCacheForUser($user);
}
});
}
}

Loading…
Cancel
Save