Commit d159aaf4 authored by Aaron Wells's avatar Aaron Wells

Bug 1620879: Changes to service groups to facilitate automation

- Adding "shortname" field to service groups
- Marking plugin-created service groups, as the ones that have
a "component" field. Make the function list for plugin-created
service groups not editable by users.
- Since users may have already edited the old "sample" service
groups, removing the "component" value from those.
- And, to avoid trouble going forward, preventing the install
of the sample service groups on new installations

behatnotneeded: Tests to be written later

Change-Id: I23c781d6f2bbf689c12de30a67882bf3f1f4aff9
parent 54b9cfc6
......@@ -8,6 +8,7 @@
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true"/>
<FIELD NAME="name" TYPE="char" LENGTH="200" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="shortname" TYPE="char" LENGTH="200" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="enabled" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" SEQUENCE="false"/>
<FIELD NAME="restrictedusers" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" SEQUENCE="false"/>
<FIELD NAME="tokenusers" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" SEQUENCE="false"/>
......@@ -20,6 +21,7 @@
</KEYS>
<INDEXES>
<INDEX NAME="nameuk" UNIQUE="true" FIELDS="name"/>
<INDEX NAME="shortnamecompix" UNIQUE="false" FIELDS="shortname,component"/>
</INDEXES>
</TABLE>
<TABLE NAME="external_functions" COMMENT="list of all external functions">
......
......@@ -483,6 +483,23 @@ function xmldb_auth_webservice_upgrade($oldversion=0) {
}
}
if ($oldversion < 2016090700) {
log_debug('Adding shortname column to external_services table');
$table = new XMLDBTable('external_services');
$field = new XMLDBField('shortname');
$field->setAttributes(XMLDB_TYPE_CHAR, 200, null, null, null, null, null, null, '', 'name');
if (!field_exists($table, $field)) {
add_field($table, $field);
$index = new XMLDBIndex('shortnamecompuix');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('shortname', 'component'));
add_index($table, $index);
}
log_debug('Clearing out "component" field from old example service groups');
set_field('external_services', 'component', '', 'component', 'webservice');
}
// sweep for webservice updates everytime
$status = external_reload_webservices();
......
......@@ -105,10 +105,11 @@ $string['servicegroup'] = 'Service group: %s';
$string['sfgdescription'] = 'Build lists of functions into service groups that can be allocated to users authorised for execution.';
$string['name'] = 'Name';
$string['component'] = 'Component';
$string['customservicegroup'] = '(Custom)';
$string['functions'] = 'Functions';
$string['enableservice'] = 'Enable or disable the service';
$string['existingserviceusers'] = 'Cannot switch to token only users because service users are linked to this service.';
$string['existingtokens'] = 'Cannot switch to authorised service users because token users exist for this service.';
$string['restricteduserswarning'] = 'Warning: There are existing token users for this service, who may be unable to access it if you enable "%s".';
$string['tokenuserswarning'] = 'Warning: There are existing token users for this service, who may be unable to access it if you disable "%s".';
$string['usersonly'] = 'Users only';
$string['tokensonly'] = 'Tokens only';
$string['switchtousers'] = 'Switch to users';
......@@ -129,6 +130,8 @@ $string['missingretvaldesc'] = 'Missing returned values description';
$string['missingparamdesc'] = 'Missing parameter description';
$string['missingimplofmeth'] = 'Missing implementation method of "%s"';
$string['cannotfindimplfile'] = 'Cannot find file with external function implementation';
$string['servicenamemustbeunique'] = 'That name is already in use by another service group.';
$string['serviceshortnamemustbeunique'] = 'That short name is already in use by another service group.';
$string['apptokens'] = 'Application connections';
$string['connections'] = 'Connection manager';
......@@ -320,6 +323,11 @@ $string['selectedcapability'] = 'Selected';
$string['selectspecificuser'] = 'Select a specific user';
$string['service'] = 'Service';
$string['serviceusers'] = 'Authorised users';
$string['servicenamelabel'] = 'Name';
$string['servicenamedesc'] = 'A human-readable name for this service group.';
$string['serviceshortnamelabel'] = 'Short name';
$string['serviceshortnamedesc'] = 'A machine-readable name for this service group. (This is the name that will be used if an external service needs to refer to this service group.)';
$string['servicecomponentnote'] = 'This service provides functionality for the component: %s';
$string['simpleauthlog'] = 'Simple authentication login';
$string['step'] = 'Step';
$string['testclient'] = 'Web service test client';
......
......@@ -11,8 +11,8 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2016071400;
$config->release = '1.1.0';
$config = new stdClass();
$config->version = 2016090700;
$config->release = '2.0.0';
$config->requires_config = 0;
$config->requires_parent = 0;
......@@ -545,16 +545,24 @@ function webservice_function_groups_form() {
),
);
$dbservices = get_records_array('external_services', null, null, 'name');
$dbservices = get_records_array(
'external_services',
null,
null,
'component, name',
'id, name, shortname, component, enabled, restrictedusers, tokenusers'
);
if ($dbservices) {
foreach ($dbservices as $service) {
$iscustomservice = ($service->component === '');
$form['elements']['id'. $service->id . '_service'] = array(
'value' => $service->name,
'value' => $service->name .
($service->shortname ? ' (' . $service->shortname . ')' : ''),
'type' => 'html',
'key' => $service->name,
);
$form['elements']['id'. $service->id . '_component'] = array(
'value' => $service->component,
'value' => ($iscustomservice ? get_string('customservicegroup', 'auth.webservice') : $service->component),
'type' => 'html',
'key' => $service->name,
);
......@@ -611,25 +619,29 @@ function webservice_function_groups_form() {
),
),
))
. pieform(array(
'name' => 'webservices_function_groups_delete_' . $service->id,
'renderer' => 'div',
'class' => 'form-as-button pull-left',
'successcallback' => 'webservice_function_groups_submit',
'jsform' => false,
'action' => get_config('wwwroot') . 'webservice/admin/index.php',
'elements' => array(
'service' => array('type' => 'hidden', 'value' => $service->id),
'action' => array('type' => 'hidden', 'value' => 'delete'),
'submit' => array(
'type' => 'button',
'usebuttontag' => true,
'class' => 'btn-default btn-sm',
'value' => '<span class="'.$deleteicon.'"></span>' . get_string('delete', 'mahara'),
'elementtitle' => get_string('delete'),
),
),
)),
. (
$iscustomservice ?
pieform(array(
'name' => 'webservices_function_groups_delete_' . $service->id,
'renderer' => 'div',
'class' => 'form-as-button pull-left',
'successcallback' => 'webservice_function_groups_submit',
'jsform' => false,
'action' => get_config('wwwroot') . 'webservice/admin/index.php',
'elements' => array(
'service' => array('type' => 'hidden', 'value' => $service->id),
'action' => array('type' => 'hidden', 'value' => 'delete'),
'submit' => array(
'type' => 'button',
'usebuttontag' => true,
'class' => 'btn-default btn-sm',
'value' => '<span class="'.$deleteicon.'"></span>' . get_string('delete', 'mahara'),
'elementtitle' => get_string('delete'),
),
),
))
: ''
),
'type' => 'html',
'key' => $service->name,
'class' => 'webserviceconfigcontrols btn-group',
......@@ -676,7 +688,7 @@ function webservice_function_groups_submit(Pieform $form, $values) {
$SESSION->add_error_msg(get_string('invalidinput', 'auth.webservice'));
}
else {
$service = array('name' => $service, 'restrictedusers' => 0, 'enabled' => 0, 'tokenusers' => 0, 'component' => 'webservice', 'ctime' => db_format_timestamp(time()));
$service = array('name' => $service, 'restrictedusers' => 0, 'enabled' => 0, 'tokenusers' => 0, 'component' => '', 'ctime' => db_format_timestamp(time()));
insert_record('external_services', $service);
$SESSION->add_ok_msg(get_string('configsaved', 'auth.webservice'));
}
......@@ -688,13 +700,17 @@ function webservice_function_groups_submit(Pieform $form, $values) {
redirect('/webservice/admin/serviceconfig.php?service=' . $values['service']);
}
else if ($values['action'] == 'delete') {
// remove everything associated with a service
$params = array($values['service']);
delete_records_select('external_tokens', "externalserviceid = ?", $params);
delete_records_select('external_services_users', "externalserviceid = ?", $params);
delete_records_select('external_services_functions', "externalserviceid = ?", $params);
delete_records('external_services', 'id', $values['service']);
$SESSION->add_ok_msg(get_string('configsaved', 'auth.webservice'));
$component = get_field('external_services', 'component', 'id', $values['service']);
// Can't manually delete plugin-provided services; only disable them.
if ($component === '') {
// remove everything associated with a service
$params = array($values['service']);
delete_records_select('external_tokens', "externalserviceid = ?", $params);
delete_records_select('external_services_users', "externalserviceid = ?", $params);
delete_records_select('external_services_functions', "externalserviceid = ?", $params);
delete_records('external_services', 'id', $values['service']);
$SESSION->add_ok_msg(get_string('configsaved', 'auth.webservice'));
}
}
}
}
......
This diff is collapsed.
......@@ -1978,6 +1978,7 @@ function external_reload_component($component, $dir=true) {
$service['enabled'] = empty($service['enabled']) ? 0 : $service['enabled'];
$service['restrictedusers'] = ((isset($service['restrictedusers']) && $service['restrictedusers'] == 1) ? 1 : 0);
$service['tokenusers'] = ((isset($service['tokenusers']) && $service['tokenusers'] == 1) ? 1 : 0);
$service['shortname'] = (isset($service['shortname']) ? $service['shortname'] : '');
$update = false;
if ($dbservice->enabled != $service['enabled']) {
......@@ -1992,7 +1993,12 @@ function external_reload_component($component, $dir=true) {
$dbservice->tokenusers = $service['tokenusers'];
$update = true;
}
if ($dbservice->shortname !== $service['shortname']) {
$dbservice->shortname = $service['shortname'];
$update = true;
}
if ($update) {
$dbservice->mtime = db_format_timestamp(time());
update_record('external_services', $dbservice);
}
......@@ -2020,11 +2026,13 @@ function external_reload_component($component, $dir=true) {
foreach ($services as $name => $service) {
$dbservice = new stdClass();
$dbservice->name = $name;
$dbservice->shortname = (isset($service['shortname']) ? $service['shortname'] : '');
$dbservice->enabled = empty($service['enabled']) ? 0 : $service['enabled'];
$dbservice->restrictedusers = ((isset($service['restrictedusers']) && $service['restrictedusers'] == 1) ? 1 : 0);
$dbservice->tokenusers = ((isset($service['tokenusers']) && $service['tokenusers'] == 1) ? 1 : 0);
$dbservice->component = $component;
$dbservice->ctime = db_format_timestamp(time());
$dbservice->mtime = $dbservice->ctime;
$dbservice->id = insert_record('external_services', $dbservice, 'id', true);
foreach ($service['functions'] as $fname) {
$newf = new stdClass();
......
......@@ -249,72 +249,11 @@ $functions = array(
);
/**
* Prepopulated service groups that propose units of access
* Prepopulated service groups
* (None are actually needed yet for the "webservice" pseudo-module.
* See module.mobileapi for one that does have service groups.)
*/
$services = array(
'User Provisioning' => array(
'functions' => array ('mahara_user_get_online_users', 'mahara_user_get_all_favourites', 'mahara_user_get_favourites', 'mahara_user_update_favourites', 'mahara_user_get_users', 'mahara_user_get_users_by_id', 'mahara_user_create_users', 'mahara_user_delete_users', 'mahara_user_update_users', 'mahara_user_get_context', 'mahara_user_get_extended_context'),
'enabled'=>1,
),
'User Query' => array(
'functions' => array ('mahara_user_get_online_users', 'mahara_user_get_all_favourites', 'mahara_user_get_favourites', 'mahara_user_get_users', 'mahara_user_get_users_by_id', 'mahara_user_get_context', 'mahara_user_get_extended_context'),
'enabled'=>1,
),
'Simple User Provisioning' => array(
'functions' => array ('mahara_user_get_online_users', 'mahara_user_get_all_favourites', 'mahara_user_get_favourites', 'mahara_user_update_favourites', 'mahara_user_get_users', 'mahara_user_get_users_by_id', 'mahara_user_create_users', 'mahara_user_delete_users', 'mahara_user_update_users', 'mahara_user_get_context', 'mahara_user_get_extended_context'),
'enabled'=>1,
'restrictedusers'=>1,
),
'Simple User Query' => array(
'functions' => array ('mahara_user_get_online_users', 'mahara_user_get_all_favourites', 'mahara_user_get_favourites', 'mahara_user_get_users', 'mahara_user_get_users_by_id', 'mahara_user_get_context', 'mahara_user_get_extended_context'),
'enabled'=>1,
'restrictedusers'=>1,
),
'UserToken User Query' => array(
'functions' => array ('mahara_user_get_my_user', 'mahara_user_get_context', 'mahara_user_get_extended_context'),
'enabled'=>1,
'tokenusers'=>1,
),
'Group Provisioning' => array(
'functions' => array ('mahara_group_get_groups', 'mahara_group_get_groups_by_id', 'mahara_group_create_groups', 'mahara_group_delete_groups', 'mahara_group_update_groups', 'mahara_group_update_group_members'),
'enabled'=>1,
),
'Group Query' => array(
'functions' => array ('mahara_group_get_groups', 'mahara_group_get_groups_by_id'),
'enabled'=>1,
),
'Simple Group Provisioning' => array(
'functions' => array ('mahara_group_get_groups', 'mahara_group_get_groups_by_id', 'mahara_group_create_groups', 'mahara_group_delete_groups', 'mahara_group_update_groups', 'mahara_group_update_group_members'),
'enabled'=>1,
'restrictedusers'=>1,
),
'Simple Group Query' => array(
'functions' => array ('mahara_group_get_groups', 'mahara_group_get_groups_by_id'),
'enabled'=>1,
'restrictedusers'=>1,
),
'Institution Provisioning' => array(
'functions' => array ('mahara_institution_add_members', 'mahara_institution_remove_members', 'mahara_institution_invite_members', 'mahara_institution_decline_members',),
'enabled'=>1,
),
'Institution Query' => array(
'functions' => array ('mahara_institution_get_members', 'mahara_institution_get_requests'),
'enabled'=>1,
),
'Simple Institution Provisioning' => array(
'functions' => array ('mahara_institution_add_members', 'mahara_institution_remove_members', 'mahara_institution_invite_members', 'mahara_institution_decline_members',),
'enabled'=>1,
'restrictedusers'=>1,
),
'Simple Institution Query' => array(
'functions' => array ('mahara_institution_get_members', 'mahara_institution_get_requests'),
'enabled'=>1,
'restrictedusers'=>1,
),
'Mahara Assignment Submission' => array(
'functions' => array ('mahara_submission_get_views_for_user', 'mahara_submission_submit_view_for_assessment', 'mahara_submission_release_submitted_view'),
'enabled'=>1,
),
);
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