MDL-42716 Assign: Implemented capability based viewing of blind details (squashed)
authorMichael Hughes <michael@phoenixproductions.org.uk>
Wed, 16 Apr 2014 13:18:33 +0000 (14:18 +0100)
committerMarina Glancy <marina@moodle.com>
Tue, 24 Jun 2014 04:27:10 +0000 (12:27 +0800)
mod/assign/db/access.php
mod/assign/gradingtable.php
mod/assign/locallib.php
mod/assign/tests/locallib_test.php
mod/assign/version.php

index 89815ab..f61579c 100644 (file)
@@ -159,6 +159,15 @@ $capabilities = array(
         )
     ),
 
+    'mod/assign:viewblinddetails' => array(
+        'riskbitmask' => RISK_PERSONAL,
+
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_MODULE,
+        'archetypes' => array(
+            'manager' => CAP_ALLOW
+        )
+    ),
 
 );
 
index 522dfa3..5506a6b 100644 (file)
@@ -90,6 +90,10 @@ class assign_grading_table extends table_sql implements renderable {
                                                   $this->assignment->get_context());
         $this->hasgrade = $this->assignment->can_grade();
 
+        // Check if we have the elevated view capablities to see the blind details.
+        $this->hasviewblind = has_capability('mod/assign:viewblinddetails',
+                $this->assignment->get_context());
+
         foreach ($assignment->get_feedback_plugins() as $plugin) {
             if ($plugin->is_visible() && $plugin->is_enabled()) {
                 foreach ($plugin->get_grading_batch_operations() as $action => $description) {
@@ -249,7 +253,7 @@ class assign_grading_table extends table_sql implements renderable {
         }
 
         // User picture.
-        if (!$this->assignment->is_blind_marking()) {
+        if ($this->hasviewblind || !$this->assignment->is_blind_marking()) {
             if (!$this->is_downloading()) {
                 $columns[] = 'picture';
                 $headers[] = get_string('pictureofuser');
@@ -272,6 +276,11 @@ class assign_grading_table extends table_sql implements renderable {
             $headers[] = get_string('recordid', 'assign');
         }
 
+        if ($this->hasviewblind) {
+                $columns[] = 'recordid';
+                $headers[] = get_string('recordid', 'assign');
+        }
+
         // Submission status.
         if ($assignment->is_any_submission_plugin_enabled()) {
             $columns[] = 'status';
index 9c323eb..f0e99ec 100644 (file)
@@ -3243,8 +3243,13 @@ class assign {
      */
     public function fullname($user) {
         if ($this->is_blind_marking()) {
-            $uniqueid = $this->get_uniqueid_for_user($user->id);
-            return get_string('participant', 'assign') . ' ' . $uniqueid;
+            $hasviewblind = has_capability('mod/assign:viewblinddetails', $this->get_context());
+            if ($hasviewblind) {\r
+                return fullname($user);\r
+            } else {
+                $uniqueid = $this->get_uniqueid_for_user($user->id);
+                return get_string('participant', 'assign') . ' ' . $uniqueid;
+            }
         } else {
             return fullname($user);
         }
index de3103a..d72f615 100644 (file)
@@ -1475,5 +1475,46 @@ Anchor link 2:<a title=\"bananas\" href=\"../logo-240x60.gif\">Link text</a>
         $this->assertTrue($assign->can_edit_submission($this->students[0]->id, $this->extrastudents[0]->id));
 
     }
+
+    /**
+     * Test if the view blind details capability works
+     */
+    public function test_can_view_blind_details() {
+        global $PAGE, $DB;
+        $teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
+        $managerrole = $DB->get_record('role', array('shortname' => 'manager'));
+
+        $student = $this->students[0];// Get a student user.
+        // Create a teacher. Shouldn't be able to view blind marking ID.
+        $teacher = $this->getDataGenerator()->create_user();
+
+        $this->getDataGenerator()->enrol_user($teacher->id,
+                                              $this->course->id,
+                                              $teacherrole->id);
+
+        // Create a manager.. Should be able to view blind marking ID.
+        $manager = $this->getDataGenerator()->create_user();
+        $this->getDataGenerator()->enrol_user($manager->id,\r
+                $this->course->id,\r
+                $managerrole->id);
+
+        // Generate blind marking assignment.
+        $assign = $this->create_instance(array('blindmarking' => 1));\r
+        $this->assertEquals(true, $assign->is_blind_marking());
+
+        // Test student names are hidden to teacher.
+        $this->setUser($teacher);\r
+        $gradingtable = new assign_grading_table($assign, 1, '', 0, true);\r
+        $output = $assign->get_renderer()->render($gradingtable);\r
+        $this->assertEquals(true, strpos($output, get_string('hiddenuser', 'assign')));    // "Participant" is somewhere on the page.
+        $this->assertEquals(false, strpos($output, fullname($student)));    // Students full name doesn't appear.
+
+        // Test student names are visible to manager.
+        $this->setUser($manager);\r
+        $gradingtable = new assign_grading_table($assign, 1, '', 0, true);\r
+        $output = $assign->get_renderer()->render($gradingtable);\r
+        $this->assertEquals(true, strpos($output, get_string('hiddenuser', 'assign')));
+        $this->assertEquals(true, strpos($output, fullname($student)));    //students full name doesn't appear.
+    }
 }
 
index 5c74a7a..447e4b0 100644 (file)
@@ -25,7 +25,7 @@
 defined('MOODLE_INTERNAL') || die();
 
 $plugin->component = 'mod_assign'; // Full name of the plugin (used for diagnostics).
-$plugin->version  = 2014051201;    // The current module version (Date: YYYYMMDDXX).
+$plugin->version  = 2014051204;    // The current module version (Date: YYYYMMDDXX).
 $plugin->requires = 2014050800;    // Requires this Moodle version.
 $plugin->cron     = 60;