From 4f83ae95ca270e5d6a8c6aefbd3c9a5282f9e59c Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Thu, 31 Aug 2006 08:51:09 +0000 Subject: [PATCH] adding capabilities --- mod/assignment/type/online/file.php | 2 +- mod/hotpot/db/access.php | 44 ++++++++++++++++++++++++++++- mod/hotpot/version.php | 2 +- mod/quiz/attempt.php | 2 +- mod/quiz/lib.php | 2 +- mod/quiz/quizfile.php | 5 ++-- mod/quiz/restorelibpre15.php | 3 +- mod/quiz/review.php | 2 +- 8 files changed, 52 insertions(+), 10 deletions(-) diff --git a/mod/assignment/type/online/file.php b/mod/assignment/type/online/file.php index cc106618aa..2a613364eb 100644 --- a/mod/assignment/type/online/file.php +++ b/mod/assignment/type/online/file.php @@ -25,7 +25,7 @@ require_login($course->id, false, $cm); - if (($USER->id != $user->id) && !isteacher($course->id)) { + if (($USER->id != $user->id) && !has_capability('mod/assignment:grade', get_context_instance(CONTEXT_MODULE, $cm->id))) { error("You can not view this assignment"); } diff --git a/mod/hotpot/db/access.php b/mod/hotpot/db/access.php index 808cb5321d..d1fdc12b49 100644 --- a/mod/hotpot/db/access.php +++ b/mod/hotpot/db/access.php @@ -33,7 +33,7 @@ $mod_hotpot_capabilities = array( - 'mod/hotpot:view' => array( + 'mod/hotpot:attempt' => array( 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, @@ -45,6 +45,48 @@ $mod_hotpot_capabilities = array( 'coursecreator' => CAP_ALLOW, 'admin' => CAP_ALLOW ) + ), + + 'mod/hotpot:viewreport' => array( + + 'captype' => 'read', + 'contextlevel' => CONTEXT_MODULE, + 'legacy' => array( + 'guest' => CAP_PREVENT, + 'student' => CAP_PREVENT, + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'coursecreator' => CAP_ALLOW, + 'admin' => CAP_ALLOW + ) + ), + + 'mod/hotpot:grade' => array( + + 'captype' => 'read', + 'contextlevel' => CONTEXT_MODULE, + 'legacy' => array( + 'guest' => CAP_PREVENT, + 'student' => CAP_PREVENT, + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'coursecreator' => CAP_ALLOW, + 'admin' => CAP_ALLOW + ) + ), + + 'mod/hotpot:deleteattempt' => array( + + 'captype' => 'read', + 'contextlevel' => CONTEXT_MODULE, + 'legacy' => array( + 'guest' => CAP_PREVENT, + 'student' => CAP_PREVENT, + 'teacher' => CAP_PREVENT, + 'editingteacher' => CAP_ALLOW, + 'coursecreator' => CAP_ALLOW, + 'admin' => CAP_ALLOW + ) ) ); diff --git a/mod/hotpot/version.php b/mod/hotpot/version.php index 6a3e843a6c..abb56c6271 100644 --- a/mod/hotpot/version.php +++ b/mod/hotpot/version.php @@ -3,7 +3,7 @@ /// Code fragment to define the version of hotpot /// This fragment is called by moodle_needs_upgrading() and /admin/index.php ///////////////////////////////////////////////////////////////////////////////// -$module->version = 2006080900; // release date of this version (see note below) +$module->version = 2006083100; // release date of this version (see note below) $module->release = 'v2.2.0'; // human-friendly version name (used in mod/hotpot/lib.php) $module->requires = 2006080900; // Requires this Moodle version $module->cron = 0; // period for cron to check this module (secs) diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php index 46f29dbd26..6fc2330fcb 100644 --- a/mod/quiz/attempt.php +++ b/mod/quiz/attempt.php @@ -57,7 +57,7 @@ } require_login($course->id, false, $cm); - $isteacher = isteacher($course->id); + $isteacher = has_capability('mod/quiz:grade', get_context_instance(CONTEXT_MODULE, $cm->id)); $coursecontext = get_context_instance(CONTEXT_COURSE, $id); // course context $context = get_context_instance(CONTEXT_MODULE, $cm->id); diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 0b38d223bb..0eb2dba5e3 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -435,7 +435,7 @@ function quiz_print_recent_mod_activity($activity, $course, $detail=false) { } - if (isteacher($course)) { + if has_capability('mod/quiz:grade', get_context_instance(CONTEXT_MODULE, $course)) { $grades = "(" . $activity->content->sumgrades . " / " . $activity->content->maxgrade . ") "; echo "wwwroot/mod/quiz/review.php?q=" . $activity->instance . "&attempt=" diff --git a/mod/quiz/quizfile.php b/mod/quiz/quizfile.php index 0f5cb70d5a..5ba5477078 100644 --- a/mod/quiz/quizfile.php +++ b/mod/quiz/quizfile.php @@ -49,9 +49,8 @@ } } else { require_login($questioncategory->course); - if (!isteacher($questioncategory->course)) { - error('Access not allowed'); - } + $cm = get_coursemodule_from_instance('quiz', $quizid); + require_capability('mod/quiz:preview', get_context_instance(CONTEXT_MODULE, $cm->id)); } } else { if (!($quiz = get_record('quiz', 'id', $quizid))) { diff --git a/mod/quiz/restorelibpre15.php b/mod/quiz/restorelibpre15.php index 5c33d76c57..823d1d2165 100644 --- a/mod/quiz/restorelibpre15.php +++ b/mod/quiz/restorelibpre15.php @@ -1494,7 +1494,8 @@ $attempt->layout = $quizquestions; //Set the preview field (code from upgrade) - if (isteacher($restore->course_id,$attempt->userid)) { + $cm = get_coursemodule_from_instance('quiz', $quiz_id); + if (has_capability('mod/quiz:preview', get_context_instance(CONTEXT_MODULE, $cm->id))) { $attempt->preview = 1; } diff --git a/mod/quiz/review.php b/mod/quiz/review.php index d4dcb460ff..9230a36116 100644 --- a/mod/quiz/review.php +++ b/mod/quiz/review.php @@ -42,7 +42,7 @@ require_login($course->id, false, $cm); $context = get_context_instance(CONTEXT_MODULE, $cm->id); $coursecontext = get_context_instance(CONTEXT_COURSE, $cm->course); - $isteacher = isteacher($course->id); + $isteacher = has_capability('mod/quiz:preview', get_context_instance(CONTEXT_MODULE, $cm->id)); $options = quiz_get_reviewoptions($quiz, $attempt, $context); $popup = $isteacher ? 0 : $quiz->popup; // Controls whether this is shown in a javascript-protected window. -- 2.39.5