LegacyDAVACL.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCA\DAV\Connector;
  25. use OCA\DAV\Connector\Sabre\DavAclPlugin;
  26. use Sabre\DAV\INode;
  27. use Sabre\DAV\PropFind;
  28. use Sabre\HTTP\URLUtil;
  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) = URLUtil::splitPath($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. }