Skip to content
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion cms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# ruff: noqa: I001
"""
Celery needs to be loaded when the cms modules are so that task
registration and discovery can work correctly.

Import sorting is intentionally disabled in this module.
isort:skip_file
"""


Expand Down
3 changes: 2 additions & 1 deletion cms/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: I001
"""
Studio unit test configuration and fixtures.

Expand All @@ -13,7 +14,7 @@
from openedx.core.pytest_hooks import DeferPlugin

# Patch the xml libs before anything else.
from openedx.core.lib.safe_lxml import defuse_xml_libs # isort:skip
from openedx.core.lib.safe_lxml import defuse_xml_libs # must patch xml libs before other imports execute
defuse_xml_libs()


Expand Down
3 changes: 1 addition & 2 deletions cms/djangoapps/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"""


from django.urls import include
from django.urls import path
from django.urls import include, path

app_name = 'cms.djangoapps.api'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@


import datetime

import ddt
import pytz
from django.test import RequestFactory

from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole
from common.djangoapps.student.tests.factories import UserFactory
from openedx.core.lib.courses import course_image_url
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.tests.django_utils import (
ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order
)
from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order

from ...serializers.course_runs import CourseRunSerializer
Expand Down
9 changes: 7 additions & 2 deletions cms/djangoapps/api/v1/tests/test_views/test_course_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@
from xmodule.contentstore.django import contentstore # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.exceptions import NotFoundError # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.tests.factories import CourseFactory, ToyCourseFactory # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.tests.django_utils import (
ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order
)
from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order
CourseFactory,
ToyCourseFactory,
)

from ...serializers.course_runs import CourseRunSerializer
from ..utils import serialize_datetime
Expand Down
2 changes: 1 addition & 1 deletion cms/djangoapps/api/v1/views/course_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
CourseRunCreateSerializer,
CourseRunImageSerializer,
CourseRunRerunSerializer,
CourseRunSerializer
CourseRunSerializer,
)


Expand Down
7 changes: 3 additions & 4 deletions cms/djangoapps/contentstore/api/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

from django.urls import reverse
from rest_framework.test import APITestCase
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory

from common.djangoapps.student.tests.factories import StaffFactory
from common.djangoapps.student.tests.factories import UserFactory
from common.djangoapps.student.tests.factories import StaffFactory, UserFactory
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory


# pylint: disable=unused-variable
Expand Down
5 changes: 2 additions & 3 deletions cms/djangoapps/contentstore/api/tests/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
from rest_framework import status
from rest_framework.test import APITestCase
from user_tasks.models import UserTaskStatus

from common.djangoapps.student.tests.factories import StaffFactory, UserFactory
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory

from common.djangoapps.student.tests.factories import StaffFactory
from common.djangoapps.student.tests.factories import UserFactory


class CourseImportViewTest(SharedModuleStoreTestCase, APITestCase):
"""
Expand Down
5 changes: 3 additions & 2 deletions cms/djangoapps/contentstore/api/tests/test_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
Tests for the course import API views
"""

from rest_framework.test import APIClient
from openedx_authz.constants.roles import COURSE_DATA_RESEARCHER, COURSE_STAFF
from rest_framework import status
from openedx_authz.constants.roles import COURSE_STAFF, COURSE_DATA_RESEARCHER
from rest_framework.test import APIClient

from common.djangoapps.student.tests.factories import UserFactory
from openedx.core.djangoapps.authz.tests.mixins import CourseAuthzTestMixin

from .base import BaseCourseViewTest


Expand Down
10 changes: 4 additions & 6 deletions cms/djangoapps/contentstore/api/tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,21 @@

import ddt
import factory

from django.conf import settings
from django.contrib.auth import get_user_model
from django.test.utils import override_settings
from django.urls import reverse
from openedx_authz.constants.roles import COURSE_DATA_RESEARCHER, COURSE_STAFF
from rest_framework import status
from rest_framework.test import APITestCase
from rest_framework.test import APIClient
from openedx.core.djangoapps.authz.tests.mixins import CourseAuthzTestMixin
from openedx_authz.constants.roles import COURSE_STAFF, COURSE_DATA_RESEARCHER
from rest_framework.test import APIClient, APITestCase

from cms.djangoapps.contentstore.api.tests.base import BaseCourseViewTest
from common.djangoapps.course_modes.models import CourseMode
from common.djangoapps.course_modes.tests.factories import CourseModeFactory
from common.djangoapps.student.tests.factories import StaffFactory, UserFactory
from openedx.core.djangoapps.authz.tests.mixins import CourseAuthzTestMixin
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory
from cms.djangoapps.contentstore.api.tests.base import BaseCourseViewTest

User = get_user_model()

Expand Down
6 changes: 3 additions & 3 deletions cms/djangoapps/contentstore/api/views/course_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

import numpy as np
from edxval.api import get_course_videos_qset
from openedx_authz.constants.permissions import COURSES_VIEW_COURSE
from rest_framework.generics import GenericAPIView
from rest_framework.response import Response
from openedx.core.djangoapps.authz.constants import LegacyAuthoringPermission
from scipy import stats
from openedx_authz.constants.permissions import COURSES_VIEW_COURSE

from openedx.core.djangoapps.authz.constants import LegacyAuthoringPermission
from openedx.core.djangoapps.authz.decorators import authz_permission_required
from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes
from openedx.core.lib.cache_utils import request_cached
from openedx.core.lib.graph_traversals import traverse_pre_order
from openedx.core.djangoapps.authz.decorators import authz_permission_required
from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order

from .utils import get_bool_param
Expand Down
6 changes: 3 additions & 3 deletions cms/djangoapps/contentstore/api/views/course_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
import edx_api_doc_tools as apidocs
from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication
from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser
from openedx_authz.constants.permissions import COURSES_VIEW_COURSE
from pytz import UTC
from rest_framework import serializers, status
from rest_framework.generics import GenericAPIView
from rest_framework.response import Response
from openedx.core.djangoapps.authz.constants import LegacyAuthoringPermission
from user_tasks.models import UserTaskStatus
from user_tasks.views import StatusViewSet
from openedx_authz.constants.permissions import COURSES_VIEW_COURSE

from cms.djangoapps.contentstore.course_info_model import get_course_updates
from cms.djangoapps.contentstore.tasks import migrate_course_legacy_library_blocks_to_item_bank
from cms.djangoapps.contentstore.views.certificates import CertificateManager
from common.djangoapps.util.proctoring import requires_escalation_email
from openedx.core.djangoapps.authz.constants import LegacyAuthoringPermission
from openedx.core.djangoapps.authz.decorators import authz_permission_required
from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser
from openedx.core.lib.api.serializers import StatusSerializerWithUuid
from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes
from openedx.core.djangoapps.authz.decorators import authz_permission_required
from xmodule.course_metadata_utils import DEFAULT_GRADING_POLICY # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order

Expand Down
19 changes: 9 additions & 10 deletions cms/djangoapps/contentstore/asset_storage_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@
from django.views.decorators.csrf import ensure_csrf_cookie
from django.views.decorators.http import require_http_methods, require_POST
from opaque_keys.edx.keys import AssetKey, CourseKey
from openedx.core.djangoapps.authz.constants import LegacyAuthoringPermission
from openedx.core.djangoapps.authz.decorators import user_has_course_permission
from openedx_authz.constants.permissions import (
COURSES_CREATE_FILES,
COURSES_DELETE_FILES,
COURSES_EDIT_FILES,
COURSES_VIEW_FILES,
)
from openedx_filters.content_authoring.filters import LMSPageURLRequested
from pymongo import ASCENDING, DESCENDING

from common.djangoapps.util.date_utils import get_default_time_display
from common.djangoapps.util.json_request import JsonResponse
from openedx.core.djangoapps.authz.constants import LegacyAuthoringPermission
from openedx.core.djangoapps.authz.decorators import user_has_course_permission
from openedx.core.djangoapps.contentserver.caching import del_cached_content
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.djangoapps.user_api.models import UserPreference
from openedx_authz.constants.permissions import (
COURSES_VIEW_FILES,
COURSES_CREATE_FILES,
COURSES_DELETE_FILES,
COURSES_EDIT_FILES,
)
from openedx_filters.content_authoring.filters import LMSPageURLRequested
from openedx.core.toggles import enable_authz_course_authoring
from xmodule.contentstore.content import StaticContent # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.contentstore.django import contentstore # lint-amnesty, pylint: disable=wrong-import-order
Expand All @@ -43,7 +43,6 @@
from .exceptions import AssetNotFoundException, AssetSizeTooLargeException
from .utils import get_files_uploads_url, get_response_format, request_response_format_is_json


REQUEST_DEFAULTS = {
'page': 0,
'page_size': 50,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
CourseLinkCheckTask,
CourseLinkUpdateTask,
LinkState,
extract_content_URLs_from_course
extract_content_URLs_from_course,
)
from cms.djangoapps.contentstore.utils import create_course_info_usage_key, get_previous_run_course_key
from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import get_xblock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
_create_dto_recursive,
_update_node_tree_and_dictionary,
generate_broken_links_descriptor,
sort_course_sections
sort_course_sections,
)
from cms.djangoapps.contentstore.tasks import LinkState, extract_content_URLs_from_course
from cms.djangoapps.contentstore.tests.utils import CourseTestCase
Expand Down
11 changes: 9 additions & 2 deletions cms/djangoapps/contentstore/course_group_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from cms.djangoapps.contentstore.utils import reverse_usage_url
from common.djangoapps.util.db import MYSQL_MAX_INT, generate_int_id
from lms.lib.utils import get_parent_unit

# Re-exported for backward compatibility - other modules import these from here
from openedx.core.djangoapps.course_groups.constants import ( # pylint: disable=unused-import
COHORT_SCHEME,
Expand All @@ -21,8 +22,14 @@
RANDOM_SCHEME,
)
from openedx.core.djangoapps.course_groups.partition_scheme import get_cohorted_user_partition
from xmodule.partitions.partitions import MINIMUM_UNUSED_PARTITION_ID, ReadOnlyUserPartitionError, UserPartition # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.partitions.partitions_service import get_all_partitions_for_course # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.partitions.partitions import ( # lint-amnesty, pylint: disable=wrong-import-order
MINIMUM_UNUSED_PARTITION_ID,
ReadOnlyUserPartitionError,
UserPartition,
)
from xmodule.partitions.partitions_service import (
get_all_partitions_for_course, # lint-amnesty, pylint: disable=wrong-import-order
)
from xmodule.split_test_block import get_split_user_partitions # lint-amnesty, pylint: disable=wrong-import-order

MINIMUM_GROUP_ID = MINIMUM_UNUSED_PARTITION_ID
Expand Down
2 changes: 1 addition & 1 deletion cms/djangoapps/contentstore/course_info_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from django.http import HttpResponseBadRequest
from django.utils.translation import gettext as _

from cms.djangoapps.contentstore.utils import track_course_update_event, send_course_update_notification
from cms.djangoapps.contentstore.utils import send_course_update_notification, track_course_update_event
from openedx.core.lib.xblock_utils import get_course_update_items
from xmodule.html_block import CourseInfoBlock # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order
Expand Down
34 changes: 16 additions & 18 deletions cms/djangoapps/contentstore/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,41 @@
Platform-wide Python APIs should be added to an appropriate api.py file instead.
"""
from __future__ import annotations

import json
import logging
import pathlib
import re
import urllib
from lxml import etree
from mimetypes import guess_type
import re

from attrs import frozen, Factory
from django.core.files.base import ContentFile
from attrs import Factory, frozen
from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.files.base import ContentFile
from django.utils.translation import gettext as _
from edxval.api import create_external_video, create_or_update_video_transcript
from lxml import etree
from opaque_keys.edx.keys import CourseKey, UsageKey
from opaque_keys.edx.locator import DefinitionLocator, LocalId
from openedx.core.djangoapps.content_tagging.types import TagValuesByObjectIdDict
from xblock.core import XBlock
from xblock.fields import ScopeIds
from xblock.runtime import IdGenerator
from xmodule.contentstore.content import StaticContent
from xmodule.contentstore.django import contentstore
from xmodule.exceptions import NotFoundError
from xmodule.modulestore.django import modulestore
from xmodule.xml_block import XmlMixin
from openedx.core.djangoapps.video_config.transcripts_utils import Transcript, build_components_import_path
from edxval.api import (
create_external_video,
create_or_update_video_transcript,
)

import openedx.core.djangoapps.content_staging.api as content_staging_api
import openedx.core.djangoapps.content_tagging.api as content_tagging_api
from cms.djangoapps.models.settings.course_grading import CourseGradingModel
from cms.lib.xblock.upstream_sync import UpstreamLink, UpstreamLinkException
from cms.lib.xblock.upstream_sync_block import fetch_customizable_fields_from_block
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
import openedx.core.djangoapps.content_staging.api as content_staging_api
import openedx.core.djangoapps.content_tagging.api as content_tagging_api
from openedx.core.djangoapps.content_staging.data import LIBRARY_SYNC_PURPOSE
from openedx.core.djangoapps.content_tagging.types import TagValuesByObjectIdDict
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.djangoapps.video_config.transcripts_utils import Transcript, build_components_import_path
from xmodule.contentstore.content import StaticContent
from xmodule.contentstore.django import contentstore
from xmodule.exceptions import NotFoundError
from xmodule.modulestore.django import modulestore
from xmodule.xml_block import XmlMixin

from .utils import reverse_course_url, reverse_library_url, reverse_usage_url

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
from django.core.management.base import BaseCommand

from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from openedx.core.djangoapps.content.learning_sequences.api import (
get_course_keys_with_outlines,
key_supports_outlines,
)
from openedx.core.djangoapps.content.learning_sequences.api import get_course_keys_with_outlines, key_supports_outlines

from ...tasks import update_outline_from_modulestore_task

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import logging

from django.core.management.base import BaseCommand
from xmodule.tabs import CourseTabList
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore

from cms.djangoapps.contentstore.models import BackfillCourseTabsConfig
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore
from xmodule.tabs import CourseTabList

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""A Command to determine if the Mongo active_versions and Django course_index tables are out of sync"""
import logging
from django.core.management.base import BaseCommand

from django.conf import settings
from django.core.management.base import BaseCommand
from opaque_keys.edx.locator import CourseLocator

from common.djangoapps.split_modulestore_django.models import SplitModulestoreCourseIndex
from xmodule.modulestore.split_mongo.mongo_connection import MongoPersistenceBackend, DjangoFlexPersistenceBackend
from xmodule.modulestore.split_mongo.mongo_connection import DjangoFlexPersistenceBackend, MongoPersistenceBackend

logger = logging.getLogger(__name__)

Expand Down
Loading
Loading