Skip to content

Commit

Permalink
MDL-53777 tool_mobile: New setting typeoflogin, including WS
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyva committed Oct 3, 2016
1 parent 8a0a741 commit c951f1f
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 2 deletions.
21 changes: 21 additions & 0 deletions admin/tool/mobile/classes/api.php
Expand Up @@ -27,6 +27,7 @@
use core_component;
use core_plugin_manager;
use context_system;
use moodle_url;

/**
* API exposed by tool_mobile
Expand All @@ -37,6 +38,13 @@
*/
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.
*
Expand Down Expand Up @@ -111,6 +119,19 @@ public static function get_site_public_settings() {
'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;
}

Expand Down
2 changes: 2 additions & 0 deletions admin/tool/mobile/classes/external.php
Expand Up @@ -140,6 +140,8 @@ public static function get_site_public_settings_returns() {
'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(),
)
);
Expand Down
7 changes: 7 additions & 0 deletions admin/tool/mobile/lang/en/tool_mobile.php
Expand Up @@ -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.';
15 changes: 15 additions & 0 deletions admin/tool/mobile/settings.php
Expand Up @@ -43,5 +43,20 @@

$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);
}
7 changes: 6 additions & 1 deletion admin/tool/mobile/tests/externallib_test.php
Expand Up @@ -31,6 +31,7 @@
require_once($CFG->dirroot . '/webservice/tests/helpers.php');

use tool_mobile\external;
use tool_mobile\api;

/**
* External learning plans webservice API tests.
Expand Down Expand Up @@ -78,17 +79,21 @@ public function test_get_site_public_settings() {
'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);
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/mobile/version.php
Expand Up @@ -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).

0 comments on commit c951f1f

Please sign in to comment.