User.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\CalDAV\Principal;
  4. use Sabre\DAV;
  5. use Sabre\DAVACL;
  6. /**
  7. * CalDAV principal.
  8. *
  9. * This is a standard user-principal for CalDAV. This principal is also a
  10. * collection and returns the caldav-proxy-read and caldav-proxy-write child
  11. * principals.
  12. *
  13. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  14. * @author Evert Pot (http://evertpot.com/)
  15. * @license http://sabre.io/license/ Modified BSD License
  16. */
  17. class User extends DAVACL\Principal implements DAV\ICollection
  18. {
  19. /**
  20. * Creates a new file in the directory.
  21. *
  22. * @param string $name Name of the file
  23. * @param resource $data initial payload, passed as a readable stream resource
  24. *
  25. * @throws DAV\Exception\Forbidden
  26. */
  27. public function createFile($name, $data = null)
  28. {
  29. throw new DAV\Exception\Forbidden('Permission denied to create file (filename '.$name.')');
  30. }
  31. /**
  32. * Creates a new subdirectory.
  33. *
  34. * @param string $name
  35. *
  36. * @throws DAV\Exception\Forbidden
  37. */
  38. public function createDirectory($name)
  39. {
  40. throw new DAV\Exception\Forbidden('Permission denied to create directory');
  41. }
  42. /**
  43. * Returns a specific child node, referenced by its name.
  44. *
  45. * @param string $name
  46. *
  47. * @return DAV\INode
  48. */
  49. public function getChild($name)
  50. {
  51. $principal = $this->principalBackend->getPrincipalByPath($this->getPrincipalURL().'/'.$name);
  52. if (!$principal) {
  53. throw new DAV\Exception\NotFound('Node with name '.$name.' was not found');
  54. }
  55. if ('calendar-proxy-read' === $name) {
  56. return new ProxyRead($this->principalBackend, $this->principalProperties);
  57. }
  58. if ('calendar-proxy-write' === $name) {
  59. return new ProxyWrite($this->principalBackend, $this->principalProperties);
  60. }
  61. throw new DAV\Exception\NotFound('Node with name '.$name.' was not found');
  62. }
  63. /**
  64. * Returns an array with all the child nodes.
  65. *
  66. * @return DAV\INode[]
  67. */
  68. public function getChildren()
  69. {
  70. $r = [];
  71. if ($this->principalBackend->getPrincipalByPath($this->getPrincipalURL().'/calendar-proxy-read')) {
  72. $r[] = new ProxyRead($this->principalBackend, $this->principalProperties);
  73. }
  74. if ($this->principalBackend->getPrincipalByPath($this->getPrincipalURL().'/calendar-proxy-write')) {
  75. $r[] = new ProxyWrite($this->principalBackend, $this->principalProperties);
  76. }
  77. return $r;
  78. }
  79. /**
  80. * Returns whether or not the child node exists.
  81. *
  82. * @param string $name
  83. *
  84. * @return bool
  85. */
  86. public function childExists($name)
  87. {
  88. try {
  89. $this->getChild($name);
  90. return true;
  91. } catch (DAV\Exception\NotFound $e) {
  92. return false;
  93. }
  94. }
  95. /**
  96. * Returns a list of ACE's for this node.
  97. *
  98. * Each ACE has the following properties:
  99. * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
  100. * currently the only supported privileges
  101. * * 'principal', a url to the principal who owns the node
  102. * * 'protected' (optional), indicating that this ACE is not allowed to
  103. * be updated.
  104. *
  105. * @return array
  106. */
  107. public function getACL()
  108. {
  109. $acl = parent::getACL();
  110. $acl[] = [
  111. 'privilege' => '{DAV:}read',
  112. 'principal' => $this->principalProperties['uri'].'/calendar-proxy-read',
  113. 'protected' => true,
  114. ];
  115. $acl[] = [
  116. 'privilege' => '{DAV:}read',
  117. 'principal' => $this->principalProperties['uri'].'/calendar-proxy-write',
  118. 'protected' => true,
  119. ];
  120. return $acl;
  121. }
  122. }