Skip to content
This repository has been archived by the owner on Oct 31, 2018. It is now read-only.

remove valarms from objects in read-only shared calendars #668

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 43 additions & 5 deletions lib/sabre/backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,7 @@ public function getCalendarObjects($calendarId) {
if (!$isShared) {
$data[] = $this->OCAddETag($row);
} else {
if (substr_count($row['calendardata'], 'CLASS') === 0) {
$data[] = $this->OCAddETag($row);
} else {
if (substr_count($row['calendardata'], 'CLASS') !== 0) {
$object = OC_VObject::parse($row['calendardata']);
if(!$object) {
return false;
Expand All @@ -315,11 +313,13 @@ public function getCalendarObjects($calendarId) {
}
}

if ($isPrivate === false) {
$data[] = $this->OCAddETag($row);
if ($isPrivate === true) {
continue;
}
}
}
$row = $this->clearFromVALARM($calendar, $row);
$data[] = $this->OCAddETag($row);
}
}
return $data;
Expand Down Expand Up @@ -358,8 +358,15 @@ public function getCalendarObject($calendarId,$objectUri) {
));
}
}
$calendar = OC_Calendar_Calendar::find($calendarId);
$isShared = ($calendar['userid'] !== OCP\USER::getUser());

$data = OC_Calendar_Object::findWhereDAVDataIs($calendarId,$objectUri);
if(is_array($data)) {
if ($isShared) {
$data = $this->clearFromVALARM($calendar, $data);
}

$data = $this->OCAddETag($data);
$object = OC_VObject::parse($data['calendardata']);
if(!$object) {
Expand Down Expand Up @@ -417,4 +424,35 @@ private function OCAddETag($row) {
$row['etag'] = '"'.md5($row['calendarid'].$row['uri'].$row['calendardata'].$row['lastmodified']).'"';
return $row;
}


/**
* @param array $calendar
* @param array $row
* @return array
* @return bool
*/
private function clearFromVALARM($calendar, $row) {
if (isset($calendar['permissions']) && !(\OCP\PERMISSION_CREATE & $calendar['permissions'] || \OCP\PERMISSION_UPDATE & $calendar['permissions'])) {
if (substr_count($row['calendardata'], 'BEGIN:VALARM') === 0) {
$data[] = $this->OCAddETag($row);
} else {
$object = OC_VObject::parse($row['calendardata']);
if(!$object) {
return false;
}

$toCheck = array('VEVENT', 'VJOURNAL', 'VTODO');
foreach ($toCheck as $type) {
foreach ($object->select($type) as $vobject) {
unset($vobject->VALARM);
}
}

$row['calendardata'] = $object->serialize();
}
}

return $row;
}
}