Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-30268 Web service : resolved version number conflict

  • Loading branch information...
commit 3a59d04c659a3157952d9e7adcc7f979f883f69f 2 parents 9dc9709 + af03513
@nebgor nebgor authored
View
5 admin/webservice/forms.php
@@ -68,6 +68,11 @@ function definition() {
get_string('restrictedusers', 'webservice'));
$mform->addHelpButton('restrictedusers', 'restrictedusers', 'webservice');
+ //can users download files
+ $mform->addElement('advcheckbox', 'downloadfiles', get_string('downloadfiles', 'webservice'));
+ $mform->setAdvanced('downloadfiles');
+ $mform->addHelpButton('downloadfiles', 'downloadfiles', 'webservice');
+
/// needed to select automatically the 'No required capability" option
$currentcapabilityexist = false;
if (empty($service->requiredcapability)) {
View
2  lang/en/webservice.php
@@ -62,6 +62,8 @@
$string['doc'] = 'Documentation';
$string['docaccessrefused'] = 'You are not allowed to see the documentation for this token';
$string['documentation'] = 'web service documentation';
+$string['downloadfiles'] = 'Can download files';
+$string['downloadfiles_help'] = 'If enabled, any user can download files with their security keys. Of course they are restricted to the files they are allowed to download in the site.';
$string['editaservice'] = 'Edit service';
$string['editservice'] = 'Edit the service: {$a->name} (id: {$a->id})';
$string['enabled'] = 'Enabled';
View
5 lib/db/install.xml 100644 → 100755
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20111101" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20111118" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
@@ -2516,7 +2516,8 @@
<FIELD NAME="component" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false" PREVIOUS="restrictedusers" NEXT="timecreated"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="component" NEXT="timemodified"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" PREVIOUS="timecreated" NEXT="shortname"/>
- <FIELD NAME="shortname" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="a unique shortname" PREVIOUS="timemodified"/>
+ <FIELD NAME="shortname" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="a unique shortname" PREVIOUS="timemodified" NEXT="downloadfiles"/>
+ <FIELD NAME="downloadfiles" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="1 if the service allow people to download file from webservice/plugins.php - 0 if not" PREVIOUS="shortname"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
View
3  lib/db/services.php
@@ -477,6 +477,7 @@
'moodle_message_send_instantmessages'),
'enabled' => 0,
'restrictedusers' => 0,
- 'shortname' => MOODLE_OFFICIAL_MOBILE_SERVICE
+ 'shortname' => MOODLE_OFFICIAL_MOBILE_SERVICE,
+ 'downloadfiles' => 1
),
);
View
14 lib/db/upgrade.php
@@ -6933,6 +6933,20 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2011111500.01);
}
+ if ($oldversion < 2011111800.01) {
+ // Define field downloadfiles to be added to external_services
+ $table = new xmldb_table('external_services');
+ $field = new xmldb_field('downloadfiles', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'shortname');
+
+ // Conditionally launch add field downloadfiles
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ // Main savepoint reached
+ upgrade_main_savepoint(true, 2011111800.01);
+ }
+
return true;
}
View
6 lib/upgradelib.php
@@ -900,6 +900,7 @@ function external_update_descriptions($component) {
$service['enabled'] = empty($service['enabled']) ? 0 : $service['enabled'];
$service['requiredcapability'] = empty($service['requiredcapability']) ? null : $service['requiredcapability'];
$service['restrictedusers'] = !isset($service['restrictedusers']) ? 1 : $service['restrictedusers'];
+ $service['downloadfiles'] = !isset($service['downloadfiles']) ? 0 : $service['downloadfiles'];
$service['shortname'] = !isset($service['shortname']) ? null : $service['shortname'];
$update = false;
@@ -911,6 +912,10 @@ function external_update_descriptions($component) {
$dbservice->restrictedusers = $service['restrictedusers'];
$update = true;
}
+ if ($dbservice->downloadfiles != $service['downloadfiles']) {
+ $dbservice->downloadfiles = $service['downloadfiles'];
+ $update = true;
+ }
//if shortname is not a PARAM_ALPHANUMEXT, fail (tested here for service update and creation)
if (isset($service['shortname']) and
(clean_param($service['shortname'], PARAM_ALPHANUMEXT) != $service['shortname'])) {
@@ -964,6 +969,7 @@ function external_update_descriptions($component) {
$dbservice->enabled = empty($service['enabled']) ? 0 : $service['enabled'];
$dbservice->requiredcapability = empty($service['requiredcapability']) ? null : $service['requiredcapability'];
$dbservice->restrictedusers = !isset($service['restrictedusers']) ? 1 : $service['restrictedusers'];
+ $dbservice->downloadfiles = !isset($service['downloadfiles']) ? 0 : $service['downloadfiles'];
$dbservice->shortname = !isset($service['shortname']) ? null : $service['shortname'];
$dbservice->component = $component;
$dbservice->timecreated = time();
View
2  version.php
@@ -30,7 +30,7 @@
defined('MOODLE_INTERNAL') || die();
-$version = 2011111800.00; // YYYYMMDD = weekly release date of this DEV branch
+$version = 2011111800.01; // YYYYMMDD = weekly release date of this DEV branch
// RR = release increments - 00 in DEV branches
// .XX = incremental changes
View
71 webservice/externallib.php
@@ -38,8 +38,7 @@ public static function get_site_info_parameters() {
new external_value(
PARAM_ALPHANUMEXT,
'service shortname'),
- 'service shortnames - by default, if the list is empty and mobile web services are enabled,
- we return the mobile service functions',
+ 'DEPRECATED PARAMETER - it was a design error in the original implementation. It is ignored now. (parameter kept for backward compatibility)',
VALUE_DEFAULT,
array()
),
@@ -51,11 +50,11 @@ public static function get_site_info_parameters() {
* Return user information including profile picture + basic site information
* Note:
* - no capability checking because we return just known information by logged user
- * @param array $serviceshortnames of service shortnames - the functions of these services will be returned
+ * @param array $serviceshortnames - DEPRECATED PARAMETER - values will be ignored - it was an original design error, we keep for backward compatibility.
* @return array
*/
public function get_site_info($serviceshortnames = array()) {
- global $USER, $SITE, $CFG;
+ global $USER, $SITE, $CFG, $DB;
$params = self::validate_parameters(self::get_site_info_parameters(),
array('serviceshortnames'=>$serviceshortnames));
@@ -63,20 +62,47 @@ public function get_site_info($serviceshortnames = array()) {
$profileimageurl = moodle_url::make_pluginfile_url(
get_context_instance(CONTEXT_USER, $USER->id)->id, 'user', 'icon', NULL, '/', 'f1');
- require_once($CFG->dirroot . "/webservice/lib.php");
- $webservice = new webservice();
+ //site information
+ $siteinfo = array(
+ 'sitename' => $SITE->fullname,
+ 'siteurl' => $CFG->wwwroot,
+ 'username' => $USER->username,
+ 'firstname' => $USER->firstname,
+ 'lastname' => $USER->lastname,
+ 'fullname' => fullname($USER),
+ 'userid' => $USER->id,
+ 'userpictureurl' => $profileimageurl->out(false)
+ );
- //If no service listed always return the mobile one by default
- if (empty($params['serviceshortnames']) and $CFG->enablewebservices) {
- $mobileservice = $webservice->get_external_service_by_shortname(MOODLE_OFFICIAL_MOBILE_SERVICE);
- if ($mobileservice->enabled) {
- $params['serviceshortnames'] = array(MOODLE_OFFICIAL_MOBILE_SERVICE); //return mobile service by default
- }
+ //Retrieve the service and functions from the web service linked to the token
+ //If you call this function directly from external (not a web service call),
+ //then it will still return site info without information about a service
+ //Note: wsusername/wspassword ws authentication is not supported.
+ $functions = array();
+ if ($CFG->enablewebservices) { //no need to check token if web service are disabled and not a ws call
+ $token = optional_param('wstoken', '', PARAM_ALPHANUM);
+
+ if (!empty($token)) { //no need to run if not a ws call
+ //retrieve service shortname
+ $servicesql = 'SELECT s.*
+ FROM {external_services} s, {external_tokens} t
+ WHERE t.externalserviceid = s.id AND token = ? AND t.userid = ? AND s.enabled = 1';
+ $service = $DB->get_record_sql($servicesql, array($token, $USER->id));
+
+ $siteinfo['downloadfiles'] = $service->downloadfiles;
+
+ if (!empty($service)) {
+ //retrieve the functions
+ $functionssql = "SELECT f.*
+ FROM {external_functions} f, {external_services_functions} sf
+ WHERE f.name = sf.functionname AND sf.externalserviceid = ?";
+ $functions = $DB->get_records_sql($functionssql, array($service->id));
+ } else {
+ throw new coding_exception('No service found in get_site_info: something is buggy, it should have fail at the ws server authentication layer.');
+ }
+ }
}
- //retrieve the functions related to the services
- $functions = $webservice->get_external_functions_by_enabled_services($params['serviceshortnames']);
-
//built up the returned values of the list of functions
$componentversions = array();
$avalaiblefunctions = array();
@@ -106,17 +132,9 @@ public function get_site_info($serviceshortnames = array()) {
$avalaiblefunctions[] = $functioninfo;
}
- return array(
- 'sitename' => $SITE->fullname,
- 'siteurl' => $CFG->wwwroot,
- 'username' => $USER->username,
- 'firstname' => $USER->firstname,
- 'lastname' => $USER->lastname,
- 'fullname' => fullname($USER),
- 'userid' => $USER->id,
- 'userpictureurl' => $profileimageurl->out(false),
- 'functions' => $avalaiblefunctions
- );
+ $siteinfo['functions'] = $avalaiblefunctions;
+
+ return $siteinfo;
}
/**
@@ -141,6 +159,7 @@ public static function get_site_info_returns() {
'version' => new external_value(PARAM_FLOAT, 'The version number of moodle site/local plugin linked to the function')
), 'functions that are available')
),
+ 'downloadfiles' => new external_value(PARAM_INT, '1 if users are allowed to download files, 0 if not', VALUE_OPTIONAL),
)
);
}
Please sign in to comment.
Something went wrong with that request. Please try again.