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

Commit

Permalink
fix user-hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
georgehrke committed Sep 12, 2014
1 parent b804dac commit e68e549
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}
}

2 comments on commit e68e549

@wanno-drijfhout
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit does not seem to prevent 'invitees' of shared calendars from deleting calendars. If I interpret r427 correctly, this is now by design. Also, line r259 is too restrictive. That seems undesirable, not?

Why not instead do something like the following?

if (!self::isAllowedToDeleteCalendar($calendar)) {
 throw new Exception(...)
}

@georgehrke
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.