Allow setting error message on originality reports

Closes PLAT-4404

Test Plan:
- Create an originality report via API and specify
  the "error_message" attribute in the request.
- Verify an originality report is created with
  the correct "error_message."
- Attempt to update an existing originality
  report via API and specify an error_message.
- Verify the originality report is updated
  with the specified error message.

Change-Id: Id455fb395232687b814d6a7fe7ea1c27a98e8fa5
Reviewed-on: https://gerrit.instructure.com/191200
Tested-by: Jenkins
Product-Review: Jesse Poulos <jpoulos@instructure.com>
Reviewed-by: Rob Orton <rob@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
Reviewed-by: Marc Phillips <mphillips@instructure.com>
QA-Review: Nathan Mills <nathanm@instructure.com>
This commit is contained in:
wdransfield 2019-04-29 09:42:45 -06:00 committed by Weston Dransfield
parent e7c3de281a
commit 41f65a19cf
5 changed files with 83 additions and 12 deletions

View File

@ -92,6 +92,10 @@ module Lti
# "tool_setting": {
# "description": "A ToolSetting object containing optional 'resource_type_code' and 'resource_url'",
# "type": "ToolSetting"
# },
# "error_report": {
# "description": "A message describing the error. If set, the workflow_state will become 'error.'",
# "type": "String"
# }
# }
# }
@ -153,6 +157,10 @@ module Lti
# May be set to "pending", "error", or "scored". If an originality score
# is provided a workflow state of "scored" will be inferred.
#
# @argument originality_report[error_message] [String]
# A message describing the error. If set, the "workflow_state"
# will be set to "error."
#
# @returns OriginalityReport
def create
begin
@ -205,6 +213,10 @@ module Lti
# May be set to "pending", "error", or "scored". If an originality score
# is provided a workflow state of "scored" will be inferred.
#
# @argument originality_report[error_message] [String]
# A message describing the error. If set, the "workflow_state"
# will be set to "error."
#
# @returns OriginalityReport
def update
if @report.update_attributes(update_report_params)
@ -242,18 +254,24 @@ module Lti
end
def create_attributes
[:originality_score,
:file_id,
:originality_report_file_id,
:originality_report_url,
:workflow_state].freeze
[
:originality_score,
:error_message,
:file_id,
:originality_report_file_id,
:originality_report_url,
:workflow_state
].freeze
end
def update_attributes
[:originality_report_file_id,
:originality_report_url,
:originality_score,
:workflow_state].freeze
[
:error_message,
:originality_report_file_id,
:originality_report_url,
:originality_score,
:workflow_state
].freeze
end
def lti_link_attributes

View File

@ -97,6 +97,7 @@ class OriginalityReport < ActiveRecord::Base
end
def infer_workflow_state
self.workflow_state = 'error' if error_message.present?
return if self.workflow_state == 'error'
self.workflow_state = self.originality_score.present? ? 'scored' : 'pending'
end

View File

@ -0,0 +1,24 @@
#
# 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 AddErrorMessageToOriginalityReports < ActiveRecord::Migration[5.1]
tag :predeploy
def change
add_column :originality_reports, :error_message, :text
end
end

View File

@ -120,7 +120,8 @@ module Lti
'updated_at',
'submission_id',
'workflow_state',
'link_id'
'link_id',
'error_message'
].freeze
get @endpoints[:show], headers: request_headers
@ -211,7 +212,8 @@ module Lti
'updated_at',
'submission_id',
'workflow_state',
'link_id'
'link_id',
'error_message'
].freeze
get @endpoints[:alt_show], headers: request_headers
expect(response).to be_successful
@ -331,6 +333,12 @@ module Lti
expect(OriginalityReport.find(@report.id).originality_report_url).to eq "http://www.test.com"
end
it "updates error_message" do
put @endpoints[:update], params: {originality_report: {error_message: "An error occured."}}, headers: request_headers
expect(response).to be_successful
expect(OriginalityReport.find(@report.id).error_message).to eq "An error occured."
end
it "updates the associated resource_url" do
put @endpoints[:update],
params: {
@ -648,7 +656,8 @@ module Lti
'updated_at',
'submission_id',
'workflow_state',
'link_id'
'link_id',
'error_message'
].freeze
post @endpoints[:create], params: {originality_report: {file_id: @attachment.id, originality_score: 0.4}}, headers: request_headers
@ -751,6 +760,19 @@ module Lti
expect(response_body['workflow_state']).to eq 'pending'
end
it 'sets the error_message' do
post @endpoints[:create],
params: {
originality_report: {
file_id: @attachment.id,
workflow_state: 'error',
error_message: 'error message'
}
},
headers: request_headers
expect(json_parse['error_message']).to eq 'error message'
end
it 'allows creating reports for any attachment in submission history' do
shard_two = @shard1
a = @course.assignments.create!(

View File

@ -165,6 +165,12 @@ describe OriginalityReport do
report_with_score.update_attributes(originality_score: 23.2)
expect(report_with_score.workflow_state).to eq 'error'
end
it "updates state to 'error' if an error message is present" do
report_with_score.save
report_with_score.update_attributes(error_message: 'An error occured.')
expect(report_with_score.workflow_state).to eq 'error'
end
end
describe '#asset_key' do