MDL-21655 big scary enrolment and roles improvements - see tacker for list of changes, includes other minor fixes too

This commit is contained in:
Petr Skoda
2010-03-31 07:41:31 +00:00
parent d1d4813ff2
commit 4f0c2d0009
225 changed files with 2941 additions and 3097 deletions
+25 -13
View File
@@ -155,7 +155,7 @@ class external_api {
}
}
return validate_param($params, $description->type, $description->allownull, get_string('errorinvalidparamsapi', 'webservice'));
} else if ($description instanceof external_single_structure) {
if (!is_array($params)) {
throw new invalid_parameter_exception(get_string('erroronlyarray', 'webservice'));
@@ -282,6 +282,8 @@ class external_api {
* @return void
*/
protected static function validate_context($context) {
global $CFG;
if (empty($context)) {
throw new invalid_parameter_exception('Context does not exist');
}
@@ -304,16 +306,26 @@ class external_api {
}
if ($context->contextlevel >= CONTEXT_COURSE) {
//TODO: temporary bloody hack, this needs to be replaced by
// proper enrolment and course visibility check
// similar to require_login() (which can not be used
// because it can be used only once and redirects)
// oh - did I say we need to rewrite enrolments in 2.0
// to solve this bloody mess?
//
// missing: hidden courses and categories, groupmembersonly,
// conditional activities, etc.
require_capability('moodle/course:view', $context);
list($context, $course, $cm) = get_context_info_array($context->id);
// must be enrolled or viewing
if (!is_enrolled($context) and !is_viewing($context)) {
throw new invalid_parameter_exception('Must be enrolled in course or be allowed to inspect it.');
}
// make sure the course is actually visible
if (!($course->visible && course_parent_visible($COURSE)) && !has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) {
throw new invalid_parameter_exception('Invalid course.');
}
// make sure the activity is actually visible
if ($cm && !$cm->visible && !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id))) {
throw new invalid_parameter_exception('Invalid activity.');
}
// verify group memebers
if (!empty($CFG->enablegroupings) and $cm and $cm->groupmembersonly and !has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id))) {
if (!groups_has_membership($cm)) {
throw new invalid_parameter_exception('Must be member of at least one group.');
}
}
//TODO: verify course completion
}
}
}
@@ -441,8 +453,8 @@ function external_generate_token($tokentype, $serviceorid, $userid, $contextorid
}
$newtoken->tokentype = $tokentype;
$newtoken->userid = $userid;
$newtoken->contextid = $context->id;
$newtoken->contextid = $context->id;
$newtoken->creatorid = $USER->id;
$newtoken->timecreated = time();
$newtoken->validuntil = $validuntil;