Skip to content

Commit

Permalink
MDL-58575 core_calendar: Properly restrict groups in event vault
Browse files Browse the repository at this point in the history
Previously we were not filtering on groups in the event vault
which meant events for all groups would be returned regardless
of which user was passed in.

This resulted in situations where one student would group overrides
for groups they were not in.
  • Loading branch information
cameorn1730 committed Apr 27, 2017
1 parent 30aa540 commit 4bd022e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions calendar/classes/local/event/data_access/event_vault.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ public function get_action_events_by_timesort(
event_interface $afterevent = null,
$limitnum = 20
) {
$courseids = array_map(function($course) {
return $course->id;
}, enrol_get_all_users_courses($user->id));

$groupids = array_reduce($courseids, function($carry, $courseid) use ($user) {
$groupings = groups_get_user_groups($courseid, $user->id);
// Grouping 0 is all groups.
return array_merge($carry, $groupings[0]);
}, []);

return $this->get_events(
null,
null,
Expand All @@ -207,8 +217,8 @@ public function get_action_events_by_timesort(
$limitnum,
CALENDAR_EVENT_TYPE_ACTION,
[$user->id],
null,
null,
$groupids ? $groupids : null,
$courseids ? $courseids : null,
true,
true,
function ($event) {
Expand All @@ -225,6 +235,7 @@ public function get_action_events_by_course(
event_interface $afterevent = null,
$limitnum = 20
) {
$groupings = groups_get_user_groups($course->id, $user->id);
return array_values(
$this->get_events(
null,
Expand All @@ -236,7 +247,7 @@ public function get_action_events_by_course(
$limitnum,
CALENDAR_EVENT_TYPE_ACTION,
[$user->id],
null,
$groupings[0] ? $groupings[0] : null,
[$course->id],
true,
true,
Expand Down

0 comments on commit 4bd022e

Please sign in to comment.