From: jerome mouneyrac Date: Wed, 6 Jan 2010 09:33:05 +0000 (+0000) Subject: webservice MDL-20805 add admin token page. To do: create and delete operation + conte... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=5ae9f539763a7ec95d314dc66597ea90c55454d4;p=moodle.git webservice MDL-20805 add admin token page. To do: create and delete operation + context support --- diff --git a/admin/settings/plugins.php b/admin/settings/plugins.php index 11e44b42f1..2949564f94 100644 --- a/admin/settings/plugins.php +++ b/admin/settings/plugins.php @@ -236,7 +236,7 @@ if ($hassiteconfig) { } } - // Web services +/// Web services $ADMIN->add('modules', new admin_category('webservicesettings', get_string('webservices', 'webservice'))); $temp = new admin_settingpage('externalservices', get_string('externalservices', 'webservice')); $temp->add(new admin_setting_manageexternalservices()); @@ -244,6 +244,7 @@ if ($hassiteconfig) { $ADMIN->add('webservicesettings', new admin_externalpage('externalservice', get_string('externalservice', 'webservice'), "$CFG->wwwroot/$CFG->admin/webservice/service.php", 'moodle/site:config', true)); $ADMIN->add('webservicesettings', new admin_externalpage('externalservicefunctions', get_string('externalservicefunctions', 'webservice'), "$CFG->wwwroot/$CFG->admin/webservice/service_functions.php", 'moodle/site:config', true)); $ADMIN->add('webservicesettings', new admin_externalpage('externalserviceusers', get_string('externalserviceusers', 'webservice'), "$CFG->wwwroot/$CFG->admin/webservice/service_users.php", 'moodle/site:config', true)); + /// manage protocol page link $temp = new admin_settingpage('webserviceprotocols', get_string('manageprotocols', 'webservice')); $temp->add(new admin_setting_managewebserviceprotocols()); if (empty($CFG->enablewebservices)) { @@ -251,6 +252,7 @@ if ($hassiteconfig) { } $temp->add(new admin_setting_configcheckbox('enablewsdocumentation', get_string('enablewsdocumentation', 'admin'), get_string('configenablewsdocumentation', 'admin'), false)); $ADMIN->add('webservicesettings', $temp); + /// links to protocol pages $webservices_available = get_plugin_list('webservice'); $active_webservices = empty($CFG->webserviceprotocols) ? array() : explode(',', $CFG->webserviceprotocols); foreach ($webservices_available as $webservice => $location) { @@ -263,6 +265,14 @@ if ($hassiteconfig) { $ADMIN->add('webservicesettings', $settings); } } + /// manage token page link + $temp = new admin_settingpage('webservicetokens', get_string('managetokens', 'webservice')); + $temp->add(new admin_setting_managewebservicetokens()); + if (empty($CFG->enablewebservices)) { + $temp->add(new admin_setting_heading('webservicesaredisabled', '', get_string('disabledwarning', 'webservice'))); + } + $ADMIN->add('webservicesettings', $temp); + if ($hassiteconfig || has_capability('moodle/question:config', $systemcontext)) { // Question type settings. diff --git a/admin/webservice/tokens.php b/admin/webservice/tokens.php new file mode 100644 index 0000000000..3f67d4fefd --- /dev/null +++ b/admin/webservice/tokens.php @@ -0,0 +1,63 @@ +. + +/** + * Web services tokens admin UI + * + * @package webservice + * @author Jerome Mouneyrac + * @copyright 2009 Moodle Pty Ltd (http://moodle.com) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once('../../config.php'); + +$PAGE->set_url('/admin/webservice/tokens.php', array()); + +require_login(); +require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)); + +$returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=webservicetokens"; + +$action = optional_param('action', '', PARAM_ACTION); +$tokenid = optional_param('tokenid', '', PARAM_SAFEDIR); +$confirm = optional_param('confirm', 0, PARAM_BOOL); + + +//////////////////////////////////////////////////////////////////////////////// +// process actions + +if (!confirm_sesskey()) { + redirect($returnurl); +} + +switch ($action) { + + case 'create': + echo "I'm creating a token yoohoo"; + break; + + case 'delete': + $token = $DB->get_record('external_tokens', array('id' => $tokenid)); + echo "coucou delete token id:".$token->id; + break; + + default: + break; +} + +redirect($returnurl); diff --git a/lang/en_utf8/webservice.php b/lang/en_utf8/webservice.php index 5bb5968bef..57df6043ee 100644 --- a/lang/en_utf8/webservice.php +++ b/lang/en_utf8/webservice.php @@ -10,6 +10,7 @@ $string['apiexplorer'] = 'API explorer'; $string['apiexplorernotavalaible'] = 'API explorer not available yet.'; $string['arguments'] = 'Arguments'; $string['configwebserviceplugins'] = 'For security reasons enable only protocols that are used.'; +$string['context'] = 'Context'; $string['deleteservice'] = 'Delete the service: $a->name (id: $a->id)'; $string['deleteserviceconfirm'] = 'Do you really want to delete external service \"$a\"?'; $string['disabledwarning'] = 'All webs service protocols are disabled, the \Enable web services\" setting can be found in the \"Advanced features\" section.'; @@ -26,9 +27,13 @@ $string['externalserviceusers'] = 'External service users'; $string['function'] = 'Function'; $string['functions'] = 'Functions'; $string['generalstructure'] = 'General structure'; +$string['httpswarning'] = 'Token strings are only displayed if your connection is secured (https)'; $string['iprestriction'] = 'IP restriction'; $string['manageprotocols'] = 'Manage protocols'; +$string['managetokens'] = 'Manage tokens'; $string['norequiredcapability'] = 'No required capability'; +$string['notoken'] = 'You have created no token.'; +$string['operation'] = 'Operation'; $string['optional'] = 'Optional'; $string['phpparam'] = 'XML-RPC (PHP structure)'; $string['phpresponse'] = 'XML-RPC (PHP structure)'; @@ -49,6 +54,7 @@ $string['restparam'] = 'REST (POST parameters)'; $string['restrictedusers'] = 'Authorised users only'; $string['selectedcapabilitydoesntexit'] = 'The currently set required capability ($a) doesn\'t exist anymore. Please change it and save the changes.'; $string['selectedcapability'] = 'Selected'; +$string['service'] = 'Service'; $string['servicename'] = 'Service name'; $string['servicesbuiltin'] = 'Built-in services'; $string['servicescustom'] = 'Custom services'; @@ -56,8 +62,10 @@ $string['serviceusers'] = 'Authorised users'; $string['serviceusersmatching'] = 'Authorised users matching'; $string['serviceuserssettings'] = 'Change settings for the authorised users'; $string['testclient'] = 'Web service test client'; +$string['token'] = 'Token'; $string['validuntil'] = 'Valid until'; $string['webservices'] = 'Web services'; +$string['webservicetokens'] = 'Web service tokens'; $string['wsdocumentation'] = 'Web service documentation'; $string['wsdocumentationdisable'] = 'Web service documentation is disabled.'; $string['wsdocumentationintro'] = 'Following is a listing of web service functions available for the username $a.
To create a client we advise you to read the Moodle documentation'; diff --git a/lib/adminlib.php b/lib/adminlib.php index df29208b15..e88c3b4843 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -6414,3 +6414,113 @@ class admin_setting_managewebserviceprotocols extends admin_setting { return highlight($query, $return); } } + + +/** + * Special class for web service token administration. + * + * @author Jerome Mouneyrac + */ +class admin_setting_managewebservicetokens extends admin_setting { + + /** + * Calls parent::__construct with specific arguments + */ + public function __construct() { + parent::__construct('webservicestokenui', get_string('managetokens', 'webservice'), '', ''); + } + + /** + * Always returns true, does nothing + * + * @return true + */ + public function get_setting() { + return true; + } + + /** + * Always returns true, does nothing + * + * @return true + */ + public function get_defaultsetting() { + return true; + } + + /** + * Always returns '', does not write anything + * + * @return string Always returns '' + */ + public function write_setting($data) { + // do not write any setting + return ''; + } + + /** + * Builds the XHTML to display the control + * + * @param string $data Unused + * @param string $query + * @return string + */ + public function output_html($data, $query='') { + global $CFG, $OUTPUT, $DB, $USER; + + // display strings + $stroperation = get_string('operation', 'webservice'); + $strtoken = get_string('token', 'webservice'); + $strservice = get_string('service', 'webservice'); + $struser = get_string('user'); + $strcontext = get_string('context', 'webservice'); + + + + + $return = $OUTPUT->heading(get_string('webservicetokens', 'webservice'), 3, 'main', true); + $return .= $OUTPUT->box_start('generalbox webservicestokenui'); + + $table = new html_table(); + $table->head = array($strtoken, $struser, $strservice, $strcontext, $stroperation); + $table->align = array('left', 'left', 'left', 'left', 'center'); + $table->width = '100%'; + $table->data = array(); + + $tokenpageurl = "$CFG->wwwroot/$CFG->admin/webservice/tokens.php?sesskey=" . sesskey(); + + //TODO: in order to let the administrator delete obsolete token, split this request in multiple request + + //here retrieve token list (including linked users firstname/lastname and linked services name) + $sql = "SELECT + token.id, token.token, user.firstname, user.lastname, service.name + FROM + {external_tokens} token, {user} user, {external_services} service + WHERE + token.creatorid=? AND service.id = token.externalserviceid AND token.userid = user.id"; + $tokens = $DB->get_records_sql($sql, array( $USER->id)); + if (!empty($tokens)) { + foreach ($tokens as $token) { + //TODO: retrieve context + + $delete = "id."\">"; + $delete .= get_string('delete').""; + + + $table->data[] = array($token->token, $token->firstname." ".$token->lastname, $token->name, '', $delete); + } + + $return .= $OUTPUT->table($table); + $return .= get_string('httpswarning', 'webservice'); + } else { + $return .= get_string('notoken', 'webservice'); + } + + $return .= $OUTPUT->box_end(); + // add a token to the table + $return .= ""; + $return .= get_string('add').""; + + return highlight($query, $return); + } +} \ No newline at end of file diff --git a/lib/db/install.xml b/lib/db/install.xml index f7cf812c94..cfff0a1665 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -2317,8 +2317,9 @@ - - + + + @@ -2327,7 +2328,8 @@ - + + @@ -2360,4 +2362,4 @@
-
+ \ No newline at end of file diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 6e013c4929..abf1f7f0c9 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2835,6 +2835,28 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); upgrade_main_savepoint($result, 2009112400); } + if ($result && $oldversion < 2010010601) { + + /// Define field creatorid to be added to external_tokens + $table = new xmldb_table('external_tokens'); + $field = new xmldb_field('creatorid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'contextid'); + + /// Conditionally launch add field creatorid + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + /// Define key creatorid (foreign) to be added to external_tokens + $table = new xmldb_table('external_tokens'); + $key = new xmldb_key('creatorid', XMLDB_KEY_FOREIGN, array('creatorid'), 'user', array('id')); + + /// Launch add key creatorid + $dbman->add_key($table, $key); + + /// Main savepoint reached + upgrade_main_savepoint($result, 2010010601); + } + return $result; } diff --git a/version.php b/version.php index e7c3aa6277..7b60e8ea9f 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2010010502; // YYYYMMDD = date of the last version bump + $version = 2010010601; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20100106)'; // Human-friendly version name