2013-04-06 04:40:05 +08:00
|
|
|
#
|
2017-04-28 12:02:05 +08:00
|
|
|
# Copyright (C) 2011 - present Instructure, Inc.
|
2013-04-06 04:40: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')
|
|
|
|
|
2015-04-09 01:21:08 +08:00
|
|
|
require 'nokogiri'
|
|
|
|
|
2013-04-06 04:40:05 +08:00
|
|
|
describe "syllabus" do
|
|
|
|
def anonymous_syllabus_access_allowed(property, value=true)
|
|
|
|
course_with_teacher(:course => @course, :active_all => true)
|
|
|
|
@course.send("#{property}=", value)
|
|
|
|
@course.save!
|
|
|
|
|
|
|
|
get "/courses/#{@course.id}/assignments/syllabus"
|
|
|
|
|
2018-08-01 01:25:10 +08:00
|
|
|
expect(response).to be_successful
|
2013-04-06 04:40:05 +08:00
|
|
|
page = Nokogiri::HTML(response.body)
|
2014-10-14 02:51:52 +08:00
|
|
|
expect(page.css('#identity a[href="/login"]')).not_to be_nil
|
|
|
|
expect(page.at_css('#syllabusContainer')).not_to be_nil
|
2013-04-06 04:40:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should allow access to public courses" do
|
|
|
|
anonymous_syllabus_access_allowed :is_public
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should allow access to a public syllabus" do
|
|
|
|
anonymous_syllabus_access_allowed :public_syllabus
|
|
|
|
end
|
2013-04-21 04:37:34 +08:00
|
|
|
|
2015-04-01 21:09:29 +08:00
|
|
|
shared_examples_for "public syllabus file verifiers" do
|
|
|
|
it "should allow viewing available files in a public syllabus" do
|
2016-12-25 13:35:06 +08:00
|
|
|
course_factory(active_all: true)
|
2015-04-01 21:09:29 +08:00
|
|
|
attachment_model
|
|
|
|
@course.syllabus_body = "<a href=\"/courses/#{@course.id}/files/#{@attachment.id}/download\">linky</a>"
|
|
|
|
@course.public_syllabus = true
|
|
|
|
@course.save!
|
|
|
|
|
|
|
|
get "/courses/#{@course.id}/assignments/syllabus"
|
|
|
|
|
2018-08-01 01:25:10 +08:00
|
|
|
expect(response).to be_successful
|
2015-04-01 21:09:29 +08:00
|
|
|
page = Nokogiri::HTML(response.body)
|
|
|
|
expect(page.css('#identity a[href="/login"]')).not_to be_nil
|
|
|
|
link = page.at_css('#course_syllabus a')
|
|
|
|
expect(link.attributes['href'].value).to include("verifier=#{@attachment.uuid}")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not allow viewing locked files in a public syllabus" do
|
2016-12-25 13:35:06 +08:00
|
|
|
course_factory(active_all: true)
|
2015-04-01 21:09:29 +08:00
|
|
|
attachment_model
|
|
|
|
@attachment.locked = true
|
|
|
|
@attachment.save!
|
|
|
|
|
|
|
|
@course.syllabus_body = "<a href=\"/courses/#{@course.id}/files/#{@attachment.id}/download\">linky</a>"
|
|
|
|
@course.public_syllabus = true
|
|
|
|
@course.save!
|
|
|
|
|
|
|
|
get "/courses/#{@course.id}/assignments/syllabus"
|
|
|
|
|
2018-08-01 01:25:10 +08:00
|
|
|
expect(response).to be_successful
|
2015-04-01 21:09:29 +08:00
|
|
|
page = Nokogiri::HTML(response.body)
|
|
|
|
expect(page.css('#identity a[href="/login"]')).not_to be_nil
|
|
|
|
link = page.at_css('#course_syllabus a')
|
|
|
|
expect(link.attributes['href'].value).to_not include("verifier=#{@attachment.uuid}")
|
|
|
|
end
|
|
|
|
end
|
2016-07-14 02:31:38 +08:00
|
|
|
|
|
|
|
shared_examples_for "public syllabus for authenticated file verifiers" do
|
|
|
|
it "should allow viewing available files in a public to authenticated syllabus" do
|
2016-12-25 13:35:06 +08:00
|
|
|
course_factory(active_all: true)
|
2016-07-14 02:31:38 +08:00
|
|
|
attachment_model
|
|
|
|
@course.syllabus_body = "<a href=\"/courses/#{@course.id}/files/#{@attachment.id}/download\">linky</a>"
|
|
|
|
@course.public_syllabus_to_auth = true
|
|
|
|
@course.public_syllabus = false
|
|
|
|
@course.save!
|
|
|
|
|
|
|
|
get "/courses/#{@course.id}/assignments/syllabus"
|
|
|
|
|
2018-08-01 01:25:10 +08:00
|
|
|
expect(response).to be_successful
|
2016-07-14 02:31:38 +08:00
|
|
|
page = Nokogiri::HTML(response.body)
|
|
|
|
expect(page.css('#identity a[href="/login"]')).not_to be_nil
|
|
|
|
link = page.at_css('#course_syllabus a')
|
|
|
|
expect(link.attributes['href'].value).to include("verifier=#{@attachment.uuid}")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not allow viewing locked files in a public to authenticated syllabus" do
|
2016-12-25 13:35:06 +08:00
|
|
|
course_factory(active_all: true)
|
2016-07-14 02:31:38 +08:00
|
|
|
attachment_model
|
|
|
|
@attachment.locked = true
|
|
|
|
@attachment.save!
|
|
|
|
|
|
|
|
@course.syllabus_body = "<a href=\"/courses/#{@course.id}/files/#{@attachment.id}/download\">linky</a>"
|
|
|
|
@course.public_syllabus = false
|
|
|
|
@course.public_syllabus_to_auth = true
|
|
|
|
@course.save!
|
|
|
|
|
|
|
|
get "/courses/#{@course.id}/assignments/syllabus"
|
|
|
|
|
2018-08-01 01:25:10 +08:00
|
|
|
expect(response).to be_successful
|
2016-07-14 02:31:38 +08:00
|
|
|
page = Nokogiri::HTML(response.body)
|
|
|
|
expect(page.css('#identity a[href="/login"]')).not_to be_nil
|
|
|
|
link = page.at_css('#course_syllabus a')
|
|
|
|
expect(link.attributes['href'].value).to_not include("verifier=#{@attachment.uuid}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "as an authenticated non-course user" do
|
|
|
|
before :each do
|
2016-12-24 07:53:27 +08:00
|
|
|
user_factory(active_all: true)
|
2016-07-14 02:31:38 +08:00
|
|
|
user_session(@user)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples "public syllabus for authenticated file verifiers"
|
|
|
|
end
|
|
|
|
|
2015-04-01 21:09:29 +08:00
|
|
|
context "as an anonymous user" do
|
|
|
|
include_examples "public syllabus file verifiers"
|
2014-12-06 02:11:25 +08:00
|
|
|
end
|
|
|
|
|
2015-04-01 21:09:29 +08:00
|
|
|
context "as an authenticated non-course user" do
|
|
|
|
before :each do
|
2016-12-24 07:53:27 +08:00
|
|
|
user_factory(active_all: true)
|
2015-04-01 21:09:29 +08:00
|
|
|
user_session(@user)
|
|
|
|
end
|
2015-02-07 01:59:38 +08:00
|
|
|
|
2015-04-01 21:09:29 +08:00
|
|
|
include_examples "public syllabus file verifiers"
|
2015-02-07 01:59:38 +08:00
|
|
|
end
|
|
|
|
|
2016-07-14 02:31:38 +08:00
|
|
|
it "as an authenticated non-course user with public_syllabus_to_auth true" do
|
2016-12-25 13:35:06 +08:00
|
|
|
course_factory.public_syllabus_to_auth = true
|
|
|
|
course_factory.public_syllabus = false
|
|
|
|
course_factory.save
|
2016-12-24 07:53:27 +08:00
|
|
|
user_factory(active_user: true)
|
2016-07-14 02:31:38 +08:00
|
|
|
user_session(@user)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-04-21 04:37:34 +08:00
|
|
|
it "should display syllabus description on syllabus course home pages" do
|
|
|
|
course_with_teacher_logged_in(:active_all => true)
|
|
|
|
syllabus_body = "test syllabus body"
|
|
|
|
@course.syllabus_body = syllabus_body
|
|
|
|
@course.default_view = "syllabus"
|
|
|
|
@course.save!
|
|
|
|
|
|
|
|
get "/courses/#{@course.id}"
|
|
|
|
|
2018-08-01 01:25:10 +08:00
|
|
|
expect(response).to be_successful
|
2013-04-21 04:37:34 +08:00
|
|
|
page = Nokogiri::HTML(response.body)
|
2014-10-14 02:51:52 +08:00
|
|
|
expect(page.at_css('#course_syllabus').text).to include(syllabus_body)
|
2013-04-21 04:37:34 +08:00
|
|
|
end
|
2013-04-06 04:40:05 +08:00
|
|
|
end
|