LegacyDAVACL.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\DAV\Connector;
  8. use OCA\DAV\Connector\Sabre\DavAclPlugin;
  9. use Sabre\DAV\INode;
  10. use Sabre\DAV\PropFind;
  11. use Sabre\DAVACL\Xml\Property\Principal;
  12. class LegacyDAVACL extends DavAclPlugin {
  13. /**
  14. * @inheritdoc
  15. */
  16. public function getCurrentUserPrincipals() {
  17. $principalV2 = $this->getCurrentUserPrincipal();
  18. if (is_null($principalV2)) {
  19. return [];
  20. }
  21. $principalV1 = $this->convertPrincipal($principalV2, false);
  22. return array_merge(
  23. [
  24. $principalV2,
  25. $principalV1
  26. ],
  27. $this->getPrincipalMembership($principalV1)
  28. );
  29. }
  30. private function convertPrincipal($principal, $toV2) {
  31. [, $name] = \Sabre\Uri\split($principal);
  32. if ($toV2) {
  33. return "principals/users/$name";
  34. }
  35. return "principals/$name";
  36. }
  37. public function propFind(PropFind $propFind, INode $node) {
  38. /* Overload current-user-principal */
  39. $propFind->handle('{DAV:}current-user-principal', function () {
  40. if ($url = parent::getCurrentUserPrincipal()) {
  41. return new Principal(Principal::HREF, $url . '/');
  42. } else {
  43. return new Principal(Principal::UNAUTHENTICATED);
  44. }
  45. });
  46. return parent::propFind($propFind, $node);
  47. }
  48. }