Allow plagiarism tool providers to set eula link

Refs PLAT-2878

Test Plan:
- Install a plagiarim tool that offers a service named
  'vnd.Canvas.Eula'. Example:
  {"endpoint"=>"http://originality.docker/eula",
   "action"=>["GET"],
   "@id"=>"http://originality.docker/lti/v2/services#vnd.Canvas.Eula",
   "@type"=>"RestService"}
- Associate the tool with an assignment.
- As a student go to the assignment submission page.
  Verify a link to the EULA is shown on the page.

Change-Id: I86d9f06609e241e302f72b1f7569054b70c6674a
Reviewed-on: https://gerrit.instructure.com/129690
Reviewed-by: Nathan Mills <nathanm@instructure.com>
QA-Review: August Thornton <august@instructure.com>
Tested-by: Jenkins
Product-Review: Karl Lloyd <karl@instructure.com>
This commit is contained in:
wdransfield 2017-10-13 13:07:55 -06:00 committed by Weston Dransfield
parent c72c21d72b
commit 0041d8beba
8 changed files with 101 additions and 8 deletions

View File

@ -164,7 +164,14 @@ class AssignmentsController < ApplicationController
@similarity_pledge = pledge_text
respond_to do |format|
format.html { render }
format.html do
render locals: {
eula_url: @assignment.tool_settings_tool
&.try(:tool_proxy)
&.find_service(Assignment::Lti::EULA_SERVICE, 'GET')
&.endpoint
}
end
format.json { render :json => @assignment.as_json(:permissions => {:user => @current_user, :session => session}) }
end
end

View File

@ -42,6 +42,8 @@ class Assignment < ActiveRecord::Base
OFFLINE_SUBMISSION_TYPES = %i(on_paper external_tool none not_graded wiki_page).freeze
SUBMITTABLE_TYPES = %w(online_quiz discussion_topic wiki_page).freeze
Lti::EULA_SERVICE = 'vnd.Canvas.Eula'.freeze
attr_accessor :previous_id, :updating_user, :copying, :user_submitted
attr_reader :assignment_changed

View File

@ -138,5 +138,11 @@ module Lti
tool_resource_type_code: message_handler&.resource_handler&.resource_type_code
).preload(:assignment).map(&:assignment)
end
def find_service(service_id, action)
ims_tool_proxy.tool_profile&.service_offered&.find do |s|
s.id.include?(service_id) && s.action.include?(action)
end
end
end
end

View File

@ -122,7 +122,12 @@
<td colspan="2">
<label class='checkbox'>
<input type="checkbox" class='turnitin_pledge' name="turnitin_pledge" value="1"/>
<%= @similarity_pledge %>
<% if eula_url.present? %>
<%= t "I agree to the tool's" %>
<%= raw("<a href='#{eula_url}'>#{t 'End-User License Agreement.'}</a>") %>
<% else %>
<%= @similarity_pledge %>
<% end %>
</label>
</td>
</tr>

View File

@ -235,7 +235,7 @@
<% end %>
<% if !@locked && can_do(@assignment, @current_user, :submit) %>
<%= render :partial => "submit_assignment" %>
<%= render :partial => "submit_assignment", locals: { eula_url: eula_url }%>
<% end %>
<%= render partial: "shared/rubrics_component" %>

View File

@ -76,10 +76,7 @@ module Lti
def submission_event_service
@_submission_event_service ||= begin
tp = IMS::LTI::Models::ToolProxy.from_json(tool_proxy.raw_data)
tp.tool_profile&.service_offered&.find do |s|
s.id.include?(SUBMISSION_EVENT_ID) && s.action.include?("POST")
end
tool_proxy.find_service(SUBMISSION_EVENT_ID, 'POST')
end
end

View File

@ -496,6 +496,45 @@ module Lti
end
end
describe "#find_service" do
let(:service_one_id) { "http://originality.docker/lti/v2/services#vnd.Canvas.SubmissionEvent" }
let(:service_one_endpoint) { "http://originality.docker/event/submission" }
let(:service_two_id) { "http://originality.docker/lti/v2/services#vnd.Canvas.Eula" }
let(:service_two_endpoint) { "http://originality.docker/eula" }
let(:tool_proxy) do
create_tool_proxy(raw_data: {
'tool_profile' => {
'service_offered' => [
{
"endpoint" => service_one_endpoint,
"action" => ["POST", "GET"],
"@id" => service_one_id,
"@type" => "RestService"
},
{
"endpoint" => service_two_endpoint,
"action" => ["GET"],
"@id" => service_two_id,
"@type" => "RestService"
}
]
}
})
end
it 'returns the service for the specified id/action pair' do
expect(tool_proxy.find_service(service_one_id, 'POST').endpoint).to eq service_one_endpoint
end
it 'considers all actions of potential services' do
expect(tool_proxy.find_service(service_one_id, 'GET').endpoint).to eq service_one_endpoint
end
it 'does not return a service if no matching action is found' do
expect(tool_proxy.find_service(service_one_id, 'PUT')).to be_nil
end
end
describe "#ims_tool_proxy" do
it 'gets the ims-lti gem version of the tool proxy' do
tool_proxy_guid = '123'

View File

@ -17,6 +17,7 @@
#
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../../lti2_spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')
describe "/assignments/show" do
@ -33,5 +34,41 @@ describe "/assignments/show" do
render 'assignments/show'
expect(response).not_to be_nil # have_tag()
end
end
context 'plagiarism platform' do
include_context 'lti2_spec_helper'
let(:eula_url) { 'https://www.test.com/eula' }
let(:eula_service) do
{
"endpoint" => eula_url,
"action" => ["GET"],
"@id" => 'http://www.test.com/lti/v2/services#vnd.Canvas.Eula',
"@type" => "RestService"
}
end
before do
allow_any_instance_of(Assignment).to receive(:multiple_due_dates?) { true }
allow(view).to receive(:eula_url) { eula_url }
end
it 'renders the eula url if present' do
tool_proxy.raw_data['tool_profile']['service_offered'] << eula_service
tool_proxy.resources << resource_handler
tool_proxy.save!
course_with_student(active_all: true)
view_context(@course, @student)
a = @course.assignments.create!(:title => "some assignment", :submission_types => 'online_upload')
allow(a).to receive(:tool_settings_tool) { message_handler }
assign(:assignment, a)
assign(:current_user_rubrics, [])
assign(:external_tools, [])
render 'assignments/show'
expect(rendered).to include "<a href='https://www.test.com/eula'>End-User License Agreement.</a>"
end
end
end