diff --git a/mod/lesson/db/access.php b/mod/lesson/db/access.php index 4da9931c6be..9e658dc4a48 100644 --- a/mod/lesson/db/access.php +++ b/mod/lesson/db/access.php @@ -52,6 +52,18 @@ $capabilities = array( ) ), + // Grade essay questions. + 'mod/lesson:grade' => array( + 'riskbitmask' => RISK_SPAM, + 'captype' => 'write', + 'contextlevel' => CONTEXT_MODULE, + 'archetypes' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ) + ), + 'mod/lesson:manage' => array( 'captype' => 'write', diff --git a/mod/lesson/essay.php b/mod/lesson/essay.php index 3026e20b9a5..11e58a40623 100644 --- a/mod/lesson/essay.php +++ b/mod/lesson/essay.php @@ -38,7 +38,7 @@ $lesson = new lesson($dblesson); require_login($course, false, $cm); $context = context_module::instance($cm->id); -require_capability('mod/lesson:edit', $context); +require_capability('mod/lesson:grade', $context); $url = new moodle_url('/mod/lesson/essay.php', array('id'=>$id)); if ($mode !== 'display') { diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php index fe2923dc83e..7bab80f8d5c 100644 --- a/mod/lesson/lib.php +++ b/mod/lesson/lib.php @@ -773,12 +773,10 @@ function lesson_supports($feature) { function lesson_extend_settings_navigation($settings, $lessonnode) { global $PAGE, $DB; - $canedit = has_capability('mod/lesson:edit', $PAGE->cm->context); - $url = new moodle_url('/mod/lesson/view.php', array('id'=>$PAGE->cm->id)); $lessonnode->add(get_string('preview', 'lesson'), $url); - if ($canedit) { + if (has_capability('mod/lesson:edit', $PAGE->cm->context)) { $url = new moodle_url('/mod/lesson/edit.php', array('id'=>$PAGE->cm->id)); $lessonnode->add(get_string('edit', 'lesson'), $url); } @@ -791,7 +789,7 @@ function lesson_extend_settings_navigation($settings, $lessonnode) { $reportsnode->add(get_string('detailedstats', 'lesson'), $url); } - if ($canedit) { + if (has_capability('mod/lesson:grade', $PAGE->cm->context)) { $url = new moodle_url('/mod/lesson/essay.php', array('id'=>$PAGE->cm->id)); $lessonnode->add(get_string('manualgrading', 'lesson'), $url); } diff --git a/mod/lesson/tabs.php b/mod/lesson/tabs.php index f804279b643..89263af1adc 100644 --- a/mod/lesson/tabs.php +++ b/mod/lesson/tabs.php @@ -51,7 +51,7 @@ $attemptscount = $DB->count_records('lesson_grades', array('lessonid'=>$lesson-> $row[] = new tabobject('view', "$CFG->wwwroot/mod/lesson/view.php?id=$cm->id", get_string('preview', 'lesson'), get_string('previewlesson', 'lesson', format_string($lesson->name))); $row[] = new tabobject('edit', "$CFG->wwwroot/mod/lesson/edit.php?id=$cm->id", get_string('edit', 'lesson'), get_string('edita', 'moodle', format_string($lesson->name))); $row[] = new tabobject('reports', "$CFG->wwwroot/mod/lesson/report.php?id=$cm->id", get_string('reports', 'lesson'), get_string('viewreports2', 'lesson', $attemptscount)); -if (has_capability('mod/lesson:edit', $context)) { +if (has_capability('mod/lesson:grade', $context)) { $row[] = new tabobject('essay', "$CFG->wwwroot/mod/lesson/essay.php?id=$cm->id", get_string('manualgrading', 'lesson')); } if ($lesson->highscores) { diff --git a/mod/lesson/tests/behat/teacher_grade_essays.feature b/mod/lesson/tests/behat/teacher_grade_essays.feature new file mode 100644 index 00000000000..e6068b55b14 --- /dev/null +++ b/mod/lesson/tests/behat/teacher_grade_essays.feature @@ -0,0 +1,57 @@ +@mod @mod_lesson +Feature: In a lesson activity, a non editing teacher can grade essay questions + As a non editing teacher + I need to grade student answers to essay questions in lesson + + @javascript + Scenario: non editing teacher grade essay questions + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@asd.com | + | teacher2 | Teacher | 2 | teacher2@asd.com | + | student1 | Student | 1 | student1@asd.com | + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | teacher2 | C1 | teacher | + | student1 | C1 | student | + And I log in as "teacher1" + And I am on homepage + And I follow "Course 1" + And I turn editing mode on + And I add a "Lesson" to section "1" and I fill the form with: + | Name | Test lesson name | + | Description | Test lesson description | + And I follow "Test lesson name" + And I follow "Add a question page" + And I set the field "Select a question type" to "Essay" + And I press "Add a question page" + And I set the following fields to these values: + | Page title | Essay question | + | Page contents |

Please write a story about a frog.

| + And I press "Save page" + And I log out + And I log in as "student1" + And I follow "Course 1" + And I follow "Test lesson name" + And I set the field "Your answer" to "

Once upon a time there was a little green frog." + And I press "Submit" + And I log out + When I log in as "teacher2" + And I follow "Course 1" + And I follow "Test lesson name" + Then I should see "Grade essays" + And I follow "Grade essays" + And I should see "Student 1" + And I should see "Essay question" + And I follow "Essay question" + And I should see "Student 1's response" + And I should see "Once upon a time there was a little green frog." + And I set the following fields to these values: + | Your comments | Well done. | + | Essay score | 1 | + And I press "Save changes" + And I should see "Changes saved" diff --git a/mod/lesson/version.php b/mod/lesson/version.php index 110187435d6..9c2e2b0c321 100644 --- a/mod/lesson/version.php +++ b/mod/lesson/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2014100600; // The current module version (Date: YYYYMMDDXX) +$plugin->version = 2014101600; // The current module version (Date: YYYYMMDDXX) $plugin->requires = 2014050800; // Requires this Moodle version $plugin->component = 'mod_lesson'; // Full name of the plugin (used for diagnostics) $plugin->cron = 0;