Skip to content

Commit

Permalink
MDL-50666 core: Rename allow_ACTION to core_role_set_ACTION_allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewhancox authored and junpataleta committed Dec 19, 2017
1 parent a63cd3e commit 64cd459
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 27 deletions.
2 changes: 1 addition & 1 deletion admin/roles/classes/allow_assign_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct() {
}

protected function set_allow($fromroleid, $targetroleid) {
allow_assign($fromroleid, $targetroleid);
core_role_set_assign_allowed($fromroleid, $targetroleid);
}

protected function get_cell_tooltip($fromrole, $targetrole) {
Expand Down
2 changes: 1 addition & 1 deletion admin/roles/classes/allow_override_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct() {
}

protected function set_allow($fromroleid, $targetroleid) {
allow_override($fromroleid, $targetroleid);
core_role_set_override_allowed($fromroleid, $targetroleid);
}

protected function get_cell_tooltip($fromrole, $targetrole) {
Expand Down
2 changes: 1 addition & 1 deletion admin/roles/classes/allow_switch_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function load_required_roles() {
}

protected function set_allow($fromroleid, $targetroleid) {
allow_switch($fromroleid, $targetroleid);
core_role_set_switch_allowed($fromroleid, $targetroleid);
}

protected function is_allowed_target($targetroleid) {
Expand Down
2 changes: 1 addition & 1 deletion admin/roles/classes/allow_view_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct() {
* @param int $targetroleid
*/
protected function set_allow($fromroleid, $targetroleid) {
allow_view($fromroleid, $targetroleid);
core_role_set_view_allowed($fromroleid, $targetroleid);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion admin/roles/classes/define_role_table_advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ protected function save_allow($type) {
$current = array_keys($this->get_allow_roles_list($type));
$wanted = $this->{'allow'.$type};

$addfunction = 'allow_'.$type;
$addfunction = "core_role_set_{$type}_allowed";
$deltable = 'role_allow_'.$type;
$field = 'allow'.$type;

Expand Down
2 changes: 1 addition & 1 deletion backup/moodle2/tests/moodle2_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ protected function prepare_for_enrolments_test($target, $additionalcaps = []) {
assign_capability($cap, CAP_ALLOW, $roleidcat, $categorycontext);
}

allow_assign($roleidcat, $studentrole->id);
core_role_set_assign_allowed($roleidcat, $studentrole->id);
role_assign($roleidcat, $user->id, $categorycontext);
accesslib_clear_all_caches_for_unit_testing();

Expand Down
2 changes: 1 addition & 1 deletion enrol/manual/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function test_enrol_users() {
$this->assignUserCapability('moodle/course:view', $context2->id, $roleid);
$this->assignUserCapability('moodle/role:assign', $context2->id, $roleid);

allow_assign($roleid, 3);
core_role_set_assign_allowed($roleid, 3);

// Call the external function.
enrol_manual_external::enrol_users(array(
Expand Down
14 changes: 7 additions & 7 deletions lib/accesslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2852,16 +2852,16 @@ function get_user_roles_with_special(context $context, $userid = 0) {
/**
* Creates a record in the role_allow_override table
*
* @param int $sroleid source roleid
* @param int $troleid target roleid
* @param int $fromroleid source roleid
* @param int $targetroleid target roleid
* @return void
*/
function allow_override($sroleid, $troleid) {
function core_role_set_override_allowed($fromroleid, $targetroleid) {
global $DB;

$record = new stdClass();
$record->roleid = $sroleid;
$record->allowoverride = $troleid;
$record->roleid = $fromroleid;
$record->allowoverride = $targetroleid;
$DB->insert_record('role_allow_override', $record);
}

Expand All @@ -2872,7 +2872,7 @@ function allow_override($sroleid, $troleid) {
* @param int $targetroleid target roleid
* @return void
*/
function allow_assign($fromroleid, $targetroleid) {
function core_role_set_assign_allowed($fromroleid, $targetroleid) {
global $DB;

$record = new stdClass();
Expand All @@ -2888,7 +2888,7 @@ function allow_assign($fromroleid, $targetroleid) {
* @param int $targetroleid target roleid
* @return void
*/
function allow_switch($fromroleid, $targetroleid) {
function core_role_set_switch_allowed($fromroleid, $targetroleid) {
global $DB;

$record = new stdClass();
Expand Down
2 changes: 1 addition & 1 deletion lib/db/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ function xmldb_main_install() {
// Default allow role matrices.
foreach ($DB->get_records('role') as $role) {
foreach (array('assign', 'override', 'switch', 'view') as $type) {
$function = 'allow_'.$type;
$function = "core_role_set_{$type}_allowed";
$allows = get_default_role_archetype_allows($type, $role->archetype);
foreach ($allows as $allowid) {
$function($role->id, $allowid);
Expand Down
45 changes: 45 additions & 0 deletions lib/deprecatedlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -6511,3 +6511,48 @@ function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxeve

return $output;
}

/**
* Creates a record in the role_allow_override table
*
* @param int $sroleid source roleid
* @param int $troleid target roleid
* @return void
* @deprecated since Moodle 3.4. MDL-50666
*/
function allow_override($sroleid, $troleid) {
debugging('allow_override() has been deprecated. Please update your code to use core_role_set_override_allowed.',
DEBUG_DEVELOPER);

core_role_set_override_allowed($sroleid, $troleid);
}

/**
* Creates a record in the role_allow_assign table
*
* @param int $fromroleid source roleid
* @param int $targetroleid target roleid
* @return void
* @deprecated since Moodle 3.4. MDL-50666
*/
function allow_assign($fromroleid, $targetroleid) {
debugging('allow_assign() has been deprecated. Please update your code to use core_role_set_assign_allowed.',
DEBUG_DEVELOPER);

core_role_set_assign_allowed($fromroleid, $targetroleid);
}

/**
* Creates a record in the role_allow_switch table
*
* @param int $fromroleid source roleid
* @param int $targetroleid target roleid
* @return void
* @deprecated since Moodle 3.4. MDL-50666
*/
function allow_switch($fromroleid, $targetroleid) {
debugging('allow_switch() has been deprecated. Please update your code to use core_role_set_switch_allowed.',
DEBUG_DEVELOPER);

core_role_set_switch_allowed($fromroleid, $targetroleid);
}
2 changes: 1 addition & 1 deletion lib/testing/generator/data_generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ public function create_role($record=null) {
foreach ($types as $type) {
$rolestocopy = get_default_role_archetype_allows($type, $record['archetype']);
foreach ($rolestocopy as $tocopy) {
$functionname = 'allow_' . $type;
$functionname = "core_role_set_{$type}_allowed";
$functionname($newroleid, $tocopy);
}
}
Expand Down
22 changes: 11 additions & 11 deletions lib/tests/accesslib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ public function test_get_default_role_archetype_allows() {
/**
* Test allowing of role assignments.
*/
public function test_allow_assign() {
public function test_core_role_set_assign_allowed() {
global $DB, $CFG;

$this->resetAfterTest();
Expand All @@ -964,7 +964,7 @@ public function test_allow_assign() {
$student = $DB->get_record('role', array('shortname'=>'student'), '*', MUST_EXIST);

$this->assertFalse($DB->record_exists('role_allow_assign', array('roleid'=>$otherid, 'allowassign'=>$student->id)));
allow_assign($otherid, $student->id);
core_role_set_assign_allowed($otherid, $student->id);
$this->assertTrue($DB->record_exists('role_allow_assign', array('roleid'=>$otherid, 'allowassign'=>$student->id)));

// Test event trigger.
Expand All @@ -984,7 +984,7 @@ public function test_allow_assign() {
/**
* Test allowing of role overrides.
*/
public function test_allow_override() {
public function test_core_role_set_override_allowed() {
global $DB, $CFG;

$this->resetAfterTest();
Expand All @@ -993,7 +993,7 @@ public function test_allow_override() {
$student = $DB->get_record('role', array('shortname'=>'student'), '*', MUST_EXIST);

$this->assertFalse($DB->record_exists('role_allow_override', array('roleid'=>$otherid, 'allowoverride'=>$student->id)));
allow_override($otherid, $student->id);
core_role_set_override_allowed($otherid, $student->id);
$this->assertTrue($DB->record_exists('role_allow_override', array('roleid'=>$otherid, 'allowoverride'=>$student->id)));

// Test event trigger.
Expand All @@ -1013,7 +1013,7 @@ public function test_allow_override() {
/**
* Test allowing of role switching.
*/
public function test_allow_switch() {
public function test_core_role_set_switch_allowed() {
global $DB, $CFG;

$this->resetAfterTest();
Expand All @@ -1022,7 +1022,7 @@ public function test_allow_switch() {
$student = $DB->get_record('role', array('shortname'=>'student'), '*', MUST_EXIST);

$this->assertFalse($DB->record_exists('role_allow_switch', array('roleid'=>$otherid, 'allowswitch'=>$student->id)));
allow_switch($otherid, $student->id);
core_role_set_switch_allowed($otherid, $student->id);
$this->assertTrue($DB->record_exists('role_allow_switch', array('roleid'=>$otherid, 'allowswitch'=>$student->id)));

// Test event trigger.
Expand All @@ -1042,7 +1042,7 @@ public function test_allow_switch() {
/**
* Test allowing of role switching.
*/
public function test_allow_view() {
public function test_core_role_set_view_allowed() {
global $DB, $CFG;

$this->resetAfterTest();
Expand All @@ -1051,7 +1051,7 @@ public function test_allow_view() {
$student = $DB->get_record('role', array('shortname' => 'student'), '*', MUST_EXIST);

$this->assertFalse($DB->record_exists('role_allow_view', array('roleid' => $otherid, 'allowview' => $student->id)));
allow_view($otherid, $student->id);
core_role_set_view_allowed($otherid, $student->id);
$this->assertTrue($DB->record_exists('role_allow_view', array('roleid' => $otherid, 'allowview' => $student->id)));

// Test event trigger.
Expand Down Expand Up @@ -1355,7 +1355,7 @@ public function test_get_viewable_roles_course() {
// Teacher can no longer see student role.
$this->assertNotContains($studentrolerename->name, array_values($viewableroles));
// Allow again teacher to view student.
allow_view($teacherrole->id, $studentrole->id);
core_role_set_view_allowed($teacherrole->id, $studentrole->id);
// Teacher can now see student role.
$viewableroles = get_viewable_roles($coursecontext);
$this->assertContains($studentrolerename->name, array_values($viewableroles));
Expand Down Expand Up @@ -1388,7 +1388,7 @@ public function test_get_viewable_roles_system() {
// Teacher can no longer see student role.
$this->assertNotContains($studentrolename, array_values($viewableroles));
// Allow again teacher to view student.
allow_view($teacherrole->id, $studentrole->id);
core_role_set_view_allowed($teacherrole->id, $studentrole->id);
// Teacher can now see student role.
$viewableroles = get_viewable_roles($context);
$this->assertContains($studentrolename, array_values($viewableroles));
Expand Down Expand Up @@ -3520,7 +3520,7 @@ public function test_get_profile_roles() {
create_role('Custom role', 'customrole', 'Custom course role');
$customrole = $DB->get_record('role', array('shortname' => 'customrole'), '*', MUST_EXIST);
set_role_contextlevels($customrole->id, [CONTEXT_COURSE]);
allow_assign($teacherrole->id, $customrole->id); // Allow teacher to assign the role in the course.
core_role_set_assign_allowed($teacherrole->id, $customrole->id); // Allow teacher to assign the role in the course.

// Set the site policy 'profileroles' to show student, teacher and non-editing teacher roles (i.e. not the custom role).
$neteacherrole = $DB->get_record('role', array('shortname' => 'teacher'), '*', MUST_EXIST);
Expand Down
1 change: 1 addition & 0 deletions lib/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ information provided here is intended especially for developers.
* Added function core_role_set_view_allowed() to check if a user should be able to see a given role.
This should be checked whenever displaying a list of roles to a user, however, core_role_set_assign_allowed may need to override it
in some cases.
* Deprecated allow_override, allow_assign and allow_switch and replaced with core_role_set_*_allowed to avoid function names conflicting.

=== 3.3.1 ===

Expand Down

0 comments on commit 64cd459

Please sign in to comment.