Merge branch 'MDL-58280-master' of git://github.com/damyon/moodle

This commit is contained in:
David Monllao 2017-04-20 12:05:42 +08:00
commit ce85011f5a
12 changed files with 647 additions and 19 deletions

View file

@ -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;
}
}

View file

@ -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 {

View file

@ -1757,7 +1757,7 @@ class core_plugin_manager {
),
'fileconverter' => array(
'unoconv'
'unoconv', 'googledrive'
),
'editor' => array(