Skip to content

Commit

Permalink
Merge branch 'MDL-58800-master' of git://github.com/damyon/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed May 4, 2017
2 parents 1e324a4 + 00879ec commit bf39e7c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions repository/googledocs/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,17 @@ public function get_file($reference, $filename = '') {
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'];
Expand Down Expand Up @@ -588,7 +594,7 @@ public function send_file($storedfile, $lifetime=null , $filter=0, $forcedownloa
$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);

Expand Down Expand Up @@ -945,6 +951,7 @@ public function reference_file_selected($reference, $context, $component, $filea
// 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 : '';
}
Expand All @@ -967,6 +974,9 @@ public function get_reference_details($reference, $filestatus = 0) {
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) {
Expand Down

0 comments on commit bf39e7c

Please sign in to comment.