MDL-37710 Assign: Fix pluginfile permission checks for student viewing their own team submission.

This change adds a function to the assign class to allow the permissions for a group submission
to be checked and updates all the submission plugins to call it.
This commit is contained in:
Damyon Wiese 2013-01-29 16:07:08 +08:00
parent cbb26eb0ec
commit 3e1b63f1c8
4 changed files with 62 additions and 29 deletions

View file

@ -40,7 +40,7 @@ function assignsubmission_file_pluginfile($course,
$filearea,
$args,
$forcedownload) {
global $USER, $DB;
global $DB, $CFG;
if ($context->contextlevel != CONTEXT_MODULE) {
return false;
@ -50,20 +50,26 @@ function assignsubmission_file_pluginfile($course,
$itemid = (int)array_shift($args);
$record = $DB->get_record('assign_submission',
array('id'=>$itemid),
'userid, assignment',
'userid, assignment, groupid',
MUST_EXIST);
$userid = $record->userid;
$groupid = $record->groupid;
if (!$assign = $DB->get_record('assign', array('id'=>$cm->instance))) {
require_once($CFG->dirroot . '/mod/assign/locallib.php');
$assign = new assign($context, $cm, $course);
if ($assign->get_instance()->id != $record->assignment) {
return false;
}
if ($assign->id != $record->assignment) {
if ($assign->get_instance()->teamsubmission &&
!$assign->can_view_group_submission($groupid)) {
return false;
}
// Check if this is the current users submission or the user has grading permission.
if ($USER->id != $userid and !has_capability('mod/assign:grade', $context)) {
if (!$assign->get_instance()->teamsubmission &&
!$assign->can_view_submission($userid)) {
return false;
}
@ -72,7 +78,7 @@ function assignsubmission_file_pluginfile($course,
$fullpath = "/{$context->id}/assignsubmission_file/$filearea/$itemid/$relativepath";
$fs = get_file_storage();
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
if (!($file = $fs->get_file_by_hash(sha1($fullpath))) || $file->is_directory()) {
return false;
}