Skip to content

Commit

Permalink
fix: studio url evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
rayzhou-bit committed Jan 9, 2025
1 parent 067e1b0 commit 37f1b7a
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions cms/djangoapps/contentstore/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1127,9 +1127,17 @@ def get_urls(content):
regex = r'\s+(?:href|src)=["\'](?!#)([^"\']*)["\']'
url_list = re.findall(regex, content)
return url_list

def is_studio_url(url):
"""Returns True if url is a studio url."""
return is_studio_url_with_base(url) or is_studio_url_without_base(url)

def is_studio_url_with_base(url):
"""Returns True if url is a studio url with cms base."""
return url.startswith('http://' + settings.CMS_BASE) or url.startswith('https://' + settings.CMS_BASE)

def is_studio_url_without_base(url):
"""Returns True if url is a studio url without cms base."""
return not url.startswith('http://') and not url.startswith('https://')

def convert_to_standard_url(url, course_key):
Expand All @@ -1140,14 +1148,14 @@ def convert_to_standard_url(url, course_key):
/static/getting-started_x250.png
/container/block-v1:edX+DemoX+Demo_Course+type@vertical+block@2152d4a4aadc4cb0af5256394a3d1fc7
"""
if is_studio_url(url):
if is_studio_url_without_base(url):
if url.startswith('/static/'):
processed_url = replace_static_urls(f'\"{url}\"', course_id=course_key)[1:-1]
return 'http://' + settings.CMS_BASE + processed_url
return 'https://' + settings.CMS_BASE + processed_url
elif url.startswith('/'):
return 'http://' + settings.CMS_BASE + url
return 'https://' + settings.CMS_BASE + url
else:
return 'http://' + settings.CMS_BASE + '/container/' + url
return 'https://' + settings.CMS_BASE + '/container/' + url
else:
return url

Expand Down Expand Up @@ -1238,14 +1246,15 @@ def filter_by_status(results):
filtered_results = []
retry_list = []
for result in results:
if result['status'] is None:
retry_list.append([result['block_id'], result['url']])
elif result['status'] == 200:
status, block_id, url = result['status'], result['block_id'], result['url']
if status is None:
retry_list.append([block_id, url])
elif status == 200:
continue
elif result['status'] == 403 and is_studio_url(result['url']):
filtered_results.append([result['block_id'], result['url'], True])
elif status == 403 and is_studio_url(url):
filtered_results.append([block_id, url, True])
else:
filtered_results.append([result['block_id'], result['url'], False])
filtered_results.append([block_id, url, False])

return filtered_results, retry_list

Expand Down

0 comments on commit 37f1b7a

Please sign in to comment.