remove document_id prefix from legacy documents when using the new api
Fixes PLAT-994 Test plan Have a really old google collab make sure it works with drive Change-Id: I6e685bb975bc2f6a84a6d3207dd0c61bd7f1d3f5 Reviewed-on: https://gerrit.instructure.com/52551 QA-Review: August Thornton <august@instructure.com> Tested-by: Jenkins Reviewed-by: Brad Humphrey <brad@instructure.com> Product-Review: Brad Humphrey <brad@instructure.com>
This commit is contained in:
parent
469635d623
commit
694cf95083
|
@ -39,7 +39,7 @@ module GoogleDocs
|
|||
def download(document_id, extensions)
|
||||
response = api_client.execute!(
|
||||
:api_method => drive.files.get,
|
||||
:parameters => { :fileId => document_id }
|
||||
:parameters => { :fileId => normalize_document_id(document_id) }
|
||||
)
|
||||
|
||||
file = response.data.to_hash
|
||||
|
@ -88,7 +88,7 @@ module GoogleDocs
|
|||
api_client.authorization.update_token!
|
||||
result = api_client.execute(
|
||||
:api_method => drive.files.delete,
|
||||
:parameters => { :fileId => document_id })
|
||||
:parameters => { :fileId => normalize_document_id(document_id) })
|
||||
if result.error? && !result.error_message.include?('File not found')
|
||||
raise DriveConnectionException, result.error_message
|
||||
end
|
||||
|
@ -101,7 +101,7 @@ module GoogleDocs
|
|||
result = api_client.execute(
|
||||
:api_method => drive.permissions.delete,
|
||||
:parameters => {
|
||||
:fileId => document_id,
|
||||
:fileId => normalize_document_id(document_id),
|
||||
:permissionId => user_id })
|
||||
if result.error?
|
||||
raise DriveConnectionException, result.error_message
|
||||
|
@ -129,7 +129,7 @@ module GoogleDocs
|
|||
result = api_client.execute(
|
||||
:api_method => drive.permissions.insert,
|
||||
:body_object => new_permission,
|
||||
:parameters => { :fileId => document_id }
|
||||
:parameters => { :fileId => normalize_document_id(document_id) }
|
||||
)
|
||||
if result.error?
|
||||
raise DriveConnectionException, result.error_message
|
||||
|
@ -163,6 +163,9 @@ module GoogleDocs
|
|||
folderize_list(api_client.execute!(:api_method => drive.files.list, :parameters => {:maxResults => 0}).data.to_hash, extensions)
|
||||
end
|
||||
|
||||
def normalize_document_id(doc_id)
|
||||
doc_id.gsub(/^.+:/, '')
|
||||
end
|
||||
|
||||
def folderize_list(documents, extensions)
|
||||
root = GoogleDocs::DriveFolder.new('/')
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
#
|
||||
# Copyright (C) 2011-2014 Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe GoogleDocs::DriveConnection do
|
||||
|
||||
let(:token) { "token" }
|
||||
let(:secret) { "secret" }
|
||||
|
||||
before do
|
||||
config = {
|
||||
"api_key" => "key",
|
||||
"secret_key" => "secret",
|
||||
}
|
||||
GoogleDocs::DriveConnection.config = proc do
|
||||
config
|
||||
end
|
||||
end
|
||||
|
||||
describe "#normalize_document_id" do
|
||||
it "should remove prefixes" do
|
||||
google_docs = GoogleDocs::DriveConnection.new(token, secret)
|
||||
|
||||
spreadsheet_id = google_docs.send(:normalize_document_id, "spreadsheet:awesome-spreadsheet-id")
|
||||
expect(spreadsheet_id).to eq("awesome-spreadsheet-id")
|
||||
|
||||
doc_id = google_docs.send(:normalize_document_id, "document:awesome-document-id")
|
||||
expect(doc_id).to eq("awesome-document-id")
|
||||
end
|
||||
|
||||
it "shouldnt do anything to normalized ids" do
|
||||
google_docs = GoogleDocs::DriveConnection.new(token, secret)
|
||||
|
||||
|
||||
spreadsheet_id = google_docs.send(:normalize_document_id, "awesome-spreadsheet-id")
|
||||
expect(spreadsheet_id).to eq("awesome-spreadsheet-id")
|
||||
|
||||
doc_id = google_docs.send(:normalize_document_id, "awesome-document-id")
|
||||
expect(doc_id).to eq("awesome-document-id")
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue