Outbox.php 3.7 KB

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