ProxyRead.php 3.8 KB

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