You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

clearMappings.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 Morris Jobke <hey@morrisjobke.de>
  10. * @author Roeland Jago Douma <roeland@famdouma.nl>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. use OCA\User_LDAP\Mapping\UserMapping;
  28. use OCA\User_LDAP\Mapping\GroupMapping;
  29. // Check user and app status
  30. \OC_JSON::checkAdminUser();
  31. \OC_JSON::checkAppEnabled('user_ldap');
  32. \OC_JSON::callCheck();
  33. $subject = (string)$_POST['ldap_clear_mapping'];
  34. $mapping = null;
  35. try {
  36. if ($subject === 'user') {
  37. $mapping = new UserMapping(\OC::$server->getDatabaseConnection());
  38. $result = $mapping->clearCb(
  39. function ($uid) {
  40. \OC::$server->getUserManager()->emit('\OC\User', 'preUnassignedUserId', [$uid]);
  41. },
  42. function ($uid) {
  43. \OC::$server->getUserManager()->emit('\OC\User', 'postUnassignedUserId', [$uid]);
  44. }
  45. );
  46. } elseif ($subject === 'group') {
  47. $mapping = new GroupMapping(\OC::$server->getDatabaseConnection());
  48. $result = $mapping->clear();
  49. }
  50. if ($mapping === null || !$result) {
  51. $l = \OC::$server->getL10N('user_ldap');
  52. throw new \Exception($l->t('Failed to clear the mappings.'));
  53. }
  54. \OC_JSON::success();
  55. } catch (\Exception $e) {
  56. \OC_JSON::error(['message' => $e->getMessage()]);
  57. }