Skip to content

Commit 0868407

Browse files
committed
Some more restructuring
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent 74d4b08 commit 0868407

6 files changed

Lines changed: 192 additions & 217 deletions

File tree

lib/DAV/Calendar.php

Lines changed: 64 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -24,72 +24,44 @@
2424

2525
use OCA\DAV\CalDAV\Integration\ExternalCalendar;
2626
use OCA\DAV\CalDAV\Plugin;
27-
use OCA\DAV\DAV\Sharing\IShareable;
27+
use OCA\Deck\Db\Acl;
2828
use OCA\Deck\Db\Board;
29-
use OCA\Deck\Db\Card;
30-
use OCA\Deck\Db\Stack;
31-
use OCA\Deck\Service\CardService;
32-
use OCA\Deck\Service\StackService;
3329
use Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet;
30+
use Sabre\DAV\Exception\Forbidden;
3431
use Sabre\DAV\PropPatch;
3532

36-
class Calendar extends ExternalCalendar implements IShareable {
33+
class Calendar extends ExternalCalendar {
3734

3835
/** @var string */
3936
private $principalUri;
40-
41-
/** @var string */
42-
private $calendarUri;
43-
4437
/** @var string[] */
4538
private $children;
46-
/**
47-
* @var \stdClass
48-
*/
49-
private $cardService;
39+
/** @var DeckCalendarBackend */
40+
private $backend;
41+
/** @var Board */
42+
private $board;
5043

51-
/**
52-
* Calendar constructor.
53-
*
54-
* @param string $principalUri
55-
* @param string $calendarUri
56-
*/
57-
public function __construct(string $principalUri, string $calendarUri, Board $board = null) {
44+
public function __construct(string $principalUri, string $calendarUri, Board $board, DeckCalendarBackend $backend) {
5845
parent::__construct('deck', $calendarUri);
5946

47+
$this->backend = $backend;
6048
$this->board = $board;
6149

6250
$this->principalUri = $principalUri;
63-
$this->calendarUri = $calendarUri;
64-
6551

6652
if ($board) {
67-
/** @var CardService $cardService */
68-
$cardService = \OC::$server->query(CardService::class);
69-
/** @var StackService $stackService */
70-
$stackService = \OC::$server->query(StackService::class);
71-
$this->children = array_merge(
72-
$cardService->findCalendarEntries($board->getId()),
73-
$stackService->findCalendarEntries($board->getId())
74-
);
53+
$this->children = $this->backend->getChildren($board->getId());
7554
} else {
7655
$this->children = [];
7756
}
7857
}
7958

80-
81-
/**
82-
* @inheritDoc
83-
*/
84-
function getOwner() {
59+
public function getOwner() {
8560
return $this->principalUri;
8661
}
8762

88-
/**
89-
* @inheritDoc
90-
*/
91-
function getACL() {
92-
return [
63+
public function getACL() {
64+
$acl = [
9365
[
9466
'privilege' => '{DAV:}read',
9567
'principal' => $this->getOwner(),
@@ -106,43 +78,41 @@ function getACL() {
10678
'protected' => true,
10779
],
10880
];
81+
if ($this->backend->checkBoardPermission($this->board->getId(), Acl::PERMISSION_EDIT)) {
82+
$acl[] = [
83+
'privilege' => '{DAV:}write',
84+
'principal' => $this->getOwner(),
85+
'protected' => true,
86+
];
87+
$acl[] = [
88+
'privilege' => '{DAV:}write-properties',
89+
'principal' => $this->getOwner(),
90+
'protected' => true,
91+
];
92+
}
93+
return $acl;
10994
}
11095

111-
/**
112-
* @inheritDoc
113-
*/
114-
function setACL(array $acl) {
115-
throw new \Sabre\DAV\Exception\Forbidden('Setting ACL is not supported on this node');
96+
public function setACL(array $acl) {
97+
throw new Forbidden('Setting ACL is not supported on this node');
11698
}
11799

118-
/**
119-
* @inheritDoc
120-
*/
121-
function getSupportedPrivilegeSet() {
100+
public function getSupportedPrivilegeSet() {
122101
return null;
123102
}
124103

125-
/**
126-
* @inheritDoc
127-
*/
128-
function calendarQuery(array $filters) {
129-
// In a real implementation this should actually filter
104+
public function calendarQuery(array $filters) {
105+
// FIXME: In a real implementation this should actually filter
130106
return array_map(function ($card) {
131107
return $card->getCalendarPrefix() . '-' . $card->getId() . '.ics';
132108
}, $this->children);
133109
}
134110

135-
/**
136-
* @inheritDoc
137-
*/
138-
function createFile($name, $data = null) {
139-
return null;
111+
public function createFile($name, $data = null) {
112+
throw new \Sabre\DAV\Exception\Forbidden('Creating a new entry is not implemented');
140113
}
141114

142-
/**
143-
* @inheritDoc
144-
*/
145-
function getChild($name) {
115+
public function getChild($name) {
146116
if ($this->childExists($name)) {
147117
$card = array_values(array_filter(
148118
$this->children,
@@ -151,15 +121,12 @@ function ($card) use (&$name) {
151121
}
152122
));
153123
if (count($card) > 0) {
154-
return new CalendarObject($this, $name, $card[0]);
124+
return new CalendarObject($this, $name, $card[0], $this->backend);
155125
}
156126
}
157127
}
158128

159-
/**
160-
* @inheritDoc
161-
*/
162-
function getChildren() {
129+
public function getChildren() {
163130
$childNames = array_map(function ($card) {
164131
return $card->getCalendarPrefix() . '-' . $card->getId() . '.ics';
165132
}, $this->children);
@@ -173,10 +140,7 @@ function getChildren() {
173140
return $children;
174141
}
175142

176-
/**
177-
* @inheritDoc
178-
*/
179-
function childExists($name) {
143+
public function childExists($name) {
180144
return count(array_filter(
181145
$this->children,
182146
function ($card) use (&$name) {
@@ -185,64 +149,51 @@ function ($card) use (&$name) {
185149
)) > 0;
186150
}
187151

188-
/**
189-
* @inheritDoc
190-
*/
191-
function delete() {
152+
153+
public function delete() {
192154
return null;
193155
}
194156

195-
/**
196-
* @inheritDoc
197-
*/
198-
function getLastModified() {
157+
public function getLastModified() {
199158
return $this->board->getLastModified();
200159
}
201160

202-
/**
203-
* @inheritDoc
204-
*/
205-
function getGroup() {
161+
public function getGroup() {
206162
return [];
207163
}
208164

209-
/**
210-
* @inheritDoc
211-
*/
212-
function propPatch(PropPatch $propPatch) {
165+
public function propPatch(PropPatch $propPatch) {
166+
$properties = [
167+
'{DAV:}displayname',
168+
'{http://apple.com/ns/ical/}calendar-color'
169+
];
170+
$propPatch->handle($properties, function ($properties) {
171+
foreach ($properties as $key => $value) {
172+
switch ($key) {
173+
case '{DAV:}displayname':
174+
if (mb_substr($value, 0, strlen('Deck: '))) {
175+
$value = mb_substr($value, strlen('Deck: '));
176+
}
177+
$this->board->setTitle($value);
178+
break;
179+
case '{http://apple.com/ns/ical/}calendar-color':
180+
$this->board->setColor(substr($value, 1));
181+
break;
182+
}
183+
}
184+
return $this->backend->updateBoard($this->board);
185+
});
213186
// We can just return here and let oc_properties handle everything
214187
}
215188

216189
/**
217190
* @inheritDoc
218191
*/
219-
function getProperties($properties) {
220-
// A backend should provide at least minimum properties
192+
public function getProperties($properties) {
221193
return [
222194
'{DAV:}displayname' => 'Deck: ' . ($this->board ? $this->board->getTitle() : 'no board object provided'),
223195
'{http://apple.com/ns/ical/}calendar-color' => '#' . $this->board->getColor(),
224-
'{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']),
196+
'{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO']),
225197
];
226198
}
227-
228-
/**
229-
* @inheritDoc
230-
*/
231-
function updateShares(array $add, array $remove) {
232-
// TODO: Implement updateShares() method.
233-
}
234-
235-
/**
236-
* @inheritDoc
237-
*/
238-
function getShares() {
239-
return [];
240-
}
241-
242-
/**
243-
* @inheritDoc
244-
*/
245-
public function getResourceId() {
246-
// TODO: Implement getResourceId() method.
247-
}
248199
}

0 commit comments

Comments
 (0)