1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
7
|
|
|
* |
8
|
|
|
* @author Joas Schilling <[email protected]> |
9
|
|
|
* @author Roeland Jago Douma <[email protected]> |
10
|
|
|
* @author Thomas Müller <[email protected]> |
11
|
|
|
* |
12
|
|
|
* @license AGPL-3.0 |
13
|
|
|
* |
14
|
|
|
* This code is free software: you can redistribute it and/or modify |
15
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
16
|
|
|
* as published by the Free Software Foundation. |
17
|
|
|
* |
18
|
|
|
* This program is distributed in the hope that it will be useful, |
19
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
20
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21
|
|
|
* GNU Affero General Public License for more details. |
22
|
|
|
* |
23
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
24
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
25
|
|
|
* |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
namespace OCA\DAV\CardDAV; |
29
|
|
|
|
30
|
|
|
use OCA\DAV\AppInfo\PluginManager; |
31
|
|
|
use OCA\DAV\CardDAV\Integration\ExternalAddressBook; |
32
|
|
|
use OCP\IConfig; |
33
|
|
|
use OCP\IL10N; |
34
|
|
|
use Sabre\CardDAV\Backend; |
35
|
|
|
use Sabre\DAV\Exception\MethodNotAllowed; |
36
|
|
|
use Sabre\DAV\MkCol; |
37
|
|
|
|
38
|
|
|
class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome { |
39
|
|
|
|
40
|
|
|
/** @var IL10N */ |
41
|
|
|
protected $l10n; |
42
|
|
|
|
43
|
|
|
/** @var IConfig */ |
44
|
|
|
protected $config; |
45
|
|
|
|
46
|
|
|
/** @var PluginManager */ |
47
|
|
|
private $pluginManager; |
48
|
|
|
|
49
|
|
|
public function __construct(Backend\BackendInterface $carddavBackend, |
50
|
|
|
string $principalUri, |
51
|
|
|
PluginManager $pluginManager) { |
52
|
|
|
parent::__construct($carddavBackend, $principalUri); |
53
|
|
|
$this->pluginManager = $pluginManager; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Returns a list of address books |
58
|
|
|
* |
59
|
|
|
* @return array |
60
|
|
|
*/ |
61
|
|
|
function getChildren() { |
|
|
|
|
62
|
|
|
if ($this->l10n === null) { |
63
|
|
|
$this->l10n = \OC::$server->getL10N('dav'); |
64
|
|
|
} |
65
|
|
|
if ($this->config === null) { |
66
|
|
|
$this->config = \OC::$server->getConfig(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$addressBooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri); |
|
|
|
|
70
|
|
|
$objects = array_map(function(array $addressBook) { |
71
|
|
|
if ($addressBook['principaluri'] === 'principals/system/system') { |
72
|
|
|
return new SystemAddressbook($this->carddavBackend, $addressBook, $this->l10n, $this->config); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return new AddressBook($this->carddavBackend, $addressBook, $this->l10n); |
76
|
|
|
}, $addressBooks); |
77
|
|
|
foreach ($this->pluginManager->getAddressBookPlugins() as $plugin) { |
78
|
|
|
$plugin->fetchAllForAddressBookHome($this->principalUri); |
79
|
|
|
} |
80
|
|
|
return $objects; |
81
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function createExtendedCollection($name, MkCol $mkCol) { |
85
|
|
|
if (ExternalAddressBook::doesViolateReservedName($name)) { |
86
|
|
|
throw new MethodNotAllowed('The resource you tried to create has a reserved name'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
parent::createExtendedCollection($name, $mkCol); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Returns a list of ACE's for this node. |
94
|
|
|
* |
95
|
|
|
* Each ACE has the following properties: |
96
|
|
|
* * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
97
|
|
|
* currently the only supported privileges |
98
|
|
|
* * 'principal', a url to the principal who owns the node |
99
|
|
|
* * 'protected' (optional), indicating that this ACE is not allowed to |
100
|
|
|
* be updated. |
101
|
|
|
* |
102
|
|
|
* @return array |
103
|
|
|
*/ |
104
|
|
|
function getACL() { |
|
|
|
|
105
|
|
|
|
106
|
|
|
$acl = parent::getACL(); |
107
|
|
|
if ($this->principalUri === 'principals/system/system') { |
|
|
|
|
108
|
|
|
$acl[] = [ |
109
|
|
|
'privilege' => '{DAV:}read', |
110
|
|
|
'principal' => '{DAV:}authenticated', |
111
|
|
|
'protected' => true, |
112
|
|
|
]; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return $acl; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.