2020-10-27 00:50:13 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-06-20 01:36:47 +08:00
|
|
|
#
|
|
|
|
# Copyright (C) 2016 - present 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/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
module Services
|
|
|
|
class SubmitHomeworkService
|
2018-12-20 06:20:36 +08:00
|
|
|
CloneUrlError = Class.new(StandardError)
|
|
|
|
|
2018-06-26 03:42:09 +08:00
|
|
|
EmailWorker = Struct.new(:message) do
|
2018-06-20 01:36:47 +08:00
|
|
|
def perform
|
|
|
|
Mailer.deliver(Mailer.create_message(message))
|
|
|
|
end
|
2018-06-26 03:42:09 +08:00
|
|
|
|
|
|
|
def on_permanent_failure(error)
|
|
|
|
Canvas::Errors.capture_exception(self.class.name, error)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
CloneUrlExecutor = Struct.new(:url, :duplicate_handling, :check_quota, :opts) do
|
|
|
|
def execute(attachment)
|
|
|
|
attachment.clone_url(url, duplicate_handling, check_quota, opts)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
Fix comments for external tool file submissions
Comments when submitting a file upload via an external tool appear to
have been broken in
https://github.com/instructure/canvas-lms/commit/8cdf400ba720623d8d2c
This commit changes the UI to again send the comment to the server, and
changes the server-side code to process the comment.
The server side code has two possible data paths:
* With InstFS:
include the comment in the JWT we send (in capture_params) to InstFS.
When InstFS is done it hits FilesController#api_capture. Now it
include comment -- so we now take the comment and pass it into
SubmitHomeworkService which submits it.
* Without InstFS:
pass the comment in when making the asynchronous job in
SubmitHomeworkService.submit_job() in this case, though.
Note: File uploads using an external tool appear to not work at all (?)
using Assignments 2. This fix is for "classic" Assignments.
Also, I can get file uploads using an external tool for group
assignments to work at all, locally or production. It was supposedly
working as of b55cf587. Someone else should check and we can create
another ticket for that apparently separate issue. I did test that the
"comment" is now getting through to the call to SubmitHomeworkService.
flag=none
closes PLAT-4390
Test plan:
- If running locally, disable Assignments 2 by editing
config/feature_flags/meeseeks_release_flags.yml and commenting out the
hardcoded "environments: development: state: on" config under
"assignments_2_student"
- You may need to run `node_modules/bin/.webpack` or `rails
canvas:compile_assets` to compile the coffeescript.
- Install an LTI tool such as Box or Google Drive which allows file
upload.
- Make an assignment that accepts file upload
- As a student, submit an assignment by choosing a file to upload with
the LTI tool. After choosing a file, add a comment and submit.
- Start asynchronous jobs if running Canvas locally.
- Previously, the assignment would be submitted with no comment. Now,
once submitted, the attachment should show up on the right side of the
assignment page for the student. Under this the comment should appear.
- Submit again, this time with no comment, and check that no comment is
added.
- InstFS team will help test this for the InstFS route.
- Test external tool file submission for group assignments on production
(or beta) and we can create another ticket
if that isn't working.
Change-Id: Ie0bbacae1e732518aae46017f72be8a72f567510
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/221096
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Product-Review: Evan Battaglia <ebattaglia@instructure.com>
Reviewed-by: Marc Phillips <mphillips@instructure.com>
QA-Review: Jonathan Featherstone <jfeatherstone@instructure.com>
2019-12-17 10:34:56 +08:00
|
|
|
CopyWorker = Struct.new(:attachment_id, :progress_id, :clone_url_executor) do
|
2018-06-26 03:42:09 +08:00
|
|
|
def progress
|
|
|
|
@progress ||= Progress.find(progress_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def attachment
|
|
|
|
@attachment ||= Attachment.find(attachment_id)
|
|
|
|
end
|
|
|
|
|
2018-12-20 06:20:36 +08:00
|
|
|
def perform
|
|
|
|
progress.start! unless progress.running?
|
|
|
|
clone_url_executor.execute(attachment)
|
|
|
|
|
|
|
|
raise(CloneUrlError, attachment.upload_error_message) if attachment.file_state == "errored"
|
|
|
|
|
|
|
|
progress.complete! unless progress.failed?
|
2021-11-18 04:34:10 +08:00
|
|
|
rescue => e
|
|
|
|
mark_as_failure(e)
|
2018-12-20 06:20:36 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def on_permanent_failure(error)
|
|
|
|
mark_as_failure(error)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def mark_as_failure(error)
|
|
|
|
Canvas::Errors.capture_exception(self.class.name, error)[:error_report]
|
|
|
|
progress.message = error
|
|
|
|
progress.save!
|
|
|
|
progress.fail!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
Fix comments for external tool file submissions
Comments when submitting a file upload via an external tool appear to
have been broken in
https://github.com/instructure/canvas-lms/commit/8cdf400ba720623d8d2c
This commit changes the UI to again send the comment to the server, and
changes the server-side code to process the comment.
The server side code has two possible data paths:
* With InstFS:
include the comment in the JWT we send (in capture_params) to InstFS.
When InstFS is done it hits FilesController#api_capture. Now it
include comment -- so we now take the comment and pass it into
SubmitHomeworkService which submits it.
* Without InstFS:
pass the comment in when making the asynchronous job in
SubmitHomeworkService.submit_job() in this case, though.
Note: File uploads using an external tool appear to not work at all (?)
using Assignments 2. This fix is for "classic" Assignments.
Also, I can get file uploads using an external tool for group
assignments to work at all, locally or production. It was supposedly
working as of b55cf587. Someone else should check and we can create
another ticket for that apparently separate issue. I did test that the
"comment" is now getting through to the call to SubmitHomeworkService.
flag=none
closes PLAT-4390
Test plan:
- If running locally, disable Assignments 2 by editing
config/feature_flags/meeseeks_release_flags.yml and commenting out the
hardcoded "environments: development: state: on" config under
"assignments_2_student"
- You may need to run `node_modules/bin/.webpack` or `rails
canvas:compile_assets` to compile the coffeescript.
- Install an LTI tool such as Box or Google Drive which allows file
upload.
- Make an assignment that accepts file upload
- As a student, submit an assignment by choosing a file to upload with
the LTI tool. After choosing a file, add a comment and submit.
- Start asynchronous jobs if running Canvas locally.
- Previously, the assignment would be submitted with no comment. Now,
once submitted, the attachment should show up on the right side of the
assignment page for the student. Under this the comment should appear.
- Submit again, this time with no comment, and check that no comment is
added.
- InstFS team will help test this for the InstFS route.
- Test external tool file submission for group assignments on production
(or beta) and we can create another ticket
if that isn't working.
Change-Id: Ie0bbacae1e732518aae46017f72be8a72f567510
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/221096
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Product-Review: Evan Battaglia <ebattaglia@instructure.com>
Reviewed-by: Marc Phillips <mphillips@instructure.com>
QA-Review: Jonathan Featherstone <jfeatherstone@instructure.com>
2019-12-17 10:34:56 +08:00
|
|
|
SubmitWorker = Struct.new(:attachment_id, :progress_id, :eula_agreement_timestamp, :comment, :clone_url_executor) do
|
2018-12-20 06:20:36 +08:00
|
|
|
def progress
|
|
|
|
@progress ||= Progress.find(progress_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def attachment
|
|
|
|
@attachment ||= Attachment.find(attachment_id)
|
2018-07-20 03:23:37 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def homework_service
|
2018-12-20 06:20:36 +08:00
|
|
|
@homework_service ||= SubmitHomeworkService.new(attachment, progress)
|
2018-07-20 03:23:37 +08:00
|
|
|
end
|
|
|
|
|
2018-06-26 03:42:09 +08:00
|
|
|
def perform
|
2018-12-20 06:20:36 +08:00
|
|
|
return unless attachment
|
2021-09-23 00:25:11 +08:00
|
|
|
|
2018-12-20 06:20:36 +08:00
|
|
|
homework_service.start!
|
2018-06-26 03:42:09 +08:00
|
|
|
clone_url_executor.execute(attachment)
|
2018-07-20 03:23:37 +08:00
|
|
|
|
2018-12-20 06:20:36 +08:00
|
|
|
raise(CloneUrlError, attachment.upload_error_message) if attachment.file_state == "errored"
|
2018-07-20 03:23:37 +08:00
|
|
|
|
Fix comments for external tool file submissions
Comments when submitting a file upload via an external tool appear to
have been broken in
https://github.com/instructure/canvas-lms/commit/8cdf400ba720623d8d2c
This commit changes the UI to again send the comment to the server, and
changes the server-side code to process the comment.
The server side code has two possible data paths:
* With InstFS:
include the comment in the JWT we send (in capture_params) to InstFS.
When InstFS is done it hits FilesController#api_capture. Now it
include comment -- so we now take the comment and pass it into
SubmitHomeworkService which submits it.
* Without InstFS:
pass the comment in when making the asynchronous job in
SubmitHomeworkService.submit_job() in this case, though.
Note: File uploads using an external tool appear to not work at all (?)
using Assignments 2. This fix is for "classic" Assignments.
Also, I can get file uploads using an external tool for group
assignments to work at all, locally or production. It was supposedly
working as of b55cf587. Someone else should check and we can create
another ticket for that apparently separate issue. I did test that the
"comment" is now getting through to the call to SubmitHomeworkService.
flag=none
closes PLAT-4390
Test plan:
- If running locally, disable Assignments 2 by editing
config/feature_flags/meeseeks_release_flags.yml and commenting out the
hardcoded "environments: development: state: on" config under
"assignments_2_student"
- You may need to run `node_modules/bin/.webpack` or `rails
canvas:compile_assets` to compile the coffeescript.
- Install an LTI tool such as Box or Google Drive which allows file
upload.
- Make an assignment that accepts file upload
- As a student, submit an assignment by choosing a file to upload with
the LTI tool. After choosing a file, add a comment and submit.
- Start asynchronous jobs if running Canvas locally.
- Previously, the assignment would be submitted with no comment. Now,
once submitted, the attachment should show up on the right side of the
assignment page for the student. Under this the comment should appear.
- Submit again, this time with no comment, and check that no comment is
added.
- InstFS team will help test this for the InstFS route.
- Test external tool file submission for group assignments on production
(or beta) and we can create another ticket
if that isn't working.
Change-Id: Ie0bbacae1e732518aae46017f72be8a72f567510
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/221096
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Product-Review: Evan Battaglia <ebattaglia@instructure.com>
Reviewed-by: Marc Phillips <mphillips@instructure.com>
QA-Review: Jonathan Featherstone <jfeatherstone@instructure.com>
2019-12-17 10:34:56 +08:00
|
|
|
homework_service.submit(eula_agreement_timestamp, comment)
|
2018-12-20 06:20:36 +08:00
|
|
|
homework_service.success!
|
2021-11-18 04:34:10 +08:00
|
|
|
rescue => e
|
|
|
|
mark_as_failure(e)
|
2018-06-26 03:42:09 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def on_permanent_failure(error)
|
|
|
|
mark_as_failure(error)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def mark_as_failure(error)
|
2018-12-20 06:20:36 +08:00
|
|
|
homework_service.failed!(error)
|
2018-06-26 03:42:09 +08:00
|
|
|
end
|
2018-06-20 01:36:47 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
class << self
|
2018-06-26 03:42:09 +08:00
|
|
|
def create_clone_url_executor(url, duplicate_handling, check_quota, opts)
|
|
|
|
CloneUrlExecutor.new(url, duplicate_handling, check_quota, opts)
|
|
|
|
end
|
|
|
|
|
Fix comments for external tool file submissions
Comments when submitting a file upload via an external tool appear to
have been broken in
https://github.com/instructure/canvas-lms/commit/8cdf400ba720623d8d2c
This commit changes the UI to again send the comment to the server, and
changes the server-side code to process the comment.
The server side code has two possible data paths:
* With InstFS:
include the comment in the JWT we send (in capture_params) to InstFS.
When InstFS is done it hits FilesController#api_capture. Now it
include comment -- so we now take the comment and pass it into
SubmitHomeworkService which submits it.
* Without InstFS:
pass the comment in when making the asynchronous job in
SubmitHomeworkService.submit_job() in this case, though.
Note: File uploads using an external tool appear to not work at all (?)
using Assignments 2. This fix is for "classic" Assignments.
Also, I can get file uploads using an external tool for group
assignments to work at all, locally or production. It was supposedly
working as of b55cf587. Someone else should check and we can create
another ticket for that apparently separate issue. I did test that the
"comment" is now getting through to the call to SubmitHomeworkService.
flag=none
closes PLAT-4390
Test plan:
- If running locally, disable Assignments 2 by editing
config/feature_flags/meeseeks_release_flags.yml and commenting out the
hardcoded "environments: development: state: on" config under
"assignments_2_student"
- You may need to run `node_modules/bin/.webpack` or `rails
canvas:compile_assets` to compile the coffeescript.
- Install an LTI tool such as Box or Google Drive which allows file
upload.
- Make an assignment that accepts file upload
- As a student, submit an assignment by choosing a file to upload with
the LTI tool. After choosing a file, add a comment and submit.
- Start asynchronous jobs if running Canvas locally.
- Previously, the assignment would be submitted with no comment. Now,
once submitted, the attachment should show up on the right side of the
assignment page for the student. Under this the comment should appear.
- Submit again, this time with no comment, and check that no comment is
added.
- InstFS team will help test this for the InstFS route.
- Test external tool file submission for group assignments on production
(or beta) and we can create another ticket
if that isn't working.
Change-Id: Ie0bbacae1e732518aae46017f72be8a72f567510
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/221096
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Product-Review: Evan Battaglia <ebattaglia@instructure.com>
Reviewed-by: Marc Phillips <mphillips@instructure.com>
QA-Review: Jonathan Featherstone <jfeatherstone@instructure.com>
2019-12-17 10:34:56 +08:00
|
|
|
def submit_job(attachment, progress, eula_agreement_timestamp, comment, executor, submit_assignment)
|
2019-07-31 01:13:57 +08:00
|
|
|
if progress.context.is_a?(Assignment) && submit_assignment
|
2018-12-20 06:20:36 +08:00
|
|
|
SubmitWorker
|
Fix comments for external tool file submissions
Comments when submitting a file upload via an external tool appear to
have been broken in
https://github.com/instructure/canvas-lms/commit/8cdf400ba720623d8d2c
This commit changes the UI to again send the comment to the server, and
changes the server-side code to process the comment.
The server side code has two possible data paths:
* With InstFS:
include the comment in the JWT we send (in capture_params) to InstFS.
When InstFS is done it hits FilesController#api_capture. Now it
include comment -- so we now take the comment and pass it into
SubmitHomeworkService which submits it.
* Without InstFS:
pass the comment in when making the asynchronous job in
SubmitHomeworkService.submit_job() in this case, though.
Note: File uploads using an external tool appear to not work at all (?)
using Assignments 2. This fix is for "classic" Assignments.
Also, I can get file uploads using an external tool for group
assignments to work at all, locally or production. It was supposedly
working as of b55cf587. Someone else should check and we can create
another ticket for that apparently separate issue. I did test that the
"comment" is now getting through to the call to SubmitHomeworkService.
flag=none
closes PLAT-4390
Test plan:
- If running locally, disable Assignments 2 by editing
config/feature_flags/meeseeks_release_flags.yml and commenting out the
hardcoded "environments: development: state: on" config under
"assignments_2_student"
- You may need to run `node_modules/bin/.webpack` or `rails
canvas:compile_assets` to compile the coffeescript.
- Install an LTI tool such as Box or Google Drive which allows file
upload.
- Make an assignment that accepts file upload
- As a student, submit an assignment by choosing a file to upload with
the LTI tool. After choosing a file, add a comment and submit.
- Start asynchronous jobs if running Canvas locally.
- Previously, the assignment would be submitted with no comment. Now,
once submitted, the attachment should show up on the right side of the
assignment page for the student. Under this the comment should appear.
- Submit again, this time with no comment, and check that no comment is
added.
- InstFS team will help test this for the InstFS route.
- Test external tool file submission for group assignments on production
(or beta) and we can create another ticket
if that isn't working.
Change-Id: Ie0bbacae1e732518aae46017f72be8a72f567510
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/221096
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Product-Review: Evan Battaglia <ebattaglia@instructure.com>
Reviewed-by: Marc Phillips <mphillips@instructure.com>
QA-Review: Jonathan Featherstone <jfeatherstone@instructure.com>
2019-12-17 10:34:56 +08:00
|
|
|
.new(attachment.id, progress.id, eula_agreement_timestamp, comment, executor)
|
2018-12-20 06:20:36 +08:00
|
|
|
.tap { |worker| enqueue_attachment_job(worker) }
|
|
|
|
else
|
|
|
|
CopyWorker
|
Fix comments for external tool file submissions
Comments when submitting a file upload via an external tool appear to
have been broken in
https://github.com/instructure/canvas-lms/commit/8cdf400ba720623d8d2c
This commit changes the UI to again send the comment to the server, and
changes the server-side code to process the comment.
The server side code has two possible data paths:
* With InstFS:
include the comment in the JWT we send (in capture_params) to InstFS.
When InstFS is done it hits FilesController#api_capture. Now it
include comment -- so we now take the comment and pass it into
SubmitHomeworkService which submits it.
* Without InstFS:
pass the comment in when making the asynchronous job in
SubmitHomeworkService.submit_job() in this case, though.
Note: File uploads using an external tool appear to not work at all (?)
using Assignments 2. This fix is for "classic" Assignments.
Also, I can get file uploads using an external tool for group
assignments to work at all, locally or production. It was supposedly
working as of b55cf587. Someone else should check and we can create
another ticket for that apparently separate issue. I did test that the
"comment" is now getting through to the call to SubmitHomeworkService.
flag=none
closes PLAT-4390
Test plan:
- If running locally, disable Assignments 2 by editing
config/feature_flags/meeseeks_release_flags.yml and commenting out the
hardcoded "environments: development: state: on" config under
"assignments_2_student"
- You may need to run `node_modules/bin/.webpack` or `rails
canvas:compile_assets` to compile the coffeescript.
- Install an LTI tool such as Box or Google Drive which allows file
upload.
- Make an assignment that accepts file upload
- As a student, submit an assignment by choosing a file to upload with
the LTI tool. After choosing a file, add a comment and submit.
- Start asynchronous jobs if running Canvas locally.
- Previously, the assignment would be submitted with no comment. Now,
once submitted, the attachment should show up on the right side of the
assignment page for the student. Under this the comment should appear.
- Submit again, this time with no comment, and check that no comment is
added.
- InstFS team will help test this for the InstFS route.
- Test external tool file submission for group assignments on production
(or beta) and we can create another ticket
if that isn't working.
Change-Id: Ie0bbacae1e732518aae46017f72be8a72f567510
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/221096
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Product-Review: Evan Battaglia <ebattaglia@instructure.com>
Reviewed-by: Marc Phillips <mphillips@instructure.com>
QA-Review: Jonathan Featherstone <jfeatherstone@instructure.com>
2019-12-17 10:34:56 +08:00
|
|
|
.new(attachment.id, progress.id, executor)
|
2018-12-20 06:20:36 +08:00
|
|
|
.tap { |worker| enqueue_attachment_job(worker) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def enqueue_attachment_job(worker)
|
|
|
|
Delayed::Job.enqueue(
|
|
|
|
worker,
|
|
|
|
priority: Delayed::HIGH_PRIORITY,
|
|
|
|
n_strand: Attachment.clone_url_strand(worker.clone_url_executor.url)
|
|
|
|
)
|
2018-06-26 03:42:09 +08:00
|
|
|
end
|
2018-07-20 03:23:37 +08:00
|
|
|
end
|
2018-06-26 03:42:09 +08:00
|
|
|
|
2018-12-20 06:20:36 +08:00
|
|
|
def initialize(attachment, progress)
|
2018-07-20 03:23:37 +08:00
|
|
|
@attachment = attachment
|
2018-12-20 06:20:36 +08:00
|
|
|
@progress = progress
|
2018-07-20 03:23:37 +08:00
|
|
|
end
|
2018-06-20 01:36:47 +08:00
|
|
|
|
Fix comments for external tool file submissions
Comments when submitting a file upload via an external tool appear to
have been broken in
https://github.com/instructure/canvas-lms/commit/8cdf400ba720623d8d2c
This commit changes the UI to again send the comment to the server, and
changes the server-side code to process the comment.
The server side code has two possible data paths:
* With InstFS:
include the comment in the JWT we send (in capture_params) to InstFS.
When InstFS is done it hits FilesController#api_capture. Now it
include comment -- so we now take the comment and pass it into
SubmitHomeworkService which submits it.
* Without InstFS:
pass the comment in when making the asynchronous job in
SubmitHomeworkService.submit_job() in this case, though.
Note: File uploads using an external tool appear to not work at all (?)
using Assignments 2. This fix is for "classic" Assignments.
Also, I can get file uploads using an external tool for group
assignments to work at all, locally or production. It was supposedly
working as of b55cf587. Someone else should check and we can create
another ticket for that apparently separate issue. I did test that the
"comment" is now getting through to the call to SubmitHomeworkService.
flag=none
closes PLAT-4390
Test plan:
- If running locally, disable Assignments 2 by editing
config/feature_flags/meeseeks_release_flags.yml and commenting out the
hardcoded "environments: development: state: on" config under
"assignments_2_student"
- You may need to run `node_modules/bin/.webpack` or `rails
canvas:compile_assets` to compile the coffeescript.
- Install an LTI tool such as Box or Google Drive which allows file
upload.
- Make an assignment that accepts file upload
- As a student, submit an assignment by choosing a file to upload with
the LTI tool. After choosing a file, add a comment and submit.
- Start asynchronous jobs if running Canvas locally.
- Previously, the assignment would be submitted with no comment. Now,
once submitted, the attachment should show up on the right side of the
assignment page for the student. Under this the comment should appear.
- Submit again, this time with no comment, and check that no comment is
added.
- InstFS team will help test this for the InstFS route.
- Test external tool file submission for group assignments on production
(or beta) and we can create another ticket
if that isn't working.
Change-Id: Ie0bbacae1e732518aae46017f72be8a72f567510
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/221096
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Product-Review: Evan Battaglia <ebattaglia@instructure.com>
Reviewed-by: Marc Phillips <mphillips@instructure.com>
QA-Review: Jonathan Featherstone <jfeatherstone@instructure.com>
2019-12-17 10:34:56 +08:00
|
|
|
def submit(eula_agreement_timestamp, comment)
|
2018-12-20 06:20:36 +08:00
|
|
|
start!
|
2018-06-20 01:36:47 +08:00
|
|
|
|
2018-12-20 06:20:36 +08:00
|
|
|
if @attachment
|
|
|
|
opts = {
|
|
|
|
submission_type: "online_upload",
|
|
|
|
submitted_at: @progress.created_at,
|
|
|
|
attachments: [@attachment],
|
2023-06-02 06:06:09 +08:00
|
|
|
eula_agreement_timestamp:,
|
|
|
|
comment:
|
2018-12-20 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@progress.context.submit_homework(@progress.user, opts)
|
|
|
|
end
|
2018-07-20 03:23:37 +08:00
|
|
|
end
|
2018-06-20 01:36:47 +08:00
|
|
|
|
2018-12-20 06:20:36 +08:00
|
|
|
def start!
|
|
|
|
progress_start!(@progress)
|
|
|
|
AttachmentUploadStatus.pending!(@attachment)
|
|
|
|
end
|
|
|
|
|
|
|
|
def success!
|
|
|
|
progress_success!(@progress, @attachment)
|
|
|
|
AttachmentUploadStatus.success!(@attachment)
|
|
|
|
end
|
|
|
|
|
|
|
|
def failed!(error)
|
|
|
|
progress_failed!(@progress, error)
|
|
|
|
AttachmentUploadStatus.failed!(@attachment, error)
|
|
|
|
failure_email if @attachment
|
2018-07-20 03:23:37 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def failure_email
|
2018-12-20 06:20:36 +08:00
|
|
|
display_name = @attachment.display_name
|
|
|
|
assignment_name = @progress.context.name
|
|
|
|
body = "Your file, #{display_name}, failed to upload to your " \
|
|
|
|
"Canvas assignment, #{assignment_name}. Please re-submit to " \
|
2018-07-20 03:23:37 +08:00
|
|
|
"the assignment or contact your instructor if you are no " \
|
|
|
|
"longer able to do so."
|
|
|
|
|
|
|
|
message = OpenStruct.new(
|
|
|
|
from_name: "notifications@instructure.com",
|
2018-12-20 06:20:36 +08:00
|
|
|
subject: "Submission upload failed: #{assignment_name}",
|
|
|
|
to: @progress.user.email,
|
2023-06-02 06:06:09 +08:00
|
|
|
body:
|
2018-07-20 03:23:37 +08:00
|
|
|
)
|
|
|
|
queue_email(message)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-12-20 06:20:36 +08:00
|
|
|
def progress_start!(progress)
|
|
|
|
unless progress.running?
|
|
|
|
progress.start
|
|
|
|
progress.save!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def progress_success!(progress, attachment)
|
|
|
|
progress.reload
|
|
|
|
progress.set_results("id" => attachment.id) if attachment
|
|
|
|
progress.complete!
|
|
|
|
end
|
|
|
|
|
|
|
|
def progress_failed!(progress, message)
|
|
|
|
progress.reload
|
|
|
|
progress.message = message
|
|
|
|
progress.save!
|
|
|
|
progress.fail
|
|
|
|
end
|
|
|
|
|
2018-07-20 03:23:37 +08:00
|
|
|
def queue_email(message)
|
|
|
|
Delayed::Job.enqueue(EmailWorker.new(message))
|
2018-06-20 01:36:47 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|