MDL-52378 singleview: Using is_disabled instead of is_locked
authorDavid Monllao <davidm@moodle.com>
Thu, 4 Feb 2016 08:17:40 +0000 (16:17 +0800)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 7 Mar 2016 22:04:52 +0000 (23:04 +0100)
grade/report/singleview/classes/local/screen/screen.php
grade/report/singleview/classes/local/screen/tablelike.php
grade/report/singleview/classes/local/ui/exclude.php
grade/report/singleview/tests/behat/singleview.feature

index 9e7ba7c..7c97600 100644 (file)
@@ -329,7 +329,7 @@ abstract class screen {
                 continue;
             }
 
-            // If the user submits Exclude grade elements without the proper 
+            // If the user submits Exclude grade elements without the proper.
             // permissions then we should refuse to update.
             if ($matches[1] === 'exclude' && !has_capability('moodle/grade:manage', $this->context)){
                 $warnings[] = get_string('nopermissions', 'error', get_string('grade:manage', 'role'));
index 2d7835d..5e5054f 100644 (file)
@@ -144,7 +144,7 @@ abstract class tablelike extends screen {
             // Singleview users without proper permissions should be presented
             // disabled checkboxes for the Exclude grade attribute.
             if ($field == 'exclude' && !has_capability('moodle/grade:manage', $this->context)){
-                $html->locked=TRUE;
+                $html->disabled = true;
             }
 
             $line[] = $html;
index 73440b5..62f7780 100644 (file)
@@ -35,13 +35,13 @@ use grade_grade;
  * @copyright 2014 Moodle Pty Ltd (http://moodle.com)
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class exclude extends grade_attribute_format implements be_checked {
+class exclude extends grade_attribute_format implements be_checked, be_disabled {
 
     /** @var string $name The name of the input */
     public $name = 'exclude';
 
-    /** @var bool $locked Is the input locked? */
-    public $locked = FALSE;
+    /** @var bool $disabled Is the checkbox disabled? */
+    public $disabled = false;
 
     /**
      * Is it checked?
@@ -53,12 +53,12 @@ class exclude extends grade_attribute_format implements be_checked {
     }
 
     /**
-     * Is it locked?
+     * Is it disabled?
      *
      * @return bool
      */
-    public function is_locked() {
-        return $this->locked;
+    public function is_disabled() {
+        return $this->disabled;
     }
 
     /**
@@ -71,8 +71,7 @@ class exclude extends grade_attribute_format implements be_checked {
             $this->get_name(),
             $this->get_label(),
             $this->is_checked(),
-            // Call checkbox constructor with locked attribute, expects integer.
-            $this->is_locked() ? 1 : 0  
+            $this->is_disabled()
         );
     }
 
index f12404d..22aba02 100644 (file)
@@ -11,6 +11,7 @@ Feature: We can use Single view
     And the following "users" exist:
       | username | firstname | lastname | email | idnumber | alternatename |
       | teacher1 | Teacher | 1 | teacher1@example.com | t1 | fred |
+      | teacher2 | No edit | 1 | teacher2@example.com | t2 | nick |
       | student1 | Student | 1 | student1@example.com | s1 | james |
       | student2 | Student | 2 | student1@example.com | s2 | holly |
       | student3 | Student | 3 | student1@example.com | s3 | anna |
@@ -27,6 +28,7 @@ Feature: We can use Single view
     And the following "course enrolments" exist:
       | user | course | role |
       | teacher1 | C1 | editingteacher |
+      | teacher2 | C1 | teacher |
       | student1 | C1 | student |
       | student2 | C1 | student |
       | student3 | C1 | student |
@@ -44,6 +46,10 @@ Feature: We can use Single view
     And the following "grade items" exist:
       | itemname | course | gradetype |
       | Test grade item | C1 | Scale |
+    And the following "permission overrides" exist:
+      | capability                  | permission | role     | contextlevel  | reference |
+      | moodle/grade:edit           | Allow      | teacher  | Course        | C1        |
+      | gradereport/singleview:view | Allow      | teacher  | Course        | C1        |
     And I log in as "teacher1"
     And I follow "Course 1"
     And I navigate to "Grades" node in "Course administration"
@@ -88,6 +94,14 @@ Feature: We can use Single view
     And the following should exist in the "generaltable" table:
         | First name (Alternate name) Surname | Grade |
         | james (Student) 1 | Very good |
+    And I log out
+    And I log in as "teacher2"
+    And I follow "Course 1"
+    And I navigate to "Grades" node in "Course administration"
+    And I click on "Single view" "option"
+    And I click on "Student 4" "option"
+    And the "Exclude for Test assignment one" "checkbox" should be disabled
+    And the "Override for Test assignment one" "checkbox" should be enabled
 
   Scenario: Single view links work on grade report.
     Given I follow "Single view for Test assignment one"