mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-35998 New mobile menu: with CSS url + existing enable mobile web services
This commit is contained in:
parent
7e8ae12a7a
commit
33af788210
7 changed files with 66 additions and 17 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue