mirror of
https://github.com/moodle/moodle.git
synced 2025-05-01 22:18:03 +02:00
MDL-58800 repository_googledocs: Switch oauth clients
We need to ensure we use the correct oauth client to download files. This change is the same as the one made to the onedrive repository where a usesystem flag is added to the file reference if the file has been copied to the system account.
This commit is contained in:
parent
175a51c472
commit
00879eca66
@ -432,11 +432,17 @@ class repository_googledocs extends repository {
|
||||
throw new repository_exception('cannotdownload', 'repository');
|
||||
}
|
||||
|
||||
$client = $this->get_user_oauth_client();
|
||||
$base = 'https://www.googleapis.com/drive/v3';
|
||||
|
||||
$source = json_decode($reference);
|
||||
|
||||
$client = null;
|
||||
if (!empty($source->usesystem)) {
|
||||
$client = \core\oauth2\api::get_system_oauth_client($this->issuer);
|
||||
} else {
|
||||
$client = $this->get_user_oauth_client();
|
||||
}
|
||||
|
||||
$base = 'https://www.googleapis.com/drive/v3';
|
||||
|
||||
$newfilename = false;
|
||||
if ($source->exportformat == 'download') {
|
||||
$params = ['alt' => 'media'];
|
||||
@ -588,7 +594,7 @@ class repository_googledocs extends repository {
|
||||
$storedfile->get_filepath(),
|
||||
$storedfile->get_filename());
|
||||
|
||||
if (empty($options['offline']) && !empty($info) && $info->is_writable()) {
|
||||
if (empty($options['offline']) && !empty($info) && $info->is_writable() && !empty($source->usesystem)) {
|
||||
// Add the current user as an OAuth writer.
|
||||
$systemauth = \core\oauth2\api::get_system_oauth_client($this->issuer);
|
||||
|
||||
@ -945,6 +951,7 @@ class repository_googledocs extends repository {
|
||||
// Update the returned reference so that the stored_file in moodle points to the newly copied file.
|
||||
$source->id = $newsource->id;
|
||||
$source->link = isset($newsource->webViewLink) ? $newsource->webViewLink : '';
|
||||
$source->usesystem = true;
|
||||
if (empty($source->link)) {
|
||||
$source->link = isset($newsource->webContentLink) ? $newsource->webContentLink : '';
|
||||
}
|
||||
@ -967,6 +974,9 @@ class repository_googledocs extends repository {
|
||||
return get_string('unknownsource', 'repository');
|
||||
}
|
||||
$source = json_decode($reference);
|
||||
if (empty($source->usesystem)) {
|
||||
return '';
|
||||
}
|
||||
$systemauth = \core\oauth2\api::get_system_oauth_client($this->issuer);
|
||||
|
||||
if ($systemauth === false) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user