SharedCalendar.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\CalDAV;
  4. use Sabre\DAV\Sharing\Plugin as SPlugin;
  5. /**
  6. * This object represents a CalDAV calendar that is shared by a different user.
  7. *
  8. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  9. * @author Evert Pot (http://evertpot.com/)
  10. * @license http://sabre.io/license/ Modified BSD License
  11. */
  12. class SharedCalendar extends Calendar implements ISharedCalendar
  13. {
  14. /**
  15. * Returns the 'access level' for the instance of this shared resource.
  16. *
  17. * The value should be one of the Sabre\DAV\Sharing\Plugin::ACCESS_
  18. * constants.
  19. *
  20. * @return int
  21. */
  22. public function getShareAccess()
  23. {
  24. return isset($this->calendarInfo['share-access']) ? $this->calendarInfo['share-access'] : SPlugin::ACCESS_NOTSHARED;
  25. }
  26. /**
  27. * This function must return a URI that uniquely identifies the shared
  28. * resource. This URI should be identical across instances, and is
  29. * also used in several other XML bodies to connect invites to
  30. * resources.
  31. *
  32. * This may simply be a relative reference to the original shared instance,
  33. * but it could also be a urn. As long as it's a valid URI and unique.
  34. *
  35. * @return string
  36. */
  37. public function getShareResourceUri()
  38. {
  39. return $this->calendarInfo['share-resource-uri'];
  40. }
  41. /**
  42. * Updates the list of sharees.
  43. *
  44. * Every item must be a Sharee object.
  45. *
  46. * @param \Sabre\DAV\Xml\Element\Sharee[] $sharees
  47. */
  48. public function updateInvites(array $sharees)
  49. {
  50. $this->caldavBackend->updateInvites($this->calendarInfo['id'], $sharees);
  51. }
  52. /**
  53. * Returns the list of people whom this resource is shared with.
  54. *
  55. * Every item in the returned array must be a Sharee object with
  56. * at least the following properties set:
  57. *
  58. * * $href
  59. * * $shareAccess
  60. * * $inviteStatus
  61. *
  62. * and optionally:
  63. *
  64. * * $properties
  65. *
  66. * @return \Sabre\DAV\Xml\Element\Sharee[]
  67. */
  68. public function getInvites()
  69. {
  70. return $this->caldavBackend->getInvites($this->calendarInfo['id']);
  71. }
  72. /**
  73. * Marks this calendar as published.
  74. *
  75. * Publishing a calendar should automatically create a read-only, public,
  76. * subscribable calendar.
  77. *
  78. * @param bool $value
  79. */
  80. public function setPublishStatus($value)
  81. {
  82. $this->caldavBackend->setPublishStatus($this->calendarInfo['id'], $value);
  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. public function getACL()
  97. {
  98. $acl = [];
  99. switch ($this->getShareAccess()) {
  100. case SPlugin::ACCESS_NOTSHARED:
  101. case SPlugin::ACCESS_SHAREDOWNER:
  102. $acl[] = [
  103. 'privilege' => '{DAV:}share',
  104. 'principal' => $this->calendarInfo['principaluri'],
  105. 'protected' => true,
  106. ];
  107. $acl[] = [
  108. 'privilege' => '{DAV:}share',
  109. 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-write',
  110. 'protected' => true,
  111. ];
  112. // no break intentional!
  113. case SPlugin::ACCESS_READWRITE:
  114. $acl[] = [
  115. 'privilege' => '{DAV:}write',
  116. 'principal' => $this->calendarInfo['principaluri'],
  117. 'protected' => true,
  118. ];
  119. $acl[] = [
  120. 'privilege' => '{DAV:}write',
  121. 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-write',
  122. 'protected' => true,
  123. ];
  124. // no break intentional!
  125. case SPlugin::ACCESS_READ:
  126. $acl[] = [
  127. 'privilege' => '{DAV:}write-properties',
  128. 'principal' => $this->calendarInfo['principaluri'],
  129. 'protected' => true,
  130. ];
  131. $acl[] = [
  132. 'privilege' => '{DAV:}write-properties',
  133. 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-write',
  134. 'protected' => true,
  135. ];
  136. $acl[] = [
  137. 'privilege' => '{DAV:}read',
  138. 'principal' => $this->calendarInfo['principaluri'],
  139. 'protected' => true,
  140. ];
  141. $acl[] = [
  142. 'privilege' => '{DAV:}read',
  143. 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-read',
  144. 'protected' => true,
  145. ];
  146. $acl[] = [
  147. 'privilege' => '{DAV:}read',
  148. 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-write',
  149. 'protected' => true,
  150. ];
  151. $acl[] = [
  152. 'privilege' => '{'.Plugin::NS_CALDAV.'}read-free-busy',
  153. 'principal' => '{DAV:}authenticated',
  154. 'protected' => true,
  155. ];
  156. break;
  157. }
  158. return $acl;
  159. }
  160. /**
  161. * This method returns the ACL's for calendar objects in this calendar.
  162. * The result of this method automatically gets passed to the
  163. * calendar-object nodes in the calendar.
  164. *
  165. * @return array
  166. */
  167. public function getChildACL()
  168. {
  169. $acl = [];
  170. switch ($this->getShareAccess()) {
  171. case SPlugin::ACCESS_NOTSHARED:
  172. case SPlugin::ACCESS_SHAREDOWNER:
  173. case SPlugin::ACCESS_READWRITE:
  174. $acl[] = [
  175. 'privilege' => '{DAV:}write',
  176. 'principal' => $this->calendarInfo['principaluri'],
  177. 'protected' => true,
  178. ];
  179. $acl[] = [
  180. 'privilege' => '{DAV:}write',
  181. 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-write',
  182. 'protected' => true,
  183. ];
  184. // no break intentional
  185. case SPlugin::ACCESS_READ:
  186. $acl[] = [
  187. 'privilege' => '{DAV:}read',
  188. 'principal' => $this->calendarInfo['principaluri'],
  189. 'protected' => true,
  190. ];
  191. $acl[] = [
  192. 'privilege' => '{DAV:}read',
  193. 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-write',
  194. 'protected' => true,
  195. ];
  196. $acl[] = [
  197. 'privilege' => '{DAV:}read',
  198. 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-read',
  199. 'protected' => true,
  200. ];
  201. break;
  202. }
  203. return $acl;
  204. }
  205. }