fix broken content notifications when referred from front page
test plan: * create a wiki page with a broken canvas link * set the page as the front page of course * if a student follows the broken link from the front page (e.g. /courses/X) it should still send the broken link notification to the teacher as if they had followed it from the page directly (e.g. /courses/X/pages/URL) closes #KNO-182 Change-Id: Ib4d561997084d7aa167f3a30cf30815f7221b8dc Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/221660 Reviewed-by: Carl Kibler <ckibler@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com> Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> QA-Review: Carl Kibler <ckibler@instructure.com> Product-Review: James Williams <jamesw@instructure.com>
This commit is contained in:
parent
fe44ce200a
commit
fff0d882bb
|
@ -19,8 +19,10 @@ module BrokenLinkHelper
|
|||
def send_broken_content!
|
||||
# call when processing a 4xx error.
|
||||
# this will examine the referrer to see if we got here because of a bad link
|
||||
return false unless request.referer
|
||||
record = Context.find_asset_by_url(request.referer)
|
||||
from_url = request.referer
|
||||
return false unless from_url
|
||||
record = Context.find_asset_by_url(from_url)
|
||||
record ||= Context.get_front_wiki_page_for_course_from_url(from_url)
|
||||
return false unless record
|
||||
body = Nokogiri::HTML(Context.asset_body(record))
|
||||
anchor = body.css("a[href$='#{request.fullpath}']").text
|
||||
|
|
|
@ -238,6 +238,18 @@ module Context
|
|||
nil
|
||||
end
|
||||
|
||||
def self.get_front_wiki_page_for_course_from_url(url)
|
||||
params = Rails.application.routes.recognize_path(url)
|
||||
if params[:controller] == "courses" && params[:action] == "show"
|
||||
course = Course.find(params[:id])
|
||||
if course.default_view == "wiki"
|
||||
course.wiki.front_page
|
||||
end
|
||||
end
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
|
||||
def self.find_asset_by_url(url)
|
||||
object = nil
|
||||
params = Rails.application.routes.recognize_path(url)
|
||||
|
@ -245,6 +257,7 @@ module Context
|
|||
group = Group.find(params[:group_id]) if params[:group_id]
|
||||
user = User.find(params[:user_id]) if params[:user_id]
|
||||
context = course || group || user
|
||||
|
||||
return nil unless context
|
||||
case params[:controller]
|
||||
when 'files'
|
||||
|
|
|
@ -85,6 +85,15 @@ describe BrokenLinkHelper, type: :controller do
|
|||
expect(send_broken_content!).to be true
|
||||
end
|
||||
|
||||
it 'should work with wiki pages set to the front page' do
|
||||
wiki_page_model(context: @course, body: "<a href='/test_error'>bad link</a>")
|
||||
@page.set_as_front_page!
|
||||
@course.update_attribute(:default_view, 'wiki')
|
||||
allow(request).to receive(:referer).and_return "/courses/#{@course.id}"
|
||||
allow(request).to receive(:path).and_return "/test_error"
|
||||
expect(send_broken_content!).to be true
|
||||
end
|
||||
|
||||
it 'should return true for unpublished content' do
|
||||
linked_assignment = @assignment
|
||||
assignment_model(course: @course).update_attributes(workflow_state: 'unpublished')
|
||||
|
|
Loading…
Reference in New Issue