-
Improvement
-
Resolution: Inactive
-
Minor
-
None
-
2.0.2
-
None
-
MOODLE_20_STABLE
* Checks if a user can assign users to a particular role in this context
|
*
|
* @param object $context
|
* @param int $targetroleid - the id of the role you want to assign users to
|
* @return boolean
|
*/
|
function user_can_assign($context, $targetroleid) {
|
global $DB;
|
|
// first check if user has override capability
|
// if not return false;
|
if (!has_capability('moodle/role:assign', $context)) {
|
return false;
|
}
|
// pull out all active roles of this user from this context(or above)
|
if ($userroles = get_user_roles($context)) {
|
foreach ($userroles as $userrole) {
|
// if any in the role_allow_override table, then it's ok
|
if ($DB->get_record('role_allow_assign', array('roleid'=>$userrole->roleid, 'allowassign'=>$targetroleid))) {
|
return true;
|
}
|
}
|
}
|
|
return false;
|
}
|
This function will return false for admin when the if condition fails. From reading the phpdoc and the function name I understand this function returns true if a user can assign a role to a context. It's why it seemed to me as admin should always be able to assign.
Either this function is confusing developers (name/phpdoc), either it needs a fix.
- has a non-specific relationship to
-
MDL-26250 Create a web service function that enrols users to a certain course
- Closed