makes LDAP's group updater dispatch type events
* fixes group share updates on added users Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
c8381c5d17
commit
51fa743c7a
|
@ -43,6 +43,9 @@ use OCA\User_LDAP\LogWrapper;
|
||||||
use OCA\User_LDAP\Mapping\GroupMapping;
|
use OCA\User_LDAP\Mapping\GroupMapping;
|
||||||
use OCA\User_LDAP\Mapping\UserMapping;
|
use OCA\User_LDAP\Mapping\UserMapping;
|
||||||
use OCA\User_LDAP\User\Manager;
|
use OCA\User_LDAP\User\Manager;
|
||||||
|
use OCP\EventDispatcher\IEventDispatcher;
|
||||||
|
use OCP\Group\Events\UserAddedEvent;
|
||||||
|
use OCP\Group\Events\UserRemovedEvent;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
|
|
||||||
class UpdateGroups extends \OC\BackgroundJob\TimedJob {
|
class UpdateGroups extends \OC\BackgroundJob\TimedJob {
|
||||||
|
@ -93,6 +96,11 @@ class UpdateGroups extends \OC\BackgroundJob\TimedJob {
|
||||||
* @param string[] $groups
|
* @param string[] $groups
|
||||||
*/
|
*/
|
||||||
private static function handleKnownGroups($groups) {
|
private static function handleKnownGroups($groups) {
|
||||||
|
/** @var IEventDispatcher $dispatcher */
|
||||||
|
$dispatcher = \OC::$server->query(IEventDispatcher::class);
|
||||||
|
$groupManager = \OC::$server->getGroupManager();
|
||||||
|
$userManager = \OC::$server->getUserManager();
|
||||||
|
|
||||||
\OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – Dealing with known Groups.', ILogger::DEBUG);
|
\OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – Dealing with known Groups.', ILogger::DEBUG);
|
||||||
$query = \OC_DB::prepare('
|
$query = \OC_DB::prepare('
|
||||||
UPDATE `*PREFIX*ldap_group_members`
|
UPDATE `*PREFIX*ldap_group_members`
|
||||||
|
@ -104,15 +112,19 @@ class UpdateGroups extends \OC\BackgroundJob\TimedJob {
|
||||||
$knownUsers = unserialize(self::$groupsFromDB[$group]['owncloudusers']);
|
$knownUsers = unserialize(self::$groupsFromDB[$group]['owncloudusers']);
|
||||||
$actualUsers = self::getGroupBE()->usersInGroup($group);
|
$actualUsers = self::getGroupBE()->usersInGroup($group);
|
||||||
$hasChanged = false;
|
$hasChanged = false;
|
||||||
|
|
||||||
|
$groupObject = $groupManager->get($group);
|
||||||
foreach (array_diff($knownUsers, $actualUsers) as $removedUser) {
|
foreach (array_diff($knownUsers, $actualUsers) as $removedUser) {
|
||||||
\OCP\Util::emitHook('OC_User', 'post_removeFromGroup', ['uid' => $removedUser, 'gid' => $group]);
|
$userObject = $userManager->get($removedUser);
|
||||||
|
$dispatcher->dispatchTyped(new UserRemovedEvent($groupObject, $userObject));
|
||||||
\OCP\Util::writeLog('user_ldap',
|
\OCP\Util::writeLog('user_ldap',
|
||||||
'bgJ "updateGroups" – "'.$removedUser.'" removed from "'.$group.'".',
|
'bgJ "updateGroups" – "'.$removedUser.'" removed from "'.$group.'".',
|
||||||
ILogger::INFO);
|
ILogger::INFO);
|
||||||
$hasChanged = true;
|
$hasChanged = true;
|
||||||
}
|
}
|
||||||
foreach (array_diff($actualUsers, $knownUsers) as $addedUser) {
|
foreach (array_diff($actualUsers, $knownUsers) as $addedUser) {
|
||||||
\OCP\Util::emitHook('OC_User', 'post_addToGroup', ['uid' => $addedUser, 'gid' => $group]);
|
$userObject = $userManager->get($addedUser);
|
||||||
|
$dispatcher->dispatchTyped(new UserAddedEvent($groupObject, $userObject));
|
||||||
\OCP\Util::writeLog('user_ldap',
|
\OCP\Util::writeLog('user_ldap',
|
||||||
'bgJ "updateGroups" – "'.$addedUser.'" added to "'.$group.'".',
|
'bgJ "updateGroups" – "'.$addedUser.'" added to "'.$group.'".',
|
||||||
ILogger::INFO);
|
ILogger::INFO);
|
||||||
|
|
|
@ -901,7 +901,6 @@ class OC {
|
||||||
public static function registerShareHooks() {
|
public static function registerShareHooks() {
|
||||||
if (\OC::$server->getSystemConfig()->getValue('installed')) {
|
if (\OC::$server->getSystemConfig()->getValue('installed')) {
|
||||||
OC_Hook::connect('OC_User', 'post_deleteUser', Hooks::class, 'post_deleteUser');
|
OC_Hook::connect('OC_User', 'post_deleteUser', Hooks::class, 'post_deleteUser');
|
||||||
OC_Hook::connect('OC_User', 'post_removeFromGroup', Hooks::class, 'post_removeFromGroupLDAP');
|
|
||||||
OC_Hook::connect('OC_User', 'post_deleteGroup', Hooks::class, 'post_deleteGroup');
|
OC_Hook::connect('OC_User', 'post_deleteGroup', Hooks::class, 'post_deleteGroup');
|
||||||
|
|
||||||
/** @var \OCP\EventDispatcher\IEventDispatcher $dispatcher */
|
/** @var \OCP\EventDispatcher\IEventDispatcher $dispatcher */
|
||||||
|
|
|
@ -30,8 +30,4 @@ class Hooks {
|
||||||
public static function post_deleteGroup($arguments) {
|
public static function post_deleteGroup($arguments) {
|
||||||
\OC::$server->getShareManager()->groupDeleted($arguments['gid']);
|
\OC::$server->getShareManager()->groupDeleted($arguments['gid']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function post_removeFromGroupLDAP($arguments) {
|
|
||||||
\OC::$server->getShareManager()->userDeletedFromGroup($arguments['uid'], $arguments['gid']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue