Browse files

Merge branch 'w28_MDL-28350_m21_wsra' of git://github.com/skodak/mood…

…le into MOODLE_21_STABLE
  • Loading branch information...
2 parents 4bc4343 + f2b1a6c commit 03368c0b2ee4244b2e6db046d766f38a4670064c @samhemelryk samhemelryk committed Jul 18, 2011
Showing with 13 additions and 1 deletion.
  1. +13 −1 enrol/externallib.php
View
14 enrol/externallib.php
@@ -121,7 +121,7 @@ public static function get_enrolled_users($courseid, $withcapability = null, $gr
$profilimgurlsmall = moodle_url::make_pluginfile_url($enrolleduser->usercontextid, 'user', 'icon', NULL, '/', 'f2');
$resultuser = array(
'courseid' => $enrolleduser->courseid,
- 'userid' => $enrolleduser->userid,
+ 'userid' => $enrolleduser->userid,
'fullname' => fullname($enrolleduser),
'profileimgurl' => $profilimgurl->out(false),
'profileimgurlsmall' => $profilimgurlsmall->out(false)
@@ -271,6 +271,12 @@ public static function role_assign($assignments) {
self::validate_context($context);
require_capability('moodle/role:assign', $context);
+ // throw an exception if user is not able to assign the role in this context
+ $roles = get_assignable_roles($context, ROLENAME_SHORT);
+ if (!key_exists($assignment['roleid'], $roles)) {
+ throw new invalid_parameter_exception('Can not assign roleid='.$assignment['roleid'].' in contextid='.$assignment['contextid']);
+ }
+
role_assign($assignment['roleid'], $assignment['userid'], $assignment['contextid']);
}
@@ -327,6 +333,12 @@ public static function role_unassign($unassignments) {
self::validate_context($context);
require_capability('moodle/role:assign', $context);
+ // throw an exception if user is not able to unassign the role in this context
+ $roles = get_assignable_roles($context, ROLENAME_SHORT);
+ if (!key_exists($unassignment['roleid'], $roles)) {
+ throw new invalid_parameter_exception('Can not unassign roleid='.$unassignment['roleid'].' in contextid='.$unassignment['contextid']);
+ }
+
role_unassign($unassignment['roleid'], $unassignment['userid'], $unassignment['contextid']);
}

0 comments on commit 03368c0

Please sign in to comment.