canvas-lms/app/models/google_docs_collaboration.rb

142 lines
4.2 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2011-02-01 09:57:29 +08:00
#
# Copyright (C) 2011 - present Instructure, Inc.
2011-02-01 09:57:29 +08:00
#
# 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/>.
#
class GoogleDocsCollaboration < Collaboration
GOOGLE_DRIVE_SERVICE = "drive.google.com"
2011-02-01 09:57:29 +08:00
def style_class
'google_docs'
end
2011-02-01 09:57:29 +08:00
def service_name
"Google Docs"
end
2011-02-01 09:57:29 +08:00
def delete_document
if self.document_id && self.user
# google docs expected an object
# drive just wants an id
Remove Google Docs plugin Google drive relevant code has been moved to the gems/google_drive Actually test google drive with mocked api responses cleaned up lots of code Fixes PLAT-1301 Test Plan: *** You'll need to use 2 separate google accounts to fully test *** ** Its helpful to have multiple chrome profiles so you dont have to log in and ** out a bunch https://support.google.com/chrome/answer/2364824?hl=en BEFORE SWITCHING TO THIS PATCH SET - Make sure you have some google doc collaborations - Directions for creating one are below - Disable your google docs plugin Switch to the patch set Enable google drive. (if not already) - You should be able to paste in a client_secrets.json - Update Redirect URI to point to your local instance (The URI should exist in the JSON) As an admin/teacher - Goto `profile/settings` and add the google drive user service - Your email should be displayed with the service - Goto Collaborations - Make sure existing collaborations still work - Click "Start new collaboration" - give it a nice name (Created by admin) - select your student - click start collaborating - You should be redirected to the new doc in google - create another collaboration without the student (Created by admin, no users) - Create an assignment with Submission Type: Online Online Entry Options: File Uploads - Make sure your student has access to the course/assignment - Goto Account settings -> Users - Click View User Groups in the top right - create a new group set with a group in it - add yourself and your student to the group - Goto the Group's Collaborations (Courses & Groups -> [group name] -> Collaborations) - Click "Start new collaboration" - give it a nice name (Created by admin for group) - select your student - click start collaborating - You should be redirected to the new doc in google As a student - Goto `profile/settings` and add the google drive user service - Your email should be displayed with the service - Goto the assignment - Submit the assignment - You should have a "Google Doc" tab - Choose a document and submit it - After it submitted, click download on the right side just to make sure its correct - Goto Collaborations - Make sure existing collaborations still work - make sure the "created by admin" collaboration works - make sure you can't see "Created by admin, no users" - Click "Start new collaboration" - give it a nice name (created by a student) - click start collaborating - You should be redirected to the new doc in google - Switch to your admin/teacher and make sure they can't access it - Edit the collaboration add the teacher, click Save - Switch to your admin/teacher and make sure they can access it - Goto `profile/settings` and REMOVE the google drive user service - Go back to collaborations - You should be forced to add the google service in order to use a collaboration - Goto the Group's Collaborations (Courses & Groups -> [group name] -> Collaborations) - Make sure you can access "Created by admin for group" - Click "Start new collaboration" - select your admin/teacher - click start collaborating - You should be redirected to the new doc in google - make sure your admin can access it to As a site admin - Disable Google Drive - Then with your student - Make sure you can still do file upload submissions on the assignment - Collaborations should no longer show up (unless you have etherpad enabled) - Google drive should no longer show up in your profile settings as a registered service Change-Id: I4dfaff6f5262743c044aadd12266fd0bd85a60e1 Reviewed-on: https://gerrit.instructure.com/69078 Reviewed-by: Andrew Butterfield <abutterfield@instructure.com> Tested-by: Jenkins QA-Review: August Thornton <august@instructure.com> Product-Review: Brad Horrocks <bhorrocks@instructure.com>
2015-12-17 05:53:11 +08:00
doc = self.document_id
google_adapter_for_user.delete_doc(doc)
2011-02-01 09:57:29 +08:00
end
end
2011-02-01 09:57:29 +08:00
def initialize_document
if !self.document_id && self.user
name = self.title
name = nil if name && name.empty?
name ||= I18n.t('lib.google_docs.default_document_name', "Instructure Doc")
result = google_adapter_for_user.create_doc(name)
if result
Remove Google Docs plugin Google drive relevant code has been moved to the gems/google_drive Actually test google drive with mocked api responses cleaned up lots of code Fixes PLAT-1301 Test Plan: *** You'll need to use 2 separate google accounts to fully test *** ** Its helpful to have multiple chrome profiles so you dont have to log in and ** out a bunch https://support.google.com/chrome/answer/2364824?hl=en BEFORE SWITCHING TO THIS PATCH SET - Make sure you have some google doc collaborations - Directions for creating one are below - Disable your google docs plugin Switch to the patch set Enable google drive. (if not already) - You should be able to paste in a client_secrets.json - Update Redirect URI to point to your local instance (The URI should exist in the JSON) As an admin/teacher - Goto `profile/settings` and add the google drive user service - Your email should be displayed with the service - Goto Collaborations - Make sure existing collaborations still work - Click "Start new collaboration" - give it a nice name (Created by admin) - select your student - click start collaborating - You should be redirected to the new doc in google - create another collaboration without the student (Created by admin, no users) - Create an assignment with Submission Type: Online Online Entry Options: File Uploads - Make sure your student has access to the course/assignment - Goto Account settings -> Users - Click View User Groups in the top right - create a new group set with a group in it - add yourself and your student to the group - Goto the Group's Collaborations (Courses & Groups -> [group name] -> Collaborations) - Click "Start new collaboration" - give it a nice name (Created by admin for group) - select your student - click start collaborating - You should be redirected to the new doc in google As a student - Goto `profile/settings` and add the google drive user service - Your email should be displayed with the service - Goto the assignment - Submit the assignment - You should have a "Google Doc" tab - Choose a document and submit it - After it submitted, click download on the right side just to make sure its correct - Goto Collaborations - Make sure existing collaborations still work - make sure the "created by admin" collaboration works - make sure you can't see "Created by admin, no users" - Click "Start new collaboration" - give it a nice name (created by a student) - click start collaborating - You should be redirected to the new doc in google - Switch to your admin/teacher and make sure they can't access it - Edit the collaboration add the teacher, click Save - Switch to your admin/teacher and make sure they can access it - Goto `profile/settings` and REMOVE the google drive user service - Go back to collaborations - You should be forced to add the google service in order to use a collaboration - Goto the Group's Collaborations (Courses & Groups -> [group name] -> Collaborations) - Make sure you can access "Created by admin for group" - Click "Start new collaboration" - select your admin/teacher - click start collaborating - You should be redirected to the new doc in google - make sure your admin can access it to As a site admin - Disable Google Drive - Then with your student - Make sure you can still do file upload submissions on the assignment - Collaborations should no longer show up (unless you have etherpad enabled) - Google drive should no longer show up in your profile settings as a registered service Change-Id: I4dfaff6f5262743c044aadd12266fd0bd85a60e1 Reviewed-on: https://gerrit.instructure.com/69078 Reviewed-by: Andrew Butterfield <abutterfield@instructure.com> Tested-by: Jenkins QA-Review: August Thornton <august@instructure.com> Product-Review: Brad Horrocks <bhorrocks@instructure.com>
2015-12-17 05:53:11 +08:00
self.document_id = result.data.id
self.data = result.data.to_json
self.url = result.data.alternateLink
end
2011-02-01 09:57:29 +08:00
end
end
2011-02-01 09:57:29 +08:00
def user_can_access_document_type?(user)
return !!google_adapter_user_service(user) if self.user && user
false
2011-02-01 09:57:29 +08:00
end
2011-02-01 09:57:29 +08:00
def authorize_user(user)
return unless self.document_id
service_user_id = google_adapter_user_service(user).service_user_id rescue nil
collaborator = self.collaborators.where(user_id: user).first
if collaborator
if collaborator.authorized_service_user_id != service_user_id
google_adapter_for_user.acl_remove(self.document_id, [collaborator.authorized_service_user_id]) if collaborator.authorized_service_user_id
Remove Google Docs plugin Google drive relevant code has been moved to the gems/google_drive Actually test google drive with mocked api responses cleaned up lots of code Fixes PLAT-1301 Test Plan: *** You'll need to use 2 separate google accounts to fully test *** ** Its helpful to have multiple chrome profiles so you dont have to log in and ** out a bunch https://support.google.com/chrome/answer/2364824?hl=en BEFORE SWITCHING TO THIS PATCH SET - Make sure you have some google doc collaborations - Directions for creating one are below - Disable your google docs plugin Switch to the patch set Enable google drive. (if not already) - You should be able to paste in a client_secrets.json - Update Redirect URI to point to your local instance (The URI should exist in the JSON) As an admin/teacher - Goto `profile/settings` and add the google drive user service - Your email should be displayed with the service - Goto Collaborations - Make sure existing collaborations still work - Click "Start new collaboration" - give it a nice name (Created by admin) - select your student - click start collaborating - You should be redirected to the new doc in google - create another collaboration without the student (Created by admin, no users) - Create an assignment with Submission Type: Online Online Entry Options: File Uploads - Make sure your student has access to the course/assignment - Goto Account settings -> Users - Click View User Groups in the top right - create a new group set with a group in it - add yourself and your student to the group - Goto the Group's Collaborations (Courses & Groups -> [group name] -> Collaborations) - Click "Start new collaboration" - give it a nice name (Created by admin for group) - select your student - click start collaborating - You should be redirected to the new doc in google As a student - Goto `profile/settings` and add the google drive user service - Your email should be displayed with the service - Goto the assignment - Submit the assignment - You should have a "Google Doc" tab - Choose a document and submit it - After it submitted, click download on the right side just to make sure its correct - Goto Collaborations - Make sure existing collaborations still work - make sure the "created by admin" collaboration works - make sure you can't see "Created by admin, no users" - Click "Start new collaboration" - give it a nice name (created by a student) - click start collaborating - You should be redirected to the new doc in google - Switch to your admin/teacher and make sure they can't access it - Edit the collaboration add the teacher, click Save - Switch to your admin/teacher and make sure they can access it - Goto `profile/settings` and REMOVE the google drive user service - Go back to collaborations - You should be forced to add the google service in order to use a collaboration - Goto the Group's Collaborations (Courses & Groups -> [group name] -> Collaborations) - Make sure you can access "Created by admin for group" - Click "Start new collaboration" - select your admin/teacher - click start collaborating - You should be redirected to the new doc in google - make sure your admin can access it to As a site admin - Disable Google Drive - Then with your student - Make sure you can still do file upload submissions on the assignment - Collaborations should no longer show up (unless you have etherpad enabled) - Google drive should no longer show up in your profile settings as a registered service Change-Id: I4dfaff6f5262743c044aadd12266fd0bd85a60e1 Reviewed-on: https://gerrit.instructure.com/69078 Reviewed-by: Andrew Butterfield <abutterfield@instructure.com> Tested-by: Jenkins QA-Review: August Thornton <august@instructure.com> Product-Review: Brad Horrocks <bhorrocks@instructure.com>
2015-12-17 05:53:11 +08:00
user_param = service_user_id
google_adapter_for_user.acl_add(self.document_id, [user_param])
collaborator.update(:authorized_service_user_id => service_user_id)
end
else
# no collaboration for this user, lets create it
add_users_to_collaborators([user])
2011-02-01 09:57:29 +08:00
end
end
2011-02-01 09:57:29 +08:00
def remove_users_from_document(users_to_remove)
Remove Google Docs plugin Google drive relevant code has been moved to the gems/google_drive Actually test google drive with mocked api responses cleaned up lots of code Fixes PLAT-1301 Test Plan: *** You'll need to use 2 separate google accounts to fully test *** ** Its helpful to have multiple chrome profiles so you dont have to log in and ** out a bunch https://support.google.com/chrome/answer/2364824?hl=en BEFORE SWITCHING TO THIS PATCH SET - Make sure you have some google doc collaborations - Directions for creating one are below - Disable your google docs plugin Switch to the patch set Enable google drive. (if not already) - You should be able to paste in a client_secrets.json - Update Redirect URI to point to your local instance (The URI should exist in the JSON) As an admin/teacher - Goto `profile/settings` and add the google drive user service - Your email should be displayed with the service - Goto Collaborations - Make sure existing collaborations still work - Click "Start new collaboration" - give it a nice name (Created by admin) - select your student - click start collaborating - You should be redirected to the new doc in google - create another collaboration without the student (Created by admin, no users) - Create an assignment with Submission Type: Online Online Entry Options: File Uploads - Make sure your student has access to the course/assignment - Goto Account settings -> Users - Click View User Groups in the top right - create a new group set with a group in it - add yourself and your student to the group - Goto the Group's Collaborations (Courses & Groups -> [group name] -> Collaborations) - Click "Start new collaboration" - give it a nice name (Created by admin for group) - select your student - click start collaborating - You should be redirected to the new doc in google As a student - Goto `profile/settings` and add the google drive user service - Your email should be displayed with the service - Goto the assignment - Submit the assignment - You should have a "Google Doc" tab - Choose a document and submit it - After it submitted, click download on the right side just to make sure its correct - Goto Collaborations - Make sure existing collaborations still work - make sure the "created by admin" collaboration works - make sure you can't see "Created by admin, no users" - Click "Start new collaboration" - give it a nice name (created by a student) - click start collaborating - You should be redirected to the new doc in google - Switch to your admin/teacher and make sure they can't access it - Edit the collaboration add the teacher, click Save - Switch to your admin/teacher and make sure they can access it - Goto `profile/settings` and REMOVE the google drive user service - Go back to collaborations - You should be forced to add the google service in order to use a collaboration - Goto the Group's Collaborations (Courses & Groups -> [group name] -> Collaborations) - Make sure you can access "Created by admin for group" - Click "Start new collaboration" - select your admin/teacher - click start collaborating - You should be redirected to the new doc in google - make sure your admin can access it to As a site admin - Disable Google Drive - Then with your student - Make sure you can still do file upload submissions on the assignment - Collaborations should no longer show up (unless you have etherpad enabled) - Google drive should no longer show up in your profile settings as a registered service Change-Id: I4dfaff6f5262743c044aadd12266fd0bd85a60e1 Reviewed-on: https://gerrit.instructure.com/69078 Reviewed-by: Andrew Butterfield <abutterfield@instructure.com> Tested-by: Jenkins QA-Review: August Thornton <august@instructure.com> Product-Review: Brad Horrocks <bhorrocks@instructure.com>
2015-12-17 05:53:11 +08:00
users_to_remove = users_to_remove.map do |user|
user_service = google_user_service(user, GOOGLE_DRIVE_SERVICE) and user_service.service_user_id
end
google_adapter_for_user.acl_remove(self.document_id, users_to_remove) if self.document_id
2011-02-01 09:57:29 +08:00
end
restrict google doc submissions by domain fixes CNVS-8949 test plan: * from a rails console, run the following: account = Account.default account.settings[:google_docs_domain] = 'example.com' account.save! * as a student, configure your google docs integration from your profile page; * attempt to submit an assignment that allows file uploads using the "google docs" tab of the submissions box; * verify that a message is displayed informing you that cannot use a google doc because your domain is incorrect; * as another user who shares a course with the first student, create a google doc collaboration and add the first student to it; * verify that the first student cannot join the collaboration; * change the account :gmail_domain setting to 'gmail.com' and verify that both assignment submissions and collaborations work as expected; * verify that if you delete the gmail domain account setting, both google doc submissions and collaborations work as expected for users with google docs integration configured. note: users added to a collaboration without a valid google docs address will receive a notification about the collaboration, but will not be able to join it. this is pre-existing behavior. Change-Id: I26f164f253710819214ccf5f2250b74b91a6774b Reviewed-on: https://gerrit.instructure.com/26436 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Zach Pendleton <zachp@instructure.com> Product-Review: Zach Pendleton <zachp@instructure.com> QA-Review: Zach Pendleton <zachp@instructure.com>
2013-11-19 03:41:10 +08:00
2011-02-01 09:57:29 +08:00
def add_users_to_document(new_users)
restrict google doc submissions by domain fixes CNVS-8949 test plan: * from a rails console, run the following: account = Account.default account.settings[:google_docs_domain] = 'example.com' account.save! * as a student, configure your google docs integration from your profile page; * attempt to submit an assignment that allows file uploads using the "google docs" tab of the submissions box; * verify that a message is displayed informing you that cannot use a google doc because your domain is incorrect; * as another user who shares a course with the first student, create a google doc collaboration and add the first student to it; * verify that the first student cannot join the collaboration; * change the account :gmail_domain setting to 'gmail.com' and verify that both assignment submissions and collaborations work as expected; * verify that if you delete the gmail domain account setting, both google doc submissions and collaborations work as expected for users with google docs integration configured. note: users added to a collaboration without a valid google docs address will receive a notification about the collaboration, but will not be able to join it. this is pre-existing behavior. Change-Id: I26f164f253710819214ccf5f2250b74b91a6774b Reviewed-on: https://gerrit.instructure.com/26436 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Zach Pendleton <zachp@instructure.com> Product-Review: Zach Pendleton <zachp@instructure.com> QA-Review: Zach Pendleton <zachp@instructure.com>
2013-11-19 03:41:10 +08:00
if document_id
domain = if context.root_account.feature_enabled?(:google_docs_domain_restriction)
context.root_account.settings[:google_docs_domain]
else
nil
end
Remove Google Docs plugin Google drive relevant code has been moved to the gems/google_drive Actually test google drive with mocked api responses cleaned up lots of code Fixes PLAT-1301 Test Plan: *** You'll need to use 2 separate google accounts to fully test *** ** Its helpful to have multiple chrome profiles so you dont have to log in and ** out a bunch https://support.google.com/chrome/answer/2364824?hl=en BEFORE SWITCHING TO THIS PATCH SET - Make sure you have some google doc collaborations - Directions for creating one are below - Disable your google docs plugin Switch to the patch set Enable google drive. (if not already) - You should be able to paste in a client_secrets.json - Update Redirect URI to point to your local instance (The URI should exist in the JSON) As an admin/teacher - Goto `profile/settings` and add the google drive user service - Your email should be displayed with the service - Goto Collaborations - Make sure existing collaborations still work - Click "Start new collaboration" - give it a nice name (Created by admin) - select your student - click start collaborating - You should be redirected to the new doc in google - create another collaboration without the student (Created by admin, no users) - Create an assignment with Submission Type: Online Online Entry Options: File Uploads - Make sure your student has access to the course/assignment - Goto Account settings -> Users - Click View User Groups in the top right - create a new group set with a group in it - add yourself and your student to the group - Goto the Group's Collaborations (Courses & Groups -> [group name] -> Collaborations) - Click "Start new collaboration" - give it a nice name (Created by admin for group) - select your student - click start collaborating - You should be redirected to the new doc in google As a student - Goto `profile/settings` and add the google drive user service - Your email should be displayed with the service - Goto the assignment - Submit the assignment - You should have a "Google Doc" tab - Choose a document and submit it - After it submitted, click download on the right side just to make sure its correct - Goto Collaborations - Make sure existing collaborations still work - make sure the "created by admin" collaboration works - make sure you can't see "Created by admin, no users" - Click "Start new collaboration" - give it a nice name (created by a student) - click start collaborating - You should be redirected to the new doc in google - Switch to your admin/teacher and make sure they can't access it - Edit the collaboration add the teacher, click Save - Switch to your admin/teacher and make sure they can access it - Goto `profile/settings` and REMOVE the google drive user service - Go back to collaborations - You should be forced to add the google service in order to use a collaboration - Goto the Group's Collaborations (Courses & Groups -> [group name] -> Collaborations) - Make sure you can access "Created by admin for group" - Click "Start new collaboration" - select your admin/teacher - click start collaborating - You should be redirected to the new doc in google - make sure your admin can access it to As a site admin - Disable Google Drive - Then with your student - Make sure you can still do file upload submissions on the assignment - Collaborations should no longer show up (unless you have etherpad enabled) - Google drive should no longer show up in your profile settings as a registered service Change-Id: I4dfaff6f5262743c044aadd12266fd0bd85a60e1 Reviewed-on: https://gerrit.instructure.com/69078 Reviewed-by: Andrew Butterfield <abutterfield@instructure.com> Tested-by: Jenkins QA-Review: August Thornton <august@instructure.com> Product-Review: Brad Horrocks <bhorrocks@instructure.com>
2015-12-17 05:53:11 +08:00
user_ids = new_users.map do |user|
google_user_service(user, GOOGLE_DRIVE_SERVICE).service_user_id rescue nil
end.compact
google_adapter_for_user.acl_add(self.document_id, user_ids, domain)
restrict google doc submissions by domain fixes CNVS-8949 test plan: * from a rails console, run the following: account = Account.default account.settings[:google_docs_domain] = 'example.com' account.save! * as a student, configure your google docs integration from your profile page; * attempt to submit an assignment that allows file uploads using the "google docs" tab of the submissions box; * verify that a message is displayed informing you that cannot use a google doc because your domain is incorrect; * as another user who shares a course with the first student, create a google doc collaboration and add the first student to it; * verify that the first student cannot join the collaboration; * change the account :gmail_domain setting to 'gmail.com' and verify that both assignment submissions and collaborations work as expected; * verify that if you delete the gmail domain account setting, both google doc submissions and collaborations work as expected for users with google docs integration configured. note: users added to a collaboration without a valid google docs address will receive a notification about the collaboration, but will not be able to join it. this is pre-existing behavior. Change-Id: I26f164f253710819214ccf5f2250b74b91a6774b Reviewed-on: https://gerrit.instructure.com/26436 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Zach Pendleton <zachp@instructure.com> Product-Review: Zach Pendleton <zachp@instructure.com> QA-Review: Zach Pendleton <zachp@instructure.com>
2013-11-19 03:41:10 +08:00
end
2011-02-01 09:57:29 +08:00
end
restrict google doc submissions by domain fixes CNVS-8949 test plan: * from a rails console, run the following: account = Account.default account.settings[:google_docs_domain] = 'example.com' account.save! * as a student, configure your google docs integration from your profile page; * attempt to submit an assignment that allows file uploads using the "google docs" tab of the submissions box; * verify that a message is displayed informing you that cannot use a google doc because your domain is incorrect; * as another user who shares a course with the first student, create a google doc collaboration and add the first student to it; * verify that the first student cannot join the collaboration; * change the account :gmail_domain setting to 'gmail.com' and verify that both assignment submissions and collaborations work as expected; * verify that if you delete the gmail domain account setting, both google doc submissions and collaborations work as expected for users with google docs integration configured. note: users added to a collaboration without a valid google docs address will receive a notification about the collaboration, but will not be able to join it. this is pre-existing behavior. Change-Id: I26f164f253710819214ccf5f2250b74b91a6774b Reviewed-on: https://gerrit.instructure.com/26436 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Zach Pendleton <zachp@instructure.com> Product-Review: Zach Pendleton <zachp@instructure.com> QA-Review: Zach Pendleton <zachp@instructure.com>
2013-11-19 03:41:10 +08:00
2011-02-01 09:57:29 +08:00
def parse_data
Remove Google Docs plugin Google drive relevant code has been moved to the gems/google_drive Actually test google drive with mocked api responses cleaned up lots of code Fixes PLAT-1301 Test Plan: *** You'll need to use 2 separate google accounts to fully test *** ** Its helpful to have multiple chrome profiles so you dont have to log in and ** out a bunch https://support.google.com/chrome/answer/2364824?hl=en BEFORE SWITCHING TO THIS PATCH SET - Make sure you have some google doc collaborations - Directions for creating one are below - Disable your google docs plugin Switch to the patch set Enable google drive. (if not already) - You should be able to paste in a client_secrets.json - Update Redirect URI to point to your local instance (The URI should exist in the JSON) As an admin/teacher - Goto `profile/settings` and add the google drive user service - Your email should be displayed with the service - Goto Collaborations - Make sure existing collaborations still work - Click "Start new collaboration" - give it a nice name (Created by admin) - select your student - click start collaborating - You should be redirected to the new doc in google - create another collaboration without the student (Created by admin, no users) - Create an assignment with Submission Type: Online Online Entry Options: File Uploads - Make sure your student has access to the course/assignment - Goto Account settings -> Users - Click View User Groups in the top right - create a new group set with a group in it - add yourself and your student to the group - Goto the Group's Collaborations (Courses & Groups -> [group name] -> Collaborations) - Click "Start new collaboration" - give it a nice name (Created by admin for group) - select your student - click start collaborating - You should be redirected to the new doc in google As a student - Goto `profile/settings` and add the google drive user service - Your email should be displayed with the service - Goto the assignment - Submit the assignment - You should have a "Google Doc" tab - Choose a document and submit it - After it submitted, click download on the right side just to make sure its correct - Goto Collaborations - Make sure existing collaborations still work - make sure the "created by admin" collaboration works - make sure you can't see "Created by admin, no users" - Click "Start new collaboration" - give it a nice name (created by a student) - click start collaborating - You should be redirected to the new doc in google - Switch to your admin/teacher and make sure they can't access it - Edit the collaboration add the teacher, click Save - Switch to your admin/teacher and make sure they can access it - Goto `profile/settings` and REMOVE the google drive user service - Go back to collaborations - You should be forced to add the google service in order to use a collaboration - Goto the Group's Collaborations (Courses & Groups -> [group name] -> Collaborations) - Make sure you can access "Created by admin for group" - Click "Start new collaboration" - select your admin/teacher - click start collaborating - You should be redirected to the new doc in google - make sure your admin can access it to As a site admin - Disable Google Drive - Then with your student - Make sure you can still do file upload submissions on the assignment - Collaborations should no longer show up (unless you have etherpad enabled) - Google drive should no longer show up in your profile settings as a registered service Change-Id: I4dfaff6f5262743c044aadd12266fd0bd85a60e1 Reviewed-on: https://gerrit.instructure.com/69078 Reviewed-by: Andrew Butterfield <abutterfield@instructure.com> Tested-by: Jenkins QA-Review: August Thornton <august@instructure.com> Product-Review: Brad Horrocks <bhorrocks@instructure.com>
2015-12-17 05:53:11 +08:00
@entry_data ||= JSON.parse(self.data)
2011-02-01 09:57:29 +08:00
end
2011-02-01 09:57:29 +08:00
def self.config
Remove Google Docs plugin Google drive relevant code has been moved to the gems/google_drive Actually test google drive with mocked api responses cleaned up lots of code Fixes PLAT-1301 Test Plan: *** You'll need to use 2 separate google accounts to fully test *** ** Its helpful to have multiple chrome profiles so you dont have to log in and ** out a bunch https://support.google.com/chrome/answer/2364824?hl=en BEFORE SWITCHING TO THIS PATCH SET - Make sure you have some google doc collaborations - Directions for creating one are below - Disable your google docs plugin Switch to the patch set Enable google drive. (if not already) - You should be able to paste in a client_secrets.json - Update Redirect URI to point to your local instance (The URI should exist in the JSON) As an admin/teacher - Goto `profile/settings` and add the google drive user service - Your email should be displayed with the service - Goto Collaborations - Make sure existing collaborations still work - Click "Start new collaboration" - give it a nice name (Created by admin) - select your student - click start collaborating - You should be redirected to the new doc in google - create another collaboration without the student (Created by admin, no users) - Create an assignment with Submission Type: Online Online Entry Options: File Uploads - Make sure your student has access to the course/assignment - Goto Account settings -> Users - Click View User Groups in the top right - create a new group set with a group in it - add yourself and your student to the group - Goto the Group's Collaborations (Courses & Groups -> [group name] -> Collaborations) - Click "Start new collaboration" - give it a nice name (Created by admin for group) - select your student - click start collaborating - You should be redirected to the new doc in google As a student - Goto `profile/settings` and add the google drive user service - Your email should be displayed with the service - Goto the assignment - Submit the assignment - You should have a "Google Doc" tab - Choose a document and submit it - After it submitted, click download on the right side just to make sure its correct - Goto Collaborations - Make sure existing collaborations still work - make sure the "created by admin" collaboration works - make sure you can't see "Created by admin, no users" - Click "Start new collaboration" - give it a nice name (created by a student) - click start collaborating - You should be redirected to the new doc in google - Switch to your admin/teacher and make sure they can't access it - Edit the collaboration add the teacher, click Save - Switch to your admin/teacher and make sure they can access it - Goto `profile/settings` and REMOVE the google drive user service - Go back to collaborations - You should be forced to add the google service in order to use a collaboration - Goto the Group's Collaborations (Courses & Groups -> [group name] -> Collaborations) - Make sure you can access "Created by admin for group" - Click "Start new collaboration" - select your admin/teacher - click start collaborating - You should be redirected to the new doc in google - make sure your admin can access it to As a site admin - Disable Google Drive - Then with your student - Make sure you can still do file upload submissions on the assignment - Collaborations should no longer show up (unless you have etherpad enabled) - Google drive should no longer show up in your profile settings as a registered service Change-Id: I4dfaff6f5262743c044aadd12266fd0bd85a60e1 Reviewed-on: https://gerrit.instructure.com/69078 Reviewed-by: Andrew Butterfield <abutterfield@instructure.com> Tested-by: Jenkins QA-Review: August Thornton <august@instructure.com> Product-Review: Brad Horrocks <bhorrocks@instructure.com>
2015-12-17 05:53:11 +08:00
GoogleDrive::Connection.config
2011-02-01 09:57:29 +08:00
end
def authorized_service_user_id_for(user)
service = google_adapter_user_service(user)
service ? service.service_user_id : nil
end
private
Remove Google Docs plugin Google drive relevant code has been moved to the gems/google_drive Actually test google drive with mocked api responses cleaned up lots of code Fixes PLAT-1301 Test Plan: *** You'll need to use 2 separate google accounts to fully test *** ** Its helpful to have multiple chrome profiles so you dont have to log in and ** out a bunch https://support.google.com/chrome/answer/2364824?hl=en BEFORE SWITCHING TO THIS PATCH SET - Make sure you have some google doc collaborations - Directions for creating one are below - Disable your google docs plugin Switch to the patch set Enable google drive. (if not already) - You should be able to paste in a client_secrets.json - Update Redirect URI to point to your local instance (The URI should exist in the JSON) As an admin/teacher - Goto `profile/settings` and add the google drive user service - Your email should be displayed with the service - Goto Collaborations - Make sure existing collaborations still work - Click "Start new collaboration" - give it a nice name (Created by admin) - select your student - click start collaborating - You should be redirected to the new doc in google - create another collaboration without the student (Created by admin, no users) - Create an assignment with Submission Type: Online Online Entry Options: File Uploads - Make sure your student has access to the course/assignment - Goto Account settings -> Users - Click View User Groups in the top right - create a new group set with a group in it - add yourself and your student to the group - Goto the Group's Collaborations (Courses & Groups -> [group name] -> Collaborations) - Click "Start new collaboration" - give it a nice name (Created by admin for group) - select your student - click start collaborating - You should be redirected to the new doc in google As a student - Goto `profile/settings` and add the google drive user service - Your email should be displayed with the service - Goto the assignment - Submit the assignment - You should have a "Google Doc" tab - Choose a document and submit it - After it submitted, click download on the right side just to make sure its correct - Goto Collaborations - Make sure existing collaborations still work - make sure the "created by admin" collaboration works - make sure you can't see "Created by admin, no users" - Click "Start new collaboration" - give it a nice name (created by a student) - click start collaborating - You should be redirected to the new doc in google - Switch to your admin/teacher and make sure they can't access it - Edit the collaboration add the teacher, click Save - Switch to your admin/teacher and make sure they can access it - Goto `profile/settings` and REMOVE the google drive user service - Go back to collaborations - You should be forced to add the google service in order to use a collaboration - Goto the Group's Collaborations (Courses & Groups -> [group name] -> Collaborations) - Make sure you can access "Created by admin for group" - Click "Start new collaboration" - select your admin/teacher - click start collaborating - You should be redirected to the new doc in google - make sure your admin can access it to As a site admin - Disable Google Drive - Then with your student - Make sure you can still do file upload submissions on the assignment - Collaborations should no longer show up (unless you have etherpad enabled) - Google drive should no longer show up in your profile settings as a registered service Change-Id: I4dfaff6f5262743c044aadd12266fd0bd85a60e1 Reviewed-on: https://gerrit.instructure.com/69078 Reviewed-by: Andrew Butterfield <abutterfield@instructure.com> Tested-by: Jenkins QA-Review: August Thornton <august@instructure.com> Product-Review: Brad Horrocks <bhorrocks@instructure.com>
2015-12-17 05:53:11 +08:00
def google_user_service(user, service_domain=GOOGLE_DRIVE_SERVICE)
google_services = user.user_services.where(service_domain: service_domain).to_a
google_services.find{|s| s.service_user_id}
end
def google_drive_for_user
refresh_token, access_token = Rails.cache.fetch(['google_drive_tokens', self.user].cache_key) do
service = self.user.user_services.where(service: "google_drive").first
service && [service.token, service.secret]
end
Remove Google Docs plugin Google drive relevant code has been moved to the gems/google_drive Actually test google drive with mocked api responses cleaned up lots of code Fixes PLAT-1301 Test Plan: *** You'll need to use 2 separate google accounts to fully test *** ** Its helpful to have multiple chrome profiles so you dont have to log in and ** out a bunch https://support.google.com/chrome/answer/2364824?hl=en BEFORE SWITCHING TO THIS PATCH SET - Make sure you have some google doc collaborations - Directions for creating one are below - Disable your google docs plugin Switch to the patch set Enable google drive. (if not already) - You should be able to paste in a client_secrets.json - Update Redirect URI to point to your local instance (The URI should exist in the JSON) As an admin/teacher - Goto `profile/settings` and add the google drive user service - Your email should be displayed with the service - Goto Collaborations - Make sure existing collaborations still work - Click "Start new collaboration" - give it a nice name (Created by admin) - select your student - click start collaborating - You should be redirected to the new doc in google - create another collaboration without the student (Created by admin, no users) - Create an assignment with Submission Type: Online Online Entry Options: File Uploads - Make sure your student has access to the course/assignment - Goto Account settings -> Users - Click View User Groups in the top right - create a new group set with a group in it - add yourself and your student to the group - Goto the Group's Collaborations (Courses & Groups -> [group name] -> Collaborations) - Click "Start new collaboration" - give it a nice name (Created by admin for group) - select your student - click start collaborating - You should be redirected to the new doc in google As a student - Goto `profile/settings` and add the google drive user service - Your email should be displayed with the service - Goto the assignment - Submit the assignment - You should have a "Google Doc" tab - Choose a document and submit it - After it submitted, click download on the right side just to make sure its correct - Goto Collaborations - Make sure existing collaborations still work - make sure the "created by admin" collaboration works - make sure you can't see "Created by admin, no users" - Click "Start new collaboration" - give it a nice name (created by a student) - click start collaborating - You should be redirected to the new doc in google - Switch to your admin/teacher and make sure they can't access it - Edit the collaboration add the teacher, click Save - Switch to your admin/teacher and make sure they can access it - Goto `profile/settings` and REMOVE the google drive user service - Go back to collaborations - You should be forced to add the google service in order to use a collaboration - Goto the Group's Collaborations (Courses & Groups -> [group name] -> Collaborations) - Make sure you can access "Created by admin for group" - Click "Start new collaboration" - select your admin/teacher - click start collaborating - You should be redirected to the new doc in google - make sure your admin can access it to As a site admin - Disable Google Drive - Then with your student - Make sure you can still do file upload submissions on the assignment - Collaborations should no longer show up (unless you have etherpad enabled) - Google drive should no longer show up in your profile settings as a registered service Change-Id: I4dfaff6f5262743c044aadd12266fd0bd85a60e1 Reviewed-on: https://gerrit.instructure.com/69078 Reviewed-by: Andrew Butterfield <abutterfield@instructure.com> Tested-by: Jenkins QA-Review: August Thornton <august@instructure.com> Product-Review: Brad Horrocks <bhorrocks@instructure.com>
2015-12-17 05:53:11 +08:00
raise GoogleDrive::NoTokenError unless refresh_token && access_token
GoogleDrive::Connection.new(refresh_token, access_token, ApplicationController.google_drive_timeout)
end
def google_adapter_for_user
Remove Google Docs plugin Google drive relevant code has been moved to the gems/google_drive Actually test google drive with mocked api responses cleaned up lots of code Fixes PLAT-1301 Test Plan: *** You'll need to use 2 separate google accounts to fully test *** ** Its helpful to have multiple chrome profiles so you dont have to log in and ** out a bunch https://support.google.com/chrome/answer/2364824?hl=en BEFORE SWITCHING TO THIS PATCH SET - Make sure you have some google doc collaborations - Directions for creating one are below - Disable your google docs plugin Switch to the patch set Enable google drive. (if not already) - You should be able to paste in a client_secrets.json - Update Redirect URI to point to your local instance (The URI should exist in the JSON) As an admin/teacher - Goto `profile/settings` and add the google drive user service - Your email should be displayed with the service - Goto Collaborations - Make sure existing collaborations still work - Click "Start new collaboration" - give it a nice name (Created by admin) - select your student - click start collaborating - You should be redirected to the new doc in google - create another collaboration without the student (Created by admin, no users) - Create an assignment with Submission Type: Online Online Entry Options: File Uploads - Make sure your student has access to the course/assignment - Goto Account settings -> Users - Click View User Groups in the top right - create a new group set with a group in it - add yourself and your student to the group - Goto the Group's Collaborations (Courses & Groups -> [group name] -> Collaborations) - Click "Start new collaboration" - give it a nice name (Created by admin for group) - select your student - click start collaborating - You should be redirected to the new doc in google As a student - Goto `profile/settings` and add the google drive user service - Your email should be displayed with the service - Goto the assignment - Submit the assignment - You should have a "Google Doc" tab - Choose a document and submit it - After it submitted, click download on the right side just to make sure its correct - Goto Collaborations - Make sure existing collaborations still work - make sure the "created by admin" collaboration works - make sure you can't see "Created by admin, no users" - Click "Start new collaboration" - give it a nice name (created by a student) - click start collaborating - You should be redirected to the new doc in google - Switch to your admin/teacher and make sure they can't access it - Edit the collaboration add the teacher, click Save - Switch to your admin/teacher and make sure they can access it - Goto `profile/settings` and REMOVE the google drive user service - Go back to collaborations - You should be forced to add the google service in order to use a collaboration - Goto the Group's Collaborations (Courses & Groups -> [group name] -> Collaborations) - Make sure you can access "Created by admin for group" - Click "Start new collaboration" - select your admin/teacher - click start collaborating - You should be redirected to the new doc in google - make sure your admin can access it to As a site admin - Disable Google Drive - Then with your student - Make sure you can still do file upload submissions on the assignment - Collaborations should no longer show up (unless you have etherpad enabled) - Google drive should no longer show up in your profile settings as a registered service Change-Id: I4dfaff6f5262743c044aadd12266fd0bd85a60e1 Reviewed-on: https://gerrit.instructure.com/69078 Reviewed-by: Andrew Butterfield <abutterfield@instructure.com> Tested-by: Jenkins QA-Review: August Thornton <august@instructure.com> Product-Review: Brad Horrocks <bhorrocks@instructure.com>
2015-12-17 05:53:11 +08:00
google_drive_for_user
end
def google_adapter_user_service(user)
Remove Google Docs plugin Google drive relevant code has been moved to the gems/google_drive Actually test google drive with mocked api responses cleaned up lots of code Fixes PLAT-1301 Test Plan: *** You'll need to use 2 separate google accounts to fully test *** ** Its helpful to have multiple chrome profiles so you dont have to log in and ** out a bunch https://support.google.com/chrome/answer/2364824?hl=en BEFORE SWITCHING TO THIS PATCH SET - Make sure you have some google doc collaborations - Directions for creating one are below - Disable your google docs plugin Switch to the patch set Enable google drive. (if not already) - You should be able to paste in a client_secrets.json - Update Redirect URI to point to your local instance (The URI should exist in the JSON) As an admin/teacher - Goto `profile/settings` and add the google drive user service - Your email should be displayed with the service - Goto Collaborations - Make sure existing collaborations still work - Click "Start new collaboration" - give it a nice name (Created by admin) - select your student - click start collaborating - You should be redirected to the new doc in google - create another collaboration without the student (Created by admin, no users) - Create an assignment with Submission Type: Online Online Entry Options: File Uploads - Make sure your student has access to the course/assignment - Goto Account settings -> Users - Click View User Groups in the top right - create a new group set with a group in it - add yourself and your student to the group - Goto the Group's Collaborations (Courses & Groups -> [group name] -> Collaborations) - Click "Start new collaboration" - give it a nice name (Created by admin for group) - select your student - click start collaborating - You should be redirected to the new doc in google As a student - Goto `profile/settings` and add the google drive user service - Your email should be displayed with the service - Goto the assignment - Submit the assignment - You should have a "Google Doc" tab - Choose a document and submit it - After it submitted, click download on the right side just to make sure its correct - Goto Collaborations - Make sure existing collaborations still work - make sure the "created by admin" collaboration works - make sure you can't see "Created by admin, no users" - Click "Start new collaboration" - give it a nice name (created by a student) - click start collaborating - You should be redirected to the new doc in google - Switch to your admin/teacher and make sure they can't access it - Edit the collaboration add the teacher, click Save - Switch to your admin/teacher and make sure they can access it - Goto `profile/settings` and REMOVE the google drive user service - Go back to collaborations - You should be forced to add the google service in order to use a collaboration - Goto the Group's Collaborations (Courses & Groups -> [group name] -> Collaborations) - Make sure you can access "Created by admin for group" - Click "Start new collaboration" - select your admin/teacher - click start collaborating - You should be redirected to the new doc in google - make sure your admin can access it to As a site admin - Disable Google Drive - Then with your student - Make sure you can still do file upload submissions on the assignment - Collaborations should no longer show up (unless you have etherpad enabled) - Google drive should no longer show up in your profile settings as a registered service Change-Id: I4dfaff6f5262743c044aadd12266fd0bd85a60e1 Reviewed-on: https://gerrit.instructure.com/69078 Reviewed-by: Andrew Butterfield <abutterfield@instructure.com> Tested-by: Jenkins QA-Review: August Thornton <august@instructure.com> Product-Review: Brad Horrocks <bhorrocks@instructure.com>
2015-12-17 05:53:11 +08:00
google_user_service(user)
end
2011-02-01 09:57:29 +08:00
end