ProxyWrite.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\CalDAV\Principal;
  4. use Sabre\DAV;
  5. use Sabre\DAVACL;
  6. /**
  7. * ProxyWrite principal.
  8. *
  9. * This class represents a principal group, hosted under the main principal.
  10. * This is needed to implement 'Calendar delegation' support. This class is
  11. * instantiated by User.
  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 ProxyWrite implements IProxyWrite
  18. {
  19. /**
  20. * Parent principal information.
  21. *
  22. * @var array
  23. */
  24. protected $principalInfo;
  25. /**
  26. * Principal Backend.
  27. *
  28. * @var DAVACL\PrincipalBackend\BackendInterface
  29. */
  30. protected $principalBackend;
  31. /**
  32. * Creates the object.
  33. *
  34. * Note that you MUST supply the parent principal information.
  35. */
  36. public function __construct(DAVACL\PrincipalBackend\BackendInterface $principalBackend, array $principalInfo)
  37. {
  38. $this->principalInfo = $principalInfo;
  39. $this->principalBackend = $principalBackend;
  40. }
  41. /**
  42. * Returns this principals name.
  43. *
  44. * @return string
  45. */
  46. public function getName()
  47. {
  48. return 'calendar-proxy-write';
  49. }
  50. /**
  51. * Returns the last modification time.
  52. */
  53. public function getLastModified()
  54. {
  55. return null;
  56. }
  57. /**
  58. * Deletes the current node.
  59. *
  60. * @throws DAV\Exception\Forbidden
  61. */
  62. public function delete()
  63. {
  64. throw new DAV\Exception\Forbidden('Permission denied to delete node');
  65. }
  66. /**
  67. * Renames the node.
  68. *
  69. * @param string $name The new name
  70. *
  71. * @throws DAV\Exception\Forbidden
  72. */
  73. public function setName($name)
  74. {
  75. throw new DAV\Exception\Forbidden('Permission denied to rename file');
  76. }
  77. /**
  78. * Returns a list of alternative urls for a principal.
  79. *
  80. * This can for example be an email address, or ldap url.
  81. *
  82. * @return array
  83. */
  84. public function getAlternateUriSet()
  85. {
  86. return [];
  87. }
  88. /**
  89. * Returns the full principal url.
  90. *
  91. * @return string
  92. */
  93. public function getPrincipalUrl()
  94. {
  95. return $this->principalInfo['uri'].'/'.$this->getName();
  96. }
  97. /**
  98. * Returns the list of group members.
  99. *
  100. * If this principal is a group, this function should return
  101. * all member principal uri's for the group.
  102. *
  103. * @return array
  104. */
  105. public function getGroupMemberSet()
  106. {
  107. return $this->principalBackend->getGroupMemberSet($this->getPrincipalUrl());
  108. }
  109. /**
  110. * Returns the list of groups this principal is member of.
  111. *
  112. * If this principal is a member of a (list of) groups, this function
  113. * should return a list of principal uri's for it's members.
  114. *
  115. * @return array
  116. */
  117. public function getGroupMembership()
  118. {
  119. return $this->principalBackend->getGroupMembership($this->getPrincipalUrl());
  120. }
  121. /**
  122. * Sets a list of group members.
  123. *
  124. * If this principal is a group, this method sets all the group members.
  125. * The list of members is always overwritten, never appended to.
  126. *
  127. * This method should throw an exception if the members could not be set.
  128. */
  129. public function setGroupMemberSet(array $principals)
  130. {
  131. $this->principalBackend->setGroupMemberSet($this->getPrincipalUrl(), $principals);
  132. }
  133. /**
  134. * Returns the displayname.
  135. *
  136. * This should be a human readable name for the principal.
  137. * If none is available, return the nodename.
  138. *
  139. * @return string
  140. */
  141. public function getDisplayName()
  142. {
  143. return $this->getName();
  144. }
  145. }