Add submission_time to originality report

Refs PLAT-4296

Test Plan:
Verify the submission version is set when
creating an originality report

Change-Id: Ic855a6381cc4c36d2c6b2cb65b56448e1052ce82
Reviewed-on: https://gerrit.instructure.com/196340
Tested-by: Jenkins
Reviewed-by: Rob Orton <rob@instructure.com>
QA-Review: Rob Orton <rob@instructure.com>
Product-Review: Rob Orton <rob@instructure.com>
This commit is contained in:
wdransfield 2019-06-03 16:41:38 -06:00 committed by Weston Dransfield
parent 1d9e6a1f51
commit 41a7fe98ef
5 changed files with 46 additions and 3 deletions

View File

@ -96,6 +96,10 @@ module Lti
# "error_report": {
# "description": "A message describing the error. If set, the workflow_state will become 'error.'",
# "type": "String"
# },
# "submission_time": {
# "description": "The submitted_at date time of the submission.",
# "type": "datetime"
# }
# }
# }

View File

@ -31,6 +31,7 @@ class OriginalityReport < ActiveRecord::Base
alias_attribute :file_id, :attachment_id
alias_attribute :originality_report_file_id, :originality_report_attachment_id
before_validation :set_submission_time
before_validation :infer_workflow_state
def state
@ -96,6 +97,10 @@ class OriginalityReport < ActiveRecord::Base
submission.assignment
end
def set_submission_time
self.submission_time = submission&.submitted_at
end
def infer_workflow_state
self.workflow_state = 'error' if error_message.present?
return if self.workflow_state == 'error'

View File

@ -0,0 +1,27 @@
#
# Copyright (C) 2019 - 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/>.
#
class AddSubmissionTimeToOriginalityReports < ActiveRecord::Migration[5.1]
tag :predeploy
disable_ddl_transaction!
def change
add_column :originality_reports, :submission_time, :datetime
add_index :originality_reports, :submission_time, algorithm: :concurrently
end
end

View File

@ -121,7 +121,8 @@ module Lti
'submission_id',
'workflow_state',
'link_id',
'error_message'
'error_message',
'submission_time'
].freeze
get @endpoints[:show], headers: request_headers
@ -213,7 +214,8 @@ module Lti
'submission_id',
'workflow_state',
'link_id',
'error_message'
'error_message',
'submission_time'
].freeze
get @endpoints[:alt_show], headers: request_headers
expect(response).to be_successful
@ -657,7 +659,8 @@ module Lti
'submission_id',
'workflow_state',
'link_id',
'error_message'
'error_message',
'submission_time'
].freeze
post @endpoints[:create], params: {originality_report: {file_id: @attachment.id, originality_score: 0.4}}, headers: request_headers

View File

@ -77,6 +77,10 @@ describe OriginalityReport do
expect(subject.errors[:submission]).to eq ["can't be blank"]
end
it 'sets the submission time' do
expect(subject.submission_time).to eq submission.submitted_at
end
it 'can have an originality report attachment' do
originality_attachemnt = attachment_model
subject.originality_report_attachment = originality_attachemnt