force google_drive usage in submissions

fixes: PLAT-917

test_plan:
try to do a submission with google docs user service  enabled, but no google drive user service. It should force you to get a google drive token

Change-Id: I80185077e8f4a66225e96fa5fd8ed8e7fe1243ea
Reviewed-on: https://gerrit.instructure.com/49070
Tested-by: Jenkins
Reviewed-by: Brad Horrocks <bhorrocks@instructure.com>
QA-Review: August Thornton <august@instructure.com>
Product-Review: Nathan Mills <nathanm@instructure.com>
This commit is contained in:
Nathan Mills 2015-02-19 10:53:42 -07:00
parent 0851e1dcfe
commit 9ecedb90b3
3 changed files with 29 additions and 3 deletions

View File

@ -132,6 +132,8 @@ class AssignmentsController < ApplicationController
google_docs = google_service_connection
@google_service = google_docs.service_type
@google_docs_token = google_docs.retrieve_access_token
@google_drive_upgrade = logged_in_user && Canvas::Plugin.find(:google_drive).try(:settings) &&
(!logged_in_user.user_services.where(service: 'google_drive').first || !(google_drive_connection.verify_access_token rescue false))
rescue GoogleDocs::NoTokenError
#do nothing
end

View File

@ -203,7 +203,7 @@
}
</style>
<% if show_google_docs %>
<% if @google_docs_token %>
<% if @google_docs_token and not @google_drive_upgrade%>
<% if @domain_root_account.feature_enabled?(:google_docs_domain_restriction) &&
@domain_root_account.settings[:google_docs_domain] &&
!@current_user.gmail.match(%r{@#{@domain_root_account.settings[:google_docs_domain]}$}) %>
@ -267,12 +267,18 @@
</div>
<% end %>
<% end %>
<% elsif @google_drive_upgrade %>
<div id="submit_google_doc_form">
<%= t 'messages.google_drives_auth_required', "Before you can submit assignments directly from Google Drive you need to authorize Canvas to access your Google Drive account:" %>
<div style="font-size: 1.1em; text-align: center; margin: 10px;">
<a class="btn" href="<%= oauth_url(:service => :google_drive, :return_to => (request.url + "#submit_google_doc_form")) %>"><%= t 'links.authorize_google_drive', "Authorize Google Drive Access" %></a>
</div>
</div>
<% else %>
<div id="submit_google_doc_form">
<%= t 'messages.google_docs_auth_required', "Before you can submit assignments directly from Google Docs you need to authorize Canvas to access your Google Docs account:" %>
<div style="font-size: 1.1em; text-align: center; margin: 10px;">
<%# TODO: do the right stuff %>
<a class="btn" href="<%= oauth_url(:service => :google_drive, :return_to => (request.url + "#submit_google_doc_form")) %>"><%= t 'links.authorize_google_docs', "Authorize Google Docs Access" %></a>
<a class="btn" href="<%= oauth_url(:service => :google_docs, :return_to => (request.url + "#submit_google_doc_form")) %>"><%= t 'links.authorize_google_docs', "Authorize Google Docs Access" %></a>
</div>
</div>
<% end %>

View File

@ -165,6 +165,24 @@ describe AssignmentsController do
get 'show', :course_id => @course.id, :id => a.id
GoogleDocs::Connection.unstub(:config)
end
it 'should force users to use google drive if availible' do
user_session(@student)
a = @course.assignments.create(:title => "some assignment")
plugin = Canvas::Plugin.find(:google_drive)
plugin_setting = PluginSetting.find_by_name(plugin.id) || PluginSetting.new(:name => plugin.id, :settings => plugin.default_settings)
plugin_setting.posted_settings = {}
plugin_setting.save!
google_docs_mock = mock('google_docs')
google_docs_mock.stubs(:service_type).returns(nil)
google_docs_mock.stubs(:retrieve_access_token).returns(nil)
controller.stubs(:google_service_connection).returns(google_docs_mock)
get 'show', :course_id => @course.id, :id => a.id
expect(response).to be_success
expect(assigns(:google_drive_upgrade)).to be_truthy
end
end
describe "GET 'syllabus'" do