@@ -34,121 +34,121 @@  | 
                                                    ||
| 34 | 34 | |
| 35 | 35 |  class CalendarObject extends \Sabre\CalDAV\CalendarObject { | 
                                                        
| 36 | 36 | |
| 37 | - /** @var IL10N */  | 
                                                        |
| 38 | - protected $l10n;  | 
                                                        |
| 39 | -  | 
                                                        |
| 40 | - /**  | 
                                                        |
| 41 | - * CalendarObject constructor.  | 
                                                        |
| 42 | - *  | 
                                                        |
| 43 | - * @param CalDavBackend $caldavBackend  | 
                                                        |
| 44 | - * @param IL10N $l10n  | 
                                                        |
| 45 | - * @param array $calendarInfo  | 
                                                        |
| 46 | - * @param array $objectData  | 
                                                        |
| 47 | - */  | 
                                                        |
| 48 | - public function __construct(CalDavBackend $caldavBackend, IL10N $l10n,  | 
                                                        |
| 49 | - array $calendarInfo,  | 
                                                        |
| 50 | -								array $objectData) { | 
                                                        |
| 51 | - parent::__construct($caldavBackend, $calendarInfo, $objectData);  | 
                                                        |
| 52 | -  | 
                                                        |
| 53 | -		if ($this->isShared()) { | 
                                                        |
| 54 | - unset($this->objectData['size']);  | 
                                                        |
| 55 | - }  | 
                                                        |
| 56 | -  | 
                                                        |
| 57 | - $this->l10n = $l10n;  | 
                                                        |
| 58 | - }  | 
                                                        |
| 59 | -  | 
                                                        |
| 60 | - /**  | 
                                                        |
| 61 | - * @inheritdoc  | 
                                                        |
| 62 | - */  | 
                                                        |
| 63 | -	function get() { | 
                                                        |
| 64 | - $data = parent::get();  | 
                                                        |
| 65 | -  | 
                                                        |
| 66 | -		if (!$this->isShared()) { | 
                                                        |
| 67 | - return $data;  | 
                                                        |
| 68 | - }  | 
                                                        |
| 69 | -  | 
                                                        |
| 70 | - $vObject = Reader::read($data);  | 
                                                        |
| 71 | -  | 
                                                        |
| 72 | - // remove VAlarms if calendar is shared read-only  | 
                                                        |
| 73 | -		if (!$this->canWrite()) { | 
                                                        |
| 74 | - $this->removeVAlarms($vObject);  | 
                                                        |
| 75 | - }  | 
                                                        |
| 76 | -  | 
                                                        |
| 77 | - // shows as busy if event is declared confidential  | 
                                                        |
| 78 | -		if ($this->objectData['classification'] === CalDavBackend::CLASSIFICATION_CONFIDENTIAL) { | 
                                                        |
| 79 | - $this->createConfidentialObject($vObject);  | 
                                                        |
| 80 | - }  | 
                                                        |
| 81 | -  | 
                                                        |
| 82 | - return $vObject->serialize();  | 
                                                        |
| 83 | - }  | 
                                                        |
| 84 | -  | 
                                                        |
| 85 | -	protected function isShared() { | 
                                                        |
| 86 | -		if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { | 
                                                        |
| 87 | - return false;  | 
                                                        |
| 88 | - }  | 
                                                        |
| 89 | -  | 
                                                        |
| 90 | -		return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']; | 
                                                        |
| 91 | - }  | 
                                                        |
| 92 | -  | 
                                                        |
| 93 | - /**  | 
                                                        |
| 94 | - * @param Component\VCalendar $vObject  | 
                                                        |
| 95 | - * @return void  | 
                                                        |
| 96 | - */  | 
                                                        |
| 97 | -	private function createConfidentialObject(Component\VCalendar $vObject) { | 
                                                        |
| 98 | - /** @var Component $vElement */  | 
                                                        |
| 99 | - $vElement = null;  | 
                                                        |
| 100 | -		if(isset($vObject->VEVENT)) { | 
                                                        |
| 101 | - $vElement = $vObject->VEVENT;  | 
                                                        |
| 102 | - }  | 
                                                        |
| 103 | -		if(isset($vObject->VJOURNAL)) { | 
                                                        |
| 104 | - $vElement = $vObject->VJOURNAL;  | 
                                                        |
| 105 | - }  | 
                                                        |
| 106 | -		if(isset($vObject->VTODO)) { | 
                                                        |
| 107 | - $vElement = $vObject->VTODO;  | 
                                                        |
| 108 | - }  | 
                                                        |
| 109 | -		if(!is_null($vElement)) { | 
                                                        |
| 110 | -			foreach ($vElement->children() as &$property) { | 
                                                        |
| 111 | - /** @var Property $property */  | 
                                                        |
| 112 | -				switch($property->name) { | 
                                                        |
| 113 | - case 'CREATED':  | 
                                                        |
| 114 | - case 'DTSTART':  | 
                                                        |
| 115 | - case 'RRULE':  | 
                                                        |
| 116 | - case 'DURATION':  | 
                                                        |
| 117 | - case 'DTEND':  | 
                                                        |
| 118 | - case 'CLASS':  | 
                                                        |
| 119 | - case 'UID':  | 
                                                        |
| 120 | - break;  | 
                                                        |
| 121 | - case 'SUMMARY':  | 
                                                        |
| 122 | -						$property->setValue($this->l10n->t('Busy')); | 
                                                        |
| 123 | - break;  | 
                                                        |
| 124 | - default:  | 
                                                        |
| 125 | - $vElement->__unset($property->name);  | 
                                                        |
| 126 | - unset($property);  | 
                                                        |
| 127 | - break;  | 
                                                        |
| 128 | - }  | 
                                                        |
| 129 | - }  | 
                                                        |
| 130 | - }  | 
                                                        |
| 131 | - }  | 
                                                        |
| 132 | -  | 
                                                        |
| 133 | - /**  | 
                                                        |
| 134 | - * @param Component\VCalendar $vObject  | 
                                                        |
| 135 | - * @return void  | 
                                                        |
| 136 | - */  | 
                                                        |
| 137 | -	private function removeVAlarms(Component\VCalendar $vObject) { | 
                                                        |
| 138 | - $subcomponents = $vObject->getComponents();  | 
                                                        |
| 139 | -  | 
                                                        |
| 140 | -		foreach($subcomponents as $subcomponent) { | 
                                                        |
| 141 | - unset($subcomponent->VALARM);  | 
                                                        |
| 142 | - }  | 
                                                        |
| 143 | - }  | 
                                                        |
| 144 | -  | 
                                                        |
| 145 | - /**  | 
                                                        |
| 146 | - * @return bool  | 
                                                        |
| 147 | - */  | 
                                                        |
| 148 | -	private function canWrite() { | 
                                                        |
| 149 | -		if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) { | 
                                                        |
| 150 | -			return !$this->calendarInfo['{http://owncloud.org/ns}read-only']; | 
                                                        |
| 151 | - }  | 
                                                        |
| 152 | - return true;  | 
                                                        |
| 153 | - }  | 
                                                        |
| 37 | + /** @var IL10N */  | 
                                                        |
| 38 | + protected $l10n;  | 
                                                        |
| 39 | +  | 
                                                        |
| 40 | + /**  | 
                                                        |
| 41 | + * CalendarObject constructor.  | 
                                                        |
| 42 | + *  | 
                                                        |
| 43 | + * @param CalDavBackend $caldavBackend  | 
                                                        |
| 44 | + * @param IL10N $l10n  | 
                                                        |
| 45 | + * @param array $calendarInfo  | 
                                                        |
| 46 | + * @param array $objectData  | 
                                                        |
| 47 | + */  | 
                                                        |
| 48 | + public function __construct(CalDavBackend $caldavBackend, IL10N $l10n,  | 
                                                        |
| 49 | + array $calendarInfo,  | 
                                                        |
| 50 | +                                array $objectData) { | 
                                                        |
| 51 | + parent::__construct($caldavBackend, $calendarInfo, $objectData);  | 
                                                        |
| 52 | +  | 
                                                        |
| 53 | +        if ($this->isShared()) { | 
                                                        |
| 54 | + unset($this->objectData['size']);  | 
                                                        |
| 55 | + }  | 
                                                        |
| 56 | +  | 
                                                        |
| 57 | + $this->l10n = $l10n;  | 
                                                        |
| 58 | + }  | 
                                                        |
| 59 | +  | 
                                                        |
| 60 | + /**  | 
                                                        |
| 61 | + * @inheritdoc  | 
                                                        |
| 62 | + */  | 
                                                        |
| 63 | +    function get() { | 
                                                        |
| 64 | + $data = parent::get();  | 
                                                        |
| 65 | +  | 
                                                        |
| 66 | +        if (!$this->isShared()) { | 
                                                        |
| 67 | + return $data;  | 
                                                        |
| 68 | + }  | 
                                                        |
| 69 | +  | 
                                                        |
| 70 | + $vObject = Reader::read($data);  | 
                                                        |
| 71 | +  | 
                                                        |
| 72 | + // remove VAlarms if calendar is shared read-only  | 
                                                        |
| 73 | +        if (!$this->canWrite()) { | 
                                                        |
| 74 | + $this->removeVAlarms($vObject);  | 
                                                        |
| 75 | + }  | 
                                                        |
| 76 | +  | 
                                                        |
| 77 | + // shows as busy if event is declared confidential  | 
                                                        |
| 78 | +        if ($this->objectData['classification'] === CalDavBackend::CLASSIFICATION_CONFIDENTIAL) { | 
                                                        |
| 79 | + $this->createConfidentialObject($vObject);  | 
                                                        |
| 80 | + }  | 
                                                        |
| 81 | +  | 
                                                        |
| 82 | + return $vObject->serialize();  | 
                                                        |
| 83 | + }  | 
                                                        |
| 84 | +  | 
                                                        |
| 85 | +    protected function isShared() { | 
                                                        |
| 86 | +        if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { | 
                                                        |
| 87 | + return false;  | 
                                                        |
| 88 | + }  | 
                                                        |
| 89 | +  | 
                                                        |
| 90 | +        return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']; | 
                                                        |
| 91 | + }  | 
                                                        |
| 92 | +  | 
                                                        |
| 93 | + /**  | 
                                                        |
| 94 | + * @param Component\VCalendar $vObject  | 
                                                        |
| 95 | + * @return void  | 
                                                        |
| 96 | + */  | 
                                                        |
| 97 | +    private function createConfidentialObject(Component\VCalendar $vObject) { | 
                                                        |
| 98 | + /** @var Component $vElement */  | 
                                                        |
| 99 | + $vElement = null;  | 
                                                        |
| 100 | +        if(isset($vObject->VEVENT)) { | 
                                                        |
| 101 | + $vElement = $vObject->VEVENT;  | 
                                                        |
| 102 | + }  | 
                                                        |
| 103 | +        if(isset($vObject->VJOURNAL)) { | 
                                                        |
| 104 | + $vElement = $vObject->VJOURNAL;  | 
                                                        |
| 105 | + }  | 
                                                        |
| 106 | +        if(isset($vObject->VTODO)) { | 
                                                        |
| 107 | + $vElement = $vObject->VTODO;  | 
                                                        |
| 108 | + }  | 
                                                        |
| 109 | +        if(!is_null($vElement)) { | 
                                                        |
| 110 | +            foreach ($vElement->children() as &$property) { | 
                                                        |
| 111 | + /** @var Property $property */  | 
                                                        |
| 112 | +                switch($property->name) { | 
                                                        |
| 113 | + case 'CREATED':  | 
                                                        |
| 114 | + case 'DTSTART':  | 
                                                        |
| 115 | + case 'RRULE':  | 
                                                        |
| 116 | + case 'DURATION':  | 
                                                        |
| 117 | + case 'DTEND':  | 
                                                        |
| 118 | + case 'CLASS':  | 
                                                        |
| 119 | + case 'UID':  | 
                                                        |
| 120 | + break;  | 
                                                        |
| 121 | + case 'SUMMARY':  | 
                                                        |
| 122 | +                        $property->setValue($this->l10n->t('Busy')); | 
                                                        |
| 123 | + break;  | 
                                                        |
| 124 | + default:  | 
                                                        |
| 125 | + $vElement->__unset($property->name);  | 
                                                        |
| 126 | + unset($property);  | 
                                                        |
| 127 | + break;  | 
                                                        |
| 128 | + }  | 
                                                        |
| 129 | + }  | 
                                                        |
| 130 | + }  | 
                                                        |
| 131 | + }  | 
                                                        |
| 132 | +  | 
                                                        |
| 133 | + /**  | 
                                                        |
| 134 | + * @param Component\VCalendar $vObject  | 
                                                        |
| 135 | + * @return void  | 
                                                        |
| 136 | + */  | 
                                                        |
| 137 | +    private function removeVAlarms(Component\VCalendar $vObject) { | 
                                                        |
| 138 | + $subcomponents = $vObject->getComponents();  | 
                                                        |
| 139 | +  | 
                                                        |
| 140 | +        foreach($subcomponents as $subcomponent) { | 
                                                        |
| 141 | + unset($subcomponent->VALARM);  | 
                                                        |
| 142 | + }  | 
                                                        |
| 143 | + }  | 
                                                        |
| 144 | +  | 
                                                        |
| 145 | + /**  | 
                                                        |
| 146 | + * @return bool  | 
                                                        |
| 147 | + */  | 
                                                        |
| 148 | +    private function canWrite() { | 
                                                        |
| 149 | +        if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) { | 
                                                        |
| 150 | +            return !$this->calendarInfo['{http://owncloud.org/ns}read-only']; | 
                                                        |
| 151 | + }  | 
                                                        |
| 152 | + return true;  | 
                                                        |
| 153 | + }  | 
                                                        |
| 154 | 154 | }  | 
                                                        
@@ -97,19 +97,19 @@ discard block  | 
                                                    ||
| 97 | 97 |  	private function createConfidentialObject(Component\VCalendar $vObject) { | 
                                                        
| 98 | 98 | /** @var Component $vElement */  | 
                                                        
| 99 | 99 | $vElement = null;  | 
                                                        
| 100 | -		if(isset($vObject->VEVENT)) { | 
                                                        |
| 100 | +		if (isset($vObject->VEVENT)) { | 
                                                        |
| 101 | 101 | $vElement = $vObject->VEVENT;  | 
                                                        
| 102 | 102 | }  | 
                                                        
| 103 | -		if(isset($vObject->VJOURNAL)) { | 
                                                        |
| 103 | +		if (isset($vObject->VJOURNAL)) { | 
                                                        |
| 104 | 104 | $vElement = $vObject->VJOURNAL;  | 
                                                        
| 105 | 105 | }  | 
                                                        
| 106 | -		if(isset($vObject->VTODO)) { | 
                                                        |
| 106 | +		if (isset($vObject->VTODO)) { | 
                                                        |
| 107 | 107 | $vElement = $vObject->VTODO;  | 
                                                        
| 108 | 108 | }  | 
                                                        
| 109 | -		if(!is_null($vElement)) { | 
                                                        |
| 109 | +		if (!is_null($vElement)) { | 
                                                        |
| 110 | 110 |  			foreach ($vElement->children() as &$property) { | 
                                                        
| 111 | 111 | /** @var Property $property */  | 
                                                        
| 112 | -				switch($property->name) { | 
                                                        |
| 112 | +				switch ($property->name) { | 
                                                        |
| 113 | 113 | case 'CREATED':  | 
                                                        
| 114 | 114 | case 'DTSTART':  | 
                                                        
| 115 | 115 | case 'RRULE':  | 
                                                        
@@ -137,7 +137,7 @@ discard block  | 
                                                    ||
| 137 | 137 |  	private function removeVAlarms(Component\VCalendar $vObject) { | 
                                                        
| 138 | 138 | $subcomponents = $vObject->getComponents();  | 
                                                        
| 139 | 139 | |
| 140 | -		foreach($subcomponents as $subcomponent) { | 
                                                        |
| 140 | +		foreach ($subcomponents as $subcomponent) { | 
                                                        |
| 141 | 141 | unset($subcomponent->VALARM);  | 
                                                        
| 142 | 142 | }  | 
                                                        
| 143 | 143 | }  | 
                                                        
@@ -45,364 +45,364 @@  | 
                                                    ||
| 45 | 45 | */  | 
                                                        
| 46 | 46 |  class Calendar extends \Sabre\CalDAV\Calendar implements IShareable { | 
                                                        
| 47 | 47 | |
| 48 | - /** @var IConfig */  | 
                                                        |
| 49 | - private $config;  | 
                                                        |
| 50 | -  | 
                                                        |
| 51 | - /** @var IL10N */  | 
                                                        |
| 52 | - protected $l10n;  | 
                                                        |
| 53 | -  | 
                                                        |
| 54 | - /**  | 
                                                        |
| 55 | - * Calendar constructor.  | 
                                                        |
| 56 | - *  | 
                                                        |
| 57 | - * @param BackendInterface $caldavBackend  | 
                                                        |
| 58 | - * @param $calendarInfo  | 
                                                        |
| 59 | - * @param IL10N $l10n  | 
                                                        |
| 60 | - * @param IConfig $config  | 
                                                        |
| 61 | - */  | 
                                                        |
| 62 | -	public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config) { | 
                                                        |
| 63 | - parent::__construct($caldavBackend, $calendarInfo);  | 
                                                        |
| 64 | -  | 
                                                        |
| 65 | -		if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { | 
                                                        |
| 66 | -			$this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays'); | 
                                                        |
| 67 | - }  | 
                                                        |
| 68 | - if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI &&  | 
                                                        |
| 69 | -			$this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) { | 
                                                        |
| 70 | -			$this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal'); | 
                                                        |
| 71 | - }  | 
                                                        |
| 72 | -  | 
                                                        |
| 73 | - $this->config = $config;  | 
                                                        |
| 74 | - $this->l10n = $l10n;  | 
                                                        |
| 75 | - }  | 
                                                        |
| 76 | -  | 
                                                        |
| 77 | - /**  | 
                                                        |
| 78 | - * Updates the list of shares.  | 
                                                        |
| 79 | - *  | 
                                                        |
| 80 | - * The first array is a list of people that are to be added to the  | 
                                                        |
| 81 | - * resource.  | 
                                                        |
| 82 | - *  | 
                                                        |
| 83 | - * Every element in the add array has the following properties:  | 
                                                        |
| 84 | - * * href - A url. Usually a mailto: address  | 
                                                        |
| 85 | - * * commonName - Usually a first and last name, or false  | 
                                                        |
| 86 | - * * summary - A description of the share, can also be false  | 
                                                        |
| 87 | - * * readOnly - A boolean value  | 
                                                        |
| 88 | - *  | 
                                                        |
| 89 | - * Every element in the remove array is just the address string.  | 
                                                        |
| 90 | - *  | 
                                                        |
| 91 | - * @param array $add  | 
                                                        |
| 92 | - * @param array $remove  | 
                                                        |
| 93 | - * @return void  | 
                                                        |
| 94 | - * @throws Forbidden  | 
                                                        |
| 95 | - */  | 
                                                        |
| 96 | -	public function updateShares(array $add, array $remove) { | 
                                                        |
| 97 | -		if ($this->isShared()) { | 
                                                        |
| 98 | - throw new Forbidden();  | 
                                                        |
| 99 | - }  | 
                                                        |
| 100 | - $this->caldavBackend->updateShares($this, $add, $remove);  | 
                                                        |
| 101 | - }  | 
                                                        |
| 102 | -  | 
                                                        |
| 103 | - /**  | 
                                                        |
| 104 | - * Returns the list of people whom this resource is shared with.  | 
                                                        |
| 105 | - *  | 
                                                        |
| 106 | - * Every element in this array should have the following properties:  | 
                                                        |
| 107 | - * * href - Often a mailto: address  | 
                                                        |
| 108 | - * * commonName - Optional, for example a first + last name  | 
                                                        |
| 109 | - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.  | 
                                                        |
| 110 | - * * readOnly - boolean  | 
                                                        |
| 111 | - * * summary - Optional, a description for the share  | 
                                                        |
| 112 | - *  | 
                                                        |
| 113 | - * @return array  | 
                                                        |
| 114 | - */  | 
                                                        |
| 115 | -	public function getShares() { | 
                                                        |
| 116 | -		if ($this->isShared()) { | 
                                                        |
| 117 | - return [];  | 
                                                        |
| 118 | - }  | 
                                                        |
| 119 | - return $this->caldavBackend->getShares($this->getResourceId());  | 
                                                        |
| 120 | - }  | 
                                                        |
| 121 | -  | 
                                                        |
| 122 | - /**  | 
                                                        |
| 123 | - * @return int  | 
                                                        |
| 124 | - */  | 
                                                        |
| 125 | -	public function getResourceId() { | 
                                                        |
| 126 | - return $this->calendarInfo['id'];  | 
                                                        |
| 127 | - }  | 
                                                        |
| 128 | -  | 
                                                        |
| 129 | - /**  | 
                                                        |
| 130 | - * @return string  | 
                                                        |
| 131 | - */  | 
                                                        |
| 132 | -	public function getPrincipalURI() { | 
                                                        |
| 133 | - return $this->calendarInfo['principaluri'];  | 
                                                        |
| 134 | - }  | 
                                                        |
| 135 | -  | 
                                                        |
| 136 | - /**  | 
                                                        |
| 137 | - * @return array  | 
                                                        |
| 138 | - */  | 
                                                        |
| 139 | -	public function getACL() { | 
                                                        |
| 140 | - $acl = [  | 
                                                        |
| 141 | - [  | 
                                                        |
| 142 | -				'privilege' => '{DAV:}read', | 
                                                        |
| 143 | - 'principal' => $this->getOwner(),  | 
                                                        |
| 144 | - 'protected' => true,  | 
                                                        |
| 145 | - ],  | 
                                                        |
| 146 | - [  | 
                                                        |
| 147 | -				'privilege' => '{DAV:}read', | 
                                                        |
| 148 | - 'principal' => $this->getOwner() . '/calendar-proxy-write',  | 
                                                        |
| 149 | - 'protected' => true,  | 
                                                        |
| 150 | - ],  | 
                                                        |
| 151 | - [  | 
                                                        |
| 152 | -				'privilege' => '{DAV:}read', | 
                                                        |
| 153 | - 'principal' => $this->getOwner() . '/calendar-proxy-read',  | 
                                                        |
| 154 | - 'protected' => true,  | 
                                                        |
| 155 | - ],  | 
                                                        |
| 156 | - ];  | 
                                                        |
| 157 | -  | 
                                                        |
| 158 | -		if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) { | 
                                                        |
| 159 | - $acl[] = [  | 
                                                        |
| 160 | -				'privilege' => '{DAV:}write', | 
                                                        |
| 161 | - 'principal' => $this->getOwner(),  | 
                                                        |
| 162 | - 'protected' => true,  | 
                                                        |
| 163 | - ];  | 
                                                        |
| 164 | - $acl[] = [  | 
                                                        |
| 165 | -				'privilege' => '{DAV:}write', | 
                                                        |
| 166 | - 'principal' => $this->getOwner() . '/calendar-proxy-write',  | 
                                                        |
| 167 | - 'protected' => true,  | 
                                                        |
| 168 | - ];  | 
                                                        |
| 169 | -		} else { | 
                                                        |
| 170 | - $acl[] = [  | 
                                                        |
| 171 | -				'privilege' => '{DAV:}write-properties', | 
                                                        |
| 172 | - 'principal' => $this->getOwner(),  | 
                                                        |
| 173 | - 'protected' => true,  | 
                                                        |
| 174 | - ];  | 
                                                        |
| 175 | - $acl[] = [  | 
                                                        |
| 176 | -				'privilege' => '{DAV:}write-properties', | 
                                                        |
| 177 | - 'principal' => $this->getOwner() . '/calendar-proxy-write',  | 
                                                        |
| 178 | - 'protected' => true,  | 
                                                        |
| 179 | - ];  | 
                                                        |
| 180 | - }  | 
                                                        |
| 181 | -  | 
                                                        |
| 182 | - $acl[] = [  | 
                                                        |
| 183 | -			'privilege' => '{DAV:}write-properties', | 
                                                        |
| 184 | - 'principal' => $this->getOwner() . '/calendar-proxy-read',  | 
                                                        |
| 185 | - 'protected' => true,  | 
                                                        |
| 186 | - ];  | 
                                                        |
| 187 | -  | 
                                                        |
| 188 | -		if (!$this->isShared()) { | 
                                                        |
| 189 | - return $acl;  | 
                                                        |
| 190 | - }  | 
                                                        |
| 191 | -  | 
                                                        |
| 192 | -		if ($this->getOwner() !== parent::getOwner()) { | 
                                                        |
| 193 | - $acl[] = [  | 
                                                        |
| 194 | -					'privilege' => '{DAV:}read', | 
                                                        |
| 195 | - 'principal' => parent::getOwner(),  | 
                                                        |
| 196 | - 'protected' => true,  | 
                                                        |
| 197 | - ];  | 
                                                        |
| 198 | -			if ($this->canWrite()) { | 
                                                        |
| 199 | - $acl[] = [  | 
                                                        |
| 200 | -					'privilege' => '{DAV:}write', | 
                                                        |
| 201 | - 'principal' => parent::getOwner(),  | 
                                                        |
| 202 | - 'protected' => true,  | 
                                                        |
| 203 | - ];  | 
                                                        |
| 204 | -			} else { | 
                                                        |
| 205 | - $acl[] = [  | 
                                                        |
| 206 | -					'privilege' => '{DAV:}write-properties', | 
                                                        |
| 207 | - 'principal' => parent::getOwner(),  | 
                                                        |
| 208 | - 'protected' => true,  | 
                                                        |
| 209 | - ];  | 
                                                        |
| 210 | - }  | 
                                                        |
| 211 | - }  | 
                                                        |
| 212 | -		if ($this->isPublic()) { | 
                                                        |
| 213 | - $acl[] = [  | 
                                                        |
| 214 | -				'privilege' => '{DAV:}read', | 
                                                        |
| 215 | - 'principal' => 'principals/system/public',  | 
                                                        |
| 216 | - 'protected' => true,  | 
                                                        |
| 217 | - ];  | 
                                                        |
| 218 | - }  | 
                                                        |
| 219 | -  | 
                                                        |
| 220 | - $acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl);  | 
                                                        |
| 221 | - $allowedPrincipals = [  | 
                                                        |
| 222 | - $this->getOwner(),  | 
                                                        |
| 223 | - $this->getOwner(). '/calendar-proxy-read',  | 
                                                        |
| 224 | - $this->getOwner(). '/calendar-proxy-write',  | 
                                                        |
| 225 | - parent::getOwner(),  | 
                                                        |
| 226 | - 'principals/system/public'  | 
                                                        |
| 227 | - ];  | 
                                                        |
| 228 | -		return array_filter($acl, function($rule) use ($allowedPrincipals) { | 
                                                        |
| 229 | - return \in_array($rule['principal'], $allowedPrincipals, true);  | 
                                                        |
| 230 | - });  | 
                                                        |
| 231 | - }  | 
                                                        |
| 232 | -  | 
                                                        |
| 233 | -	public function getChildACL() { | 
                                                        |
| 234 | - return $this->getACL();  | 
                                                        |
| 235 | - }  | 
                                                        |
| 236 | -  | 
                                                        |
| 237 | -	public function getOwner() { | 
                                                        |
| 238 | -		if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { | 
                                                        |
| 239 | -			return $this->calendarInfo['{http://owncloud.org/ns}owner-principal']; | 
                                                        |
| 240 | - }  | 
                                                        |
| 241 | - return parent::getOwner();  | 
                                                        |
| 242 | - }  | 
                                                        |
| 243 | -  | 
                                                        |
| 244 | -	public function delete() { | 
                                                        |
| 245 | -		if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) && | 
                                                        |
| 246 | -			$this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) { | 
                                                        |
| 247 | - $principal = 'principal:' . parent::getOwner();  | 
                                                        |
| 248 | - $shares = $this->caldavBackend->getShares($this->getResourceId());  | 
                                                        |
| 249 | -			$shares = array_filter($shares, function($share) use ($principal){ | 
                                                        |
| 250 | - return $share['href'] === $principal;  | 
                                                        |
| 251 | - });  | 
                                                        |
| 252 | -			if (empty($shares)) { | 
                                                        |
| 253 | - throw new Forbidden();  | 
                                                        |
| 254 | - }  | 
                                                        |
| 255 | -  | 
                                                        |
| 256 | - $this->caldavBackend->updateShares($this, [], [  | 
                                                        |
| 257 | - $principal  | 
                                                        |
| 258 | - ]);  | 
                                                        |
| 259 | - return;  | 
                                                        |
| 260 | - }  | 
                                                        |
| 261 | -  | 
                                                        |
| 262 | - // Remember when a user deleted their birthday calendar  | 
                                                        |
| 263 | - // in order to not regenerate it on the next contacts change  | 
                                                        |
| 264 | -		if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { | 
                                                        |
| 265 | - $principalURI = $this->getPrincipalURI();  | 
                                                        |
| 266 | - $userId = substr($principalURI, 17);  | 
                                                        |
| 267 | -  | 
                                                        |
| 268 | - $this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'no');  | 
                                                        |
| 269 | - }  | 
                                                        |
| 270 | -  | 
                                                        |
| 271 | - parent::delete();  | 
                                                        |
| 272 | - }  | 
                                                        |
| 273 | -  | 
                                                        |
| 274 | -	public function propPatch(PropPatch $propPatch) { | 
                                                        |
| 275 | - // parent::propPatch will only update calendars table  | 
                                                        |
| 276 | - // if calendar is shared, changes have to be made to the properties table  | 
                                                        |
| 277 | -		if (!$this->isShared()) { | 
                                                        |
| 278 | - parent::propPatch($propPatch);  | 
                                                        |
| 279 | - }  | 
                                                        |
| 280 | - }  | 
                                                        |
| 281 | -  | 
                                                        |
| 282 | -	public function getChild($name) { | 
                                                        |
| 283 | -  | 
                                                        |
| 284 | - $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);  | 
                                                        |
| 285 | -  | 
                                                        |
| 286 | -		if (!$obj) { | 
                                                        |
| 287 | -			throw new NotFound('Calendar object not found'); | 
                                                        |
| 288 | - }  | 
                                                        |
| 289 | -  | 
                                                        |
| 290 | -		if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { | 
                                                        |
| 291 | -			throw new NotFound('Calendar object not found'); | 
                                                        |
| 292 | - }  | 
                                                        |
| 293 | -  | 
                                                        |
| 294 | - $obj['acl'] = $this->getChildACL();  | 
                                                        |
| 295 | -  | 
                                                        |
| 296 | - return new CalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);  | 
                                                        |
| 297 | -  | 
                                                        |
| 298 | - }  | 
                                                        |
| 299 | -  | 
                                                        |
| 300 | -	public function getChildren() { | 
                                                        |
| 301 | -  | 
                                                        |
| 302 | - $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']);  | 
                                                        |
| 303 | - $children = [];  | 
                                                        |
| 304 | -		foreach ($objs as $obj) { | 
                                                        |
| 305 | -			if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { | 
                                                        |
| 306 | - continue;  | 
                                                        |
| 307 | - }  | 
                                                        |
| 308 | - $obj['acl'] = $this->getChildACL();  | 
                                                        |
| 309 | - $children[] = new CalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);  | 
                                                        |
| 310 | - }  | 
                                                        |
| 311 | - return $children;  | 
                                                        |
| 312 | -  | 
                                                        |
| 313 | - }  | 
                                                        |
| 314 | -  | 
                                                        |
| 315 | -	public function getMultipleChildren(array $paths) { | 
                                                        |
| 316 | -  | 
                                                        |
| 317 | - $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths);  | 
                                                        |
| 318 | - $children = [];  | 
                                                        |
| 319 | -		foreach ($objs as $obj) { | 
                                                        |
| 320 | -			if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { | 
                                                        |
| 321 | - continue;  | 
                                                        |
| 322 | - }  | 
                                                        |
| 323 | - $obj['acl'] = $this->getChildACL();  | 
                                                        |
| 324 | - $children[] = new CalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);  | 
                                                        |
| 325 | - }  | 
                                                        |
| 326 | - return $children;  | 
                                                        |
| 327 | -  | 
                                                        |
| 328 | - }  | 
                                                        |
| 329 | -  | 
                                                        |
| 330 | -	public function childExists($name) { | 
                                                        |
| 331 | - $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);  | 
                                                        |
| 332 | -		if (!$obj) { | 
                                                        |
| 333 | - return false;  | 
                                                        |
| 334 | - }  | 
                                                        |
| 335 | -		if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { | 
                                                        |
| 336 | - return false;  | 
                                                        |
| 337 | - }  | 
                                                        |
| 338 | -  | 
                                                        |
| 339 | - return true;  | 
                                                        |
| 340 | - }  | 
                                                        |
| 341 | -  | 
                                                        |
| 342 | -	public function calendarQuery(array $filters) { | 
                                                        |
| 343 | -  | 
                                                        |
| 344 | - $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters);  | 
                                                        |
| 345 | -		if ($this->isShared()) { | 
                                                        |
| 346 | -			return array_filter($uris, function ($uri) { | 
                                                        |
| 347 | - return $this->childExists($uri);  | 
                                                        |
| 348 | - });  | 
                                                        |
| 349 | - }  | 
                                                        |
| 350 | -  | 
                                                        |
| 351 | - return $uris;  | 
                                                        |
| 352 | - }  | 
                                                        |
| 353 | -  | 
                                                        |
| 354 | - /**  | 
                                                        |
| 355 | - * @param boolean $value  | 
                                                        |
| 356 | - * @return string|null  | 
                                                        |
| 357 | - */  | 
                                                        |
| 358 | -	public function setPublishStatus($value) { | 
                                                        |
| 359 | - $publicUri = $this->caldavBackend->setPublishStatus($value, $this);  | 
                                                        |
| 360 | - $this->calendarInfo['publicuri'] = $publicUri;  | 
                                                        |
| 361 | - return $publicUri;  | 
                                                        |
| 362 | - }  | 
                                                        |
| 363 | -  | 
                                                        |
| 364 | - /**  | 
                                                        |
| 365 | - * @return mixed $value  | 
                                                        |
| 366 | - */  | 
                                                        |
| 367 | -	public function getPublishStatus() { | 
                                                        |
| 368 | - return $this->caldavBackend->getPublishStatus($this);  | 
                                                        |
| 369 | - }  | 
                                                        |
| 370 | -  | 
                                                        |
| 371 | -	public function canWrite() { | 
                                                        |
| 372 | -		if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { | 
                                                        |
| 373 | - return false;  | 
                                                        |
| 374 | - }  | 
                                                        |
| 375 | -  | 
                                                        |
| 376 | -		if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) { | 
                                                        |
| 377 | -			return !$this->calendarInfo['{http://owncloud.org/ns}read-only']; | 
                                                        |
| 378 | - }  | 
                                                        |
| 379 | - return true;  | 
                                                        |
| 380 | - }  | 
                                                        |
| 381 | -  | 
                                                        |
| 382 | -	private function isPublic() { | 
                                                        |
| 383 | -		return isset($this->calendarInfo['{http://owncloud.org/ns}public']); | 
                                                        |
| 384 | - }  | 
                                                        |
| 385 | -  | 
                                                        |
| 386 | -	protected function isShared() { | 
                                                        |
| 387 | -		if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { | 
                                                        |
| 388 | - return false;  | 
                                                        |
| 389 | - }  | 
                                                        |
| 390 | -  | 
                                                        |
| 391 | -		return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']; | 
                                                        |
| 392 | - }  | 
                                                        |
| 393 | -  | 
                                                        |
| 394 | -	public function isSubscription() { | 
                                                        |
| 395 | -		return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']); | 
                                                        |
| 396 | - }  | 
                                                        |
| 397 | -  | 
                                                        |
| 398 | - /**  | 
                                                        |
| 399 | - * @inheritDoc  | 
                                                        |
| 400 | - */  | 
                                                        |
| 401 | -	public function getChanges($syncToken, $syncLevel, $limit = null) { | 
                                                        |
| 402 | -		if (!$syncToken && $limit) { | 
                                                        |
| 403 | - throw new UnsupportedLimitOnInitialSyncException();  | 
                                                        |
| 404 | - }  | 
                                                        |
| 405 | -  | 
                                                        |
| 406 | - return parent::getChanges($syncToken, $syncLevel, $limit);  | 
                                                        |
| 407 | - }  | 
                                                        |
| 48 | + /** @var IConfig */  | 
                                                        |
| 49 | + private $config;  | 
                                                        |
| 50 | +  | 
                                                        |
| 51 | + /** @var IL10N */  | 
                                                        |
| 52 | + protected $l10n;  | 
                                                        |
| 53 | +  | 
                                                        |
| 54 | + /**  | 
                                                        |
| 55 | + * Calendar constructor.  | 
                                                        |
| 56 | + *  | 
                                                        |
| 57 | + * @param BackendInterface $caldavBackend  | 
                                                        |
| 58 | + * @param $calendarInfo  | 
                                                        |
| 59 | + * @param IL10N $l10n  | 
                                                        |
| 60 | + * @param IConfig $config  | 
                                                        |
| 61 | + */  | 
                                                        |
| 62 | +    public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config) { | 
                                                        |
| 63 | + parent::__construct($caldavBackend, $calendarInfo);  | 
                                                        |
| 64 | +  | 
                                                        |
| 65 | +        if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { | 
                                                        |
| 66 | +            $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays'); | 
                                                        |
| 67 | + }  | 
                                                        |
| 68 | + if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI &&  | 
                                                        |
| 69 | +            $this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) { | 
                                                        |
| 70 | +            $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal'); | 
                                                        |
| 71 | + }  | 
                                                        |
| 72 | +  | 
                                                        |
| 73 | + $this->config = $config;  | 
                                                        |
| 74 | + $this->l10n = $l10n;  | 
                                                        |
| 75 | + }  | 
                                                        |
| 76 | +  | 
                                                        |
| 77 | + /**  | 
                                                        |
| 78 | + * Updates the list of shares.  | 
                                                        |
| 79 | + *  | 
                                                        |
| 80 | + * The first array is a list of people that are to be added to the  | 
                                                        |
| 81 | + * resource.  | 
                                                        |
| 82 | + *  | 
                                                        |
| 83 | + * Every element in the add array has the following properties:  | 
                                                        |
| 84 | + * * href - A url. Usually a mailto: address  | 
                                                        |
| 85 | + * * commonName - Usually a first and last name, or false  | 
                                                        |
| 86 | + * * summary - A description of the share, can also be false  | 
                                                        |
| 87 | + * * readOnly - A boolean value  | 
                                                        |
| 88 | + *  | 
                                                        |
| 89 | + * Every element in the remove array is just the address string.  | 
                                                        |
| 90 | + *  | 
                                                        |
| 91 | + * @param array $add  | 
                                                        |
| 92 | + * @param array $remove  | 
                                                        |
| 93 | + * @return void  | 
                                                        |
| 94 | + * @throws Forbidden  | 
                                                        |
| 95 | + */  | 
                                                        |
| 96 | +    public function updateShares(array $add, array $remove) { | 
                                                        |
| 97 | +        if ($this->isShared()) { | 
                                                        |
| 98 | + throw new Forbidden();  | 
                                                        |
| 99 | + }  | 
                                                        |
| 100 | + $this->caldavBackend->updateShares($this, $add, $remove);  | 
                                                        |
| 101 | + }  | 
                                                        |
| 102 | +  | 
                                                        |
| 103 | + /**  | 
                                                        |
| 104 | + * Returns the list of people whom this resource is shared with.  | 
                                                        |
| 105 | + *  | 
                                                        |
| 106 | + * Every element in this array should have the following properties:  | 
                                                        |
| 107 | + * * href - Often a mailto: address  | 
                                                        |
| 108 | + * * commonName - Optional, for example a first + last name  | 
                                                        |
| 109 | + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.  | 
                                                        |
| 110 | + * * readOnly - boolean  | 
                                                        |
| 111 | + * * summary - Optional, a description for the share  | 
                                                        |
| 112 | + *  | 
                                                        |
| 113 | + * @return array  | 
                                                        |
| 114 | + */  | 
                                                        |
| 115 | +    public function getShares() { | 
                                                        |
| 116 | +        if ($this->isShared()) { | 
                                                        |
| 117 | + return [];  | 
                                                        |
| 118 | + }  | 
                                                        |
| 119 | + return $this->caldavBackend->getShares($this->getResourceId());  | 
                                                        |
| 120 | + }  | 
                                                        |
| 121 | +  | 
                                                        |
| 122 | + /**  | 
                                                        |
| 123 | + * @return int  | 
                                                        |
| 124 | + */  | 
                                                        |
| 125 | +    public function getResourceId() { | 
                                                        |
| 126 | + return $this->calendarInfo['id'];  | 
                                                        |
| 127 | + }  | 
                                                        |
| 128 | +  | 
                                                        |
| 129 | + /**  | 
                                                        |
| 130 | + * @return string  | 
                                                        |
| 131 | + */  | 
                                                        |
| 132 | +    public function getPrincipalURI() { | 
                                                        |
| 133 | + return $this->calendarInfo['principaluri'];  | 
                                                        |
| 134 | + }  | 
                                                        |
| 135 | +  | 
                                                        |
| 136 | + /**  | 
                                                        |
| 137 | + * @return array  | 
                                                        |
| 138 | + */  | 
                                                        |
| 139 | +    public function getACL() { | 
                                                        |
| 140 | + $acl = [  | 
                                                        |
| 141 | + [  | 
                                                        |
| 142 | +                'privilege' => '{DAV:}read', | 
                                                        |
| 143 | + 'principal' => $this->getOwner(),  | 
                                                        |
| 144 | + 'protected' => true,  | 
                                                        |
| 145 | + ],  | 
                                                        |
| 146 | + [  | 
                                                        |
| 147 | +                'privilege' => '{DAV:}read', | 
                                                        |
| 148 | + 'principal' => $this->getOwner() . '/calendar-proxy-write',  | 
                                                        |
| 149 | + 'protected' => true,  | 
                                                        |
| 150 | + ],  | 
                                                        |
| 151 | + [  | 
                                                        |
| 152 | +                'privilege' => '{DAV:}read', | 
                                                        |
| 153 | + 'principal' => $this->getOwner() . '/calendar-proxy-read',  | 
                                                        |
| 154 | + 'protected' => true,  | 
                                                        |
| 155 | + ],  | 
                                                        |
| 156 | + ];  | 
                                                        |
| 157 | +  | 
                                                        |
| 158 | +        if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) { | 
                                                        |
| 159 | + $acl[] = [  | 
                                                        |
| 160 | +                'privilege' => '{DAV:}write', | 
                                                        |
| 161 | + 'principal' => $this->getOwner(),  | 
                                                        |
| 162 | + 'protected' => true,  | 
                                                        |
| 163 | + ];  | 
                                                        |
| 164 | + $acl[] = [  | 
                                                        |
| 165 | +                'privilege' => '{DAV:}write', | 
                                                        |
| 166 | + 'principal' => $this->getOwner() . '/calendar-proxy-write',  | 
                                                        |
| 167 | + 'protected' => true,  | 
                                                        |
| 168 | + ];  | 
                                                        |
| 169 | +        } else { | 
                                                        |
| 170 | + $acl[] = [  | 
                                                        |
| 171 | +                'privilege' => '{DAV:}write-properties', | 
                                                        |
| 172 | + 'principal' => $this->getOwner(),  | 
                                                        |
| 173 | + 'protected' => true,  | 
                                                        |
| 174 | + ];  | 
                                                        |
| 175 | + $acl[] = [  | 
                                                        |
| 176 | +                'privilege' => '{DAV:}write-properties', | 
                                                        |
| 177 | + 'principal' => $this->getOwner() . '/calendar-proxy-write',  | 
                                                        |
| 178 | + 'protected' => true,  | 
                                                        |
| 179 | + ];  | 
                                                        |
| 180 | + }  | 
                                                        |
| 181 | +  | 
                                                        |
| 182 | + $acl[] = [  | 
                                                        |
| 183 | +            'privilege' => '{DAV:}write-properties', | 
                                                        |
| 184 | + 'principal' => $this->getOwner() . '/calendar-proxy-read',  | 
                                                        |
| 185 | + 'protected' => true,  | 
                                                        |
| 186 | + ];  | 
                                                        |
| 187 | +  | 
                                                        |
| 188 | +        if (!$this->isShared()) { | 
                                                        |
| 189 | + return $acl;  | 
                                                        |
| 190 | + }  | 
                                                        |
| 191 | +  | 
                                                        |
| 192 | +        if ($this->getOwner() !== parent::getOwner()) { | 
                                                        |
| 193 | + $acl[] = [  | 
                                                        |
| 194 | +                    'privilege' => '{DAV:}read', | 
                                                        |
| 195 | + 'principal' => parent::getOwner(),  | 
                                                        |
| 196 | + 'protected' => true,  | 
                                                        |
| 197 | + ];  | 
                                                        |
| 198 | +            if ($this->canWrite()) { | 
                                                        |
| 199 | + $acl[] = [  | 
                                                        |
| 200 | +                    'privilege' => '{DAV:}write', | 
                                                        |
| 201 | + 'principal' => parent::getOwner(),  | 
                                                        |
| 202 | + 'protected' => true,  | 
                                                        |
| 203 | + ];  | 
                                                        |
| 204 | +            } else { | 
                                                        |
| 205 | + $acl[] = [  | 
                                                        |
| 206 | +                    'privilege' => '{DAV:}write-properties', | 
                                                        |
| 207 | + 'principal' => parent::getOwner(),  | 
                                                        |
| 208 | + 'protected' => true,  | 
                                                        |
| 209 | + ];  | 
                                                        |
| 210 | + }  | 
                                                        |
| 211 | + }  | 
                                                        |
| 212 | +        if ($this->isPublic()) { | 
                                                        |
| 213 | + $acl[] = [  | 
                                                        |
| 214 | +                'privilege' => '{DAV:}read', | 
                                                        |
| 215 | + 'principal' => 'principals/system/public',  | 
                                                        |
| 216 | + 'protected' => true,  | 
                                                        |
| 217 | + ];  | 
                                                        |
| 218 | + }  | 
                                                        |
| 219 | +  | 
                                                        |
| 220 | + $acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl);  | 
                                                        |
| 221 | + $allowedPrincipals = [  | 
                                                        |
| 222 | + $this->getOwner(),  | 
                                                        |
| 223 | + $this->getOwner(). '/calendar-proxy-read',  | 
                                                        |
| 224 | + $this->getOwner(). '/calendar-proxy-write',  | 
                                                        |
| 225 | + parent::getOwner(),  | 
                                                        |
| 226 | + 'principals/system/public'  | 
                                                        |
| 227 | + ];  | 
                                                        |
| 228 | +        return array_filter($acl, function($rule) use ($allowedPrincipals) { | 
                                                        |
| 229 | + return \in_array($rule['principal'], $allowedPrincipals, true);  | 
                                                        |
| 230 | + });  | 
                                                        |
| 231 | + }  | 
                                                        |
| 232 | +  | 
                                                        |
| 233 | +    public function getChildACL() { | 
                                                        |
| 234 | + return $this->getACL();  | 
                                                        |
| 235 | + }  | 
                                                        |
| 236 | +  | 
                                                        |
| 237 | +    public function getOwner() { | 
                                                        |
| 238 | +        if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { | 
                                                        |
| 239 | +            return $this->calendarInfo['{http://owncloud.org/ns}owner-principal']; | 
                                                        |
| 240 | + }  | 
                                                        |
| 241 | + return parent::getOwner();  | 
                                                        |
| 242 | + }  | 
                                                        |
| 243 | +  | 
                                                        |
| 244 | +    public function delete() { | 
                                                        |
| 245 | +        if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) && | 
                                                        |
| 246 | +            $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) { | 
                                                        |
| 247 | + $principal = 'principal:' . parent::getOwner();  | 
                                                        |
| 248 | + $shares = $this->caldavBackend->getShares($this->getResourceId());  | 
                                                        |
| 249 | +            $shares = array_filter($shares, function($share) use ($principal){ | 
                                                        |
| 250 | + return $share['href'] === $principal;  | 
                                                        |
| 251 | + });  | 
                                                        |
| 252 | +            if (empty($shares)) { | 
                                                        |
| 253 | + throw new Forbidden();  | 
                                                        |
| 254 | + }  | 
                                                        |
| 255 | +  | 
                                                        |
| 256 | + $this->caldavBackend->updateShares($this, [], [  | 
                                                        |
| 257 | + $principal  | 
                                                        |
| 258 | + ]);  | 
                                                        |
| 259 | + return;  | 
                                                        |
| 260 | + }  | 
                                                        |
| 261 | +  | 
                                                        |
| 262 | + // Remember when a user deleted their birthday calendar  | 
                                                        |
| 263 | + // in order to not regenerate it on the next contacts change  | 
                                                        |
| 264 | +        if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { | 
                                                        |
| 265 | + $principalURI = $this->getPrincipalURI();  | 
                                                        |
| 266 | + $userId = substr($principalURI, 17);  | 
                                                        |
| 267 | +  | 
                                                        |
| 268 | + $this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'no');  | 
                                                        |
| 269 | + }  | 
                                                        |
| 270 | +  | 
                                                        |
| 271 | + parent::delete();  | 
                                                        |
| 272 | + }  | 
                                                        |
| 273 | +  | 
                                                        |
| 274 | +    public function propPatch(PropPatch $propPatch) { | 
                                                        |
| 275 | + // parent::propPatch will only update calendars table  | 
                                                        |
| 276 | + // if calendar is shared, changes have to be made to the properties table  | 
                                                        |
| 277 | +        if (!$this->isShared()) { | 
                                                        |
| 278 | + parent::propPatch($propPatch);  | 
                                                        |
| 279 | + }  | 
                                                        |
| 280 | + }  | 
                                                        |
| 281 | +  | 
                                                        |
| 282 | +    public function getChild($name) { | 
                                                        |
| 283 | +  | 
                                                        |
| 284 | + $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);  | 
                                                        |
| 285 | +  | 
                                                        |
| 286 | +        if (!$obj) { | 
                                                        |
| 287 | +            throw new NotFound('Calendar object not found'); | 
                                                        |
| 288 | + }  | 
                                                        |
| 289 | +  | 
                                                        |
| 290 | +        if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { | 
                                                        |
| 291 | +            throw new NotFound('Calendar object not found'); | 
                                                        |
| 292 | + }  | 
                                                        |
| 293 | +  | 
                                                        |
| 294 | + $obj['acl'] = $this->getChildACL();  | 
                                                        |
| 295 | +  | 
                                                        |
| 296 | + return new CalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);  | 
                                                        |
| 297 | +  | 
                                                        |
| 298 | + }  | 
                                                        |
| 299 | +  | 
                                                        |
| 300 | +    public function getChildren() { | 
                                                        |
| 301 | +  | 
                                                        |
| 302 | + $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']);  | 
                                                        |
| 303 | + $children = [];  | 
                                                        |
| 304 | +        foreach ($objs as $obj) { | 
                                                        |
| 305 | +            if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { | 
                                                        |
| 306 | + continue;  | 
                                                        |
| 307 | + }  | 
                                                        |
| 308 | + $obj['acl'] = $this->getChildACL();  | 
                                                        |
| 309 | + $children[] = new CalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);  | 
                                                        |
| 310 | + }  | 
                                                        |
| 311 | + return $children;  | 
                                                        |
| 312 | +  | 
                                                        |
| 313 | + }  | 
                                                        |
| 314 | +  | 
                                                        |
| 315 | +    public function getMultipleChildren(array $paths) { | 
                                                        |
| 316 | +  | 
                                                        |
| 317 | + $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths);  | 
                                                        |
| 318 | + $children = [];  | 
                                                        |
| 319 | +        foreach ($objs as $obj) { | 
                                                        |
| 320 | +            if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { | 
                                                        |
| 321 | + continue;  | 
                                                        |
| 322 | + }  | 
                                                        |
| 323 | + $obj['acl'] = $this->getChildACL();  | 
                                                        |
| 324 | + $children[] = new CalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);  | 
                                                        |
| 325 | + }  | 
                                                        |
| 326 | + return $children;  | 
                                                        |
| 327 | +  | 
                                                        |
| 328 | + }  | 
                                                        |
| 329 | +  | 
                                                        |
| 330 | +    public function childExists($name) { | 
                                                        |
| 331 | + $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);  | 
                                                        |
| 332 | +        if (!$obj) { | 
                                                        |
| 333 | + return false;  | 
                                                        |
| 334 | + }  | 
                                                        |
| 335 | +        if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { | 
                                                        |
| 336 | + return false;  | 
                                                        |
| 337 | + }  | 
                                                        |
| 338 | +  | 
                                                        |
| 339 | + return true;  | 
                                                        |
| 340 | + }  | 
                                                        |
| 341 | +  | 
                                                        |
| 342 | +    public function calendarQuery(array $filters) { | 
                                                        |
| 343 | +  | 
                                                        |
| 344 | + $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters);  | 
                                                        |
| 345 | +        if ($this->isShared()) { | 
                                                        |
| 346 | +            return array_filter($uris, function ($uri) { | 
                                                        |
| 347 | + return $this->childExists($uri);  | 
                                                        |
| 348 | + });  | 
                                                        |
| 349 | + }  | 
                                                        |
| 350 | +  | 
                                                        |
| 351 | + return $uris;  | 
                                                        |
| 352 | + }  | 
                                                        |
| 353 | +  | 
                                                        |
| 354 | + /**  | 
                                                        |
| 355 | + * @param boolean $value  | 
                                                        |
| 356 | + * @return string|null  | 
                                                        |
| 357 | + */  | 
                                                        |
| 358 | +    public function setPublishStatus($value) { | 
                                                        |
| 359 | + $publicUri = $this->caldavBackend->setPublishStatus($value, $this);  | 
                                                        |
| 360 | + $this->calendarInfo['publicuri'] = $publicUri;  | 
                                                        |
| 361 | + return $publicUri;  | 
                                                        |
| 362 | + }  | 
                                                        |
| 363 | +  | 
                                                        |
| 364 | + /**  | 
                                                        |
| 365 | + * @return mixed $value  | 
                                                        |
| 366 | + */  | 
                                                        |
| 367 | +    public function getPublishStatus() { | 
                                                        |
| 368 | + return $this->caldavBackend->getPublishStatus($this);  | 
                                                        |
| 369 | + }  | 
                                                        |
| 370 | +  | 
                                                        |
| 371 | +    public function canWrite() { | 
                                                        |
| 372 | +        if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { | 
                                                        |
| 373 | + return false;  | 
                                                        |
| 374 | + }  | 
                                                        |
| 375 | +  | 
                                                        |
| 376 | +        if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) { | 
                                                        |
| 377 | +            return !$this->calendarInfo['{http://owncloud.org/ns}read-only']; | 
                                                        |
| 378 | + }  | 
                                                        |
| 379 | + return true;  | 
                                                        |
| 380 | + }  | 
                                                        |
| 381 | +  | 
                                                        |
| 382 | +    private function isPublic() { | 
                                                        |
| 383 | +        return isset($this->calendarInfo['{http://owncloud.org/ns}public']); | 
                                                        |
| 384 | + }  | 
                                                        |
| 385 | +  | 
                                                        |
| 386 | +    protected function isShared() { | 
                                                        |
| 387 | +        if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { | 
                                                        |
| 388 | + return false;  | 
                                                        |
| 389 | + }  | 
                                                        |
| 390 | +  | 
                                                        |
| 391 | +        return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']; | 
                                                        |
| 392 | + }  | 
                                                        |
| 393 | +  | 
                                                        |
| 394 | +    public function isSubscription() { | 
                                                        |
| 395 | +        return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']); | 
                                                        |
| 396 | + }  | 
                                                        |
| 397 | +  | 
                                                        |
| 398 | + /**  | 
                                                        |
| 399 | + * @inheritDoc  | 
                                                        |
| 400 | + */  | 
                                                        |
| 401 | +    public function getChanges($syncToken, $syncLevel, $limit = null) { | 
                                                        |
| 402 | +        if (!$syncToken && $limit) { | 
                                                        |
| 403 | + throw new UnsupportedLimitOnInitialSyncException();  | 
                                                        |
| 404 | + }  | 
                                                        |
| 405 | +  | 
                                                        |
| 406 | + return parent::getChanges($syncToken, $syncLevel, $limit);  | 
                                                        |
| 407 | + }  | 
                                                        |
| 408 | 408 | }  | 
                                                        
@@ -28,63 +28,63 @@  | 
                                                    ||
| 28 | 28 | |
| 29 | 29 |  class PublicCalendar extends Calendar { | 
                                                        
| 30 | 30 | |
| 31 | - /**  | 
                                                        |
| 32 | - * @param string $name  | 
                                                        |
| 33 | - * @throws NotFound  | 
                                                        |
| 34 | - * @return PublicCalendarObject  | 
                                                        |
| 35 | - */  | 
                                                        |
| 36 | -	public function getChild($name) { | 
                                                        |
| 37 | - $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);  | 
                                                        |
| 31 | + /**  | 
                                                        |
| 32 | + * @param string $name  | 
                                                        |
| 33 | + * @throws NotFound  | 
                                                        |
| 34 | + * @return PublicCalendarObject  | 
                                                        |
| 35 | + */  | 
                                                        |
| 36 | +    public function getChild($name) { | 
                                                        |
| 37 | + $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);  | 
                                                        |
| 38 | 38 | |
| 39 | -		if (!$obj) { | 
                                                        |
| 40 | -			throw new NotFound('Calendar object not found'); | 
                                                        |
| 41 | - }  | 
                                                        |
| 42 | -		if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { | 
                                                        |
| 43 | -			throw new NotFound('Calendar object not found'); | 
                                                        |
| 44 | - }  | 
                                                        |
| 45 | - $obj['acl'] = $this->getChildACL();  | 
                                                        |
| 39 | +        if (!$obj) { | 
                                                        |
| 40 | +            throw new NotFound('Calendar object not found'); | 
                                                        |
| 41 | + }  | 
                                                        |
| 42 | +        if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { | 
                                                        |
| 43 | +            throw new NotFound('Calendar object not found'); | 
                                                        |
| 44 | + }  | 
                                                        |
| 45 | + $obj['acl'] = $this->getChildACL();  | 
                                                        |
| 46 | 46 | |
| 47 | - return new PublicCalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);  | 
                                                        |
| 48 | - }  | 
                                                        |
| 47 | + return new PublicCalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);  | 
                                                        |
| 48 | + }  | 
                                                        |
| 49 | 49 | |
| 50 | - /**  | 
                                                        |
| 51 | - * @return PublicCalendarObject[]  | 
                                                        |
| 52 | - */  | 
                                                        |
| 53 | -	public function getChildren() { | 
                                                        |
| 54 | - $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']);  | 
                                                        |
| 55 | - $children = [];  | 
                                                        |
| 56 | -		foreach ($objs as $obj) { | 
                                                        |
| 57 | -			if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { | 
                                                        |
| 58 | - continue;  | 
                                                        |
| 59 | - }  | 
                                                        |
| 60 | - $obj['acl'] = $this->getChildACL();  | 
                                                        |
| 61 | - $children[] = new PublicCalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);  | 
                                                        |
| 62 | - }  | 
                                                        |
| 63 | - return $children;  | 
                                                        |
| 64 | - }  | 
                                                        |
| 50 | + /**  | 
                                                        |
| 51 | + * @return PublicCalendarObject[]  | 
                                                        |
| 52 | + */  | 
                                                        |
| 53 | +    public function getChildren() { | 
                                                        |
| 54 | + $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']);  | 
                                                        |
| 55 | + $children = [];  | 
                                                        |
| 56 | +        foreach ($objs as $obj) { | 
                                                        |
| 57 | +            if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { | 
                                                        |
| 58 | + continue;  | 
                                                        |
| 59 | + }  | 
                                                        |
| 60 | + $obj['acl'] = $this->getChildACL();  | 
                                                        |
| 61 | + $children[] = new PublicCalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);  | 
                                                        |
| 62 | + }  | 
                                                        |
| 63 | + return $children;  | 
                                                        |
| 64 | + }  | 
                                                        |
| 65 | 65 | |
| 66 | - /**  | 
                                                        |
| 67 | - * @param string[] $paths  | 
                                                        |
| 68 | - * @return PublicCalendarObject[]  | 
                                                        |
| 69 | - */  | 
                                                        |
| 70 | -	public function getMultipleChildren(array $paths) { | 
                                                        |
| 71 | - $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths);  | 
                                                        |
| 72 | - $children = [];  | 
                                                        |
| 73 | -		foreach ($objs as $obj) { | 
                                                        |
| 74 | -			if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { | 
                                                        |
| 75 | - continue;  | 
                                                        |
| 76 | - }  | 
                                                        |
| 77 | - $obj['acl'] = $this->getChildACL();  | 
                                                        |
| 78 | - $children[] = new PublicCalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);  | 
                                                        |
| 79 | - }  | 
                                                        |
| 80 | - return $children;  | 
                                                        |
| 81 | - }  | 
                                                        |
| 66 | + /**  | 
                                                        |
| 67 | + * @param string[] $paths  | 
                                                        |
| 68 | + * @return PublicCalendarObject[]  | 
                                                        |
| 69 | + */  | 
                                                        |
| 70 | +    public function getMultipleChildren(array $paths) { | 
                                                        |
| 71 | + $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths);  | 
                                                        |
| 72 | + $children = [];  | 
                                                        |
| 73 | +        foreach ($objs as $obj) { | 
                                                        |
| 74 | +            if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { | 
                                                        |
| 75 | + continue;  | 
                                                        |
| 76 | + }  | 
                                                        |
| 77 | + $obj['acl'] = $this->getChildACL();  | 
                                                        |
| 78 | + $children[] = new PublicCalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);  | 
                                                        |
| 79 | + }  | 
                                                        |
| 80 | + return $children;  | 
                                                        |
| 81 | + }  | 
                                                        |
| 82 | 82 | |
| 83 | - /**  | 
                                                        |
| 84 | - * public calendars are always shared  | 
                                                        |
| 85 | - * @return bool  | 
                                                        |
| 86 | - */  | 
                                                        |
| 87 | -	protected function isShared() { | 
                                                        |
| 88 | - return true;  | 
                                                        |
| 89 | - }  | 
                                                        |
| 83 | + /**  | 
                                                        |
| 84 | + * public calendars are always shared  | 
                                                        |
| 85 | + * @return bool  | 
                                                        |
| 86 | + */  | 
                                                        |
| 87 | +    protected function isShared() { | 
                                                        |
| 88 | + return true;  | 
                                                        |
| 89 | + }  | 
                                                        |
| 90 | 90 | }  |