2013-05-08 11:47:07 -04:00
|
|
|
<?php
|
2024-05-29 05:32:54 -04:00
|
|
|
|
2013-05-08 11:47:07 -04:00
|
|
|
/**
|
2024-05-29 05:32:54 -04:00
|
|
|
* SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2013-05-08 11:47:07 -04:00
|
|
|
*/
|
2014-11-05 07:05:07 -05:00
|
|
|
use OCA\User_LDAP\Mapping\GroupMapping;
|
|
|
|
|
use OCA\User_LDAP\Mapping\UserMapping;
|
2023-03-13 13:46:30 -04:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2025-02-03 09:34:01 -05:00
|
|
|
use OCP\IDBConnection;
|
|
|
|
|
use OCP\IUserManager;
|
2023-03-13 13:46:30 -04:00
|
|
|
use OCP\Server;
|
|
|
|
|
use OCP\User\Events\BeforeUserIdUnassignedEvent;
|
|
|
|
|
use OCP\User\Events\UserIdUnassignedEvent;
|
2024-10-10 06:40:31 -04:00
|
|
|
use OCP\Util;
|
2014-11-05 07:05:07 -05:00
|
|
|
|
2013-05-08 11:47:07 -04:00
|
|
|
// Check user and app status
|
2018-03-22 08:19:29 -04:00
|
|
|
\OC_JSON::checkAdminUser();
|
|
|
|
|
\OC_JSON::checkAppEnabled('user_ldap');
|
|
|
|
|
\OC_JSON::callCheck();
|
2013-05-08 11:47:07 -04:00
|
|
|
|
2015-02-13 07:33:20 -05:00
|
|
|
$subject = (string)$_POST['ldap_clear_mapping'];
|
2014-11-05 07:05:07 -05:00
|
|
|
$mapping = null;
|
|
|
|
|
try {
|
2018-03-15 09:16:43 -04:00
|
|
|
if ($subject === 'user') {
|
2023-03-13 13:46:30 -04:00
|
|
|
$mapping = Server::get(UserMapping::class);
|
|
|
|
|
/** @var IEventDispatcher $dispatcher */
|
|
|
|
|
$dispatcher = Server::get(IEventDispatcher::class);
|
2018-03-15 09:16:43 -04:00
|
|
|
$result = $mapping->clearCb(
|
2023-03-13 13:46:30 -04:00
|
|
|
function (string $uid) use ($dispatcher): void {
|
|
|
|
|
$dispatcher->dispatchTyped(new BeforeUserIdUnassignedEvent($uid));
|
2025-02-13 06:50:56 -05:00
|
|
|
/** @psalm-suppress UndefinedInterfaceMethod For now we have to emit, will be removed when all hooks are removed */
|
2025-02-03 09:34:01 -05:00
|
|
|
Server::get(IUserManager::class)->emit('\OC\User', 'preUnassignedUserId', [$uid]);
|
2018-03-15 09:16:43 -04:00
|
|
|
},
|
2023-03-13 13:46:30 -04:00
|
|
|
function (string $uid) use ($dispatcher): void {
|
|
|
|
|
$dispatcher->dispatchTyped(new UserIdUnassignedEvent($uid));
|
2025-02-13 06:50:56 -05:00
|
|
|
/** @psalm-suppress UndefinedInterfaceMethod For now we have to emit, will be removed when all hooks are removed */
|
2025-02-03 09:34:01 -05:00
|
|
|
Server::get(IUserManager::class)->emit('\OC\User', 'postUnassignedUserId', [$uid]);
|
2018-03-15 09:16:43 -04:00
|
|
|
}
|
|
|
|
|
);
|
2020-04-10 04:35:09 -04:00
|
|
|
} elseif ($subject === 'group') {
|
2025-02-03 09:34:01 -05:00
|
|
|
$mapping = new GroupMapping(Server::get(IDBConnection::class));
|
2018-03-15 09:16:43 -04:00
|
|
|
$result = $mapping->clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($mapping === null || !$result) {
|
2024-10-10 06:40:31 -04:00
|
|
|
$l = Util::getL10N('user_ldap');
|
2014-11-05 07:05:07 -05:00
|
|
|
throw new \Exception($l->t('Failed to clear the mappings.'));
|
|
|
|
|
}
|
2018-03-22 08:19:29 -04:00
|
|
|
\OC_JSON::success();
|
2014-11-05 07:05:07 -05:00
|
|
|
} catch (\Exception $e) {
|
2020-03-26 04:30:18 -04:00
|
|
|
\OC_JSON::error(['message' => $e->getMessage()]);
|
2013-08-18 05:02:08 -04:00
|
|
|
}
|