Site admins can register google drive as a user service

Fixed a bug cause by incorrectly registering a user service (not call
UserService.register). Google Drive will now call the appropriate
method.

Fixes PLAT-950

Test Plan

Pre-Conditions:
1. Have GoogleDocs and Google Drive plugins set up on account
2. Have a site admin that does not have Google Drive services registered
in their user settings.

Steps to Reproduce:
1. Log in as a site admin.
2. Click Settings.
3. Click on the Google Drive icon under Other Services and authorize it
when the prompt appears.
4. Notice a green banner displays, saying it's been authorized, but the
Google Drive service does not appear under the Registered Services
section below.
5. Navigate to Collaborations and click "Start a new collaboration."
6. Select Google Docs under "Collaborate using"
7. Click "Authorize Google Drive Access" and accept the prompt.

Change-Id: If7008fcfea093f2869ceb06c2b8f8cd1832e7b29
Reviewed-on: https://gerrit.instructure.com/51237
Tested-by: Jenkins
Reviewed-by: Brad Humphrey <brad@instructure.com>
Product-Review: Brad Humphrey <brad@instructure.com>
QA-Review: Steven Shepherd <sshepherd@instructure.com>
This commit is contained in:
Brad Horrocks 2015-03-30 14:16:48 -06:00
parent 7293b94a5c
commit d7c36b531f
2 changed files with 51 additions and 20 deletions

View File

@ -221,12 +221,15 @@ class UsersController < ApplicationController
session.delete(:oauth_gdrive_nonce)
if logged_in_user
service = UserService.where(user_id: @current_user, service: 'google_drive', service_domain: 'drive.google.com').first_or_initialize
service.service_user_id = user_info['permissionId']
service.service_user_name = user_info['user']['emailAddress']
service.token = client.authorization.refresh_token
service.secret = client.authorization.access_token
service.save
UserService.register(
:service => "google_drive",
:service_domain => "drive.google.com",
:token => client.authorization.refresh_token,
:secret => client.authorization.access_token,
:user => logged_in_user,
:service_user_id => user_info['permissionId'],
:service_user_name => user_info['user']['emailAddress']
)
else
session[:oauth_gdrive_access_token] = client.authorization.access_token
session[:oauth_gdrive_refresh_token] = client.authorization.refresh_token

View File

@ -17,45 +17,49 @@
#
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
require File.expand_path(File.dirname(__FILE__) + '/../sharding_spec_helper')
describe UserService do
before :once do
user_service_model
end
it "should have a useful workflow" do
expect(@user_service.state).to eql(:active)
@user_service.failed_request
expect(@user_service.state).to eql(:failed)
end
it "should have a named scope for type" do
@user_service.type = 'BookmarkService'
@user_service.save!
expect(UserService.of_type('BookmarkService').first.id).to eql(@user_service.id)
end
it "should have a named scope for service" do
expect(UserService.for_service(@user_service)).to eq [@user_service]
expect(UserService.for_service(@user_service.service)).to eq [@user_service]
end
it "should have a service_name" do
expect(@user_service.service_name).to eql('Value For Service')
end
it "should be able to crypt a password" do
expect(@user_service.crypted_password).to be_nil
@user_service.password = 'password'
expect(@user_service.crypted_password).not_to be_nil
expect(@user_service.decrypted_password).to eql('password')
end
context "registration" do
specs_require_sharding
it "should be able to register a UserService, defaulting to a GoogleDocs service" do
@registration = UserService.register(
:user => user_model,
:token => 'some token',
:user => user_model,
:token => 'some token',
:secret => 'some secret',
:service_user_id => @user.id,
:service_user_name => @user.name,
@ -85,7 +89,7 @@ describe UserService do
expect(us.service_user_name).to eql('some username')
expect(us.decrypted_password).to eql('password')
end
it "should be able to register a diigo service" do
params = {}
params[:service] = 'diigo'
@ -100,7 +104,31 @@ describe UserService do
expect(us.service_user_name).to eql('some username')
expect(us.decrypted_password).to eql('password')
end
it 'Should allow user services to be setup cross shard' do
user = User.new
@shard1.activate { user.save! }
@shard2.activate do
@registration = UserService.register(
:user => user,
:token => 'some token',
:secret => 'some secret',
:service_user_id => user.id,
:service_user_name => user.name,
:service_user_url => 'some url',
:password => 'password'
)
expect(@registration.token).to eql('some token')
expect(@registration.secret).to eql('some secret')
expect(@registration.service_user_id).to eql(user.id)
expect(@registration.service_user_name).to eql(user.name)
expect(@registration.service_user_url).to eql('some url')
expect(@registration.decrypted_password).to eql('password')
expect(@registration.type).to eql('DocumentService')
end
end
it "should not be able to register an unknown service type" do
params = {}
params[:service] = 'some crazy service'
@ -110,7 +138,7 @@ describe UserService do
expect{UserService.register_from_params(user_model, params)}.to raise_error("Unknown Service Type")
end
end
context "service type disambiguation" do
it "should know that google_docs means 'DocumentService" do
expect(UserService.service_type('google_docs')).to eql('DocumentService')
@ -119,15 +147,15 @@ describe UserService do
it "should know that google_drive means 'DocumentService" do
expect(UserService.service_type('google_drive')).to eql('DocumentService')
end
it "should know that diigo means BookmarkService" do
expect(UserService.service_type('diigo')).to eql('BookmarkService')
end
it "should know that delicious means BookmarkService" do
expect(UserService.service_type('delicious')).to eql('BookmarkService')
end
it "should use other things as a generic UserService" do
expect(UserService.service_type('anything else')).to eql('UserService')
end