1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ownCloud - Addressbook |
4
|
|
|
* |
5
|
|
|
* @author Thomas Tanghus |
6
|
|
|
* @copyright 2012-2014 Thomas Tanghus ([email protected]) |
7
|
|
|
* |
8
|
|
|
* This library is free software; you can redistribute it and/or |
9
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
10
|
|
|
* License as published by the Free Software Foundation; either |
11
|
|
|
* version 3 of the License, or any later version. |
12
|
|
|
* |
13
|
|
|
* This library 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 |
19
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace OCA\Contacts\CardDAV; |
24
|
|
|
|
25
|
|
|
use OCA\Contacts; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* This class overrides \Sabre\CardDAV\Card::getACL() |
29
|
|
|
* to return read/write permissions based on user and shared state. |
30
|
|
|
*/ |
31
|
|
|
class Card extends \Sabre\CardDAV\Card { |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Array with information about the containing addressbook |
35
|
|
|
* |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
protected $addressBookInfo; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Constructor |
42
|
|
|
* |
43
|
|
|
* @param \Sabre\CardDAV\Backend\AbstractBackend $carddavBackend |
44
|
|
|
* @param array $addressBookInfo |
45
|
|
|
* @param array $cardData |
46
|
|
|
*/ |
47
|
|
|
public function __construct(\Sabre\CardDAV\Backend\AbstractBackend $carddavBackend, array $addressBookInfo, array $cardData) { |
48
|
|
|
|
49
|
|
|
$this->addressBookInfo = $addressBookInfo; |
50
|
|
|
parent::__construct($carddavBackend, $addressBookInfo, $cardData); |
51
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Returns a list of ACE's for this node. |
56
|
|
|
* |
57
|
|
|
* Each ACE has the following properties: |
58
|
|
|
* * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
59
|
|
|
* currently the only supported privileges |
60
|
|
|
* * 'principal', a url to the principal who owns the node |
61
|
|
|
* * 'protected' (optional), indicating that this ACE is not allowed to |
62
|
|
|
* be updated. |
63
|
|
|
* |
64
|
|
|
* @return array |
65
|
|
|
*/ |
66
|
|
|
public function getACL() { |
67
|
|
|
|
68
|
|
|
$readprincipal = $this->getOwner(); |
69
|
|
|
$writeprincipal = $this->getOwner(); |
70
|
|
|
$uid = $this->carddavBackend->userIDByPrincipal($this->getOwner()); |
71
|
|
|
$currentUid = \OC::$server->getUserSession()->getUser()->getUId(); |
72
|
|
|
|
73
|
|
|
if($uid != $currentUid) { |
74
|
|
|
list(, $id) = explode('::', $this->addressBookInfo['id']); |
75
|
|
|
$sharedAddressbook = \OCP\Share::getItemSharedWithBySource('addressbook', $id); |
76
|
|
|
if ($sharedAddressbook && ($sharedAddressbook['permissions'] & \OCP\PERMISSION_READ)) { |
77
|
|
|
$readprincipal = 'principals/' . $currentUid; |
78
|
|
|
} |
79
|
|
|
if ($sharedAddressbook && ($sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE)) { |
80
|
|
|
$writeprincipal = 'principals/' . $currentUid; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return array( |
85
|
|
|
array( |
86
|
|
|
'privilege' => '{DAV:}read', |
87
|
|
|
'principal' => $readprincipal, |
88
|
|
|
'protected' => true, |
89
|
|
|
), |
90
|
|
|
array( |
91
|
|
|
'privilege' => '{DAV:}write', |
92
|
|
|
'principal' => $writeprincipal, |
93
|
|
|
'protected' => true, |
94
|
|
|
), |
95
|
|
|
|
96
|
|
|
); |
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
} |
101
|
|
|
|