Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions .github/workflows/semgrep.yml

This file was deleted.

1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ REQ_FILES = \
requirements/edx/testing \
requirements/edx/assets \
requirements/edx/development \
requirements/edx/semgrep \
scripts/xblock/requirements \
scripts/user_retirement/requirements/base \
scripts/user_retirement/requirements/testing \
Expand Down
2 changes: 0 additions & 2 deletions cms/djangoapps/cms_user_tasks/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from celery.utils.log import get_task_logger
from django.conf import settings
from django.core import mail
from edx_django_utils.monitoring import set_code_owner_attribute

from common.djangoapps.edxmako.shortcuts import render_to_string
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
Expand All @@ -20,7 +19,6 @@


@shared_task(bind=True)
@set_code_owner_attribute
def send_task_complete_email(self, task_name, task_state_text, dest_addr, detail_url,
olx_validation_text=None, is_course_optimizer_task=False):
"""
Expand Down
162 changes: 140 additions & 22 deletions cms/djangoapps/contentstore/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
from django.test import RequestFactory
from django.utils.text import get_valid_filename
from edx_django_utils.monitoring import (
set_code_owner_attribute,
set_code_owner_attribute_from_module,
set_custom_attribute,
set_custom_attributes_for_course_key,
)
Expand Down Expand Up @@ -166,7 +164,6 @@ def clone_instance(instance, field_values):


@shared_task
@set_code_owner_attribute
def rerun_course(source_course_key_string, destination_course_key_string, user_id, fields=None):
"""
Reruns a course in a new celery task.
Expand Down Expand Up @@ -262,7 +259,6 @@ def _parse_time(time_isoformat):


@shared_task
@set_code_owner_attribute
def update_search_index(course_id, triggered_time_isoformat):
""" Updates course search index. """
try:
Expand Down Expand Up @@ -293,7 +289,6 @@ def update_search_index(course_id, triggered_time_isoformat):


@shared_task
@set_code_owner_attribute
def update_library_index(library_id, triggered_time_isoformat):
""" Updates course search index. """
try:
Expand All @@ -307,7 +302,6 @@ def update_library_index(library_id, triggered_time_isoformat):


@shared_task
@set_code_owner_attribute
def update_special_exams_and_publish(course_key_str):
"""
Registers special exams for a given course and calls publishing flow.
Expand Down Expand Up @@ -368,13 +362,11 @@ def generate_name(cls, arguments_dict):


@shared_task(base=CourseExportTask, bind=True)
# Note: The decorator @set_code_owner_attribute cannot be used here because the UserTaskMixin
# does stack inspection and can't handle additional decorators.
def export_olx(self, user_id, course_key_string, language):
"""
Export a course or library to an OLX .tar.gz archive and prepare it for download.
"""
set_code_owner_attribute_from_module(__name__)
courselike_key = CourseKey.from_string(course_key_string)

try:
Expand Down Expand Up @@ -546,14 +538,12 @@ def sync_discussion_settings(course_key, user):


@shared_task(base=CourseImportTask, bind=True)
# Note: The decorator @set_code_owner_attribute cannot be used here because the UserTaskMixin
# does stack inspection and can't handle additional decorators.
# pylint: disable=too-many-statements
def import_olx(self, user_id, course_key_string, archive_path, archive_name, language):
"""
Import a course or library from a provided OLX .tar.gz or .zip archive.
"""
set_code_owner_attribute_from_module(__name__)
current_step = 'Unpacking'
courselike_key = CourseKey.from_string(course_key_string)
set_custom_attributes_for_course_key(courselike_key)
Expand Down Expand Up @@ -789,7 +779,6 @@ def read_chunk():


@shared_task
@set_code_owner_attribute
def update_all_outlines_from_modulestore_task():
"""
Celery task that creates multiple celery tasks - one per learning_sequence course outline
Expand All @@ -816,7 +805,6 @@ def update_all_outlines_from_modulestore_task():


@shared_task
@set_code_owner_attribute
def update_outline_from_modulestore_task(course_key_str: str):
"""
Celery task that creates a learning_sequence course outline.
Expand Down Expand Up @@ -961,7 +949,6 @@ def _get_users_by_access_level(v1_library_key):


@shared_task(time_limit=30)
@set_code_owner_attribute
def delete_v1_library(v1_library_key_string):
"""
Delete a v1 library index by key string.
Expand All @@ -987,6 +974,146 @@ def delete_v1_library(v1_library_key_string):
}


@shared_task(time_limit=30)
def validate_all_library_source_blocks_ids_for_course(course_key_string, v1_to_v2_lib_map):
"""Search a Modulestore for all library source blocks in a course by querying mongo.
replace all source_library_ids with the corresponding v2 value from the map
"""
course_id = CourseKey.from_string(course_key_string)
store = modulestore()
with store.bulk_operations(course_id):
visited = []
for branch in [ModuleStoreEnum.BranchName.draft, ModuleStoreEnum.BranchName.published]:
blocks = store.get_items(
course_id.for_branch(branch),
settings={'source_library_id': {'$exists': True}}
)
for xblock in blocks:
if xblock.source_library_id not in v1_to_v2_lib_map.values():
# pylint: disable=broad-except
raise Exception(
f'{xblock.source_library_id} in {course_id} is not found in mapping. Validation failed'
)
visited.append(xblock.source_library_id)
# return sucess
return visited


@shared_task(time_limit=30)
def replace_all_library_source_blocks_ids_for_course(course_key_string, v1_to_v2_lib_map): # pylint: disable=useless-return
"""Search a Modulestore for all library source blocks in a course by querying mongo.
replace all source_library_ids with the corresponding v2 value from the map.

This will trigger a publish on the course for every published library source block.
"""
store = modulestore()
course_id = CourseKey.from_string(course_key_string)

with store.bulk_operations(course_id):
#for branch in [ModuleStoreEnum.BranchName.draft, ModuleStoreEnum.BranchName.published]:
draft_blocks, published_blocks = [
store.get_items(
course_id.for_branch(branch),
settings={'source_library_id': {'$exists': True}}
)
for branch in [ModuleStoreEnum.BranchName.draft, ModuleStoreEnum.BranchName.published]
]

published_dict = {block.location: block for block in published_blocks}

for draft_library_source_block in draft_blocks:
try:
new_source_id = str(v1_to_v2_lib_map[draft_library_source_block.source_library_id])
except KeyError:
#skip invalid keys
LOGGER.error(
'Key %s not found in mapping. Skipping block for course %s',
str({draft_library_source_block.source_library_id}),
str(course_id)
)
continue

# The publsihed branch should be updated as well as the draft branch
# This way, if authors "discard changes," they won't be reverted back to the V1 lib.
# However, we also don't want to publish the draft branch.
try:
if published_dict[draft_library_source_block.location] is not None:
#temporarily set the published version to be the draft & publish it.
temp = published_dict[draft_library_source_block.location]
temp.source_library_id = new_source_id
store.update_item(temp, None)
store.publish(temp.location, None)
draft_library_source_block.source_library_id = new_source_id
store.update_item(draft_library_source_block, None)
except KeyError:
#Warn, but just update the draft block if no published block for draft block.
LOGGER.warning(
'No matching published block for draft block %s',
str(draft_library_source_block.location)
)
draft_library_source_block.source_library_id = new_source_id
store.update_item(draft_library_source_block, None)
# return success
return


@shared_task(time_limit=30)
def undo_all_library_source_blocks_ids_for_course(course_key_string, v1_to_v2_lib_map): # pylint: disable=useless-return
"""Search a Modulestore for all library source blocks in a course by querying mongo.
replace all source_library_ids with the corresponding v1 value from the inverted map.
This is exists to undo changes made previously.
"""
course_id = CourseKey.from_string(course_key_string)

v2_to_v1_lib_map = {v: k for k, v in v1_to_v2_lib_map.items()}

store = modulestore()
draft_blocks, published_blocks = [
store.get_items(
course_id.for_branch(branch),
settings={'source_library_id': {'$exists': True}}
)
for branch in [ModuleStoreEnum.BranchName.draft, ModuleStoreEnum.BranchName.published]
]

published_dict = {block.location: block for block in published_blocks}

for draft_library_source_block in draft_blocks:
try:
new_source_id = str(v2_to_v1_lib_map[draft_library_source_block.source_library_id])
except KeyError:
#skip invalid keys
LOGGER.error(
'Key %s not found in mapping. Skipping block for course %s',
str({draft_library_source_block.source_library_id}),
str(course_id)
)
continue

# The publsihed branch should be updated as well as the draft branch
# This way, if authors "discard changes," they won't be reverted back to the V1 lib.
# However, we also don't want to publish the draft branch.
try:
if published_dict[draft_library_source_block.location] is not None:
#temporarily set the published version to be the draft & publish it.
temp = published_dict[draft_library_source_block.location]
temp.source_library_id = new_source_id
store.update_item(temp, None)
store.publish(temp.location, None)
draft_library_source_block.source_library_id = new_source_id
store.update_item(draft_library_source_block, None)
except KeyError:
#Warn, but just update the draft block if no published block for draft block.
LOGGER.warning(
'No matching published block for draft block %s',
str(draft_library_source_block.location)
)
draft_library_source_block.source_library_id = new_source_id
store.update_item(draft_library_source_block, None)
# return success
return


class CourseLinkCheckTask(UserTask): # pylint: disable=abstract-method
"""
Base class for course link check tasks.
Expand Down Expand Up @@ -1021,13 +1148,11 @@ def generate_name(cls, arguments_dict):


@shared_task(base=CourseLinkCheckTask, bind=True)
# Note: The decorator @set_code_owner_attribute cannot be used here because the UserTaskMixin
# does stack inspection and can't handle additional decorators.
def check_broken_links(self, user_id, course_key_string, language):
"""
Checks for broken links in a course and store the results in a file.
"""
set_code_owner_attribute_from_module(__name__)
return _check_broken_links(self, user_id, course_key_string, language)


Expand Down Expand Up @@ -1495,7 +1620,6 @@ def _write_broken_links_to_file(broken_or_locked_urls, broken_links_file):


@shared_task
@set_code_owner_attribute
def handle_create_xblock_upstream_link(usage_key):
"""
Create upstream link for a single xblock.
Expand Down Expand Up @@ -1523,7 +1647,6 @@ def handle_create_xblock_upstream_link(usage_key):


@shared_task
@set_code_owner_attribute
def handle_update_xblock_upstream_link(usage_key):
"""
Update upstream link for a single xblock.
Expand All @@ -1540,7 +1663,6 @@ def handle_update_xblock_upstream_link(usage_key):


@shared_task
@set_code_owner_attribute
def create_or_update_upstream_links(
course_key_str: str,
force: bool = False,
Expand Down Expand Up @@ -1581,7 +1703,6 @@ def create_or_update_upstream_links(


@shared_task
@set_code_owner_attribute
def handle_unlink_upstream_block(upstream_usage_key_string: str) -> None:
"""
Handle updates needed to downstream blocks when the upstream link is severed.
Expand All @@ -1601,7 +1722,6 @@ def handle_unlink_upstream_block(upstream_usage_key_string: str) -> None:


@shared_task
@set_code_owner_attribute
def handle_unlink_upstream_container(upstream_container_key_string: str) -> None:
"""
Handle updates needed to downstream blocks when the upstream link is severed.
Expand Down Expand Up @@ -1658,7 +1778,6 @@ def update_course_rerun_links(
"""
Updates course links to point to the latest re-run.
"""
set_code_owner_attribute_from_module(__name__)
return _update_course_rerun_links(
self, user_id, course_id, action, data, language
)
Expand Down Expand Up @@ -2214,7 +2333,6 @@ def migrate_course_legacy_library_blocks_to_item_bank(
leaving migrated blocks as drafts.
"""
ensure_cms("Legacy library content references may only be executed in CMS")
set_code_owner_attribute_from_module(__name__)
_cancel_old_tasks(course_key, self.status.user, [self.status.task_id])
try:
key = CourseKey.from_string(course_key)
Expand Down
2 changes: 0 additions & 2 deletions cms/djangoapps/export_course_metadata/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from celery import shared_task
from django.core.files.base import ContentFile
from edx_django_utils.monitoring import set_code_owner_attribute
from opaque_keys.edx.keys import CourseKey

from openedx.core.djangoapps.schedules.content_highlights import get_all_course_highlights
Expand All @@ -15,7 +14,6 @@


@shared_task(bind=True)
@set_code_owner_attribute
def export_course_metadata_task(self, course_key_string): # pylint: disable=unused-argument
"""
Export course metadata
Expand Down
Loading
Loading