3737from opaque_keys .edx .locator import LibraryLocator , LibraryContainerLocator
3838from organizations .api import add_organization_course , ensure_organization
3939from organizations .exceptions import InvalidOrganizationException
40- from organizations .models import Organization , OrganizationCourse
40+ from organizations .models import Organization
4141from path import Path as path
4242from pytz import UTC
4343from user_tasks .models import UserTaskArtifact , UserTaskStatus
9898ALL_ALLOWED_XBLOCKS = frozenset (
9999 [entry_point .name for entry_point in entry_points (group = "xblock.v1" )]
100100)
101+ DEFAULT_HEADERS = {
102+ "User-Agent" : (
103+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
104+ "AppleWebKit/537.36 (KHTML, like Gecko) "
105+ "Chrome/115.0.0.0 Safari/537.36"
106+ ),
107+ "Accept" : "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" ,
108+ "Connection" : "keep-alive" ,
109+ }
101110
102111
103112class LinkState :
@@ -163,12 +172,6 @@ def rerun_course(source_course_key_string, destination_course_key_string, user_i
163172 # call edxval to attach videos to the rerun
164173 copy_course_videos (source_course_key , destination_course_key )
165174
166- # Copy OrganizationCourse
167- organization_course = OrganizationCourse .objects .filter (course_id = source_course_key_string ).first ()
168-
169- if organization_course :
170- clone_instance (organization_course , {'course_id' : destination_course_key_string })
171-
172175 # Copy RestrictedCourse
173176 restricted_course = RestrictedCourse .objects .filter (course_key = source_course_key ).first ()
174177
@@ -178,7 +181,7 @@ def rerun_course(source_course_key_string, destination_course_key_string, user_i
178181 for country_access_rule in country_access_rules :
179182 clone_instance (country_access_rule , {'restricted_course' : new_restricted_course })
180183
181- org_data = ensure_organization (source_course_key .org )
184+ org_data = ensure_organization (destination_course_key .org )
182185 add_organization_course (org_data , destination_course_key )
183186 return "succeeded"
184187
@@ -473,12 +476,12 @@ def sync_discussion_settings(course_key, user):
473476
474477 if (
475478 ENABLE_NEW_STRUCTURE_DISCUSSIONS .is_enabled ()
476- and not course .discussions_settings ['provider_type' ] == Provider .OPEN_EDX
479+ and not course .discussions_settings .get ('provider_type' , None ) == Provider .OPEN_EDX
480+ and not course .discussions_settings .get ('provider' , None ) == Provider .OPEN_EDX
477481 ):
478482 LOGGER .info (f"New structure is enabled, also updating { course_key } to use new provider" )
479483 course .discussions_settings ['enable_graded_units' ] = False
480484 course .discussions_settings ['unit_level_visibility' ] = True
481- course .discussions_settings ['provider' ] = Provider .OPEN_EDX
482485 course .discussions_settings ['provider_type' ] = Provider .OPEN_EDX
483486 modulestore ().update_item (course , user .id )
484487
@@ -1261,7 +1264,7 @@ async def _validate_urls_access_in_batches(url_list, course_key, batch_size=100)
12611264
12621265async def _validate_batch (batch , course_key ):
12631266 """Validate a batch of URLs"""
1264- async with aiohttp .ClientSession () as session :
1267+ async with aiohttp .ClientSession (headers = DEFAULT_HEADERS ) as session :
12651268 tasks = [_validate_url_access (session , url_data , course_key ) for url_data in batch ]
12661269 batch_results = await asyncio .gather (* tasks )
12671270 return batch_results
@@ -1286,6 +1289,7 @@ async def _validate_url_access(session, url_data, course_key):
12861289 }
12871290 """
12881291 block_id , url = url_data
1292+ url = url .strip () # Trim leading/trailing whitespace
12891293 result = {'block_id' : block_id , 'url' : url }
12901294 standardized_url = _convert_to_standard_url (url , course_key )
12911295 try :
0 commit comments