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

Do not allow deleting shared calendars. #495

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
21 changes: 14 additions & 7 deletions lib/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,9 @@ public static function touchCalendar($id) {
* @param integer $id
* @return boolean
*/
public static function deleteCalendar($id) {
public static function deleteCalendar($id, $force=false) {
$calendar = self::find($id);
$isShared = ($calendar['userid'] !== OCP\User::getUser());
if (!self::isAllowedToDeleteCalendar($calendar)) {
$sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id);
if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_DELETE)) {
Expand All @@ -264,15 +265,21 @@ public static function deleteCalendar($id) {
);
}
}
$stmt = OCP\DB::prepare( 'DELETE FROM `*PREFIX*clndr_calendars` WHERE `id` = ?' );
$stmt->execute(array($id));

$stmt = OCP\DB::prepare( 'DELETE FROM `*PREFIX*clndr_objects` WHERE `calendarid` = ?' );
$stmt->execute(array($id));
if (!$isShared || $force) {
$stmt = OCP\DB::prepare( 'DELETE FROM `*PREFIX*clndr_calendars` WHERE `id` = ?' );
$stmt->execute(array($id));

$stmt = OCP\DB::prepare( 'DELETE FROM `*PREFIX*clndr_objects` WHERE `calendarid` = ?' );
$stmt->execute(array($id));

OCP\Share::unshareAll('calendar', $id);
OCP\Share::unshareAll('calendar', $id);

OCP\Util::emitHook('OC_Calendar', 'deleteCalendar', $id);
} else {
OCP\Share::unshareFromSelf('calendar', $id, true);
}

OCP\Util::emitHook('OC_Calendar', 'deleteCalendar', $id);
if(OCP\USER::isLoggedIn() and count(self::allCalendars(OCP\USER::getUser())) == 0) {
self::addDefaultCalendars(OCP\USER::getUser());
}
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static function deleteUser($parameters) {

foreach($calendars as $calendar) {
if($parameters['uid'] === $calendar['userid']) {
OC_Calendar_Calendar::deleteCalendar($calendar['id']);
OC_Calendar_Calendar::deleteCalendar($calendar['id'], true);
}
}

Expand Down