MDL-53777 tool_mobile: New setting typeoflogin, including WS

This commit is contained in:
Juan Leyva 2016-04-25 18:40:27 +02:00
parent 8a0a7414b2
commit c951f1fe58
6 changed files with 52 additions and 2 deletions

View File

@ -27,6 +27,7 @@ namespace tool_mobile;
use core_component;
use core_plugin_manager;
use context_system;
use moodle_url;
/**
* API exposed by tool_mobile
@ -37,6 +38,13 @@ use context_system;
*/
class api {
/** @var int to identify the login via app. */
const LOGIN_VIA_APP = 1;
/** @var int to identify the login via browser. */
const LOGIN_VIA_BROWSER = 2;
/** @var int to identify the login via an embedded browser. */
const LOGIN_VIA_EMBEDDED_BROWSER = 3;
/**
* Returns a list of Moodle plugins supporting the mobile app.
*
@ -111,6 +119,19 @@ class api {
'maintenanceenabled' => $CFG->maintenance_enabled,
'maintenancemessage' => format_text($CFG->maintenance_message),
);
$typeoflogin = get_config('tool_mobile', 'typeoflogin');
// Not found, edge case.
if ($typeoflogin === false) {
$typeoflogin = self::LOGIN_VIA_APP; // Defaults to via app.
}
$settings['typeoflogin'] = $typeoflogin;
if ($typeoflogin == self::LOGIN_VIA_BROWSER or
$typeoflogin == self::LOGIN_VIA_EMBEDDED_BROWSER) {
$url = new moodle_url("/$CFG->admin/tool/mobile/launch.php");
$settings['launchurl'] = $url->out(false);
}
return $settings;
}

View File

@ -140,6 +140,8 @@ class external extends external_api {
'enablemobilewebservice' => new external_value(PARAM_INT, 'Whether the Mobile service is enabled.'),
'maintenanceenabled' => new external_value(PARAM_INT, 'Whether site maintenance is enabled.'),
'maintenancemessage' => new external_value(PARAM_RAW, 'Maintenance message.'),
'typeoflogin' => new external_value(PARAM_INT, 'The type of login. 1 for app, 2 for browser, 3 for embedded.'),
'launchurl' => new external_value(PARAM_URL, 'SSO login launch URL. Empty if it won\'t be used.', VALUE_OPTIONAL),
'warnings' => new external_warnings(),
)
);

View File

@ -22,4 +22,11 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['forcedurlscheme'] = 'The URL scheme allows to open the mobile app from other apps like the browser. Use this setting if you want to allow only your custom branded app to be opened by the browser.';
$string['forcedurlscheme_key'] = 'URL scheme';
$string['loginintheapp'] = 'Via the app';
$string['logininthebrowser'] = 'Via a browser window (for SSO plugins)';
$string['loginintheembeddedbrowser'] = 'Via an embedded browser (for SSO plugins)';
$string['pluginname'] = 'Moodle Mobile tools';
$string['typeoflogin'] = 'Type of login';
$string['typeoflogin_desc'] = 'Choose the type of login.';

View File

@ -43,5 +43,20 @@ if ($hassiteconfig) {
$temp->add(new admin_setting_configtext('mobilecssurl', new lang_string('mobilecssurl', 'admin'),
new lang_string('configmobilecssurl', 'admin'), '', PARAM_URL));
// Type of login.
$options = array(
tool_mobile\api::LOGIN_VIA_APP => new lang_string('loginintheapp', 'tool_mobile'),
tool_mobile\api::LOGIN_VIA_BROWSER => new lang_string('logininthebrowser', 'tool_mobile'),
tool_mobile\api::LOGIN_VIA_EMBEDDED_BROWSER => new lang_string('loginintheembeddedbrowser', 'tool_mobile'),
);
$temp->add(new admin_setting_configselect('tool_mobile/typeoflogin',
new lang_string('typeoflogin', 'tool_mobile'),
new lang_string('typeoflogin_desc', 'tool_mobile'), 1, $options));
$temp->add(new admin_setting_configtext('tool_mobile/forcedurlscheme',
new lang_string('forcedurlscheme_key', 'tool_mobile'),
new lang_string('forcedurlscheme', 'tool_mobile'), '', PARAM_NOTAGS));
$ADMIN->add('webservicesettings', $temp);
}

View File

@ -31,6 +31,7 @@ global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
use tool_mobile\external;
use tool_mobile\api;
/**
* External learning plans webservice API tests.
@ -78,17 +79,21 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
'enablemobilewebservice' => $CFG->enablemobilewebservice,
'maintenanceenabled' => $CFG->maintenance_enabled,
'maintenancemessage' => format_text($CFG->maintenance_message),
'typeoflogin' => api::LOGIN_VIA_APP,
'warnings' => array()
);
$this->assertEquals($expected, $result);
// Change a value.
// Change some values.
set_config('registerauth', 'email');
$authinstructions = 'Something with <b>html tags</b>';
set_config('auth_instructions', $authinstructions);
set_config('typeoflogin', api::LOGIN_VIA_BROWSER, 'tool_mobile');
$expected['registerauth'] = 'email';
$expected['authinstructions'] = format_text($authinstructions);
$expected['typeoflogin'] = api::LOGIN_VIA_BROWSER;
$expected['launchurl'] = "$CFG->wwwroot/$CFG->admin/tool/mobile/launch.php";;
$result = external::get_site_public_settings();
$result = external_api::clean_returnvalue(external::get_site_public_settings_returns(), $result);

View File

@ -23,6 +23,6 @@
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2016052301; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2016052302; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2016051900; // Requires this Moodle version.
$plugin->component = 'tool_mobile'; // Full name of the plugin (used for diagnostics).