2012-03-26 04:23:05 +08:00
|
|
|
#
|
2017-04-28 12:12:06 +08:00
|
|
|
# Copyright (C) 2012 - present Instructure, Inc.
|
2012-03-26 04:23:05 +08:00
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
|
|
|
|
|
|
|
describe ContentExport do
|
2017-05-23 05:56:50 +08:00
|
|
|
before :once do
|
|
|
|
course_with_teacher(:active_all => true)
|
|
|
|
@ce = @course.content_exports.create!
|
|
|
|
end
|
2012-03-26 04:23:05 +08:00
|
|
|
|
|
|
|
context "export_object?" do
|
|
|
|
|
|
|
|
it "should return true for everything if there are no copy options" do
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.export_object?(@ce)).to eq true
|
2012-03-26 04:23:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return true for everything if 'everything' is selected" do
|
|
|
|
@ce.selected_content = {:everything => "1"}
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.export_object?(@ce)).to eq true
|
2012-03-26 04:23:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return false for nil objects" do
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.export_object?(nil)).to eq false
|
2012-03-26 04:23:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return true for all object types if the all_ option is true" do
|
|
|
|
@ce.selected_content = {:all_content_exports => "1"}
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.export_object?(@ce)).to eq true
|
2012-03-26 04:23:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return false for objects not selected" do
|
|
|
|
@ce.save!
|
|
|
|
@ce.selected_content = {:all_content_exports => "0"}
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.export_object?(@ce)).to eq false
|
2012-03-26 04:23:05 +08:00
|
|
|
@ce.selected_content = {:content_exports => {}}
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.export_object?(@ce)).to eq false
|
2012-03-26 04:23:05 +08:00
|
|
|
@ce.selected_content = {:content_exports => {CC::CCHelper.create_key(@ce) => "0"}}
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.export_object?(@ce)).to eq false
|
2012-03-26 04:23:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return true for selected objects" do
|
|
|
|
@ce.save!
|
|
|
|
@ce.selected_content = {:content_exports => {CC::CCHelper.create_key(@ce) => "1"}}
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.export_object?(@ce)).to eq true
|
2012-03-26 04:23:05 +08:00
|
|
|
end
|
2012-05-24 11:37:28 +08:00
|
|
|
end
|
|
|
|
|
2017-02-15 01:58:57 +08:00
|
|
|
context "Quizzes2 Export" do
|
|
|
|
before :once do
|
2017-03-09 04:04:36 +08:00
|
|
|
quiz = @course.quizzes.create!(:title => 'quiz1')
|
2017-03-03 00:38:59 +08:00
|
|
|
Account.default.context_external_tools.create!(
|
|
|
|
name: 'Quizzes.Next',
|
|
|
|
consumer_key: 'test_key',
|
|
|
|
shared_secret: 'test_secret',
|
|
|
|
tool_id: 'Quizzes 2',
|
|
|
|
url: 'http://example.com/launch'
|
|
|
|
)
|
2017-03-09 04:04:36 +08:00
|
|
|
@ce = @course.content_exports.create!(
|
2017-02-22 05:23:13 +08:00
|
|
|
:export_type => ContentExport::QUIZZES2,
|
2017-03-09 04:04:36 +08:00
|
|
|
:selected_content => quiz.id,
|
|
|
|
:user => @user
|
2017-02-22 05:23:13 +08:00
|
|
|
)
|
2017-12-15 13:46:24 +08:00
|
|
|
@course.root_account.settings[:provision] = {'lti' => 'lti url'}
|
|
|
|
@course.root_account.save!
|
2017-02-15 01:58:57 +08:00
|
|
|
end
|
|
|
|
|
2017-12-15 13:46:24 +08:00
|
|
|
it "changes the workflow_state when :quizzes_next is enabled" do
|
|
|
|
@course.enable_feature!(:quizzes_next)
|
2017-02-15 01:58:57 +08:00
|
|
|
expect { @ce.export_without_send_later }.to change { @ce.workflow_state }
|
|
|
|
expect(@ce.workflow_state).to eq "exported"
|
|
|
|
end
|
|
|
|
|
2017-12-15 13:46:24 +08:00
|
|
|
it "fails the content export when :quizzes_next is disabled" do
|
|
|
|
@course.disable_feature!(:quizzes_next)
|
2017-02-15 01:58:57 +08:00
|
|
|
@ce.export_without_send_later
|
|
|
|
expect(@ce.workflow_state).to eq "created"
|
|
|
|
end
|
2017-03-09 04:04:36 +08:00
|
|
|
|
|
|
|
it "composes the payload with assignment details" do
|
2017-12-15 13:46:24 +08:00
|
|
|
@course.enable_feature!(:quizzes_next)
|
2017-03-09 04:04:36 +08:00
|
|
|
@ce.export_without_send_later
|
|
|
|
expect(@ce.settings[:quizzes2][:assignment]).not_to be_empty
|
|
|
|
end
|
2017-06-15 05:27:24 +08:00
|
|
|
|
|
|
|
it "composes the payload with course UUID" do
|
2017-12-15 13:46:24 +08:00
|
|
|
@course.enable_feature!(:quizzes_next)
|
2017-06-15 05:27:24 +08:00
|
|
|
@ce.export_without_send_later
|
|
|
|
expect(@ce.settings[:quizzes2][:assignment][:course_uuid]).to eq(@course.uuid)
|
|
|
|
end
|
2017-03-09 04:04:36 +08:00
|
|
|
|
|
|
|
it "composes the payload with qti details" do
|
2017-12-15 13:46:24 +08:00
|
|
|
@course.enable_feature!(:quizzes_next)
|
2017-03-09 04:04:36 +08:00
|
|
|
@ce.export_without_send_later
|
involve user in generating non-public links
fixes RECNVS-12
and make public links explicit. note that for non-inst-fs file storage,
the user parameter to the existing authenticated_url method is unused.
so for non-inst-fs, the following sets of methods are equivalent:
* authenticated_url_for_user(*) == public_url == authenticated_url
* download_url_for_user(*) == public_download_url (was download_url)
* inline_url_for_user(*) == public_inline_url (was inline_url)
the choice of `public_...` over `..._for_user` methods in the refactoring
should thus be a no-op except when inst-fs is enabled. with inst-fs enabled,
the `public_...` methods produce URLs usable by any user (including
those not logged in!); this matches non-inst-fs behavior. the
`..._for_user` methods produce URLs usable only by the user for whom
they were generated, and should be preferred where public access is not
necessary.
after this refactor, make public links for google doc previews short
lived and consolidate some code around google doc preview links.
test-plan:
- enable inst-fs
[per-user inst-fs JWTs]
- have a student and a teacher in a course with an assignment
- as the teacher upload an image to the course files, then add the
image to the course syllabus
- as the student, attempt to view the course syllabus. should see the
image in the course syllabus (prior to this commit would fail)
- copy the inst-fs URL the student's browser was redirected to when
viewing the file
- as the teacher attempt to access the image directly using the
student's inst-fs URL; should fail
[public inst-fs JWTs]
- as the teacher, upload a course card image (example of public file)
- as the teacher, view the course card image and copy the inst-fs URL
redirected to
- as the student, attempt to access the course card image directly
using the copied inst-fs URL; should succeed
[google docs preview]
- disable canvadocs on the account if enabled
- as the teacher, upload a PDF to the course files
- find the PDF in the course files and preview it
- preview should be displayed via embedded google docs iframe
- preview should succeed
Change-Id: I8384cbb89f1522022e2f06579e6381de5ed0076c
Reviewed-on: https://gerrit.instructure.com/133889
Tested-by: Jenkins
Reviewed-by: Andrew Huff <ahuff@instructure.com>
QA-Review: Collin Parrish <cparrish@instructure.com>
Product-Review: Jacob Fugal <jacob@instructure.com>
2017-11-28 05:10:55 +08:00
|
|
|
expect(@ce.settings[:quizzes2][:qti_export][:url]).to eq(@ce.attachment.public_download_url)
|
2017-03-09 04:04:36 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "completes with export_type of 'quizzes2'" do
|
2017-12-15 13:46:24 +08:00
|
|
|
@course.enable_feature!(:quizzes_next)
|
2017-03-09 04:04:36 +08:00
|
|
|
@ce.export_without_send_later
|
|
|
|
expect(@ce.export_type).to eq('quizzes2')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'failure cases' do
|
|
|
|
it "fails if the quiz exporter fails" do
|
2017-12-15 13:46:24 +08:00
|
|
|
@course.enable_feature!(:quizzes_next)
|
2018-04-27 01:27:49 +08:00
|
|
|
allow_any_instance_of(Exporters::Quizzes2Exporter).to receive(:export).and_return(false)
|
2017-03-09 04:04:36 +08:00
|
|
|
@ce.export_without_send_later
|
|
|
|
expect(@ce.workflow_state).to eq "failed"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if the qti exporter fails" do
|
2017-12-15 13:46:24 +08:00
|
|
|
@course.enable_feature!(:quizzes_next)
|
2017-03-09 04:04:36 +08:00
|
|
|
allow_any_instance_of(CC::CCExporter).to receive(:export).and_return(false)
|
|
|
|
@ce.export_without_send_later
|
2018-04-27 01:27:49 +08:00
|
|
|
expect(@ce.workflow_state).to eq "failed"
|
2017-03-09 04:04:36 +08:00
|
|
|
end
|
|
|
|
end
|
2019-09-23 20:15:29 +08:00
|
|
|
|
|
|
|
context 'when newquizzes_on_quiz_page is enabled' do
|
|
|
|
before do
|
|
|
|
@course.enable_feature!(:quizzes_next)
|
|
|
|
@course.root_account.enable_feature!(:newquizzes_on_quiz_page)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets up assignment and content_export settings' do
|
|
|
|
expect(@ce).to receive(:export)
|
|
|
|
@ce.queue_api_job({})
|
|
|
|
expect(@ce.settings['quizzes2']).not_to be_nil
|
|
|
|
assignment_id = @ce.settings['quizzes2']['assignment']['assignment_id']
|
|
|
|
assignment = Assignment.find_by(id: assignment_id)
|
|
|
|
expect(assignment).not_to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
# CC export is the first step of Quiz migration
|
|
|
|
# Canvas then sends live events to N.Q
|
|
|
|
# N.Q finally imports the CC package
|
|
|
|
it 'completes CC export for new quizzes migration' do
|
|
|
|
cc_exporter = CC::CCExporter.new(@ce)
|
|
|
|
expect(CC::CCExporter).to receive(:new).and_return(cc_exporter)
|
|
|
|
expect(cc_exporter).to receive(:export).and_call_original
|
|
|
|
@ce.quizzes2_build_assignment
|
|
|
|
@ce.export_without_send_later
|
|
|
|
expect(@ce.settings[:quizzes2][:qti_export][:url]).to eq(@ce.attachment.public_download_url)
|
|
|
|
expect(@ce.export_type).to eq('quizzes2')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'marks failure if CC export is failed' do
|
|
|
|
cc_exporter = CC::CCExporter.new(@ce)
|
|
|
|
expect(CC::CCExporter).to receive(:new).and_return(cc_exporter)
|
|
|
|
# CC exporter fails and returns false
|
|
|
|
expect(cc_exporter).to receive(:export).and_return(false)
|
|
|
|
@ce.quizzes2_build_assignment
|
|
|
|
assignment_id = @ce.settings['quizzes2']['assignment']['assignment_id']
|
|
|
|
@ce.export_without_send_later
|
|
|
|
assignment = Assignment.find_by(id: assignment_id)
|
|
|
|
expect(assignment.workflow_state).to eq('failed_to_migrate')
|
|
|
|
expect(@ce.workflow_state).to eq('failed')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when failed assignment is provided' do
|
|
|
|
let(:failed_assignment) do
|
|
|
|
@course.assignments.create!(
|
|
|
|
position: 777,
|
|
|
|
assignment_group: assignment_group
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:assignment_group) do
|
|
|
|
@course.assignment_groups.create!(name: 'group_123')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates assignment with expected group and position' do
|
|
|
|
@ce.quizzes2_build_assignment(failed_assignment_id: failed_assignment.id)
|
|
|
|
expect(@ce.settings[:quizzes2][:assignment]).not_to be_empty
|
|
|
|
assignment_id = @ce.settings[:quizzes2][:assignment][:assignment_id]
|
|
|
|
assignment = Assignment.find(assignment_id)
|
|
|
|
expect(assignment.position).to be(777)
|
|
|
|
expect(assignment.assignment_group.id).to be(assignment_group.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-02-15 01:58:57 +08:00
|
|
|
end
|
|
|
|
|
2012-05-24 11:37:28 +08:00
|
|
|
context "add_item_to_export" do
|
|
|
|
it "should not add nil" do
|
|
|
|
@ce.add_item_to_export(nil)
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.selected_content).to be_empty
|
2012-05-24 11:37:28 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should only add data model objects" do
|
|
|
|
@ce.add_item_to_export("hi")
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.selected_content).to be_empty
|
2012-03-26 04:23:05 +08:00
|
|
|
|
2012-05-24 11:37:28 +08:00
|
|
|
@ce.selected_content = { :assignments => nil }
|
|
|
|
@ce.save!
|
|
|
|
|
|
|
|
assignment_model
|
|
|
|
@ce.add_item_to_export(@assignment)
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.selected_content[:assignments]).not_to be_empty
|
2012-05-24 11:37:28 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not add objects if everything is already set" do
|
|
|
|
assignment_model
|
|
|
|
@ce.add_item_to_export(@assignment)
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.selected_content).to be_empty
|
2012-05-24 11:37:28 +08:00
|
|
|
|
|
|
|
@ce.selected_content = { :everything => 1 }
|
|
|
|
@ce.save!
|
|
|
|
|
|
|
|
@ce.add_item_to_export(@assignment)
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.selected_content.keys.map(&:to_s)).to eq ["everything"]
|
2012-05-24 11:37:28 +08:00
|
|
|
end
|
2012-03-26 04:23:05 +08:00
|
|
|
end
|
|
|
|
|
2012-05-09 07:08:24 +08:00
|
|
|
context "notifications" do
|
2014-06-30 19:34:00 +08:00
|
|
|
before :once do
|
2017-05-23 05:56:50 +08:00
|
|
|
@ce.update_attribute(:user_id, @user.id)
|
2012-05-09 07:08:24 +08:00
|
|
|
Notification.create!(:name => 'Content Export Finished', :category => 'Migration')
|
|
|
|
Notification.create!(:name => 'Content Export Failed', :category => 'Migration')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should send notifications immediately" do
|
2013-03-20 03:10:46 +08:00
|
|
|
communication_channel_model.confirm!
|
2012-05-09 07:08:24 +08:00
|
|
|
|
|
|
|
['created', 'exporting', 'exported_for_course_copy', 'deleted'].each do |workflow|
|
2019-04-05 01:07:07 +08:00
|
|
|
@ce.workflow_state = workflow
|
2012-05-09 07:08:24 +08:00
|
|
|
expect { @ce.save! }.to change(DelayedMessage, :count).by 0
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.messages_sent['Content Export Finished']).to be_blank
|
|
|
|
expect(@ce.messages_sent['Content Export Failed']).to be_blank
|
2012-05-09 07:08:24 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
@ce.workflow_state = 'exported'
|
|
|
|
expect { @ce.save! }.to change(DelayedMessage, :count).by 0
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.messages_sent['Content Export Finished']).not_to be_blank
|
2012-05-09 07:08:24 +08:00
|
|
|
|
|
|
|
@ce.workflow_state = 'failed'
|
|
|
|
expect { @ce.save! }.to change(DelayedMessage, :count).by 0
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.messages_sent['Content Export Failed']).not_to be_blank
|
2012-05-09 07:08:24 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not send emails as part of a content migration (course copy)" do
|
2013-08-08 06:19:48 +08:00
|
|
|
@cm = ContentMigration.new(:user => @user, :copy_options => {:everything => "1"}, :context => @course)
|
2012-05-09 07:08:24 +08:00
|
|
|
@ce.content_migration = @cm
|
|
|
|
@ce.save!
|
|
|
|
|
|
|
|
@ce.workflow_state = 'exported'
|
|
|
|
expect { @ce.save! }.to change(DelayedMessage, :count).by 0
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.messages_sent['Content Export Finished']).to be_blank
|
2012-05-09 07:08:24 +08:00
|
|
|
|
|
|
|
@ce.workflow_state = 'failed'
|
|
|
|
expect { @ce.save! }.to change(DelayedMessage, :count).by 0
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.messages_sent['Content Export Failed']).to be_blank
|
2012-05-09 07:08:24 +08:00
|
|
|
end
|
|
|
|
end
|
2017-05-23 05:56:50 +08:00
|
|
|
|
|
|
|
describe "#expired?" do
|
|
|
|
it "marks as expired after X days" do
|
|
|
|
ContentExport.where(id: @ce.id).update_all(created_at: 35.days.ago)
|
|
|
|
expect(@ce.reload).to be_expired
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not mark new exports as expired" do
|
|
|
|
expect(@ce.reload).not_to be_expired
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not mark as expired if setting is 0" do
|
|
|
|
Setting.set('content_exports_expire_after_days', '0')
|
|
|
|
ContentExport.where(id: @ce.id).update_all(created_at: 35.days.ago)
|
|
|
|
expect(@ce.reload).not_to be_expired
|
|
|
|
end
|
2019-09-21 05:28:10 +08:00
|
|
|
|
|
|
|
it "does not mark expired if part of a ContentShare" do
|
|
|
|
@teacher.sent_content_shares.create!(read_state: 'read', name: 'test', content_export_id: @ce.id)
|
|
|
|
ContentExport.where(id: @ce.id).update_all(created_at: 35.days.ago)
|
|
|
|
expect(@ce.reload).not_to be_expired
|
|
|
|
end
|
2017-05-23 05:56:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "#expired" do
|
|
|
|
it "marks as expired after X days" do
|
|
|
|
ContentExport.where(id: @ce.id).update_all(created_at: 35.days.ago)
|
|
|
|
expect(ContentExport.expired.pluck(:id)).to eq [@ce.id]
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not mark new exports as expired" do
|
|
|
|
expect(ContentExport.expired.pluck(:id)).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not mark as expired if setting is 0" do
|
|
|
|
Setting.set('content_exports_expire_after_days', '0')
|
|
|
|
ContentExport.where(id: @ce.id).update_all(created_at: 35.days.ago)
|
|
|
|
expect(ContentExport.expired.pluck(:id)).to be_empty
|
|
|
|
end
|
|
|
|
end
|
2019-04-05 01:07:07 +08:00
|
|
|
|
|
|
|
context "global_identifiers" do
|
|
|
|
it "should be automatically set to true" do
|
|
|
|
cc_export = @course.content_exports.create!(:export_type => ContentExport::COURSE_COPY)
|
|
|
|
expect(cc_export.global_identifiers).to eq true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not set if there are any other exports in the context that weren't set" do
|
|
|
|
prev_export = @course.content_exports.create!(:export_type => ContentExport::COURSE_COPY)
|
|
|
|
prev_export.update_attribute(:global_identifiers, false)
|
|
|
|
cc_export = @course.content_exports.create!(:export_type => ContentExport::COURSE_COPY)
|
|
|
|
expect(cc_export.global_identifiers).to eq false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should use global asset strings for keys if set" do
|
|
|
|
export = @course.content_exports.create!(:export_type => ContentExport::COURSE_COPY)
|
|
|
|
a = @course.assignments.create!
|
|
|
|
expect(a).to receive(:global_asset_string).once.and_call_original
|
|
|
|
export.create_key(a)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should use local asset strings for keys if not set" do
|
|
|
|
export = @course.content_exports.create!(:export_type => ContentExport::COURSE_COPY)
|
|
|
|
export.update_attribute(:global_identifiers, false)
|
|
|
|
a = @course.assignments.create!
|
|
|
|
expect(a).to receive(:asset_string).once.and_call_original
|
|
|
|
export.create_key(a)
|
|
|
|
end
|
|
|
|
end
|
2012-05-09 07:08:24 +08:00
|
|
|
end
|