diff --git a/app/controllers/lti/originality_reports_api_controller.rb b/app/controllers/lti/originality_reports_api_controller.rb index 8a09f9e7a63..70954e54ef4 100644 --- a/app/controllers/lti/originality_reports_api_controller.rb +++ b/app/controllers/lti/originality_reports_api_controller.rb @@ -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 diff --git a/app/models/originality_report.rb b/app/models/originality_report.rb index 53e4792dc2f..2397c4f5b71 100644 --- a/app/models/originality_report.rb +++ b/app/models/originality_report.rb @@ -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 diff --git a/db/migrate/20190429145838_add_error_message_to_originality_reports.rb b/db/migrate/20190429145838_add_error_message_to_originality_reports.rb new file mode 100644 index 00000000000..0b1a4464253 --- /dev/null +++ b/db/migrate/20190429145838_add_error_message_to_originality_reports.rb @@ -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 . + +class AddErrorMessageToOriginalityReports < ActiveRecord::Migration[5.1] + tag :predeploy + + def change + add_column :originality_reports, :error_message, :text + end +end diff --git a/spec/apis/lti/originality_reports_api_spec.rb b/spec/apis/lti/originality_reports_api_spec.rb index d5e2a702305..faeaea2e7ba 100644 --- a/spec/apis/lti/originality_reports_api_spec.rb +++ b/spec/apis/lti/originality_reports_api_spec.rb @@ -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!( diff --git a/spec/models/originality_report_spec.rb b/spec/models/originality_report_spec.rb index f5b119b2cc3..c99a6c8b6cb 100644 --- a/spec/models/originality_report_spec.rb +++ b/spec/models/originality_report_spec.rb @@ -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