Skip to content

Commit

Permalink
MDL-49314 webservices: Check groups using groups_user_groups_visible
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyva committed Apr 1, 2015
1 parent aa5faf0 commit 9cd1093
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions completion/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public static function get_activities_completion_status_parameters() {
public static function get_activities_completion_status($courseid, $userid) {
global $CFG, $USER;
require_once($CFG->libdir . '/grouplib.php');

$warnings = array();
$arrayparams = array(
'courseid' => $courseid,
Expand All @@ -159,17 +160,9 @@ public static function get_activities_completion_status($courseid, $userid) {
// Check that current user have permissions to see this user's activities.
if ($user->id != $USER->id) {
require_capability('report/progress:view', $context);
$groupmode = groups_get_course_groupmode($course);

if ($groupmode == SEPARATEGROUPS && !has_capability('moodle/site:accessallgroups', $context)) {

$usergroups = groups_get_all_groups($course->id, $user->id);
$currentusergroups = groups_get_all_groups($course->id, $USER->id);
$samegroups = array_intersect_key($currentusergroups, $usergroups);
if (empty($samegroups)) {
// We are not in the same group!
throw new moodle_exception('accessdenied', 'admin');
}
if (!groups_user_groups_visible($course, $user->id)) {
// We are not in the same group!
throw new moodle_exception('accessdenied', 'admin');
}
}

Expand All @@ -182,7 +175,7 @@ public static function get_activities_completion_status($courseid, $userid) {
foreach ($activities as $activity) {

// Check if current user has visibility on this activity.
if (!$activity->visible or !$activity->uservisible) {
if (!$activity->uservisible) {
continue;
}

Expand All @@ -202,7 +195,7 @@ public static function get_activities_completion_status($courseid, $userid) {
'instance' => $activity->instance,
'state' => $state,
'timecompleted' => $timecompleted,
'tracking' => $activity->completion == COMPLETION_TRACKING_AUTOMATIC ? 'auto' : 'manual'
'tracking' => $activity->completion
);
}

Expand All @@ -225,12 +218,15 @@ public static function get_activities_completion_status_returns() {
'statuses' => new external_multiple_structure(
new external_single_structure(
array(
'cmid' => new external_value(PARAM_INT, 'Comment ID'),
'modname' => new external_value(PARAM_PLUGIN, 'Activity module name'),
'instance' => new external_value(PARAM_INT, 'Instance ID'),
'state' => new external_value(PARAM_INT, 'Completion state value'),
'timecompleted' => new external_value(PARAM_INT, 'Timestamp for completed activity'),
'tracking' => new external_value(PARAM_ALPHA, 'Tracking (auto/manual)'),
'cmid' => new external_value(PARAM_INT, 'comment ID'),
'modname' => new external_value(PARAM_PLUGIN, 'activity module name'),
'instance' => new external_value(PARAM_INT, 'instance ID'),
'state' => new external_value(PARAM_INT, 'completion state value:
0 means incomplete, 1 complete,
2 complete pass, 3 complete fail'),
'timecompleted' => new external_value(PARAM_INT, 'timestamp for completed activity'),
'tracking' => new external_value(PARAM_INT, 'type of tracking:
0 means none, 1 manual, 2 automatic'),
), 'Activity'
), 'List of activities status'
),
Expand Down

0 comments on commit 9cd1093

Please sign in to comment.