LegacyDAVACL.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  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, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\DAV\Connector;
  26. use OCA\DAV\Connector\Sabre\DavAclPlugin;
  27. use Sabre\DAV\INode;
  28. use Sabre\DAV\PropFind;
  29. use Sabre\DAVACL\Xml\Property\Principal;
  30. class LegacyDAVACL extends DavAclPlugin {
  31. /**
  32. * @inheritdoc
  33. */
  34. public function getCurrentUserPrincipals() {
  35. $principalV2 = $this->getCurrentUserPrincipal();
  36. if (is_null($principalV2)) return [];
  37. $principalV1 = $this->convertPrincipal($principalV2, false);
  38. return array_merge(
  39. [
  40. $principalV2,
  41. $principalV1
  42. ],
  43. $this->getPrincipalMembership($principalV1)
  44. );
  45. }
  46. private function convertPrincipal($principal, $toV2) {
  47. list(, $name) = \Sabre\Uri\split($principal);
  48. if ($toV2) {
  49. return "principals/users/$name";
  50. }
  51. return "principals/$name";
  52. }
  53. public function propFind(PropFind $propFind, INode $node) {
  54. /* Overload current-user-principal */
  55. $propFind->handle('{DAV:}current-user-principal', function () {
  56. if ($url = parent::getCurrentUserPrincipal()) {
  57. return new Principal(Principal::HREF, $url . '/');
  58. } else {
  59. return new Principal(Principal::UNAUTHENTICATED);
  60. }
  61. });
  62. return parent::propFind($propFind, $node);
  63. }
  64. }