use a Setting for link validator redirect filter

so if flickr changes its "image unavailable" redirect target,
we can adapt without a hotfix

test plan:
 - ensure deleted flickr photos still appear in the
   course link validator

refs ADMIN-2280

Change-Id: I5c478d5da77c4857e4bf872fb1c04e108b7ee9ae
Reviewed-on: https://gerrit.instructure.com/174798
Reviewed-by: Carl Kibler <ckibler@instructure.com>
Tested-by: Jenkins
QA-Review: Carl Kibler <ckibler@instructure.com>
Product-Review: Jeremy Stanley <jeremy@instructure.com>
This commit is contained in:
Jeremy Stanley 2018-12-08 15:07:25 -07:00
parent 2b9313cdec
commit 705599b91e
1 changed files with 2 additions and 1 deletions

View File

@ -307,11 +307,12 @@ class CourseLinkValidator
# ping the url and make sure we get a 200
def reachable_url?(url)
@unavailable_photo_redirect_pattern ||= Regexp.new(Setting.get('unavailable_photo_redirect_pattern', 'yimg\.com/.+/photo_unavailable.png$'))
redirect_proc = lambda do |response|
# flickr does a redirect to this file when a photo is deleted/not found;
# treat this as a broken image instead of following the redirect
url = response['Location']
raise RuntimeError("photo unavailable") if url =~ /yimg\.com\/.+\/photo_unavailable.png$/
raise RuntimeError("photo unavailable") if url =~ @unavailable_photo_redirect_pattern
end
begin