mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-55785 mod_glossary: Check user can create new entries
This commit is contained in:
parent
f0e1808fc4
commit
fad980b26f
@ -226,6 +226,7 @@ class mod_glossary_external extends external_api {
|
||||
$modes[$glossary->displayformat] = self::get_browse_modes_from_display_format($glossary->displayformat);
|
||||
}
|
||||
$glossary->browsemodes = $modes[$glossary->displayformat];
|
||||
$glossary->canaddentry = has_capability('mod/glossary:write', $context) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -292,7 +293,8 @@ class mod_glossary_external extends external_api {
|
||||
'groupingid' => new external_value(PARAM_INT, 'Grouping ID'),
|
||||
'browsemodes' => new external_multiple_structure(
|
||||
new external_value(PARAM_ALPHA, 'Modes of browsing allowed')
|
||||
)
|
||||
),
|
||||
'canaddentry' => new external_value(PARAM_INT, 'Whether the user can add a new entry', VALUE_OPTIONAL),
|
||||
), 'Glossaries')
|
||||
),
|
||||
'warnings' => new external_warnings())
|
||||
|
@ -62,6 +62,8 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
$this->assertCount(2, $glossaries['glossaries']);
|
||||
$this->assertEquals('First Glossary', $glossaries['glossaries'][0]['name']);
|
||||
$this->assertEquals('Second Glossary', $glossaries['glossaries'][1]['name']);
|
||||
$this->assertEquals(1, $glossaries['glossaries'][0]['canaddentry']);
|
||||
$this->assertEquals(1, $glossaries['glossaries'][1]['canaddentry']);
|
||||
|
||||
// Check results with specific course IDs.
|
||||
$glossaries = mod_glossary_external::get_glossaries_by_courses(array($c1->id, $c2->id));
|
||||
@ -74,6 +76,7 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
$this->assertEquals('course', $glossaries['warnings'][0]['item']);
|
||||
$this->assertEquals($c2->id, $glossaries['warnings'][0]['itemid']);
|
||||
$this->assertEquals('1', $glossaries['warnings'][0]['warningcode']);
|
||||
$this->assertEquals(1, $glossaries['glossaries'][0]['canaddentry']);
|
||||
|
||||
// Now as admin.
|
||||
$this->setAdminUser();
|
||||
@ -83,6 +86,7 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
$this->assertCount(1, $glossaries['glossaries']);
|
||||
$this->assertEquals('Third Glossary', $glossaries['glossaries'][0]['name']);
|
||||
$this->assertEquals(1, $glossaries['glossaries'][0]['canaddentry']);
|
||||
}
|
||||
|
||||
public function test_view_glossary() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user