diff --git a/calendar/lib.php b/calendar/lib.php index 86ca22ff20e..dc56f91fd63 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -2977,6 +2977,48 @@ function calendar_update_subscription_events($subscriptionid) { return $return; } +/** + * Checks to see if the user can edit a given subscription feed. + * + * @param mixed $subscriptionorid Subscription object or id + * @return bool true if current user can edit the subscription else false + */ +function calendar_can_edit_subscription($subscriptionorid) { + global $DB; + + if (is_array($subscriptionorid)) { + $subscription = (object)$subscriptionorid; + } else if (is_object($subscriptionorid)) { + $subscription = $subscriptionorid; + } else { + $subscription = $DB->get_record('event_subscriptions', array('id' => $subscriptionorid), '*', MUST_EXIST); + } + $allowed = new stdClass; + $courseid = $subscription->courseid; + $groupid = $subscription->groupid; + calendar_get_allowed_types($allowed, $courseid); + switch ($subscription->eventtype) { + case 'user': + return $allowed->user; + case 'course': + if (isset($allowed->courses[$courseid])) { + return $allowed->courses[$courseid]; + } else { + return false; + } + case 'site': + return $allowed->site; + case 'group': + if (isset($allowed->groups[$groupid])) { + return $allowed->groups[$groupid]; + } else { + return false; + } + default: + return false; + } +} + /** * Update calendar subscriptions. * diff --git a/calendar/managesubscriptions.php b/calendar/managesubscriptions.php index 53b11a0656f..cc726f13d70 100644 --- a/calendar/managesubscriptions.php +++ b/calendar/managesubscriptions.php @@ -82,7 +82,11 @@ if (!empty($formdata)) { } else if (!empty($subscriptionid)) { // The user is wanting to perform an action upon an existing subscription. require_sesskey(); // Must have sesskey for all actions. - $importresults = calendar_process_subscription_row($subscriptionid, $pollinterval, $action); + if (calendar_can_edit_subscription($subscriptionid)) { + $importresults = calendar_process_subscription_row($subscriptionid, $pollinterval, $action); + } else { + print_error('nopermissions', 'error', $PAGE->url, get_string('managesubscriptions', 'calendar')); + } } $sql = 'SELECT *