mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-58280 fileconverter_googledrive: More helpful errors
Detect some config errors and give a better error message.
This commit is contained in:
parent
32f01c546c
commit
0b1a14aef9
@ -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;
|
||||
}
|
||||
|
@ -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.';
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user