From cbc028dbae479bafba78ddfe4a31c805fc27562a Mon Sep 17 00:00:00 2001 From: Jean-Michel Vedrine Date: Thu, 27 Nov 2014 21:29:30 +0100 Subject: [PATCH] MDL-36877 Lesson: final page not displayed if show gradebook set to no --- .../tests/behat/link_to_gradebook.feature | 103 ++++++++++++++++++ mod/lesson/view.php | 9 +- 2 files changed, 105 insertions(+), 7 deletions(-) create mode 100644 mod/lesson/tests/behat/link_to_gradebook.feature diff --git a/mod/lesson/tests/behat/link_to_gradebook.feature b/mod/lesson/tests/behat/link_to_gradebook.feature new file mode 100644 index 00000000000..9c66d7e4fea --- /dev/null +++ b/mod/lesson/tests/behat/link_to_gradebook.feature @@ -0,0 +1,103 @@ +@mod @mod_lesson +Feature: link to gradebook on the end of lesson page + In order to allow students to see their lesson grades + As a teacher + I need to provide a link to gradebook on the end of lesson page + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@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 | + | student1 | C1 | student | + And I log in as "teacher1" + And I follow "Course 1" + And I turn editing mode on + And I click on "Edit settings" "link" in the "Administration" "block" + And I set the following fields to these values: + | Show gradebook to students | No | + And I press "Save changes" + And I add a "Lesson" to section "1" and I fill the form with: + | Name | Test lesson | + | Description | Test lesson description | + And I follow "Test lesson" + And I follow "Add a content page" + And I set the following fields to these values: + | Page title | First page name | + | Page contents | First page contents | + | id_answer_editor_0 | Next page | + | id_jumpto_0 | Next page | + And I press "Save page" + And I set the field "qtype" to "Add a content page" + And I set the following fields to these values: + | Page title | Second page name | + | Page contents | Second page contents | + | id_answer_editor_0 | Previous page | + | id_jumpto_0 | Previous page | + | id_answer_editor_1 | Next page | + | id_jumpto_1 | Next page | + And I press "Save page" + @javascript + Scenario: Link to gradebook for non practice lesson + Given I log out + When I log in as "student1" + And I follow "Course 1" + And I follow "Test lesson" + And I press "Next page" + And I press "Next page" + Then I should see "Congratulations - end of lesson reached" + And I should see "View grades" + + @javascript + Scenario: No link to gradebook for non graded lesson + Given I follow "Test lesson" + And I navigate to "Edit settings" node in "Lesson administration" + And I set the following fields to these values: + | Type | None | + And I press "Save and display" + And I log out + When I log in as "student1" + And I follow "Course 1" + And I follow "Test lesson" + And I press "Next page" + And I press "Next page" + Then I should see "Congratulations - end of lesson reached" + And I should not see "View grades" + + @javascript + Scenario: No link to gradebook for practice lesson + Given I follow "Test lesson" + And I navigate to "Edit settings" node in "Lesson administration" + And I set the following fields to these values: + | Practice lesson | Yes | + And I press "Save and display" + And I log out + When I log in as "student1" + And I follow "Course 1" + And I follow "Test lesson" + And I press "Next page" + And I press "Next page" + Then I should see "Congratulations - end of lesson reached" + And I should not see "View grades" + + @javascript + Scenario: No link to gradebook if no gradereport/user:view capability + Given I log out + And I log in as "admin" + And I set the following system permissions of "Student" role: + | capability | permission | + | gradereport/user:view | Prevent | + And I log out + When I log in as "student1" + And I follow "Course 1" + And I follow "Test lesson" + And I press "Next page" + And I press "Next page" + Then I should see "Congratulations - end of lesson reached" + And I should not see "View grades" \ No newline at end of file diff --git a/mod/lesson/view.php b/mod/lesson/view.php index 1006825af75..046dbc99080 100644 --- a/mod/lesson/view.php +++ b/mod/lesson/view.php @@ -503,12 +503,6 @@ if ($pageid != LESSON_EOL) { } $lessoncontent .= $OUTPUT->box_end(); //End of Lesson button to Continue. - // after all the grade processing, check to see if "Show Grades" is off for the course - // if yes, redirect to the course page - if (!$course->showgrades) { - redirect(new moodle_url('/course/view.php', array('id'=>$course->id))); - } - // high scores code if ($lesson->highscores && !$canmanage && !$lesson->practice) { $lessoncontent .= $OUTPUT->box_start('center'); @@ -574,7 +568,8 @@ if ($pageid != LESSON_EOL) { $url = new moodle_url('/course/view.php', array('id'=>$course->id)); $lessoncontent .= html_writer::link($url, get_string('returnto', 'lesson', format_string($course->fullname, true)), array('class'=>'centerpadded lessonbutton standardbutton')); - if (!$lesson->practice) { + if (has_capability('gradereport/user:view', context_course::instance($course->id)) + && $lesson->grade != 0 && !$lesson->practice) { $url = new moodle_url('/grade/index.php', array('id' => $course->id)); $lessoncontent .= html_writer::link($url, get_string('viewgrades', 'lesson'), array('class' => 'centerpadded lessonbutton standardbutton'));