Skip to content
Browse files

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

…le into MOODLE_20_STABLE
  • Loading branch information...
2 parents 50296e1 + 4b9cb37 commit e3f6f3089673ba492ec3ea918a0213564825aed4 @samhemelryk samhemelryk committed Jul 18, 2011
Showing with 12 additions and 0 deletions.
  1. +12 −0 enrol/externallib.php
View
12 enrol/externallib.php
@@ -175,6 +175,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']);
}
@@ -231,6 +237,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 e3f6f30

Please sign in to comment.
Something went wrong with that request. Please try again.