1<?php
2
3namespace Sabre\CalDAV\Schedule;
4
5use Sabre\DAV;
6use Sabre\CalDAV;
7use Sabre\DAVACL;
8
9/**
10 * The CalDAV scheduling outbox
11 *
12 * The outbox is mainly used as an endpoint in the tree for a client to do
13 * free-busy requests. This functionality is completely handled by the
14 * Scheduling plugin, so this object is actually mostly static.
15 *
16 * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
17 * @author Evert Pot (http://evertpot.com/)
18 * @license http://sabre.io/license/ Modified BSD License
19 */
20class Outbox extends DAV\Collection implements IOutbox {
21
22    /**
23     * The principal Uri
24     *
25     * @var string
26     */
27    protected $principalUri;
28
29    /**
30     * Constructor
31     *
32     * @param string $principalUri
33     */
34    function __construct($principalUri) {
35
36        $this->principalUri = $principalUri;
37
38    }
39
40    /**
41     * Returns the name of the node.
42     *
43     * This is used to generate the url.
44     *
45     * @return string
46     */
47    function getName() {
48
49        return 'outbox';
50
51    }
52
53    /**
54     * Returns an array with all the child nodes
55     *
56     * @return \Sabre\DAV\INode[]
57     */
58    function getChildren() {
59
60        return [];
61
62    }
63
64    /**
65     * Returns the owner principal
66     *
67     * This must be a url to a principal, or null if there's no owner
68     *
69     * @return string|null
70     */
71    function getOwner() {
72
73        return $this->principalUri;
74
75    }
76
77    /**
78     * Returns a group principal
79     *
80     * This must be a url to a principal, or null if there's no owner
81     *
82     * @return string|null
83     */
84    function getGroup() {
85
86        return null;
87
88    }
89
90    /**
91     * Returns a list of ACE's for this node.
92     *
93     * Each ACE has the following properties:
94     *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
95     *     currently the only supported privileges
96     *   * 'principal', a url to the principal who owns the node
97     *   * 'protected' (optional), indicating that this ACE is not allowed to
98     *      be updated.
99     *
100     * @return array
101     */
102    function getACL() {
103
104        return [
105            [
106                'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-query-freebusy',
107                'principal' => $this->getOwner(),
108                'protected' => true,
109            ],
110            [
111                'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-post-vevent',
112                'principal' => $this->getOwner(),
113                'protected' => true,
114            ],
115            [
116                'privilege' => '{DAV:}read',
117                'principal' => $this->getOwner(),
118                'protected' => true,
119            ],
120            [
121                'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-query-freebusy',
122                'principal' => $this->getOwner() . '/calendar-proxy-write',
123                'protected' => true,
124            ],
125            [
126                'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-post-vevent',
127                'principal' => $this->getOwner() . '/calendar-proxy-write',
128                'protected' => true,
129            ],
130            [
131                'privilege' => '{DAV:}read',
132                'principal' => $this->getOwner() . '/calendar-proxy-read',
133                'protected' => true,
134            ],
135            [
136                'privilege' => '{DAV:}read',
137                'principal' => $this->getOwner() . '/calendar-proxy-write',
138                'protected' => true,
139            ],
140        ];
141
142    }
143
144    /**
145     * Updates the ACL
146     *
147     * This method will receive a list of new ACE's.
148     *
149     * @param array $acl
150     * @return void
151     */
152    function setACL(array $acl) {
153
154        throw new DAV\Exception\MethodNotAllowed('You\'re not allowed to update the ACL');
155
156    }
157
158    /**
159     * Returns the list of supported privileges for this node.
160     *
161     * The returned data structure is a list of nested privileges.
162     * See Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple
163     * standard structure.
164     *
165     * If null is returned from this method, the default privilege set is used,
166     * which is fine for most common usecases.
167     *
168     * @return array|null
169     */
170    function getSupportedPrivilegeSet() {
171
172        $default = DAVACL\Plugin::getDefaultSupportedPrivilegeSet();
173        $default['aggregates'][] = [
174            'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-query-freebusy',
175        ];
176        $default['aggregates'][] = [
177            'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-post-vevent',
178        ];
179
180        return $default;
181
182    }
183
184}
185