MDL-37106 calendar: Proper capability checks should be done before processing an ical request

This commit is contained in:
Ankit Agarwal
2013-01-08 14:03:38 +08:00
committed by Dan Poltawski
parent d161e37488
commit 7a216229ab
2 changed files with 47 additions and 1 deletions
+42
View File
@@ -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.
*
+5 -1
View File
@@ -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 *