ExtStorageConfigHandler.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\User_LDAP\Handler;
  7. use OCA\Files_External\Config\IConfigHandler;
  8. use OCA\Files_External\Config\SimpleSubstitutionTrait;
  9. use OCA\Files_External\Config\UserContext;
  10. use OCA\User_LDAP\User_Proxy;
  11. class ExtStorageConfigHandler extends UserContext implements IConfigHandler {
  12. use SimpleSubstitutionTrait;
  13. /**
  14. * @param mixed $optionValue
  15. * @return mixed the same type as $optionValue
  16. * @since 16.0.0
  17. * @throws \Exception
  18. */
  19. public function handle($optionValue) {
  20. $this->placeholder = 'home';
  21. $user = $this->getUser();
  22. if ($user === null) {
  23. return $optionValue;
  24. }
  25. $backend = $user->getBackend();
  26. if (!$backend instanceof User_Proxy) {
  27. return $optionValue;
  28. }
  29. $access = $backend->getLDAPAccess($user->getUID());
  30. if (!$access) {
  31. return $optionValue;
  32. }
  33. $attribute = $access->connection->ldapExtStorageHomeAttribute;
  34. if (empty($attribute)) {
  35. return $optionValue;
  36. }
  37. $ldapUser = $access->userManager->get($user->getUID());
  38. $extHome = $ldapUser !== null ? $ldapUser->getExtStorageHome() : '';
  39. return $this->processInput($optionValue, $extHome);
  40. }
  41. }