From dae038acf9f730d500154967786afeb1cffdc952 Mon Sep 17 00:00:00 2001 From: Juan David Buitrago Date: Tue, 15 Feb 2022 11:39:59 -0500 Subject: [PATCH 1/3] refactor: modified the imports to use openedx-events library --- openedx/core/djangoapps/discussions/data.py | 46 ------------------- .../core/djangoapps/discussions/handlers.py | 6 +-- .../core/djangoapps/discussions/signals.py | 18 -------- openedx/core/djangoapps/discussions/tasks.py | 6 +-- .../discussions/tests/test_handlers.py | 2 +- .../discussions/tests/test_tasks.py | 2 +- 6 files changed, 8 insertions(+), 72 deletions(-) delete mode 100644 openedx/core/djangoapps/discussions/data.py delete mode 100644 openedx/core/djangoapps/discussions/signals.py diff --git a/openedx/core/djangoapps/discussions/data.py b/openedx/core/djangoapps/discussions/data.py deleted file mode 100644 index eb6a4841f793..000000000000 --- a/openedx/core/djangoapps/discussions/data.py +++ /dev/null @@ -1,46 +0,0 @@ -""" -Data classes for discussions -""" -from typing import List - -import attr -from opaque_keys.edx.keys import CourseKey, UsageKey - -# TODO: These data models will be moved to openedx_events. They are currently here to simplify the PR. - - -@attr.s(frozen=True) -class DiscussionTopicContext: - """ - Context for linking the external id for a discussion topic to its associated usage key. - - The ``title`` is cached to improve the performance, since otherwise we'd - need to look it up in the course structure each time. - - The ``group_id`` can be used for providers that don't internally support - cohorting but we can emulate that wuth different contexts for different groups. - """ - title = attr.ib(type=str) - usage_key = attr.ib(type=UsageKey, default=None) - group_id = attr.ib(type=int, default=None) - external_id = attr.ib(type=str, default=None) - ordering = attr.ib(type=int, default=None) - - -@attr.s(frozen=True) -class CourseDiscussionConfigurationData: - """ - Course configuration information for discussions. - - Contains all the metadata needed to configure discussions for a course. - - The ``contexts`` field contains all the contexts for which discussion - is to be enabled. - """ - course_key = attr.ib(type=CourseKey) - provider_type = attr.ib(type=str) - enable_in_context = attr.ib(type=bool, default=True) - enable_graded_units = attr.ib(type=bool, default=False) - unit_level_visibility = attr.ib(type=bool, default=False) - plugin_configuration = attr.ib(type=dict, default={}) - contexts = attr.ib(type=List[DiscussionTopicContext], factory=list) diff --git a/openedx/core/djangoapps/discussions/handlers.py b/openedx/core/djangoapps/discussions/handlers.py index c2da0b84a6ff..ed118691ee1b 100644 --- a/openedx/core/djangoapps/discussions/handlers.py +++ b/openedx/core/djangoapps/discussions/handlers.py @@ -6,13 +6,13 @@ from django.db import transaction -from openedx.core.djangoapps.discussions.data import CourseDiscussionConfigurationData +from openedx_events.learning.data import CourseDiscussionConfigurationData +from openedx_events.learning.signals import COURSE_DISCUSSIONS_CHANGED from openedx.core.djangoapps.discussions.models import ( DEFAULT_PROVIDER_TYPE, DiscussionTopicLink, DiscussionsConfiguration, ) -from openedx.core.djangoapps.discussions.signals import COURSE_DISCUSSIONS_UPDATED log = logging.getLogger(__name__) @@ -98,4 +98,4 @@ def update_course_discussion_config(configuration: CourseDiscussionConfiguration ).save() -COURSE_DISCUSSIONS_UPDATED.connect(handle_course_discussion_config_update) +COURSE_DISCUSSIONS_CHANGED.connect(handle_course_discussion_config_update) diff --git a/openedx/core/djangoapps/discussions/signals.py b/openedx/core/djangoapps/discussions/signals.py deleted file mode 100644 index 53eb9608a3a4..000000000000 --- a/openedx/core/djangoapps/discussions/signals.py +++ /dev/null @@ -1,18 +0,0 @@ -""" -Signals for discussions -""" -from openedx_events.tooling import OpenEdxPublicSignal - -from openedx.core.djangoapps.discussions.data import CourseDiscussionConfigurationData - -# TODO: This will be moved to openedx_events. It's currently here to simplify the PR. -# .. event_type: org.openedx.learning.discussions.configuration.change.v1 -# .. event_name: COURSE_DISCUSSIONS_UPDATED -# .. event_description: emitted when the configuration for a course's discussions changes in the course -# .. event_data: CourseDiscussionConfigurationData -COURSE_DISCUSSIONS_UPDATED = OpenEdxPublicSignal( - event_type="org.openedx.learning.discussions.configuration.change.v1", - data={ - "configuration": CourseDiscussionConfigurationData - } -) diff --git a/openedx/core/djangoapps/discussions/tasks.py b/openedx/core/djangoapps/discussions/tasks.py index e49e0009d1ba..6bda6de435e8 100644 --- a/openedx/core/djangoapps/discussions/tasks.py +++ b/openedx/core/djangoapps/discussions/tasks.py @@ -9,9 +9,9 @@ from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore -from .data import CourseDiscussionConfigurationData, DiscussionTopicContext +from openedx_events.learning.data import CourseDiscussionConfigurationData, DiscussionTopicContext from .models import DiscussionsConfiguration -from .signals import COURSE_DISCUSSIONS_UPDATED +from openedx_events.learning.signals import COURSE_DISCUSSIONS_CHANGED log = logging.getLogger(__name__) @@ -27,7 +27,7 @@ def update_discussions_settings_from_course_task(course_key_str: str): """ course_key = CourseKey.from_string(course_key_str) config_data = update_discussions_settings_from_course(course_key) - COURSE_DISCUSSIONS_UPDATED.send_event(configuration=config_data) + COURSE_DISCUSSIONS_CHANGED.send_event(configuration=config_data) def update_discussions_settings_from_course(course_key: CourseKey) -> CourseDiscussionConfigurationData: diff --git a/openedx/core/djangoapps/discussions/tests/test_handlers.py b/openedx/core/djangoapps/discussions/tests/test_handlers.py index 90e077ccb14d..de8e1391841b 100644 --- a/openedx/core/djangoapps/discussions/tests/test_handlers.py +++ b/openedx/core/djangoapps/discussions/tests/test_handlers.py @@ -8,7 +8,7 @@ from django.test import TestCase from opaque_keys.edx.keys import CourseKey -from openedx.core.djangoapps.discussions.data import CourseDiscussionConfigurationData, DiscussionTopicContext +from openedx_events.learning.data import CourseDiscussionConfigurationData, DiscussionTopicContext from openedx.core.djangoapps.discussions.handlers import update_course_discussion_config from openedx.core.djangoapps.discussions.models import DiscussionTopicLink, DiscussionsConfiguration diff --git a/openedx/core/djangoapps/discussions/tests/test_tasks.py b/openedx/core/djangoapps/discussions/tests/test_tasks.py index 256450bea319..b5aa7ff60c46 100644 --- a/openedx/core/djangoapps/discussions/tests/test_tasks.py +++ b/openedx/core/djangoapps/discussions/tests/test_tasks.py @@ -7,7 +7,7 @@ from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory -from openedx.core.djangoapps.discussions.data import DiscussionTopicContext +from openedx_events.learning.data import DiscussionTopicContext from openedx.core.djangoapps.discussions.tasks import update_discussions_settings_from_course From 4ed0c65db3438661a4de67901a3b22d2b0be020c Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Thu, 3 Mar 2022 11:45:51 -0400 Subject: [PATCH 2/3] chore: upgrade openedx-events to latest version --- requirements/edx/base.txt | 2 +- requirements/edx/development.txt | 2 +- requirements/edx/testing.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements/edx/base.txt b/requirements/edx/base.txt index d7e2c3639d43..15fcdc0908c6 100644 --- a/requirements/edx/base.txt +++ b/requirements/edx/base.txt @@ -701,7 +701,7 @@ oauthlib==3.0.1 # social-auth-core openedx-calc==3.0.1 # via -r requirements/edx/base.in -openedx-events==0.8.0 +openedx-events==0.8.1 # via -r requirements/edx/base.in openedx-filters==0.5.0 # via -r requirements/edx/base.in diff --git a/requirements/edx/development.txt b/requirements/edx/development.txt index 45c73ebd1ca4..c7ea00e1ef66 100644 --- a/requirements/edx/development.txt +++ b/requirements/edx/development.txt @@ -937,7 +937,7 @@ oauthlib==3.0.1 # social-auth-core openedx-calc==3.0.1 # via -r requirements/edx/testing.txt -openedx-events==0.8.0 +openedx-events==0.8.1 # via -r requirements/edx/testing.txt openedx-filters==0.5.0 # via -r requirements/edx/testing.txt diff --git a/requirements/edx/testing.txt b/requirements/edx/testing.txt index 296763adf059..dbbdc83d430b 100644 --- a/requirements/edx/testing.txt +++ b/requirements/edx/testing.txt @@ -885,7 +885,7 @@ oauthlib==3.0.1 # social-auth-core openedx-calc==3.0.1 # via -r requirements/edx/base.txt -openedx-events==0.8.0 +openedx-events==0.8.1 # via -r requirements/edx/base.txt openedx-filters==0.5.0 # via -r requirements/edx/base.txt From 5dcaa62dbf1743a67e76a99579706f0817ae79e4 Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Thu, 3 Mar 2022 11:46:16 -0400 Subject: [PATCH 3/3] fix: ran isort to avoid style errors --- openedx/core/djangoapps/discussions/tasks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openedx/core/djangoapps/discussions/tasks.py b/openedx/core/djangoapps/discussions/tasks.py index 6bda6de435e8..2af578755cfa 100644 --- a/openedx/core/djangoapps/discussions/tasks.py +++ b/openedx/core/djangoapps/discussions/tasks.py @@ -6,12 +6,12 @@ from celery import shared_task from edx_django_utils.monitoring import set_code_owner_attribute from opaque_keys.edx.keys import CourseKey - +from openedx_events.learning.data import CourseDiscussionConfigurationData, DiscussionTopicContext +from openedx_events.learning.signals import COURSE_DISCUSSIONS_CHANGED from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore -from openedx_events.learning.data import CourseDiscussionConfigurationData, DiscussionTopicContext + from .models import DiscussionsConfiguration -from openedx_events.learning.signals import COURSE_DISCUSSIONS_CHANGED log = logging.getLogger(__name__)