Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

from cms.djangoapps.contentstore.models import BackfillCourseTabsConfig

from openedx.core.djangoapps.content.course_overviews.models import CourseOverview

logger = logging.getLogger(__name__)


Expand All @@ -29,9 +31,13 @@ class Command(BaseCommand):
help = (
'Backfill default course tabs for all courses. This command is essentially for when a new default '
'tab is added and we need to update all existing courses. Any new courses will pick up the new '
'tab automatically via course creation and the CourseTabList.initialize_default method.'
'tab automatically via course creation and the CourseTabList.initialize_default method. '
'Can pass an optional flag --no-publish to skip publishing the courses.'
)

def add_arguments(self, parser):
parser.add_argument('--no-publish', action='store_true', help="Skip publishing courses")

def handle(self, *args, **options):
"""
Gathers all course keys in the modulestore and updates the course tabs
Expand Down Expand Up @@ -59,10 +65,15 @@ def handle(self, *args, **options):
new_tabs = {tab.type for tab in course.tabs}

if existing_tabs != new_tabs:
# This will trigger the Course Published Signal which is necessary to update
# the corresponding Course Overview
logger.info(f'Updating tabs for {course_key}.')
store.update_item(course, ModuleStoreEnum.UserID.mgmt_command)
if options['no_publish']:
# This will update the course block and overview without
# triggering course published signal
store.update_item(course, ModuleStoreEnum.UserID.mgmt_command, no_signals=True)
CourseOverview.load_from_module_store(course.id)
else:
# This will trigger the Course Published Signal
store.update_item(course, ModuleStoreEnum.UserID.mgmt_command)
logger.info(f'Successfully updated tabs for {course_key}.')
except Exception as err: # pylint: disable=broad-except
logger.exception(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,15 @@ def copy_from_template(self, source_keys, dest_key, user_id, **kwargs): # lint-
keys_to_check.extend(children)
return new_keys

def update_item(self, descriptor, user_id, allow_not_found=False, force=False, asides=None, **kwargs): # lint-amnesty, pylint: disable=arguments-differ
def update_item(self, descriptor, user_id, allow_not_found=False, force=False, asides=None, no_signals=False, **kwargs): # lint-amnesty, pylint: disable=arguments-differ
old_descriptor_locn = descriptor.location
descriptor.location = self._map_revision_to_branch(old_descriptor_locn)
emit_signals = descriptor.location.branch == ModuleStoreEnum.BranchName.published \
or descriptor.location.block_type in DIRECT_ONLY_CATEGORIES

if no_signals:
emit_signals = False

with self.bulk_operations(descriptor.location.course_key, emit_signals=emit_signals):
item = super().update_item(
descriptor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_get_authenticated_user(self):
response = self.client.get(self.url)
assert response.status_code == 200
assert not response.data.get('is_staff')
# 'Course', and 'Progress' tabs
# 'Course' and 'Progress' tabs
assert len(response.data.get('tabs', [])) == 3

@ddt.data(True, False)
Expand Down