ExtStorageConfigHandler.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Julius Härtl <jus@bitgrid.net>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\User_LDAP\Handler;
  26. use OCA\Files_External\Config\IConfigHandler;
  27. use OCA\Files_External\Config\SimpleSubstitutionTrait;
  28. use OCA\Files_External\Config\UserContext;
  29. use OCA\User_LDAP\User_Proxy;
  30. class ExtStorageConfigHandler extends UserContext implements IConfigHandler {
  31. use SimpleSubstitutionTrait;
  32. /**
  33. * @param mixed $optionValue
  34. * @return mixed the same type as $optionValue
  35. * @since 16.0.0
  36. * @throws \Exception
  37. */
  38. public function handle($optionValue) {
  39. $this->placeholder = 'home';
  40. $user = $this->getUser();
  41. if ($user === null) {
  42. return $optionValue;
  43. }
  44. $backend = $user->getBackend();
  45. if (!$backend instanceof User_Proxy) {
  46. return $optionValue;
  47. }
  48. $access = $backend->getLDAPAccess($user->getUID());
  49. if (!$access) {
  50. return $optionValue;
  51. }
  52. $attribute = $access->connection->ldapExtStorageHomeAttribute;
  53. if (empty($attribute)) {
  54. return $optionValue;
  55. }
  56. $ldapUser = $access->userManager->get($user->getUID());
  57. $extHome = $ldapUser !== null ? $ldapUser->getExtStorageHome() : '';
  58. return $this->processInput($optionValue, $extHome);
  59. }
  60. }