Merge branch 'MDL-43619-m26' of git://github.com/sammarshallou/moodle into MOODLE_26_STABLE
This commit is contained in:
+10
-3
@@ -2615,8 +2615,11 @@ function get_default_role_archetype_allows($type, $archetype) {
|
||||
* Reset role capabilities to default according to selected role archetype.
|
||||
* If no archetype selected, removes all capabilities.
|
||||
*
|
||||
* @param int $roleid
|
||||
* @return void
|
||||
* This applies to capabilities that are assigned to the role (that you could
|
||||
* edit in the 'define roles' interface), and not to any capability overrides
|
||||
* in different locations.
|
||||
*
|
||||
* @param int $roleid ID of role to reset capabilities for
|
||||
*/
|
||||
function reset_role_capabilities($roleid) {
|
||||
global $DB;
|
||||
@@ -2626,11 +2629,15 @@ function reset_role_capabilities($roleid) {
|
||||
|
||||
$systemcontext = context_system::instance();
|
||||
|
||||
$DB->delete_records('role_capabilities', array('roleid'=>$roleid));
|
||||
$DB->delete_records('role_capabilities',
|
||||
array('roleid' => $roleid, 'contextid' => $systemcontext->id));
|
||||
|
||||
foreach($defaultcaps as $cap=>$permission) {
|
||||
assign_capability($cap, $permission, $roleid, $systemcontext->id);
|
||||
}
|
||||
|
||||
// Mark the system context dirty.
|
||||
context_system::instance()->mark_dirty();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2799,6 +2799,41 @@ class core_accesslib_testcase extends advanced_testcase {
|
||||
}
|
||||
$this->assertEquals($perms1, $perms2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests reset_role_capabilities function.
|
||||
*/
|
||||
public function test_reset_role_capabilities() {
|
||||
global $DB;
|
||||
$this->resetAfterTest(true);
|
||||
$generator = $this->getDataGenerator();
|
||||
|
||||
// Create test course and user, enrol one in the other.
|
||||
$course = $generator->create_course();
|
||||
$user = $generator->create_user();
|
||||
$roleid = $DB->get_field('role', 'id', array('shortname' => 'student'), MUST_EXIST);
|
||||
$generator->enrol_user($user->id, $course->id, $roleid);
|
||||
|
||||
// Change student role so it DOES have 'mod/forum:addinstance'.
|
||||
$systemcontext = context_system::instance();
|
||||
assign_capability('mod/forum:addinstance', CAP_ALLOW, $roleid, $systemcontext->id);
|
||||
|
||||
// Override course so it does NOT allow students 'mod/forum:viewdiscussion'.
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
assign_capability('mod/forum:viewdiscussion', CAP_PREVENT, $roleid, $coursecontext->id);
|
||||
|
||||
// Check expected capabilities so far.
|
||||
$this->assertTrue(has_capability('mod/forum:addinstance', $coursecontext, $user));
|
||||
$this->assertFalse(has_capability('mod/forum:viewdiscussion', $coursecontext, $user));
|
||||
|
||||
// Oops, allowing student to add forums was a mistake, let's reset the role.
|
||||
reset_role_capabilities($roleid);
|
||||
|
||||
// Check new expected capabilities - role capabilities should have been reset,
|
||||
// while the override at course level should remain.
|
||||
$this->assertFalse(has_capability('mod/forum:addinstance', $coursecontext, $user));
|
||||
$this->assertFalse(has_capability('mod/forum:viewdiscussion', $coursecontext, $user));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user