mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 01:16:44 +02:00
Merge branch 'MDL-58280-master' of git://github.com/damyon/moodle
This commit is contained in:
commit
ce85011f5a
12 changed files with 647 additions and 19 deletions
|
@ -180,9 +180,25 @@ class issuer extends persistent {
|
|||
return false;
|
||||
}
|
||||
$sys = system_account::get_record(['issuerid' => $this->get('id')]);
|
||||
if (!empty($sys) and !empty($sys->get('refreshtoken'))) {
|
||||
return true;
|
||||
if (empty($sys) || empty($sys->get('refreshtoken'))) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
$scopes = api::get_system_scopes_for_issuer($this);
|
||||
|
||||
$grantedscopes = $sys->get('grantedscopes');
|
||||
|
||||
$scopes = explode(' ', $scopes);
|
||||
|
||||
foreach ($scopes as $scope) {
|
||||
if (!empty($scope)) {
|
||||
if (strpos(' ' . $grantedscopes . ' ', ' ' . $scope . ' ') === false) {
|
||||
// We have not been granted all the scopes that are required.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ require_once($CFG->libdir . '/filelib.php');
|
|||
abstract class rest {
|
||||
|
||||
/** @var curl $curl */
|
||||
private $curl;
|
||||
protected $curl;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -66,7 +66,7 @@ abstract class rest {
|
|||
* @param string $rawpost Optional param to include in the body of a post.
|
||||
* @return string|object
|
||||
*/
|
||||
public function call($functionname, $functionargs, $rawpost = false) {
|
||||
public function call($functionname, $functionargs, $rawpost = false, $contenttype = false) {
|
||||
$functions = $this->get_api_functions();
|
||||
$supportedmethods = [ 'get', 'put', 'post', 'patch', 'head', 'delete' ];
|
||||
if (empty($functions[$functionname])) {
|
||||
|
@ -106,7 +106,11 @@ abstract class rest {
|
|||
$callargs = $rawpost;
|
||||
}
|
||||
|
||||
$this->curl->setHeader('Content-type: application/json');
|
||||
if (empty($contenttype)) {
|
||||
$this->curl->setHeader('Content-type: application/json');
|
||||
} else {
|
||||
$this->curl->setHeader('Content-type: ' . $contenttype);
|
||||
}
|
||||
$response = $this->curl->$method($endpoint, $callargs);
|
||||
|
||||
if ($this->curl->errno == 0) {
|
||||
|
@ -117,6 +121,8 @@ abstract class rest {
|
|||
throw new rest_exception($json->error->code . ': ' . $json->error->message);
|
||||
}
|
||||
return $json;
|
||||
} else if ($responsetype == 'headers') {
|
||||
$response = $this->curl->get_raw_response();
|
||||
}
|
||||
return $response;
|
||||
} else {
|
||||
|
|
|
@ -1757,7 +1757,7 @@ class core_plugin_manager {
|
|||
),
|
||||
|
||||
'fileconverter' => array(
|
||||
'unoconv'
|
||||
'unoconv', 'googledrive'
|
||||
),
|
||||
|
||||
'editor' => array(
|
||||
|
|
|
@ -3603,20 +3603,31 @@ class curl {
|
|||
* @return bool
|
||||
*/
|
||||
public function put($url, $params = array(), $options = array()) {
|
||||
$file = $params['file'];
|
||||
if (!is_file($file)) {
|
||||
return null;
|
||||
}
|
||||
$fp = fopen($file, 'r');
|
||||
$size = filesize($file);
|
||||
$options['CURLOPT_PUT'] = 1;
|
||||
$options['CURLOPT_INFILESIZE'] = $size;
|
||||
$options['CURLOPT_INFILE'] = $fp;
|
||||
if (!isset($this->options['CURLOPT_USERPWD'])) {
|
||||
$this->setopt(array('CURLOPT_USERPWD'=>'anonymous: noreply@moodle.org'));
|
||||
$file = '';
|
||||
$fp = false;
|
||||
if (isset($params['file'])) {
|
||||
$file = $params['file'];
|
||||
if (is_file($file)) {
|
||||
$fp = fopen($file, 'r');
|
||||
$size = filesize($file);
|
||||
$options['CURLOPT_PUT'] = 1;
|
||||
$options['CURLOPT_INFILESIZE'] = $size;
|
||||
$options['CURLOPT_INFILE'] = $fp;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
if (!isset($this->options['CURLOPT_USERPWD'])) {
|
||||
$this->setopt(array('CURLOPT_USERPWD' => 'anonymous: noreply@moodle.org'));
|
||||
}
|
||||
} else {
|
||||
$options['CURLOPT_CUSTOMREQUEST'] = 'PUT';
|
||||
$options['CURLOPT_POSTFIELDS'] = $params;
|
||||
}
|
||||
|
||||
$ret = $this->request($url, $options);
|
||||
fclose($fp);
|
||||
if ($fp !== false) {
|
||||
fclose($fp);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue