1
0

Outbox.php 3.5 KB

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