mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 00:16:46 +02:00
MDL-12886 one more external group function, other minor fixes
This commit is contained in:
parent
f507217757
commit
246f6da2b8
6 changed files with 122 additions and 33 deletions
|
@ -140,8 +140,8 @@ class webservice_rest_server extends webservice_base_server {
|
|||
$single = '<SINGLE>'."\n";
|
||||
foreach ($desc->keys as $key=>$subdesc) {
|
||||
if (!array_key_exists($key, $returns)) {
|
||||
if ($subdesc->rewquired) {
|
||||
$single .= '<ERROR>Missing required key</ERROR>';
|
||||
if ($subdesc->required) {
|
||||
$single .= '<ERROR>Missing required key "'.$key.'"</ERROR>';
|
||||
continue;
|
||||
} else {
|
||||
//optional field
|
||||
|
|
|
@ -36,7 +36,8 @@ require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
|||
|
||||
// list of all available functions for testing - please note there must be explicit
|
||||
// support for testing of each functions, the parameter conversion and form is hardcoded
|
||||
$functions = array('moodle_group_create_groups', 'moodle_group_get_groups');
|
||||
// TODO: automate this list by fetching all known functiosn from db and looking if client form defined
|
||||
$functions = array('moodle_group_create_groups', 'moodle_group_get_groups', 'moodle_group_get_course_groups');
|
||||
$functions = array_combine($functions, $functions);
|
||||
if (!isset($functions[$function])) { // whitelisting security
|
||||
$function = '';
|
||||
|
@ -109,6 +110,9 @@ if ($mform->is_cancelled()) {
|
|||
$params['groupids'][] = $data->groupids[$i];
|
||||
}
|
||||
|
||||
} else if ($function === 'moodle_group_get_course_groups') {
|
||||
$params['courseid'] = $data->courseid;
|
||||
|
||||
} else {
|
||||
throw new coding_exception('Testing of function '.$function.' not implemented yet!');
|
||||
}
|
||||
|
|
|
@ -22,32 +22,6 @@ class webservice_test_client_form extends moodleform {
|
|||
|
||||
// === Test client forms ===
|
||||
|
||||
class moodle_group_get_groups_form extends moodleform {
|
||||
public function definition() {
|
||||
global $CFG;
|
||||
|
||||
$mform = $this->_form;
|
||||
|
||||
$mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
|
||||
|
||||
//note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
|
||||
$mform->addElement('text', 'wsusername', 'wsusername');
|
||||
$mform->addElement('text', 'wspassword', 'wspassword');
|
||||
$mform->addElement('text', 'groupids[0]', 'groupids[0]');
|
||||
$mform->addElement('text', 'groupids[1]', 'groupids[1]');
|
||||
$mform->addElement('text', 'groupids[2]', 'groupids[2]');
|
||||
$mform->addElement('text', 'groupids[3]', 'groupids[3]');
|
||||
|
||||
$mform->addElement('hidden', 'function');
|
||||
$mform->setType('function', PARAM_SAFEDIR);
|
||||
|
||||
$mform->addElement('hidden', 'protocol');
|
||||
$mform->setType('protocol', PARAM_SAFEDIR);
|
||||
|
||||
$this->add_action_buttons(true, get_string('execute', 'webservice'));
|
||||
}
|
||||
}
|
||||
|
||||
class moodle_group_create_groups_form extends moodleform {
|
||||
public function definition() {
|
||||
global $CFG;
|
||||
|
@ -75,3 +49,53 @@ class moodle_group_create_groups_form extends moodleform {
|
|||
$this->add_action_buttons(true, get_string('execute', 'webservice'));
|
||||
}
|
||||
}
|
||||
|
||||
class moodle_group_get_groups_form extends moodleform {
|
||||
public function definition() {
|
||||
global $CFG;
|
||||
|
||||
$mform = $this->_form;
|
||||
|
||||
$mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
|
||||
|
||||
//note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
|
||||
$mform->addElement('text', 'wsusername', 'wsusername');
|
||||
$mform->addElement('text', 'wspassword', 'wspassword');
|
||||
$mform->addElement('text', 'groupids[0]', 'groupids[0]');
|
||||
$mform->addElement('text', 'groupids[1]', 'groupids[1]');
|
||||
$mform->addElement('text', 'groupids[2]', 'groupids[2]');
|
||||
$mform->addElement('text', 'groupids[3]', 'groupids[3]');
|
||||
|
||||
$mform->addElement('hidden', 'function');
|
||||
$mform->setType('function', PARAM_SAFEDIR);
|
||||
|
||||
$mform->addElement('hidden', 'protocol');
|
||||
$mform->setType('protocol', PARAM_SAFEDIR);
|
||||
|
||||
$this->add_action_buttons(true, get_string('execute', 'webservice'));
|
||||
}
|
||||
}
|
||||
|
||||
class moodle_group_get_course_groups_form extends moodleform {
|
||||
public function definition() {
|
||||
global $CFG;
|
||||
|
||||
$mform = $this->_form;
|
||||
|
||||
$mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
|
||||
|
||||
//note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
|
||||
$mform->addElement('text', 'wsusername', 'wsusername');
|
||||
$mform->addElement('text', 'wspassword', 'wspassword');
|
||||
$mform->addElement('text', 'courseid', 'courseid');
|
||||
|
||||
$mform->addElement('hidden', 'function');
|
||||
$mform->setType('function', PARAM_SAFEDIR);
|
||||
|
||||
$mform->addElement('hidden', 'protocol');
|
||||
$mform->setType('protocol', PARAM_SAFEDIR);
|
||||
|
||||
$this->add_action_buttons(true, get_string('execute', 'webservice'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue