From e68e54985dd1eb01b36bb07c8d4f3e4faa013a21 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 12 Sep 2014 19:48:16 +0200 Subject: [PATCH] fix user-hooks --- lib/calendar.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/calendar.php b/lib/calendar.php index f5cf937cf..0aac3edea 100644 --- a/lib/calendar.php +++ b/lib/calendar.php @@ -254,7 +254,7 @@ public static function touchCalendar($id) { */ public static function deleteCalendar($id) { $calendar = self::find($id); - if ($calendar['userid'] != OCP\User::getUser() && !OC_Group::inGroup(OCP\User::getUser(), 'admin')) { + if (!self::isAllowedToDeleteCalendar($calendar)) { $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id); if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_DELETE)) { throw new Exception( @@ -408,4 +408,26 @@ public static function generateTextColor($calendarcolor) { public static function getUsersEmails($names) { return \OCP\Config::getUserValue(\OCP\User::getUser(), 'settings', 'email'); } + + + /** + * @param array $calendar + * @param string $userId + * @return boolean + */ + private static function isAllowedToDeleteCalendar($calendar) { + $userId = OCP\User::getUser(); + + if ($calendar['userid'] === $userId) { + return true; + } + if (OC_User::isAdminUser($userId)) { + return true; + } + if (OC_SubAdmin::isUserAccessible($userId, $calendar['userid'])) { + return true; + } + + return false; + } }