From 33af78821061d2f6a70757ea3c0d8cae419cc77c Mon Sep 17 00:00:00 2001 From: Jerome Mouneyrac Date: Thu, 18 Oct 2012 15:13:58 +0800 Subject: [PATCH] MDL-35998 New mobile menu: with CSS url + existing enable mobile web services --- admin/settings/plugins.php | 3 -- admin/settings/server.php | 9 ++++ lang/en/admin.php | 3 ++ lib/adminlib.php | 59 +++++++++++++++++++++------ version.php | 2 +- webservice/externallib.php | 6 ++- webservice/tests/externallib_test.php | 1 + 7 files changed, 66 insertions(+), 17 deletions(-) diff --git a/admin/settings/plugins.php b/admin/settings/plugins.php index 29d0665dd3f..48db9fa9057 100644 --- a/admin/settings/plugins.php +++ b/admin/settings/plugins.php @@ -253,9 +253,6 @@ if ($hassiteconfig) { $ADMIN->add('webservicesettings', new admin_externalpage('webservicedocumentation', new lang_string('wsdocapi', 'webservice'), "$CFG->wwwroot/$CFG->admin/webservice/documentation.php", 'moodle/site:config', false)); /// manage service $temp = new admin_settingpage('externalservices', new lang_string('externalservices', 'webservice')); - $enablemobiledocurl = new moodle_url(get_docs_url('Enable_mobile_web_services')); - $enablemobiledoclink = html_writer::link($enablemobiledocurl, new lang_string('documentation')); - $temp->add(new admin_setting_enablemobileservice('enablemobilewebservice', new lang_string('enablemobilewebservice', 'admin'), new lang_string('configenablemobilewebservice', 'admin', $enablemobiledoclink), 0)); $temp->add(new admin_setting_heading('manageserviceshelpexplaination', new lang_string('information', 'webservice'), new lang_string('servicehelpexplanation', 'webservice'))); $temp->add(new admin_setting_manageexternalservices()); $ADMIN->add('webservicesettings', $temp); diff --git a/admin/settings/server.php b/admin/settings/server.php index 0c8746e9846..e8405692c9b 100644 --- a/admin/settings/server.php +++ b/admin/settings/server.php @@ -4,6 +4,15 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page + // Mobile + $mobile = new admin_settingpage('mobile', new lang_string('mobile','admin'), 'moodle/site:config', false); + $mobile->add(new admin_setting_configtext('mobilecssurl', new lang_string('mobilecssurl', 'admin'), new lang_string('configmobilecssurl','admin'), '', PARAM_URL)); + $enablemobiledocurl = new moodle_url(get_docs_url('Enable_mobile_web_services')); + $enablemobiledoclink = html_writer::link($enablemobiledocurl, new lang_string('documentation')); + $mobile->add(new admin_setting_enablemobileservice('enablemobilewebservice', + new lang_string('enablemobilewebservice', 'admin'), + new lang_string('configenablemobilewebservice', 'admin', $enablemobiledoclink), 0)); + $ADMIN->add('server', $mobile); // "systempaths" settingpage $temp = new admin_settingpage('systempaths', new lang_string('systempaths','admin')); diff --git a/lang/en/admin.php b/lang/en/admin.php index f8be0511783..6547942f4a6 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -255,6 +255,7 @@ $string['configminpasswordlength'] = 'Passwords must be at least these many char $string['configminpasswordlower'] = 'Passwords must have at least these many lower case letters.'; $string['configminpasswordnonalphanum'] = 'Passwords must have at least these many non-alphanumeric characters.'; $string['configminpasswordupper'] = 'Passwords must have at least these many upper case letters.'; +$string['configmobilecssurl'] = 'Custom CSS file to customize your mobile app interface.'; $string['configmodchooserdefault'] = 'Should the activity chooser be presented to users by default?'; $string['configmycoursesperpage'] = 'Maximum number of courses to display in any list of a user\'s own courses'; $string['configmymoodleredirect'] = 'This setting forces redirects to /my on login for non-admins and replaces the top level site navigation with /my'; @@ -686,6 +687,8 @@ $string['mnetrestore_extusers_admin'] = 'Note: This backup file $string['mnetrestore_extusers_mismatch'] = 'Note: This backup file apparently originates from a different Moodle installation and contains remote Moodle Network user accounts that may fail to restore. This operation is unsupported. If you are certain that it was created on this Moodle installation, or you can ensure that all the needed Moodle Network Hosts are configured, you may want to still try the restore.'; $string['mnetrestore_extusers_noadmin'] = 'Note: This backup file seems to come from a different Moodle installation and contains remote Moodle Network user accounts. You are not allowed to execute this type of restore. Contact the administrator of the site or, alternatively, restore this course without any user information (modules, files...)'; $string['mnetrestore_extusers_switchuserauth'] = 'Remote Moodle Network user {$a->username} (coming from {$a->mnethosturl}) switched to local {$a->auth} authenticated user.'; +$string['mobile'] = 'Mobile'; +$string['mobilecssurl'] = 'CSS'; $string['modchooserdefault'] = 'Activity chooser default'; $string['modeditdefaults'] = 'Default values for activity settings'; $string['modsettings'] = 'Manage activities'; diff --git a/lib/adminlib.php b/lib/adminlib.php index deef07ed2e7..cbd10cea082 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -6749,16 +6749,21 @@ class admin_setting_managerepository extends admin_setting { */ class admin_setting_enablemobileservice extends admin_setting_configcheckbox { - private $xmlrpcuse; //boolean: true => capability 'webservice/xmlrpc:use' is set for authenticated user role + /** @var boolean True means that the capability 'webservice/xmlrpc:use' is set for authenticated user role */ + private $xmlrpcuse; + /** @var boolean True means that the capability 'webservice/rest:use' is set for authenticated user role */ + private $restuse; /** - * Return true if Authenticated user role has the capability 'webservice/xmlrpc:use', otherwise false + * Return true if Authenticated user role has the capability 'webservice/xmlrpc:use' and 'webservice/rest:use', otherwise false. + * * @return boolean */ - private function is_xmlrpc_cap_allowed() { + private function is_protocol_cap_allowed() { global $DB, $CFG; - //if the $this->xmlrpcuse variable is not set, it needs to be set + // We keep xmlrpc enabled for backward compatibility. + // If the $this->xmlrpcuse variable is not set, it needs to be set. if (empty($this->xmlrpcuse) and $this->xmlrpcuse!==false) { $params = array(); $params['permission'] = CAP_ALLOW; @@ -6767,20 +6772,29 @@ class admin_setting_enablemobileservice extends admin_setting_configcheckbox { $this->xmlrpcuse = $DB->record_exists('role_capabilities', $params); } - return $this->xmlrpcuse; + // If the $this->restuse variable is not set, it needs to be set. + if (empty($this->restuse) and $this->restuse!==false) { + $params = array(); + $params['permission'] = CAP_ALLOW; + $params['roleid'] = $CFG->defaultuserroleid; + $params['capability'] = 'webservice/rest:use'; + $this->restuse = $DB->record_exists('role_capabilities', $params); + } + + return ($this->xmlrpcuse && $this->restuse); } /** - * Set the 'webservice/xmlrpc:use' to the Authenticated user role (allow or not) + * Set the 'webservice/xmlrpc:use'/'webservice/rest:use' to the Authenticated user role (allow or not) * @param type $status true to allow, false to not set */ - private function set_xmlrpc_cap($status) { + private function set_protocol_cap($status) { global $CFG; - if ($status and !$this->is_xmlrpc_cap_allowed()) { + if ($status and !$this->is_protocol_cap_allowed()) { //need to allow the cap $permission = CAP_ALLOW; $assign = true; - } else if (!$status and $this->is_xmlrpc_cap_allowed()){ + } else if (!$status and $this->is_protocol_cap_allowed()){ //need to disallow the cap $permission = CAP_INHERIT; $assign = true; @@ -6788,6 +6802,7 @@ class admin_setting_enablemobileservice extends admin_setting_configcheckbox { if (!empty($assign)) { $systemcontext = get_system_context(); assign_capability('webservice/xmlrpc:use', $permission, $CFG->defaultuserroleid, $systemcontext->id, true); + assign_capability('webservice/rest:use', $permission, $CFG->defaultuserroleid, $systemcontext->id, true); } } @@ -6834,7 +6849,7 @@ class admin_setting_enablemobileservice extends admin_setting_configcheckbox { require_once($CFG->dirroot . '/webservice/lib.php'); $webservicemanager = new webservice(); $mobileservice = $webservicemanager->get_external_service_by_shortname(MOODLE_OFFICIAL_MOBILE_SERVICE); - if ($mobileservice->enabled and $this->is_xmlrpc_cap_allowed()) { + if ($mobileservice->enabled and $this->is_protocol_cap_allowed()) { return $this->config_read($this->name); //same as returning 1 } else { return 0; @@ -6860,6 +6875,7 @@ class admin_setting_enablemobileservice extends admin_setting_configcheckbox { require_once($CFG->dirroot . '/webservice/lib.php'); $webservicemanager = new webservice(); + $updateprotocol = false; if ((string)$data === $this->yes) { //code run when enable mobile web service //enable web service systeme if necessary @@ -6875,11 +6891,20 @@ class admin_setting_enablemobileservice extends admin_setting_configcheckbox { if (!in_array('xmlrpc', $activeprotocols)) { $activeprotocols[] = 'xmlrpc'; + $updateprotocol = true; + } + + if (!in_array('rest', $activeprotocols)) { + $activeprotocols[] = 'rest'; + $updateprotocol = true; + } + + if ($updateprotocol) { set_config('webserviceprotocols', implode(',', $activeprotocols)); } //allow xml-rpc:use capability for authenticated user - $this->set_xmlrpc_cap(true); + $this->set_protocol_cap(true); } else { //disable web service system if no other services are enabled @@ -6894,11 +6919,21 @@ class admin_setting_enablemobileservice extends admin_setting_configcheckbox { $protocolkey = array_search('xmlrpc', $activeprotocols); if ($protocolkey !== false) { unset($activeprotocols[$protocolkey]); + $updateprotocol = true; + } + + $protocolkey = array_search('rest', $activeprotocols); + if ($protocolkey !== false) { + unset($activeprotocols[$protocolkey]); + $updateprotocol = true; + } + + if ($updateprotocol) { set_config('webserviceprotocols', implode(',', $activeprotocols)); } //disallow xml-rpc:use capability for authenticated user - $this->set_xmlrpc_cap(false); + $this->set_protocol_cap(false); } //disable the mobile service diff --git a/version.php b/version.php index 4bba4738bd0..8b5ac6cc3fd 100644 --- a/version.php +++ b/version.php @@ -30,7 +30,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2012101800.00; // YYYYMMDD = weekly release date of this DEV branch +$version = 2012101800.01; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes diff --git a/webservice/externallib.php b/webservice/externallib.php index 98d94b41be5..f1d7a682b5f 100644 --- a/webservice/externallib.php +++ b/webservice/externallib.php @@ -155,6 +155,9 @@ class core_webservice_external extends external_api { $siteinfo['functions'] = $availablefunctions; + // Mobile CSS theme and alternative login url + $siteinfo['mobilecssurl'] = get_config('admin', 'mobilecssurl'); + return $siteinfo; } @@ -191,7 +194,8 @@ class core_webservice_external extends external_api { 'downloadfiles' => new external_value(PARAM_INT, '1 if users are allowed to download files, 0 if not', VALUE_OPTIONAL), 'release' => new external_value(PARAM_TEXT, 'Moodle release number', VALUE_OPTIONAL), - 'version' => new external_value(PARAM_TEXT, 'Moodle version number', VALUE_OPTIONAL) + 'version' => new external_value(PARAM_TEXT, 'Moodle version number', VALUE_OPTIONAL), + 'mobilecssurl' => new external_value(PARAM_URL, 'Mobile custom CSS theme', VALUE_OPTIONAL) ) ); } diff --git a/webservice/tests/externallib_test.php b/webservice/tests/externallib_test.php index 6a8cdd462f1..004ae8531fe 100644 --- a/webservice/tests/externallib_test.php +++ b/webservice/tests/externallib_test.php @@ -84,6 +84,7 @@ class core_webservice_external_testcase extends externallib_advanced_testcase { $this->assertEquals(true, $siteinfo['downloadfiles']); $this->assertEquals($CFG->release, $siteinfo['release']); $this->assertEquals($CFG->version, $siteinfo['version']); + $this->assertEquals(get_config('admin', 'mobilecssurl'), $siteinfo['mobilecssurl']); } }