diff --git a/files/converter/googledrive/classes/converter.php b/files/converter/googledrive/classes/converter.php index 831c20f31d8..db189e61ba8 100644 --- a/files/converter/googledrive/classes/converter.php +++ b/files/converter/googledrive/classes/converter.php @@ -234,6 +234,10 @@ class converter implements \core_files\converter_interface { return false; } + if (!$issuer->get('enabled')) { + return false; + } + if (!$issuer->is_system_account_connected()) { return false; } diff --git a/files/converter/googledrive/lang/en/fileconverter_googledrive.php b/files/converter/googledrive/lang/en/fileconverter_googledrive.php index f118f0ef711..b99ed87428b 100644 --- a/files/converter/googledrive/lang/en/fileconverter_googledrive.php +++ b/files/converter/googledrive/lang/en/fileconverter_googledrive.php @@ -32,3 +32,7 @@ $string['test_converter'] = 'Test this converter is working properly.'; $string['test_conversion'] = 'Test document conversion'; $string['test_conversionready'] = 'This document converter is configured properly.'; $string['test_conversionnotready'] = 'This document converter is not configured properly.'; +$string['test_issuerinvalid'] = 'The OAuth service in the document converter settings is set to an invalid value.'; +$string['test_issuernotenabled'] = 'The OAuth service set in the document converter settings is not enabled.'; +$string['test_issuernotconnected'] = 'The OAuth service set in the document converter settings does not have a system account connected.'; +$string['test_issuernotset'] = 'The OAuth service needs to be set in the document converter settings.'; diff --git a/files/converter/googledrive/test.php b/files/converter/googledrive/test.php index fa764caad90..d090db182a0 100644 --- a/files/converter/googledrive/test.php +++ b/files/converter/googledrive/test.php @@ -57,7 +57,36 @@ if ($result) { $msg .= html_writer::link($pdflink, get_string('test_conversion', 'fileconverter_googledrive')); $msg .= html_writer::empty_tag('br'); } else { - $msg = $OUTPUT->notification(get_string('test_conversionnotready', 'fileconverter_googledrive'), 'warning'); + + // Diagnostics time. + $issuerid = get_config('fileconverter_googledrive', 'issuerid'); + $msg = ''; + if (empty($issuerid)) { + $msg = $OUTPUT->notification(get_string('test_issuernotset', 'fileconverter_googledrive'), 'warning'); + } + + if (empty($msg)) { + $issuer = \core\oauth2\api::get_issuer($issuerid); + if (empty($issuer)) { + $msg = $OUTPUT->notification(get_string('test_issuerinvalid', 'fileconverter_googledrive'), 'warning'); + } + } + + if (empty($msg)) { + if (!$issuer->get('enabled')) { + $msg = $OUTPUT->notification(get_string('test_issuernotenabled', 'fileconverter_googledrive'), 'warning'); + } + } + + if (empty($msg)) { + if (!$issuer->is_system_account_connected()) { + $msg = $OUTPUT->notification(get_string('test_issuernotconnected', 'fileconverter_googledrive'), 'warning'); + } + } + + if (empty($msg)) { + $msg = $OUTPUT->notification(get_string('test_conversionnotready', 'fileconverter_googledrive'), 'warning'); + } } $returl = new moodle_url('/admin/settings.php', array('section' => 'fileconvertergoogledrive')); $msg .= $OUTPUT->continue_button($returl); diff --git a/lib/classes/oauth2/issuer.php b/lib/classes/oauth2/issuer.php index e58b07c1b89..7960ea654d1 100644 --- a/lib/classes/oauth2/issuer.php +++ b/lib/classes/oauth2/issuer.php @@ -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; } }