2012-08-24 04:54:14 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ownCloud - Addressbook
|
|
|
|
*
|
|
|
|
* @author Thomas Tanghus
|
2014-01-26 00:40:22 +01:00
|
|
|
* @copyright 2012-2014 Thomas Tanghus (thomas@tanghus.net)
|
2012-08-24 04:54:14 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-03-05 11:08:04 +01:00
|
|
|
namespace OCA\Contacts\CardDAV;
|
|
|
|
|
|
|
|
use OCA\Contacts;
|
|
|
|
|
2012-08-24 04:54:14 +02:00
|
|
|
/**
|
2014-05-26 22:09:12 +02:00
|
|
|
* This class overrides \Sabre\CardDAV\Card::getACL()
|
2012-08-24 04:54:14 +02:00
|
|
|
* to return read/write permissions based on user and shared state.
|
|
|
|
*/
|
2014-05-26 22:09:12 +02:00
|
|
|
class Card extends \Sabre\CardDAV\Card {
|
2012-08-24 04:54:14 +02:00
|
|
|
|
2014-03-23 19:02:16 +01:00
|
|
|
/**
|
|
|
|
* Array with information about the containing addressbook
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $addressBookInfo;
|
2012-08-24 04:54:14 +02:00
|
|
|
|
2014-03-23 19:02:16 +01:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
2014-05-26 22:09:12 +02:00
|
|
|
* @param \Sabre\CardDAV\Backend\AbstractBackend $carddavBackend
|
2014-03-23 19:02:16 +01:00
|
|
|
* @param array $addressBookInfo
|
|
|
|
* @param array $cardData
|
|
|
|
*/
|
2014-05-26 22:09:12 +02:00
|
|
|
public function __construct(\Sabre\CardDAV\Backend\AbstractBackend $carddavBackend, array $addressBookInfo, array $cardData) {
|
2012-08-24 04:54:14 +02:00
|
|
|
|
2014-03-23 19:02:16 +01:00
|
|
|
$this->addressBookInfo = $addressBookInfo;
|
2012-08-24 04:54:14 +02:00
|
|
|
parent::__construct($carddavBackend, $addressBookInfo, $cardData);
|
|
|
|
|
2014-03-23 19:02:16 +01:00
|
|
|
}
|
2012-08-24 04:54:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of ACE's for this node.
|
|
|
|
*
|
|
|
|
* Each ACE has the following properties:
|
|
|
|
* * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
|
|
|
|
* currently the only supported privileges
|
|
|
|
* * 'principal', a url to the principal who owns the node
|
|
|
|
* * 'protected' (optional), indicating that this ACE is not allowed to
|
|
|
|
* be updated.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getACL() {
|
|
|
|
|
|
|
|
$readprincipal = $this->getOwner();
|
|
|
|
$writeprincipal = $this->getOwner();
|
2013-03-12 09:15:40 +01:00
|
|
|
$uid = $this->carddavBackend->userIDByPrincipal($this->getOwner());
|
2015-02-16 18:42:41 +01:00
|
|
|
$currentUid = \OC::$server->getUserSession()->getUser()->getUId();
|
2012-08-24 04:54:14 +02:00
|
|
|
|
2015-02-16 18:42:41 +01:00
|
|
|
if($uid != $currentUid) {
|
2014-03-23 19:02:16 +01:00
|
|
|
list(, $id) = explode('::', $this->addressBookInfo['id']);
|
2013-04-08 01:27:35 +02:00
|
|
|
$sharedAddressbook = \OCP\Share::getItemSharedWithBySource('addressbook', $id);
|
2013-03-05 11:08:04 +01:00
|
|
|
if ($sharedAddressbook && ($sharedAddressbook['permissions'] & \OCP\PERMISSION_READ)) {
|
2015-02-16 18:42:41 +01:00
|
|
|
$readprincipal = 'principals/' . $currentUid;
|
2012-08-24 04:54:14 +02:00
|
|
|
}
|
2013-03-05 11:08:04 +01:00
|
|
|
if ($sharedAddressbook && ($sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE)) {
|
2015-02-16 18:42:41 +01:00
|
|
|
$writeprincipal = 'principals/' . $currentUid;
|
2012-08-24 04:54:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
'privilege' => '{DAV:}read',
|
|
|
|
'principal' => $readprincipal,
|
|
|
|
'protected' => true,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'privilege' => '{DAV:}write',
|
|
|
|
'principal' => $writeprincipal,
|
|
|
|
'protected' => true,
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-05-26 22:09:12 +02:00
|
|
|
}
|