mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-58784 mod_glossary: student can see his entries before approval
This commit is contained in:
parent
48ad73619f
commit
7b14c50bb0
2 changed files with 19 additions and 7 deletions
|
@ -658,7 +658,7 @@ function mod_glossary_get_tagged_entries($tag, $exclusivemode = false, $fromctx
|
||||||
|
|
||||||
// Build the SQL query.
|
// Build the SQL query.
|
||||||
$ctxselect = context_helper::get_preload_record_columns_sql('ctx');
|
$ctxselect = context_helper::get_preload_record_columns_sql('ctx');
|
||||||
$query = "SELECT ge.id, ge.concept, ge.glossaryid, ge.approved,
|
$query = "SELECT ge.id, ge.concept, ge.glossaryid, ge.approved, ge.userid,
|
||||||
cm.id AS cmid, c.id AS courseid, c.shortname, c.fullname, $ctxselect
|
cm.id AS cmid, c.id AS courseid, c.shortname, c.fullname, $ctxselect
|
||||||
FROM {glossary_entries} ge
|
FROM {glossary_entries} ge
|
||||||
JOIN {glossary} g ON g.id = ge.glossaryid
|
JOIN {glossary} g ON g.id = ge.glossaryid
|
||||||
|
@ -705,11 +705,14 @@ function mod_glossary_get_tagged_entries($tag, $exclusivemode = false, $fromctx
|
||||||
$modinfo = get_fast_modinfo($builder->get_course($courseid));
|
$modinfo = get_fast_modinfo($builder->get_course($courseid));
|
||||||
// Set accessibility of this item and all other items in the same course.
|
// Set accessibility of this item and all other items in the same course.
|
||||||
$builder->walk(function ($taggeditem) use ($courseid, $modinfo, $builder) {
|
$builder->walk(function ($taggeditem) use ($courseid, $modinfo, $builder) {
|
||||||
|
global $USER;
|
||||||
if ($taggeditem->courseid == $courseid) {
|
if ($taggeditem->courseid == $courseid) {
|
||||||
$accessible = false;
|
$accessible = false;
|
||||||
if (($cm = $modinfo->get_cm($taggeditem->cmid)) && $cm->uservisible) {
|
if (($cm = $modinfo->get_cm($taggeditem->cmid)) && $cm->uservisible) {
|
||||||
if ($taggeditem->approved) {
|
if ($taggeditem->approved) {
|
||||||
$accessible = true;
|
$accessible = true;
|
||||||
|
} else if ($taggeditem->userid == $USER->id) {
|
||||||
|
$accessible = true;
|
||||||
} else {
|
} else {
|
||||||
$accessible = has_capability('mod/glossary:approve', context_module::instance($cm->id));
|
$accessible = has_capability('mod/glossary:approve', context_module::instance($cm->id));
|
||||||
}
|
}
|
||||||
|
|
|
@ -245,6 +245,14 @@ class mod_glossary_lib_testcase extends advanced_testcase {
|
||||||
$course3 = $this->getDataGenerator()->create_course();
|
$course3 = $this->getDataGenerator()->create_course();
|
||||||
$course2 = $this->getDataGenerator()->create_course();
|
$course2 = $this->getDataGenerator()->create_course();
|
||||||
$course1 = $this->getDataGenerator()->create_course();
|
$course1 = $this->getDataGenerator()->create_course();
|
||||||
|
|
||||||
|
// Create and enrol a student.
|
||||||
|
$student = self::getDataGenerator()->create_user();
|
||||||
|
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
|
||||||
|
$this->getDataGenerator()->enrol_user($student->id, $course1->id, $studentrole->id, 'manual');
|
||||||
|
$this->getDataGenerator()->enrol_user($student->id, $course2->id, $studentrole->id, 'manual');
|
||||||
|
|
||||||
|
// Create glossaries and entries.
|
||||||
$glossary1 = $this->getDataGenerator()->create_module('glossary', array('course' => $course1->id));
|
$glossary1 = $this->getDataGenerator()->create_module('glossary', array('course' => $course1->id));
|
||||||
$glossary2 = $this->getDataGenerator()->create_module('glossary', array('course' => $course2->id));
|
$glossary2 = $this->getDataGenerator()->create_module('glossary', array('course' => $course2->id));
|
||||||
$glossary3 = $this->getDataGenerator()->create_module('glossary', array('course' => $course3->id));
|
$glossary3 = $this->getDataGenerator()->create_module('glossary', array('course' => $course3->id));
|
||||||
|
@ -254,6 +262,7 @@ class mod_glossary_lib_testcase extends advanced_testcase {
|
||||||
$entry14 = $glossarygenerator->create_content($glossary1);
|
$entry14 = $glossarygenerator->create_content($glossary1);
|
||||||
$entry15 = $glossarygenerator->create_content($glossary1, array('tags' => array('Cats')));
|
$entry15 = $glossarygenerator->create_content($glossary1, array('tags' => array('Cats')));
|
||||||
$entry16 = $glossarygenerator->create_content($glossary1, array('tags' => array('Cats'), 'approved' => false));
|
$entry16 = $glossarygenerator->create_content($glossary1, array('tags' => array('Cats'), 'approved' => false));
|
||||||
|
$entry17 = $glossarygenerator->create_content($glossary1, array('tags' => array('Cats'), 'approved' => false, 'userid' => $student->id));
|
||||||
$entry21 = $glossarygenerator->create_content($glossary2, array('tags' => array('Cats')));
|
$entry21 = $glossarygenerator->create_content($glossary2, array('tags' => array('Cats')));
|
||||||
$entry22 = $glossarygenerator->create_content($glossary2, array('tags' => array('Cats', 'Dogs')));
|
$entry22 = $glossarygenerator->create_content($glossary2, array('tags' => array('Cats', 'Dogs')));
|
||||||
$entry23 = $glossarygenerator->create_content($glossary2, array('tags' => array('mice', 'Cats')));
|
$entry23 = $glossarygenerator->create_content($glossary2, array('tags' => array('mice', 'Cats')));
|
||||||
|
@ -262,6 +271,7 @@ class mod_glossary_lib_testcase extends advanced_testcase {
|
||||||
$tag = core_tag_tag::get_by_name(0, 'Cats');
|
$tag = core_tag_tag::get_by_name(0, 'Cats');
|
||||||
|
|
||||||
// Admin can see everything.
|
// Admin can see everything.
|
||||||
|
// Get first page of tagged entries (first 5 entries).
|
||||||
$res = mod_glossary_get_tagged_entries($tag, /*$exclusivemode = */false,
|
$res = mod_glossary_get_tagged_entries($tag, /*$exclusivemode = */false,
|
||||||
/*$fromctx = */0, /*$ctx = */0, /*$rec = */1, /*$entry = */0);
|
/*$fromctx = */0, /*$ctx = */0, /*$rec = */1, /*$entry = */0);
|
||||||
$this->assertRegExp('/'.$entry11->concept.'</', $res->content);
|
$this->assertRegExp('/'.$entry11->concept.'</', $res->content);
|
||||||
|
@ -270,12 +280,14 @@ class mod_glossary_lib_testcase extends advanced_testcase {
|
||||||
$this->assertNotRegExp('/'.$entry14->concept.'</', $res->content);
|
$this->assertNotRegExp('/'.$entry14->concept.'</', $res->content);
|
||||||
$this->assertRegExp('/'.$entry15->concept.'</', $res->content);
|
$this->assertRegExp('/'.$entry15->concept.'</', $res->content);
|
||||||
$this->assertRegExp('/'.$entry16->concept.'</', $res->content);
|
$this->assertRegExp('/'.$entry16->concept.'</', $res->content);
|
||||||
|
$this->assertNotRegExp('/'.$entry17->concept.'</', $res->content);
|
||||||
$this->assertNotRegExp('/'.$entry21->concept.'</', $res->content);
|
$this->assertNotRegExp('/'.$entry21->concept.'</', $res->content);
|
||||||
$this->assertNotRegExp('/'.$entry22->concept.'</', $res->content);
|
$this->assertNotRegExp('/'.$entry22->concept.'</', $res->content);
|
||||||
$this->assertNotRegExp('/'.$entry23->concept.'</', $res->content);
|
$this->assertNotRegExp('/'.$entry23->concept.'</', $res->content);
|
||||||
$this->assertNotRegExp('/'.$entry31->concept.'</', $res->content);
|
$this->assertNotRegExp('/'.$entry31->concept.'</', $res->content);
|
||||||
$this->assertEmpty($res->prevpageurl);
|
$this->assertEmpty($res->prevpageurl);
|
||||||
$this->assertNotEmpty($res->nextpageurl);
|
$this->assertNotEmpty($res->nextpageurl);
|
||||||
|
// Get second page of tagged entries (second 5 entries).
|
||||||
$res = mod_glossary_get_tagged_entries($tag, /*$exclusivemode = */false,
|
$res = mod_glossary_get_tagged_entries($tag, /*$exclusivemode = */false,
|
||||||
/*$fromctx = */0, /*$ctx = */0, /*$rec = */1, /*$entry = */1);
|
/*$fromctx = */0, /*$ctx = */0, /*$rec = */1, /*$entry = */1);
|
||||||
$this->assertNotRegExp('/'.$entry11->concept.'</', $res->content);
|
$this->assertNotRegExp('/'.$entry11->concept.'</', $res->content);
|
||||||
|
@ -284,6 +296,7 @@ class mod_glossary_lib_testcase extends advanced_testcase {
|
||||||
$this->assertNotRegExp('/'.$entry14->concept.'</', $res->content);
|
$this->assertNotRegExp('/'.$entry14->concept.'</', $res->content);
|
||||||
$this->assertNotRegExp('/'.$entry15->concept.'</', $res->content);
|
$this->assertNotRegExp('/'.$entry15->concept.'</', $res->content);
|
||||||
$this->assertNotRegExp('/'.$entry16->concept.'</', $res->content);
|
$this->assertNotRegExp('/'.$entry16->concept.'</', $res->content);
|
||||||
|
$this->assertRegExp('/'.$entry17->concept.'</', $res->content);
|
||||||
$this->assertRegExp('/'.$entry21->concept.'</', $res->content);
|
$this->assertRegExp('/'.$entry21->concept.'</', $res->content);
|
||||||
$this->assertRegExp('/'.$entry22->concept.'</', $res->content);
|
$this->assertRegExp('/'.$entry22->concept.'</', $res->content);
|
||||||
$this->assertRegExp('/'.$entry23->concept.'</', $res->content);
|
$this->assertRegExp('/'.$entry23->concept.'</', $res->content);
|
||||||
|
@ -291,11 +304,6 @@ class mod_glossary_lib_testcase extends advanced_testcase {
|
||||||
$this->assertNotEmpty($res->prevpageurl);
|
$this->assertNotEmpty($res->prevpageurl);
|
||||||
$this->assertEmpty($res->nextpageurl);
|
$this->assertEmpty($res->nextpageurl);
|
||||||
|
|
||||||
// Create and enrol a user.
|
|
||||||
$student = self::getDataGenerator()->create_user();
|
|
||||||
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
|
|
||||||
$this->getDataGenerator()->enrol_user($student->id, $course1->id, $studentrole->id, 'manual');
|
|
||||||
$this->getDataGenerator()->enrol_user($student->id, $course2->id, $studentrole->id, 'manual');
|
|
||||||
$this->setUser($student);
|
$this->setUser($student);
|
||||||
core_tag_index_builder::reset_caches();
|
core_tag_index_builder::reset_caches();
|
||||||
|
|
||||||
|
@ -320,7 +328,8 @@ class mod_glossary_lib_testcase extends advanced_testcase {
|
||||||
$this->assertNotRegExp('/'.$entry23->concept.'/', $res->content);
|
$this->assertNotRegExp('/'.$entry23->concept.'/', $res->content);
|
||||||
$this->assertEmpty($res->nextpageurl);
|
$this->assertEmpty($res->nextpageurl);
|
||||||
|
|
||||||
// User cannot see hidden entries.
|
// User cannot see unapproved entries unless he is an author.
|
||||||
$this->assertNotRegExp('/'.$entry16->concept.'/', $res->content);
|
$this->assertNotRegExp('/'.$entry16->concept.'/', $res->content);
|
||||||
|
$this->assertRegExp('/'.$entry17->concept.'/', $res->content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue