Commit e3a5a37c authored by Son Nguyen's avatar Son Nguyen Committed by Gerrit Code Review
Browse files

Merge "Bug 1507865: Some webservices clean up of test client area"

parents 89baf4da 09e8fc4d
......@@ -169,6 +169,8 @@ $string['testclientinstructions'] = 'This is the interactive test client facilit
$string['executed'] = 'Function call executed';
$string['invaliduserpass'] = 'Invalid web services username / web services password supplied for "%s"';
$string['invalidtoken'] = 'Invalid web services token supplied';
$string['iterationtitle'] = '%s iteration: %s';
$string['unabletoruntestclient'] = 'Web service test client needs to be run under https in production mode or have $cfg->productionmode = false in your config.php';
//oauth server registry
$string['accesstokens'] = 'OAuth access tokens';
......
......@@ -4,6 +4,8 @@
</div>
{if $disabled}
<div class="error alert alert-warning">{str tag=wsauthnotenabled section='auth.webservice'}</div>
{elseif $disabledhttps}
<div class="error alert alert-warning">{str tag=unabletoruntestclient section='auth.webservice'}</div>
{elseif $disabledprotocols}
<div class="error alert alert-warning">{str tag=nowsprotocolsenabled section='auth.webservice' arg1=$disabledprotocols}</div>
{else}
......
......@@ -59,13 +59,13 @@ class mahara_group_external extends external_api {
'grouptype' => new external_value(PARAM_ALPHANUMEXT, 'Group type: ' . implode(',', $group_types)),
'category' => new external_value(PARAM_TEXT, 'Group category - the title of an existing group category', VALUE_OPTIONAL),
'editroles' => new external_value(PARAM_ALPHANUMEXT, 'Edit roles allowed: ' . implode(',', $group_edit_roles), VALUE_OPTIONAL),
'open' => new external_value(PARAM_INTEGER, 'Boolean 1/0 open - Users can join the group without approval from group administrators', VALUE_DEFAULT, '0'),
'controlled' => new external_value(PARAM_INTEGER, 'Boolean 1/0 controlled - Group administrators can add users to the group without their consent, and members cannot choose to leave', VALUE_DEFAULT, '0'),
'request' => new external_value(PARAM_INTEGER, 'Boolean 1/0 request - Users can send membership requests to group administrators', VALUE_DEFAULT, '0'),
'submitpages' => new external_value(PARAM_INTEGER, 'Boolean 1/0 submitpages - Members can submit pages to the group', VALUE_DEFAULT),
'public' => new external_value(PARAM_INTEGER, 'Boolean 1/0 public group', VALUE_DEFAULT),
'viewnotify' => new external_value(PARAM_INTEGER, 'Boolean 1/0 for Shared page notifications', VALUE_DEFAULT),
'usersautoadded' => new external_value(PARAM_INTEGER, 'Boolean 1/0 for auto-adding users', VALUE_DEFAULT),
'open' => new external_value(PARAM_BOOL, 'Open - Users can join the group without approval from group administrators', VALUE_DEFAULT, '0'),
'controlled' => new external_value(PARAM_BOOL, 'Controlled - Group administrators can add users to the group without their consent, and members cannot choose to leave', VALUE_DEFAULT, '0'),
'request' => new external_value(PARAM_BOOL, 'Request - Users can send membership requests to group administrators', VALUE_DEFAULT, '0'),
'submitpages' => new external_value(PARAM_BOOL, 'Submit pages - Members can submit pages to the group', VALUE_DEFAULT),
'public' => new external_value(PARAM_BOOL, 'Public group', VALUE_DEFAULT),
'viewnotify' => new external_value(PARAM_BOOL, 'Shared page notifications', VALUE_DEFAULT),
'usersautoadded' => new external_value(PARAM_BOOL, 'Auto-adding users', VALUE_DEFAULT),
'members' => new external_multiple_structure(
new external_single_structure(
array(
......@@ -342,13 +342,13 @@ class mahara_group_external extends external_api {
'grouptype' => new external_value(PARAM_ALPHANUMEXT, 'Group type: ' . implode(',', $group_types), VALUE_OPTIONAL),
'category' => new external_value(PARAM_TEXT, 'Group category - the title of an existing group category', VALUE_OPTIONAL),
'editroles' => new external_value(PARAM_ALPHANUMEXT, 'Edit roles allowed: ' . implode(',', $group_edit_roles), VALUE_OPTIONAL),
'open' => new external_value(PARAM_INTEGER, 'Boolean 1/0 open - Users can join the group without approval from group administrators', VALUE_DEFAULT),
'controlled' => new external_value(PARAM_INTEGER, 'Boolean 1/0 controlled - Group administrators can add users to the group without their consent, and members cannot choose to leave', VALUE_DEFAULT),
'request' => new external_value(PARAM_INTEGER, 'Boolean 1/0 request - Users can send membership requests to group administrators', VALUE_DEFAULT),
'submitpages' => new external_value(PARAM_INTEGER, 'Boolean 1/0 submitpages - Members can submit pages to the group', VALUE_DEFAULT),
'public' => new external_value(PARAM_INTEGER, 'Boolean 1/0 public group', VALUE_DEFAULT),
'viewnotify' => new external_value(PARAM_INTEGER, 'Boolean 1/0 for Shared page notifications', VALUE_DEFAULT),
'usersautoadded' => new external_value(PARAM_INTEGER, 'Boolean 1/0 for auto-adding users', VALUE_DEFAULT),
'open' => new external_value(PARAM_BOOL, 'Open - Users can join the group without approval from group administrators', VALUE_DEFAULT),
'controlled' => new external_value(PARAM_BOOL, 'Controlled - Group administrators can add users to the group without their consent, and members cannot choose to leave', VALUE_DEFAULT),
'request' => new external_value(PARAM_BOOL, 'Request - Users can send membership requests to group administrators', VALUE_DEFAULT),
'submitpages' => new external_value(PARAM_BOOL, 'Submit pages - Members can submit pages to the group', VALUE_DEFAULT),
'public' => new external_value(PARAM_BOOL, 'Public group', VALUE_DEFAULT),
'viewnotify' => new external_value(PARAM_BOOL, 'Shared page notifications', VALUE_DEFAULT),
'usersautoadded' => new external_value(PARAM_BOOL, 'Auto-adding users', VALUE_DEFAULT),
'members' => new external_multiple_structure(
new external_single_structure(
array(
......@@ -796,13 +796,13 @@ class mahara_group_external extends external_api {
'grouptype' => new external_value(PARAM_ALPHANUMEXT, 'Group type: ' . implode(',', $group_types)),
'category' => new external_value(PARAM_TEXT, 'Group category - the title of an existing group category'),
'editroles' => new external_value(PARAM_ALPHANUMEXT, 'Edit roles allowed: ' . implode(',', $group_edit_roles)),
'open' => new external_value(PARAM_INTEGER, 'Boolean 1/0 open - Users can join the group without approval from group administrators'),
'controlled' => new external_value(PARAM_INTEGER, 'Boolean 1/0 controlled - Group administrators can add users to the group without their consent, and members cannot choose to leave'),
'request' => new external_value(PARAM_INTEGER, 'Boolean 1/0 request - Users can send membership requests to group administrators'),
'submitpages' => new external_value(PARAM_INTEGER, 'Boolean 1/0 submitpages - Members can submit pages to the group'),
'public' => new external_value(PARAM_INTEGER, 'Boolean 1/0 public group'),
'viewnotify' => new external_value(PARAM_INTEGER, 'Boolean 1/0 for Shared page notifications'),
'usersautoadded' => new external_value(PARAM_INTEGER, 'Boolean 1/0 for auto-adding users'),
'open' => new external_value(PARAM_BOOL, 'Open - Users can join the group without approval from group administrators'),
'controlled' => new external_value(PARAM_BOOL, 'Controlled - Group administrators can add users to the group without their consent, and members cannot choose to leave'),
'request' => new external_value(PARAM_BOOL, 'Request - Users can send membership requests to group administrators'),
'submitpages' => new external_value(PARAM_BOOL, 'Submit pages - Members can submit pages to the group'),
'public' => new external_value(PARAM_BOOL, 'Public group'),
'viewnotify' => new external_value(PARAM_BOOL, 'Shared page notifications'),
'usersautoadded' => new external_value(PARAM_BOOL, 'Auto-adding users'),
'members' => new external_multiple_structure(
new external_single_structure(
array(
......
......@@ -71,26 +71,26 @@ class mahara_user_external extends external_api {
'users' => new external_multiple_structure(
new external_single_structure(
array(
'username' => new external_value(PARAM_RAW, 'Username policy is defined in Mahara security config'),
'password' => new external_value(PARAM_RAW, 'Plain text password consisting of any characters'),
'username' => new external_value(PARAM_RAW, 'Between 3 and 30 characters long. Letters, numbers and most standard symbols are allowed'),
'password' => new external_value(PARAM_RAW, 'Must be at least 6 characters long. Must be different from the username'),
'firstname' => new external_value(PARAM_NOTAGS, 'The first name(s) of the user'),
'lastname' => new external_value(PARAM_NOTAGS, 'The family name of the user'),
'email' => new external_value(PARAM_EMAIL, 'A valid and unique email address'),
'institution' => new external_value(PARAM_SAFEDIR, 'Mahara institution', VALUE_DEFAULT, 'mahara', NULL_NOT_ALLOWED),
'auth' => new external_value(PARAM_SAFEDIR, 'Auth plugins include manual, ldap, imap, etc', VALUE_DEFAULT, 'internal', NULL_NOT_ALLOWED),
'quota' => new external_value(PARAM_INTEGER, 'Option storage quota', VALUE_OPTIONAL),
'forcepasswordchange' => new external_value(PARAM_INTEGER, 'Boolean 1/0 for forcing password change on first login', VALUE_DEFAULT, '0'),
'forcepasswordchange' => new external_value(PARAM_BOOL, 'Forcing password change on first login', VALUE_DEFAULT, '0'),
'studentid' => new external_value(PARAM_RAW, 'An arbitrary ID code number for the student', VALUE_DEFAULT, ''),
'remoteuser' => new external_value(PARAM_RAW, 'Remote user Id', VALUE_DEFAULT, ''),
'preferredname' => new external_value(PARAM_TEXT, 'Userpreferred name', VALUE_OPTIONAL),
'address' => new external_value(PARAM_RAW, 'Introduction text', VALUE_OPTIONAL),
'preferredname' => new external_value(PARAM_TEXT, 'User preferred name', VALUE_OPTIONAL),
'address' => new external_value(PARAM_RAW, 'Street address of the user', VALUE_OPTIONAL),
'town' => new external_value(PARAM_NOTAGS, 'Home town of the user', VALUE_OPTIONAL),
'city' => new external_value(PARAM_NOTAGS, 'Home city of the user', VALUE_OPTIONAL),
'country' => new external_value(PARAM_ALPHA, 'Home country code of the user, such as NZ', VALUE_OPTIONAL),
'homenumber' => new external_value(PARAM_RAW, 'Home phone number', VALUE_OPTIONAL),
'businessnumber' => new external_value(PARAM_RAW, 'business phone number', VALUE_OPTIONAL),
'mobilenumber' => new external_value(PARAM_RAW, 'mobile phone number', VALUE_OPTIONAL),
'faxnumber' => new external_value(PARAM_RAW, 'fax number', VALUE_OPTIONAL),
'businessnumber' => new external_value(PARAM_RAW, 'Business phone number', VALUE_OPTIONAL),
'mobilenumber' => new external_value(PARAM_RAW, 'Mobile phone number', VALUE_OPTIONAL),
'faxnumber' => new external_value(PARAM_RAW, 'Fax number', VALUE_OPTIONAL),
'introduction' => new external_value(PARAM_RAW, 'Introduction text', VALUE_OPTIONAL),
'officialwebsite' => new external_value(PARAM_RAW, 'Official user website', VALUE_OPTIONAL),
'personalwebsite' => new external_value(PARAM_RAW, 'Personal website', VALUE_OPTIONAL),
......@@ -225,8 +225,8 @@ class mahara_user_external extends external_api {
'users' => new external_multiple_structure(
new external_single_structure(
array(
'id' => new external_value(PARAM_NUMBER, 'ID of the favourites owner', VALUE_OPTIONAL),
'username' => new external_value(PARAM_RAW, 'Username of the favourites owner', VALUE_OPTIONAL),
'id' => new external_value(PARAM_NUMBER, 'ID of the user to delete', VALUE_OPTIONAL),
'username' => new external_value(PARAM_RAW, 'Username of the user to delete', VALUE_OPTIONAL),
)
)
)
......@@ -311,7 +311,7 @@ class mahara_user_external extends external_api {
'institution' => new external_value(PARAM_TEXT, 'Mahara institution', VALUE_OPTIONAL),
'auth' => new external_value(PARAM_TEXT, 'Auth plugins include manual, ldap, imap, etc', VALUE_OPTIONAL),
'quota' => new external_value(PARAM_INTEGER, 'Option storage quota', VALUE_OPTIONAL),
'forcepasswordchange' => new external_value(PARAM_INTEGER, 'Boolean 1/0 for forcing password change on first login', VALUE_OPTIONAL),
'forcepasswordchange' => new external_value(PARAM_BOOL, 'Forcing password change on first login', VALUE_OPTIONAL),
'studentid' => new external_value(PARAM_RAW, 'An arbitrary ID code number for the student', VALUE_OPTIONAL),
'remoteuser' => new external_value(PARAM_RAW, 'Remote user Id', VALUE_OPTIONAL),
'preferredname' => new external_value(PARAM_TEXT, 'Userpreferred name', VALUE_OPTIONAL),
......@@ -438,9 +438,9 @@ class mahara_user_external extends external_api {
'users' => new external_multiple_structure(
new external_single_structure(
array(
'id' => new external_value(PARAM_NUMBER, 'ID of the favourites owner', VALUE_OPTIONAL),
'username' => new external_value(PARAM_RAW, 'Username of the favourites owner', VALUE_OPTIONAL),
'remoteuser' => new external_value(PARAM_RAW, 'Remote username of the favourites owner', VALUE_OPTIONAL),
'id' => new external_value(PARAM_NUMBER, 'ID of the user', VALUE_OPTIONAL),
'username' => new external_value(PARAM_RAW, 'Username of the user', VALUE_OPTIONAL),
'remoteuser' => new external_value(PARAM_RAW, 'Remote username of the user', VALUE_OPTIONAL),
)
)
)
......
......@@ -23,6 +23,10 @@ define('SUBSECTIONHEADING', get_string('testclient', 'auth.webservice'));
$protocol = param_alpha('protocol', '');
$authtype = param_alpha('authtype', '');
$service = param_integer('service', 0);
$cancel = param_alpha('cancel_submit', null);
if ($cancel) {
redirect('/webservice/testclient.php');
}
if ($service != 0) {
$dbs = get_record('external_services', 'id', $service);
}
......@@ -124,18 +128,57 @@ if (!empty($authtype)) {
// we are go - build the form for function parameters
if ($function != 0 && !empty($dbsf)) {
$vars = testclient_get_interface($dbsf->functionname);
$iterationtitle = preg_replace('/_NUM_.*/', '', $vars[0]['name']);
$elements['spacer'] = array('type' => 'html', 'value' => '<br/><h3>' . get_string('enterparameters', 'auth.webservice') . '</h3>');
for ($i=0;$i<=$iterations; $i++) {
if (!empty($vars)) {
$elements['spacer'] = array('type' => 'html', 'value' => '<br/><h4>' . get_string('iterationtitle', 'auth.webservice', ucfirst($iterationtitle), ($i + 1)) . '</h4>');
}
foreach ($vars as $var) {
$name = preg_replace('/NUM/', $i, $var['name']);
$elements[$name] = array('title' => $name, 'type' => 'text',);
$title = preg_replace('/^(.*?)_NUM_/', '', $var['name']);
$title = preg_replace('/_NUM_/', ' / ', $title);
$type = (trim($var['type']) == 'bool') ? 'switchbox' : 'text';
if ($title == 'institution') {
// Let see if we can fetch the exact allowed values
$elements[$name] = get_institution_selector();
}
else if ($title == 'country') {
$countries = getoptions_country();
$options = array('' => get_string('nocountryselected')) + $countries;
$elements[$name] = array(
'type' => 'select',
'title' => $title,
'options' => $options,
'description' => $var['desc'],
);
}
else if ($title == 'auth') {
$authinstances = auth_get_auth_instances();
$options = array();
foreach ($authinstances as $authinstance) {
$options[$authinstance->instancename] = $authinstance->displayname . ': ' . $authinstance->instancename;
}
$elements[$name] = array(
'type' => 'select',
'title' => $title,
'options' => $options,
'description' => $var['desc'],
);
}
else if ($title == 'password') {
$elements[$name] = array('title' => $title, 'type' => 'password', 'description' => $var['desc']);
}
else {
$elements[$name] = array('title' => $title, 'type' => $type, 'description' => $var['desc']);
}
}
}
if ($authtype == 'user') {
$username = param_alphanum('cancel_submit', null) ? '' : param_alphanum('wsusername', '');
$password = param_alphanum('cancel_submit', null) ? '' : param_alphanum('wspassword', '');
$elements['wsusername'] = array('title' => 'wsusername', 'type' => 'text', 'value' => $username);
$elements['wspassword'] = array('title' => 'wspassword', 'type' => 'text', 'value' => $password);
$elements['wsusername'] = array('title' => 'wsusername', 'type' => 'text', 'value' => $username, 'autocomplete' => 'off');
$elements['wspassword'] = array('title' => 'wspassword', 'type' => 'password', 'value' => $password, 'autocomplete' => 'off');
if ($username) {
$params[]= 'wsusername=' . $username;
}
......@@ -145,7 +188,7 @@ if (!empty($authtype)) {
}
else {
$wstoken = param_alphanum('cancel_submit', null) ? '' : param_alphanum('wstoken', '');
$elements['wstoken'] = array('title' => 'wstoken', 'type' => 'text', 'value' => $wstoken);
$elements['wstoken'] = array('title' => 'wstoken', 'type' => 'text', 'value' => $wstoken, 'autocomplete' => 'off');
if ($wstoken) {
$params[]= 'wstoken=' . $wstoken;
}
......@@ -182,6 +225,7 @@ $webservice_menu = PluginAuthWebservice::admin_menu_items();
$smarty->assign('SUBPAGENAV', $webservice_menu);
// Check that webservices is enabled
$smarty->assign('disabled', (get_config('webservice_enabled') ? false : true));
$smarty->assign('disabledhttps', ((!is_https() && get_config('productionmode')) ? true : false));
$smarty->assign('disabledprotocols', (empty($elements['protocol']['options']) ? get_config('wwwroot') . 'webservice/admin/index.php' : false));
$smarty->display('auth:webservice:testclient.tpl');
die;
......@@ -201,11 +245,31 @@ function testclient_get_interface($functionname) {
list($name, $type) = explode('=', $str);
$name = preg_replace('/\]\[/', '_', $name);
$name = preg_replace('/[\]\[]/', '', $name);
$vars[]= array('name' => $name, 'type' => $type);
$desc = testclient_parameters_desc($fdesc, $name);
$vars[]= array('name' => $name, 'type' => $type, 'desc' => $desc);
}
return $vars;
}
function testclient_parameters_desc($fdesc, $name) {
// Do we have any parameter_desc information?
$name = explode('_NUM_', $name);
if (!isset($fdesc->parameters_desc) && !isset($fdesc->parameters_desc->keys[$name[0]])) {
return null;
}
// Do we have any description information for the field?
if (count($name) > 1 && isset($fdesc->parameters_desc->keys[$name[0]]->content->keys[$name[1]])) {
if (count($name) == 2) {
$result = $fdesc->parameters_desc->keys[$name[0]]->content->keys[$name[1]]->desc;
}
else if (count($name) == 3) {
$result = $fdesc->parameters_desc->keys[$name[0]]->content->keys[$name[1]]->content->keys[$name[2]]->desc;
}
return $result;
}
return null;
}
/**
* Return indented REST param description
* @param object $paramdescription
......@@ -236,10 +300,12 @@ function testclient_parameters($paramdescription, $paramstring) {
$paramstring = $paramstring . '=';
switch ($paramdescription->type) {
case PARAM_BOOL:
$type = 'bool';
break;
case PARAM_INT:
$type = 'int';
break;
case PARAM_FLOAT;
case PARAM_FLOAT:
$type = 'double';
break;
default:
......@@ -373,6 +439,8 @@ function testclient_submit(Pieform $form, $values) {
$results = $client->call($dbsf->functionname, $inputs, true);
} catch (Exception $e) {
$results = "exception: " . $e->getMessage();
# split the string up by sentances and error code for easier reading
$results = preg_replace('/(\.|\|)/', "\n", $results);
}
$SESSION->set('ws_call_results', serialize($results));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment