1
0

clearMappings.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christopher Schäpers <kondou@ts.unde.re>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. use OCA\User_LDAP\Mapping\UserMapping;
  27. use OCA\User_LDAP\Mapping\GroupMapping;
  28. // Check user and app status
  29. \OC_JSON::checkAdminUser();
  30. \OC_JSON::checkAppEnabled('user_ldap');
  31. \OC_JSON::callCheck();
  32. $subject = (string)$_POST['ldap_clear_mapping'];
  33. $mapping = null;
  34. try {
  35. if ($subject === 'user') {
  36. $mapping = \OCP\Server::get(UserMapping::class);
  37. $result = $mapping->clearCb(
  38. function ($uid) {
  39. \OC::$server->getUserManager()->emit('\OC\User', 'preUnassignedUserId', [$uid]);
  40. },
  41. function ($uid) {
  42. \OC::$server->getUserManager()->emit('\OC\User', 'postUnassignedUserId', [$uid]);
  43. }
  44. );
  45. } elseif ($subject === 'group') {
  46. $mapping = new GroupMapping(\OC::$server->getDatabaseConnection());
  47. $result = $mapping->clear();
  48. }
  49. if ($mapping === null || !$result) {
  50. $l = \OC::$server->getL10N('user_ldap');
  51. throw new \Exception($l->t('Failed to clear the mappings.'));
  52. }
  53. \OC_JSON::success();
  54. } catch (\Exception $e) {
  55. \OC_JSON::error(['message' => $e->getMessage()]);
  56. }