Outbox.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2018, Georg Ehrke
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\DAV\CalDAV;
  26. use OCP\IConfig;
  27. use Sabre\CalDAV\Plugin as CalDAVPlugin;
  28. /**
  29. * Class Outbox
  30. *
  31. * @package OCA\DAV\CalDAV
  32. */
  33. class Outbox extends \Sabre\CalDAV\Schedule\Outbox {
  34. /** @var IConfig */
  35. private $config;
  36. /** @var null|bool */
  37. private $disableFreeBusy = null;
  38. /**
  39. * Outbox constructor.
  40. *
  41. * @param IConfig $config
  42. * @param string $principalUri
  43. */
  44. public function __construct(IConfig $config, string $principalUri) {
  45. parent::__construct($principalUri);
  46. $this->config = $config;
  47. }
  48. /**
  49. * Returns a list of ACE's for this node.
  50. *
  51. * Each ACE has the following properties:
  52. * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
  53. * currently the only supported privileges
  54. * * 'principal', a url to the principal who owns the node
  55. * * 'protected' (optional), indicating that this ACE is not allowed to
  56. * be updated.
  57. *
  58. * @return array
  59. */
  60. public function getACL() {
  61. // getACL is called so frequently that we cache the config result
  62. if ($this->disableFreeBusy === null) {
  63. $this->disableFreeBusy = ($this->config->getAppValue('dav', 'disableFreeBusy', 'no') === 'yes');
  64. }
  65. $commonAcl = [
  66. [
  67. 'privilege' => '{DAV:}read',
  68. 'principal' => $this->getOwner(),
  69. 'protected' => true,
  70. ],
  71. [
  72. 'privilege' => '{DAV:}read',
  73. 'principal' => $this->getOwner() . '/calendar-proxy-read',
  74. 'protected' => true,
  75. ],
  76. [
  77. 'privilege' => '{DAV:}read',
  78. 'principal' => $this->getOwner() . '/calendar-proxy-write',
  79. 'protected' => true,
  80. ],
  81. ];
  82. // schedule-send is an aggregate privilege for:
  83. // - schedule-send-invite
  84. // - schedule-send-reply
  85. // - schedule-send-freebusy
  86. //
  87. // If FreeBusy is disabled, we have to remove the latter privilege
  88. if ($this->disableFreeBusy) {
  89. return array_merge($commonAcl, [
  90. [
  91. 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-invite',
  92. 'principal' => $this->getOwner(),
  93. 'protected' => true,
  94. ],
  95. [
  96. 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-invite',
  97. 'principal' => $this->getOwner() . '/calendar-proxy-write',
  98. 'protected' => true,
  99. ],
  100. [
  101. 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-reply',
  102. 'principal' => $this->getOwner(),
  103. 'protected' => true,
  104. ],
  105. [
  106. 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-reply',
  107. 'principal' => $this->getOwner() . '/calendar-proxy-write',
  108. 'protected' => true,
  109. ],
  110. ]);
  111. }
  112. return array_merge($commonAcl, [
  113. [
  114. 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send',
  115. 'principal' => $this->getOwner(),
  116. 'protected' => true,
  117. ],
  118. [
  119. 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send',
  120. 'principal' => $this->getOwner() . '/calendar-proxy-write',
  121. 'protected' => true,
  122. ],
  123. ]);
  124. }
  125. }