Merge branch 'wip-MDL-51486-master' of git://github.com/abgreeve/moodle
authorAndrew Nicols <andrew@nicols.co.uk>
Wed, 4 Nov 2015 03:35:38 +0000 (11:35 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Wed, 4 Nov 2015 03:35:38 +0000 (11:35 +0800)
mod/data/lib.php
mod/data/tests/lib_test.php

index 20079f2..f4eaaa6 100644 (file)
@@ -1566,6 +1566,11 @@ function mod_data_rating_can_see_item_ratings($params) {
         throw new rating_exception('invaliditemid');
     }
 
+    // User can see ratings of all participants.
+    if ($info->groupid == 0) {
+        return true;
+    }
+
     $course = $DB->get_record('course', array('id' => $info->course), '*', MUST_EXIST);
     $cm = get_coursemodule_from_instance('data', $info->dataid, $course->id, false, MUST_EXIST);
 
index a723222..7d87cde 100644 (file)
@@ -544,6 +544,16 @@ class mod_data_lib_testcase extends advanced_testcase {
 
         $field->define_field($fielddetail);
         $field->insert_field();
+
+        // Add a record with a group id of zero (all participants).
+        $recordid1 = data_add_record($data, 0);
+
+        $datacontent = array();
+        $datacontent['fieldid'] = $field->field->id;
+        $datacontent['recordid'] = $recordid1;
+        $datacontent['content'] = 'Obelix';
+        $DB->insert_record('data_content', $datacontent);
+
         $recordid = data_add_record($data, $group1->id);
 
         $datacontent = array();
@@ -554,30 +564,46 @@ class mod_data_lib_testcase extends advanced_testcase {
 
         // Now try to access it as various users.
         unassign_capability('moodle/site:accessallgroups', $role->id);
+        // Eveyone should have access to the record with the group id of zero.
+        $params1 = array('contextid' => 2,
+                        'component' => 'mod_data',
+                        'ratingarea' => 'entry',
+                        'itemid' => $recordid1,
+                        'scaleid' => 2);
+
         $params = array('contextid' => 2,
                         'component' => 'mod_data',
                         'ratingarea' => 'entry',
                         'itemid' => $recordid,
                         'scaleid' => 2);
+
         $this->setUser($user1);
         $this->assertTrue(mod_data_rating_can_see_item_ratings($params));
+        $this->assertTrue(mod_data_rating_can_see_item_ratings($params1));
         $this->setUser($user2);
         $this->assertTrue(mod_data_rating_can_see_item_ratings($params));
+        $this->assertTrue(mod_data_rating_can_see_item_ratings($params1));
         $this->setUser($user3);
         $this->assertFalse(mod_data_rating_can_see_item_ratings($params));
+        $this->assertTrue(mod_data_rating_can_see_item_ratings($params1));
         $this->setUser($user4);
         $this->assertFalse(mod_data_rating_can_see_item_ratings($params));
+        $this->assertTrue(mod_data_rating_can_see_item_ratings($params1));
 
         // Now try with accessallgroups cap and make sure everything is visible.
         assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $role->id, $context->id);
         $this->setUser($user1);
         $this->assertTrue(mod_data_rating_can_see_item_ratings($params));
+        $this->assertTrue(mod_data_rating_can_see_item_ratings($params1));
         $this->setUser($user2);
         $this->assertTrue(mod_data_rating_can_see_item_ratings($params));
+        $this->assertTrue(mod_data_rating_can_see_item_ratings($params1));
         $this->setUser($user3);
         $this->assertTrue(mod_data_rating_can_see_item_ratings($params));
+        $this->assertTrue(mod_data_rating_can_see_item_ratings($params1));
         $this->setUser($user4);
         $this->assertTrue(mod_data_rating_can_see_item_ratings($params));
+        $this->assertTrue(mod_data_rating_can_see_item_ratings($params1));
 
         // Change group mode and verify visibility.
         $course->groupmode = VISIBLEGROUPS;
@@ -585,12 +611,16 @@ class mod_data_lib_testcase extends advanced_testcase {
         unassign_capability('moodle/site:accessallgroups', $role->id);
         $this->setUser($user1);
         $this->assertTrue(mod_data_rating_can_see_item_ratings($params));
+        $this->assertTrue(mod_data_rating_can_see_item_ratings($params1));
         $this->setUser($user2);
         $this->assertTrue(mod_data_rating_can_see_item_ratings($params));
+        $this->assertTrue(mod_data_rating_can_see_item_ratings($params1));
         $this->setUser($user3);
         $this->assertTrue(mod_data_rating_can_see_item_ratings($params));
+        $this->assertTrue(mod_data_rating_can_see_item_ratings($params1));
         $this->setUser($user4);
         $this->assertTrue(mod_data_rating_can_see_item_ratings($params));
+        $this->assertTrue(mod_data_rating_can_see_item_ratings($params1));
 
     }
 }