User.php 3.7 KB

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