diff --git a/.gitignore b/.gitignore index 4a33fa1a40df..26775845b486 100644 --- a/.gitignore +++ b/.gitignore @@ -132,7 +132,7 @@ build /src/ \#*\# .env/ -django_comment_common/comment_client/python +openedx/core/djangoapps/django_comment_common/comment_client/python autodeploy.properties .ws_migrations_complete dist diff --git a/cms/djangoapps/contentstore/management/commands/import.py b/cms/djangoapps/contentstore/management/commands/import.py index 539d9b937747..7aed4105d14e 100644 --- a/cms/djangoapps/contentstore/management/commands/import.py +++ b/cms/djangoapps/contentstore/management/commands/import.py @@ -2,7 +2,7 @@ Script for importing courseware from XML format """ from django.core.management.base import BaseCommand -from django_comment_common.utils import are_permissions_roles_seeded, seed_permissions_roles +from openedx.core.djangoapps.django_comment_common.utils import are_permissions_roles_seeded, seed_permissions_roles from xmodule.contentstore.django import contentstore from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_import.py b/cms/djangoapps/contentstore/management/commands/tests/test_import.py index 9de69759245e..c5771171f8c9 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_import.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_import.py @@ -9,7 +9,7 @@ from django.core.management import call_command from path import Path as path -from django_comment_common.utils import are_permissions_roles_seeded +from openedx.core.djangoapps.django_comment_common.utils import are_permissions_roles_seeded from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index 897badaa0a7c..5b48c6fd9e2c 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -35,7 +35,7 @@ from contentstore.config import waffle from course_action_state.managers import CourseActionStateItemNotFoundError from course_action_state.models import CourseRerunState, CourseRerunUIStateManager -from django_comment_common.utils import are_permissions_roles_seeded +from openedx.core.djangoapps.django_comment_common.utils import are_permissions_roles_seeded from openedx.core.lib.tempdir import mkdtemp_clean from student import auth from student.models import CourseEnrollment diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index 9a8db4941f62..27ebbaebfb72 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -15,8 +15,8 @@ from pytz import UTC from six import text_type -from django_comment_common.models import assign_default_role -from django_comment_common.utils import seed_permissions_roles +from openedx.core.djangoapps.django_comment_common.models import assign_default_role +from openedx.core.djangoapps.django_comment_common.utils import seed_permissions_roles from openedx.core.djangoapps.site_configuration.models import SiteConfiguration from openedx.features.content_type_gating.models import ContentTypeGatingConfig from openedx.features.content_type_gating.partitions import CONTENT_TYPE_GATING_SCHEME diff --git a/cms/envs/common.py b/cms/envs/common.py index 84a087ffe7cb..3c3e6bb67e47 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -1055,8 +1055,8 @@ # Ability to detect and special-case crawler behavior 'openedx.core.djangoapps.crawlers', - # comment common - 'django_comment_common', + # Discussion + 'openedx.core.djangoapps.django_comment_common', # for course creator table 'django.contrib.admin', diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index 54a25fe2eb3f..ba0536cb7256 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -50,10 +50,8 @@ from slumber.exceptions import HttpClientError, HttpServerError from user_util import user_util -import django_comment_common.comment_client as cc from edx_django_utils.cache import RequestCache from student.signals import UNENROLL_DONE, ENROLL_STATUS_CHANGE, ENROLLMENT_TRACK_UPDATED -from lms.djangoapps.certificates.models import GeneratedCertificate from course_modes.models import CourseMode, get_cosmetic_verified_display_price from courseware.models import ( CourseDynamicUpgradeDeadlineConfiguration, @@ -62,7 +60,9 @@ ) from enrollment.api import _default_course_mode +from lms.djangoapps.certificates.models import GeneratedCertificate from openedx.core.djangoapps.content.course_overviews.models import CourseOverview +import openedx.core.djangoapps.django_comment_common.comment_client as cc from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.xmodule_django.models import NoneToEmptyManager from openedx.core.djangolib.model_mixins import DeletableByUserValue diff --git a/common/djangoapps/student/role_helpers.py b/common/djangoapps/student/role_helpers.py index 373b2e909862..5af2b75e47ce 100644 --- a/common/djangoapps/student/role_helpers.py +++ b/common/djangoapps/student/role_helpers.py @@ -1,7 +1,7 @@ """ Helpers for student roles """ -from django_comment_common.models import ( +from openedx.core.djangoapps.django_comment_common.models import ( FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, FORUM_ROLE_GROUP_MODERATOR, diff --git a/docs/common_djangoapps.rst b/docs/common_djangoapps.rst index 071833e1692d..b10d78d87e85 100644 --- a/docs/common_djangoapps.rst +++ b/docs/common_djangoapps.rst @@ -10,7 +10,6 @@ LMS and Studio. common/djangoapps/course_action_state/modules common/djangoapps/course_modes/modules common/djangoapps/database_fixups/modules - common/djangoapps/django_comment_common/modules common/djangoapps/edxmako/modules common/djangoapps/enrollment/modules common/djangoapps/entitlements/modules diff --git a/lms/djangoapps/ccx/migrations/0004_seed_forum_roles_in_ccx_courses.py b/lms/djangoapps/ccx/migrations/0004_seed_forum_roles_in_ccx_courses.py index 5e577bf40627..41d526301b1a 100644 --- a/lms/djangoapps/ccx/migrations/0004_seed_forum_roles_in_ccx_courses.py +++ b/lms/djangoapps/ccx/migrations/0004_seed_forum_roles_in_ccx_courses.py @@ -8,9 +8,9 @@ from django.db import migrations from django.http import Http404 -from django_comment_common.models import FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, \ +from openedx.core.djangoapps.django_comment_common.models import FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, \ FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_STUDENT -from django_comment_common.utils import STUDENT_ROLE_PERMISSIONS, MODERATOR_ROLE_PERMISSIONS, \ +from openedx.core.djangoapps.django_comment_common.utils import STUDENT_ROLE_PERMISSIONS, MODERATOR_ROLE_PERMISSIONS, \ ADMINISTRATOR_ROLE_PERMISSIONS log = logging.getLogger("edx.ccx") diff --git a/lms/djangoapps/ccx/tests/test_views.py b/lms/djangoapps/ccx/tests/test_views.py index 1d8e253e2c29..7e1fa7899595 100644 --- a/lms/djangoapps/ccx/tests/test_views.py +++ b/lms/djangoapps/ccx/tests/test_views.py @@ -23,9 +23,6 @@ from courseware.tests.factories import StudentModuleFactory from courseware.tests.helpers import LoginEnrollmentTestCase from courseware.testutils import FieldOverrideTestMixin -from lms.djangoapps.discussion.django_comment_client.utils import has_forum_access -from django_comment_common.models import FORUM_ROLE_ADMINISTRATOR -from django_comment_common.utils import are_permissions_roles_seeded from edx_django_utils.cache import RequestCache from edxmako.shortcuts import render_to_response from lms.djangoapps.ccx.models import CustomCourseForEdX @@ -34,9 +31,12 @@ from lms.djangoapps.ccx.tests.utils import CcxTestCase, flatten from lms.djangoapps.ccx.utils import ccx_course, is_email from lms.djangoapps.ccx.views import get_date +from lms.djangoapps.discussion.django_comment_client.utils import has_forum_access from lms.djangoapps.grades.tasks import compute_all_grades_for_course from lms.djangoapps.instructor.access import allow_access, list_with_level from openedx.core.djangoapps.content.course_overviews.models import CourseOverview +from openedx.core.djangoapps.django_comment_common.models import FORUM_ROLE_ADMINISTRATOR +from openedx.core.djangoapps.django_comment_common.utils import are_permissions_roles_seeded from student.models import CourseEnrollment, CourseEnrollmentAllowed from student.roles import CourseCcxCoachRole, CourseInstructorRole, CourseStaffRole from student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory diff --git a/lms/djangoapps/ccx/views.py b/lms/djangoapps/ccx/views.py index 6dcab2753627..4b634d58b731 100644 --- a/lms/djangoapps/ccx/views.py +++ b/lms/djangoapps/ccx/views.py @@ -25,9 +25,6 @@ from courseware.access import has_access from courseware.courses import get_course_by_id -from lms.djangoapps.courseware.field_overrides import disable_overrides -from django_comment_common.models import FORUM_ROLE_ADMINISTRATOR, assign_role -from django_comment_common.utils import seed_permissions_roles from edxmako.shortcuts import render_to_response from lms.djangoapps.ccx.models import CustomCourseForEdX from lms.djangoapps.ccx.overrides import ( @@ -48,9 +45,12 @@ get_enrollment_action_and_identifiers, parse_date, ) +from lms.djangoapps.courseware.field_overrides import disable_overrides from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from lms.djangoapps.instructor.enrollment import enroll_email, get_email_params from lms.djangoapps.instructor.views.gradebook_api import get_grade_book_page +from openedx.core.djangoapps.django_comment_common.models import FORUM_ROLE_ADMINISTRATOR, assign_role +from openedx.core.djangoapps.django_comment_common.utils import seed_permissions_roles from student.models import CourseEnrollment from student.roles import CourseCcxCoachRole from xmodule.modulestore.django import SignalHandler diff --git a/lms/djangoapps/discussion/README.rst b/lms/djangoapps/discussion/README.rst index dd85fe0516cb..12f472c79494 100644 --- a/lms/djangoapps/discussion/README.rst +++ b/lms/djangoapps/discussion/README.rst @@ -8,8 +8,8 @@ Direction: Move and Extract =========================== Discussions related functionality is scattered across a number of places and should be better consolidated. Today we have: -* ``common/djangoapps/django_comment_common`` * ``lms/djangoapps/discussion`` +* ``openedx/core/djangoapps/django_comment_common`` * ``openedx/core/lib/xblock_builtin/xblock_discussion`` Ideally, what we want in the long term is for all of this extracted into a new repository that holds the code for both the inline discussion XBlock as well as all the Django apps. Use of the notifier API should be replaced with edx-ace. diff --git a/lms/djangoapps/discussion/django_comment_client/base/tests.py b/lms/djangoapps/discussion/django_comment_client/base/tests.py index e83c800af0c5..eebfd4ac198c 100644 --- a/lms/djangoapps/discussion/django_comment_client/base/tests.py +++ b/lms/djangoapps/discussion/django_comment_client/base/tests.py @@ -27,17 +27,19 @@ ) from lms.djangoapps.discussion.django_comment_client.tests.unicode import UnicodeTestMixin from lms.djangoapps.discussion.django_comment_client.tests.utils import CohortedTestCase, ForumsEnableMixin -from django_comment_common.comment_client import Thread -from django_comment_common.models import ( +from openedx.core.djangoapps.django_comment_common.comment_client import Thread +from openedx.core.djangoapps.django_comment_common.models import ( assign_role, CourseDiscussionSettings, FORUM_ROLE_STUDENT, Role ) -from django_comment_common.utils import ThreadContext, seed_permissions_roles, set_course_discussion_settings from lms.djangoapps.teams.tests.factories import CourseTeamFactory, CourseTeamMembershipFactory from openedx.core.djangoapps.course_groups.cohorts import set_course_cohorted from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory +from openedx.core.djangoapps.django_comment_common.utils import ( + ThreadContext, seed_permissions_roles, set_course_discussion_settings +) from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES from student.roles import CourseStaffRole, UserBasedRole from student.tests.factories import CourseAccessRoleFactory, CourseEnrollmentFactory, UserFactory @@ -73,7 +75,7 @@ def _set_mock_request_data(self, mock_request, data): mock_request.return_value = self._create_response_mock(data) -@patch('django_comment_common.comment_client.utils.requests.request', autospec=True) +@patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) class CreateThreadGroupIdTestCase( MockRequestSetupMixin, CohortedTestCase, @@ -108,7 +110,7 @@ def test_group_info_in_response(self, mock_request): self._assert_json_response_contains_group_info(response) -@patch('django_comment_common.comment_client.utils.requests.request', autospec=True) +@patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) @disable_signal(views, 'thread_edited') @disable_signal(views, 'thread_voted') @disable_signal(views, 'thread_deleted') @@ -366,7 +368,7 @@ def update_thread_helper(self, mock_request): @ddt.ddt -@patch('django_comment_common.comment_client.utils.requests.request', autospec=True) +@patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) @disable_signal(views, 'thread_created') @disable_signal(views, 'thread_edited') class ViewsQueryCountTestCase( @@ -419,7 +421,7 @@ def test_update_thread(self, mock_request): @ddt.ddt -@patch('django_comment_common.comment_client.utils.requests.request', autospec=True) +@patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) class ViewsTestCase( ForumsEnableMixin, UrlResetMixin, @@ -1066,7 +1068,7 @@ def test_endorse_comment(self, mock_request): self.assertEqual(response.status_code, 200) -@patch("django_comment_common.comment_client.utils.requests.request", autospec=True) +@patch("openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request", autospec=True) @disable_signal(views, 'comment_endorsed') class ViewPermissionsTestCase(ForumsEnableMixin, UrlResetMixin, SharedModuleStoreTestCase, MockRequestSetupMixin): @@ -1195,7 +1197,7 @@ def setUpTestData(cls): cls.student = UserFactory.create() CourseEnrollmentFactory(user=cls.student, course_id=cls.course.id) - @patch('django_comment_common.comment_client.utils.requests.request', autospec=True) + @patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) def _test_unicode_data(self, text, mock_request,): """ Test to make sure unicode data in a thread doesn't break it. @@ -1241,7 +1243,7 @@ def setUpTestData(cls): 'lms.djangoapps.discussion.django_comment_client.utils.get_discussion_categories_ids', return_value=["test_commentable"], ) - @patch('django_comment_common.comment_client.utils.requests.request', autospec=True) + @patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) def _test_unicode_data(self, text, mock_request, mock_get_discussion_id_map): self._set_mock_request_data(mock_request, { "user_id": str(self.student.id), @@ -1282,7 +1284,7 @@ def setUpTestData(cls): cls.student = UserFactory.create() CourseEnrollmentFactory(user=cls.student, course_id=cls.course.id) - @patch('django_comment_common.comment_client.utils.requests.request', autospec=True) + @patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) def _test_unicode_data(self, text, mock_request): commentable_id = "non_team_dummy_id" self._set_mock_request_data(mock_request, { @@ -1329,7 +1331,7 @@ def setUpTestData(cls): cls.student = UserFactory.create() CourseEnrollmentFactory(user=cls.student, course_id=cls.course.id) - @patch('django_comment_common.comment_client.utils.requests.request', autospec=True) + @patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) def _test_unicode_data(self, text, mock_request): self._set_mock_request_data(mock_request, { "user_id": str(self.student.id), @@ -1369,7 +1371,7 @@ def setUpTestData(cls): cls.student = UserFactory.create() CourseEnrollmentFactory(user=cls.student, course_id=cls.course.id) - @patch('django_comment_common.comment_client.utils.requests.request', autospec=True) + @patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) def _test_unicode_data(self, text, mock_request): """ Create a comment with unicode in it. @@ -1397,7 +1399,7 @@ def _test_unicode_data(self, text, mock_request): @ddt.ddt -@patch("django_comment_common.comment_client.utils.requests.request", autospec=True) +@patch("openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request", autospec=True) @disable_signal(views, 'thread_voted') @disable_signal(views, 'thread_edited') @disable_signal(views, 'comment_created') @@ -1764,7 +1766,7 @@ def setUpTestData(cls): CourseAccessRoleFactory(course_id=cls.course.id, user=cls.student, role='Wizard') @patch('eventtracking.tracker.emit') - @patch('django_comment_common.comment_client.utils.requests.request', autospec=True) + @patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) def test_thread_created_event(self, __, mock_emit): request = RequestFactory().post( "dummy_url", { @@ -1793,7 +1795,7 @@ def test_thread_created_event(self, __, mock_emit): self.assertEquals(event['anonymous_to_peers'], False) @patch('eventtracking.tracker.emit') - @patch('django_comment_common.comment_client.utils.requests.request', autospec=True) + @patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) def test_response_event(self, mock_request, mock_emit): """ Check to make sure an event is fired when a user responds to a thread. @@ -1819,7 +1821,7 @@ def test_response_event(self, mock_request, mock_emit): self.assertEqual(event['options']['followed'], True) @patch('eventtracking.tracker.emit') - @patch('django_comment_common.comment_client.utils.requests.request', autospec=True) + @patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) def test_comment_event(self, mock_request, mock_emit): """ Ensure an event is fired when someone comments on a response. @@ -1846,7 +1848,7 @@ def test_comment_event(self, mock_request, mock_emit): self.assertEqual(event['options']['followed'], False) @patch('eventtracking.tracker.emit') - @patch('django_comment_common.comment_client.utils.requests.request', autospec=True) + @patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) @ddt.data(( 'create_thread', 'edx.forum.thread.created', { @@ -1898,7 +1900,7 @@ def test_team_events(self, view_name, event_name, view_data, view_kwargs, mock_r ) @ddt.unpack @patch('eventtracking.tracker.emit') - @patch('django_comment_common.comment_client.utils.requests.request', autospec=True) + @patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) def test_thread_voted_event(self, view_name, obj_id_name, obj_type, mock_request, mock_emit): undo = view_name.startswith('undo') @@ -1960,7 +1962,7 @@ def make_request(self, method='get', course_id=None, **kwargs): request.view_name = "users" return views.users(request, course_id=text_type(course_id)) - @patch('django_comment_common.comment_client.utils.requests.request', autospec=True) + @patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) def test_finds_exact_match(self, mock_request): self.set_post_counts(mock_request) response = self.make_request(username="other") @@ -1970,7 +1972,7 @@ def test_finds_exact_match(self, mock_request): [{"id": self.other_user.id, "username": self.other_user.username}] ) - @patch('django_comment_common.comment_client.utils.requests.request', autospec=True) + @patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) def test_finds_no_match(self, mock_request): self.set_post_counts(mock_request) response = self.make_request(username="othor") @@ -2007,7 +2009,7 @@ def test_requires_requestor_enrolled_in_course(self): self.assertIn("errors", content) self.assertNotIn("users", content) - @patch('django_comment_common.comment_client.utils.requests.request', autospec=True) + @patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) def test_requires_matched_user_has_forum_content(self, mock_request): self.set_post_counts(mock_request, 0, 0) response = self.make_request(username="other") diff --git a/lms/djangoapps/discussion/django_comment_client/base/views.py b/lms/djangoapps/discussion/django_comment_client/base/views.py index 5961d9881526..85cd67116fb5 100644 --- a/lms/djangoapps/discussion/django_comment_client/base/views.py +++ b/lms/djangoapps/discussion/django_comment_client/base/views.py @@ -21,21 +21,6 @@ from opaque_keys.edx.keys import CourseKey from six import text_type -import django_comment_common.comment_client as cc -from django_comment_common.signals import ( - comment_created, - comment_deleted, - comment_edited, - comment_endorsed, - comment_voted, - thread_created, - thread_deleted, - thread_edited, - thread_voted, - thread_followed, - thread_unfollowed, -) -from django_comment_common.utils import ThreadContext from courseware.access import has_access from courseware.courses import get_course_by_id, get_course_overview_with_access, get_course_with_access from lms.djangoapps.courseware.exceptions import CourseAccessRedirect @@ -56,6 +41,21 @@ is_comment_too_deep, prepare_content ) +import openedx.core.djangoapps.django_comment_common.comment_client as cc +from openedx.core.djangoapps.django_comment_common.signals import ( + comment_created, + comment_deleted, + comment_edited, + comment_endorsed, + comment_voted, + thread_created, + thread_deleted, + thread_edited, + thread_voted, + thread_followed, + thread_unfollowed, +) +from openedx.core.djangoapps.django_comment_common.utils import ThreadContext import eventtracking from util.file import store_uploaded_file @@ -99,7 +99,7 @@ def track_created_event(request, event_name, course, obj, data): """ Send analytics event for a newly created thread, response or comment. """ - data['truncated'] = bool(len(obj.body) > TRACKING_MAX_FORUM_BODY) + data['truncated'] = len(obj.body) > TRACKING_MAX_FORUM_BODY data['body'] = obj.body[:TRACKING_MAX_FORUM_BODY] track_forum_event(request, event_name, course, obj, data) diff --git a/lms/djangoapps/discussion/django_comment_client/middleware.py b/lms/djangoapps/discussion/django_comment_client/middleware.py index d109afd9d788..5ab3cd29a8f2 100644 --- a/lms/djangoapps/discussion/django_comment_client/middleware.py +++ b/lms/djangoapps/discussion/django_comment_client/middleware.py @@ -5,7 +5,7 @@ from six import text_type from lms.djangoapps.discussion.django_comment_client.utils import JsonError -from django_comment_common.comment_client import CommentClientRequestError +from openedx.core.djangoapps.django_comment_common.comment_client import CommentClientRequestError log = logging.getLogger(__name__) diff --git a/lms/djangoapps/discussion/django_comment_client/models.py b/lms/djangoapps/discussion/django_comment_client/models.py index 76d27be3bf18..94c3831800aa 100644 --- a/lms/djangoapps/discussion/django_comment_client/models.py +++ b/lms/djangoapps/discussion/django_comment_client/models.py @@ -1 +1 @@ -# This file is intentionally blank. It has been moved to common/djangoapps/django_comment_common +# This file is intentionally blank. It has been moved to openedx/core/djangoapps/django_comment_common diff --git a/lms/djangoapps/discussion/django_comment_client/permissions.py b/lms/djangoapps/discussion/django_comment_client/permissions.py index cd777dd03036..7ec72ad1d614 100644 --- a/lms/djangoapps/discussion/django_comment_client/permissions.py +++ b/lms/djangoapps/discussion/django_comment_client/permissions.py @@ -9,10 +9,12 @@ from edx_django_utils.cache import DEFAULT_REQUEST_CACHE from opaque_keys.edx.keys import CourseKey -from django_comment_common.comment_client import Thread -from django_comment_common.models import CourseDiscussionSettings, all_permissions_for_user_in_course -from django_comment_common.utils import get_course_discussion_settings from lms.djangoapps.teams.models import CourseTeam +from openedx.core.djangoapps.django_comment_common.comment_client import Thread +from openedx.core.djangoapps.django_comment_common.models import ( + CourseDiscussionSettings, all_permissions_for_user_in_course, +) +from openedx.core.djangoapps.django_comment_common.utils import get_course_discussion_settings from openedx.core.lib.cache_utils import request_cached diff --git a/lms/djangoapps/discussion/django_comment_client/tests/factories.py b/lms/djangoapps/discussion/django_comment_client/tests/factories.py index f95c92abbc79..471e632904cb 100644 --- a/lms/djangoapps/discussion/django_comment_client/tests/factories.py +++ b/lms/djangoapps/discussion/django_comment_client/tests/factories.py @@ -1,7 +1,7 @@ # pylint: disable=missing-docstring from factory.django import DjangoModelFactory -from django_comment_common.models import Permission, Role +from openedx.core.djangoapps.django_comment_common.models import Permission, Role class RoleFactory(DjangoModelFactory): diff --git a/lms/djangoapps/discussion/django_comment_client/tests/group_id.py b/lms/djangoapps/discussion/django_comment_client/tests/group_id.py index a3953d8213ba..ecd918e54206 100644 --- a/lms/djangoapps/discussion/django_comment_client/tests/group_id.py +++ b/lms/djangoapps/discussion/django_comment_client/tests/group_id.py @@ -4,9 +4,9 @@ from course_modes.models import CourseMode from course_modes.tests.factories import CourseModeFactory -from django_comment_common.models import CourseDiscussionSettings -from django_comment_common.utils import set_course_discussion_settings from lms.djangoapps.teams.tests.factories import CourseTeamFactory +from openedx.core.djangoapps.django_comment_common.models import CourseDiscussionSettings +from openedx.core.djangoapps.django_comment_common.utils import set_course_discussion_settings class GroupIdAssertionMixin(object): diff --git a/lms/djangoapps/discussion/django_comment_client/tests/test_middleware.py b/lms/djangoapps/discussion/django_comment_client/tests/test_middleware.py index 4574a89c3738..e8877462c9e3 100644 --- a/lms/djangoapps/discussion/django_comment_client/tests/test_middleware.py +++ b/lms/djangoapps/discussion/django_comment_client/tests/test_middleware.py @@ -6,7 +6,7 @@ from six import text_type import lms.djangoapps.discussion.django_comment_client.middleware as middleware -import django_comment_common.comment_client +import openedx.core.djangoapps.django_comment_common.comment_client as comment_client class AjaxExceptionTestCase(TestCase): @@ -16,9 +16,9 @@ def setUp(self): self.a = middleware.AjaxExceptionMiddleware() self.request1 = django.http.HttpRequest() self.request0 = django.http.HttpRequest() - self.exception1 = django_comment_common.comment_client.CommentClientRequestError('{}', 401) - self.exception2 = django_comment_common.comment_client.CommentClientRequestError('Foo!', 404) - self.exception0 = django_comment_common.comment_client.CommentClient500Error("Holy crap the server broke!") + self.exception1 = comment_client.CommentClientRequestError('{}', 401) + self.exception2 = comment_client.CommentClientRequestError('Foo!', 404) + self.exception0 = comment_client.CommentClient500Error("Holy crap the server broke!") self.request1.META['HTTP_X_REQUESTED_WITH'] = "XMLHttpRequest" self.request0.META['HTTP_X_REQUESTED_WITH'] = "SHADOWFAX" diff --git a/lms/djangoapps/discussion/django_comment_client/tests/test_models.py b/lms/djangoapps/discussion/django_comment_client/tests/test_models.py index e7dbe05ffd1c..8e7c287d965e 100644 --- a/lms/djangoapps/discussion/django_comment_client/tests/test_models.py +++ b/lms/djangoapps/discussion/django_comment_client/tests/test_models.py @@ -4,7 +4,7 @@ from django.test.testcases import TestCase from opaque_keys.edx.keys import CourseKey -import django_comment_common.models as models +import openedx.core.djangoapps.django_comment_common.models as models from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_MODULESTORE, ModuleStoreTestCase from xmodule.modulestore.tests.factories import ToyCourseFactory diff --git a/lms/djangoapps/discussion/django_comment_client/tests/test_utils.py b/lms/djangoapps/discussion/django_comment_client/tests/test_utils.py index 8a52ec3c3836..e6306f90e1a9 100644 --- a/lms/djangoapps/discussion/django_comment_client/tests/test_utils.py +++ b/lms/djangoapps/discussion/django_comment_client/tests/test_utils.py @@ -17,18 +17,6 @@ from course_modes.tests.factories import CourseModeFactory from courseware.tabs import get_course_tab_list from courseware.tests.factories import InstructorFactory -from django_comment_common.comment_client.utils import CommentClientMaintenanceError, perform_request -from django_comment_common.models import ( - CourseDiscussionSettings, - ForumsConfig, - assign_role, - DiscussionsIdMapping, -) -from django_comment_common.utils import ( - get_course_discussion_settings, - seed_permissions_roles, - set_course_discussion_settings -) from lms.djangoapps.discussion.django_comment_client.constants import TYPE_ENTRY, TYPE_SUBCATEGORY from lms.djangoapps.discussion.django_comment_client.tests.factories import RoleFactory from lms.djangoapps.discussion.django_comment_client.tests.unicode import UnicodeTestMixin @@ -38,6 +26,18 @@ from openedx.core.djangoapps.course_groups import cohorts from openedx.core.djangoapps.course_groups.cohorts import set_course_cohorted from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory, config_course_cohorts +from openedx.core.djangoapps.django_comment_common.comment_client.utils import CommentClientMaintenanceError, perform_request +from openedx.core.djangoapps.django_comment_common.models import ( + CourseDiscussionSettings, + ForumsConfig, + assign_role, + DiscussionsIdMapping, +) +from openedx.core.djangoapps.django_comment_common.utils import ( + get_course_discussion_settings, + seed_permissions_roles, + set_course_discussion_settings +) from openedx.core.djangoapps.util.testing import ContentGroupTestCase from student.roles import CourseStaffRole from student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory diff --git a/lms/djangoapps/discussion/django_comment_client/tests/utils.py b/lms/djangoapps/discussion/django_comment_client/tests/utils.py index db652fe44c1b..baaec6381140 100644 --- a/lms/djangoapps/discussion/django_comment_client/tests/utils.py +++ b/lms/djangoapps/discussion/django_comment_client/tests/utils.py @@ -3,8 +3,10 @@ """ from mock import patch -from django_comment_common.models import ForumsConfig, Role -from django_comment_common.utils import CourseDiscussionSettings, seed_permissions_roles, set_course_discussion_settings +from openedx.core.djangoapps.django_comment_common.models import ForumsConfig, Role +from openedx.core.djangoapps.django_comment_common.utils import ( + CourseDiscussionSettings, seed_permissions_roles, set_course_discussion_settings, +) from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory from student.tests.factories import CourseEnrollmentFactory, UserFactory from util.testing import UrlResetMixin diff --git a/lms/djangoapps/discussion/django_comment_client/utils.py b/lms/djangoapps/discussion/django_comment_client/utils.py index 3a58366b52b5..265892b6bae4 100644 --- a/lms/djangoapps/discussion/django_comment_client/utils.py +++ b/lms/djangoapps/discussion/django_comment_client/utils.py @@ -21,14 +21,14 @@ check_permissions_by_view, get_team, has_permission, ) from lms.djangoapps.discussion.django_comment_client.settings import MAX_COMMENT_DEPTH -from django_comment_common.models import ( +from openedx.core.djangoapps.django_comment_common.models import ( FORUM_ROLE_STUDENT, FORUM_ROLE_COMMUNITY_TA, CourseDiscussionSettings, DiscussionsIdMapping, Role ) -from django_comment_common.utils import get_course_discussion_settings +from openedx.core.djangoapps.django_comment_common.utils import get_course_discussion_settings from openedx.core.djangoapps.course_groups.cohorts import get_cohort_id, get_cohort_names, is_course_cohorted from openedx.core.lib.cache_utils import request_cached from student.models import get_user_by_username_or_email diff --git a/lms/djangoapps/discussion/management/commands/assign_role.py b/lms/djangoapps/discussion/management/commands/assign_role.py index 40cadd511383..2c42d8755a8b 100644 --- a/lms/djangoapps/discussion/management/commands/assign_role.py +++ b/lms/djangoapps/discussion/management/commands/assign_role.py @@ -3,7 +3,7 @@ from django.contrib.auth.models import User from django.core.management.base import BaseCommand -from django_comment_common.models import Role +from openedx.core.djangoapps.django_comment_common.models import Role class Command(BaseCommand): diff --git a/lms/djangoapps/discussion/management/commands/assign_roles_for_course.py b/lms/djangoapps/discussion/management/commands/assign_roles_for_course.py index 855af4a75f6d..4f54de64ca80 100644 --- a/lms/djangoapps/discussion/management/commands/assign_roles_for_course.py +++ b/lms/djangoapps/discussion/management/commands/assign_roles_for_course.py @@ -8,7 +8,7 @@ from __future__ import print_function from django.core.management.base import BaseCommand -from django_comment_common.models import assign_default_role_on_enrollment +from openedx.core.djangoapps.django_comment_common.models import assign_default_role_on_enrollment from student.models import CourseEnrollment diff --git a/lms/djangoapps/discussion/management/commands/create_roles_for_existing.py b/lms/djangoapps/discussion/management/commands/create_roles_for_existing.py index 78f91012ec69..04d32da224d8 100644 --- a/lms/djangoapps/discussion/management/commands/create_roles_for_existing.py +++ b/lms/djangoapps/discussion/management/commands/create_roles_for_existing.py @@ -7,7 +7,7 @@ from __future__ import print_function from django.core.management.base import BaseCommand -from django_comment_common.models import assign_default_role_on_enrollment +from openedx.core.djangoapps.django_comment_common.models import assign_default_role_on_enrollment from student.models import CourseEnrollment diff --git a/lms/djangoapps/discussion/management/commands/reload_forum_users.py b/lms/djangoapps/discussion/management/commands/reload_forum_users.py index bb7c79a55028..402891ddaab1 100644 --- a/lms/djangoapps/discussion/management/commands/reload_forum_users.py +++ b/lms/djangoapps/discussion/management/commands/reload_forum_users.py @@ -4,9 +4,9 @@ """ from __future__ import print_function -import django_comment_common.comment_client as cc from django.contrib.auth.models import User from django.core.management.base import BaseCommand +import openedx.core.djangoapps.django_comment_common.comment_client as cc class Command(BaseCommand): diff --git a/lms/djangoapps/discussion/management/commands/seed_permissions_roles.py b/lms/djangoapps/discussion/management/commands/seed_permissions_roles.py index 5586df0d15dc..6d5529d5ec97 100644 --- a/lms/djangoapps/discussion/management/commands/seed_permissions_roles.py +++ b/lms/djangoapps/discussion/management/commands/seed_permissions_roles.py @@ -3,8 +3,8 @@ Management command to seed default permissions and roles. """ from django.core.management.base import BaseCommand -from django_comment_common.utils import seed_permissions_roles from opaque_keys.edx.keys import CourseKey +from openedx.core.djangoapps.django_comment_common.utils import seed_permissions_roles class Command(BaseCommand): diff --git a/lms/djangoapps/discussion/management/commands/sync_user_info.py b/lms/djangoapps/discussion/management/commands/sync_user_info.py index 03d8998bd4cb..43a553f355e1 100644 --- a/lms/djangoapps/discussion/management/commands/sync_user_info.py +++ b/lms/djangoapps/discussion/management/commands/sync_user_info.py @@ -3,9 +3,9 @@ discussion service (later info will be synced automatically) """ -import django_comment_common.comment_client as cc from django.contrib.auth.models import User from django.core.management.base import BaseCommand +import openedx.core.djangoapps.django_comment_common.comment_client as cc class Command(BaseCommand): diff --git a/lms/djangoapps/discussion/notifier_api/tests.py b/lms/djangoapps/discussion/notifier_api/tests.py index a088b3077002..ccaee5044e87 100644 --- a/lms/djangoapps/discussion/notifier_api/tests.py +++ b/lms/djangoapps/discussion/notifier_api/tests.py @@ -8,10 +8,10 @@ from django.test.utils import override_settings from opaque_keys.edx.locator import CourseLocator -from django_comment_common.models import Permission, Role from lms.djangoapps.discussion.notification_prefs import NOTIFICATION_PREF_KEY from lms.djangoapps.discussion.notifier_api.views import NotifierUsersViewSet from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory +from openedx.core.djangoapps.django_comment_common.models import Permission, Role from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY from openedx.core.djangoapps.user_api.models import UserPreference from openedx.core.djangoapps.user_api.tests.factories import UserPreferenceFactory diff --git a/lms/djangoapps/discussion/rest_api/api.py b/lms/djangoapps/discussion/rest_api/api.py index 8b9b9ecae811..9337fe057bc0 100644 --- a/lms/djangoapps/discussion/rest_api/api.py +++ b/lms/djangoapps/discussion/rest_api/api.py @@ -14,21 +14,6 @@ from opaque_keys.edx.locator import CourseKey from rest_framework.exceptions import PermissionDenied -from django_comment_common.comment_client.comment import Comment -from django_comment_common.comment_client.thread import Thread -from django_comment_common.comment_client.utils import CommentClientRequestError -from django_comment_common.signals import ( - comment_created, - comment_deleted, - comment_edited, - comment_voted, - thread_created, - thread_deleted, - thread_edited, - thread_voted -) -from django_comment_common.utils import get_course_discussion_settings - from lms.djangoapps.courseware.courses import get_course_with_access from lms.djangoapps.discussion.rest_api.exceptions import ( CommentNotFoundError, DiscussionDisabledError, ThreadNotFoundError, @@ -51,6 +36,20 @@ ) from lms.djangoapps.courseware.exceptions import CourseAccessRedirect from lms.djangoapps.discussion.rest_api.pagination import DiscussionAPIPagination +from openedx.core.djangoapps.django_comment_common.comment_client.comment import Comment +from openedx.core.djangoapps.django_comment_common.comment_client.thread import Thread +from openedx.core.djangoapps.django_comment_common.comment_client.utils import CommentClientRequestError +from openedx.core.djangoapps.django_comment_common.signals import ( + comment_created, + comment_deleted, + comment_edited, + comment_voted, + thread_created, + thread_deleted, + thread_edited, + thread_voted +) +from openedx.core.djangoapps.django_comment_common.utils import get_course_discussion_settings from openedx.core.djangoapps.user_api.accounts.views import AccountViewSet from openedx.core.lib.exceptions import CourseNotFoundError, DiscussionNotFoundError, PageNotFoundError diff --git a/lms/djangoapps/discussion/rest_api/forms.py b/lms/djangoapps/discussion/rest_api/forms.py index 773b7a58de94..237e77e25b30 100644 --- a/lms/djangoapps/discussion/rest_api/forms.py +++ b/lms/djangoapps/discussion/rest_api/forms.py @@ -11,7 +11,9 @@ from six import text_type from courseware.courses import get_course_with_access -from django_comment_common.models import Role, FORUM_ROLE_MODERATOR, FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_GROUP_MODERATOR +from openedx.core.djangoapps.django_comment_common.models import ( + Role, FORUM_ROLE_MODERATOR, FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_GROUP_MODERATOR, +) from openedx.core.djangoapps.util.forms import ExtendedNullBooleanField, MultiValueField diff --git a/lms/djangoapps/discussion/rest_api/permissions.py b/lms/djangoapps/discussion/rest_api/permissions.py index 3327c9fd1b36..dc1e4b997193 100644 --- a/lms/djangoapps/discussion/rest_api/permissions.py +++ b/lms/djangoapps/discussion/rest_api/permissions.py @@ -1,8 +1,8 @@ """ Discussion API permission logic """ -from django_comment_common.comment_client.comment import Comment -from django_comment_common.comment_client.thread import Thread +from openedx.core.djangoapps.django_comment_common.comment_client.comment import Comment +from openedx.core.djangoapps.django_comment_common.comment_client.thread import Thread def _is_author(cc_content, context): diff --git a/lms/djangoapps/discussion/rest_api/serializers.py b/lms/djangoapps/discussion/rest_api/serializers.py index 9e4d113926f2..fc465ef6c56a 100644 --- a/lms/djangoapps/discussion/rest_api/serializers.py +++ b/lms/djangoapps/discussion/rest_api/serializers.py @@ -9,17 +9,17 @@ from django.urls import reverse from rest_framework import serializers -from django_comment_common.models import ( +from openedx.core.djangoapps.django_comment_common.models import ( FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_MODERATOR, Role, ) -from django_comment_common.comment_client.comment import Comment -from django_comment_common.comment_client.thread import Thread -from django_comment_common.comment_client.user import User as CommentClientUser -from django_comment_common.comment_client.utils import CommentClientRequestError -from django_comment_common.utils import get_course_discussion_settings +from openedx.core.djangoapps.django_comment_common.comment_client.comment import Comment +from openedx.core.djangoapps.django_comment_common.comment_client.thread import Thread +from openedx.core.djangoapps.django_comment_common.comment_client.user import User as CommentClientUser +from openedx.core.djangoapps.django_comment_common.comment_client.utils import CommentClientRequestError +from openedx.core.djangoapps.django_comment_common.utils import get_course_discussion_settings from lms.djangoapps.discussion.django_comment_client.utils import ( is_comment_too_deep, get_group_id_for_user, get_group_name, ) diff --git a/lms/djangoapps/discussion/rest_api/tests/test_api.py b/lms/djangoapps/discussion/rest_api/tests/test_api.py index fe8fdd83ec28..76661edf2a93 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_api.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_api.py @@ -41,7 +41,7 @@ make_paginated_api_response ) from lms.djangoapps.discussion.django_comment_client.tests.utils import ForumsEnableMixin -from django_comment_common.models import ( +from openedx.core.djangoapps.django_comment_common.models import ( FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_MODERATOR, diff --git a/lms/djangoapps/discussion/rest_api/tests/test_permissions.py b/lms/djangoapps/discussion/rest_api/tests/test_permissions.py index 6e7ce7ebdb0a..71b9744228e6 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_permissions.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_permissions.py @@ -11,9 +11,9 @@ get_initializable_comment_fields, get_initializable_thread_fields ) -from django_comment_common.comment_client.comment import Comment -from django_comment_common.comment_client.thread import Thread -from django_comment_common.comment_client.user import User +from openedx.core.djangoapps.django_comment_common.comment_client.comment import Comment +from openedx.core.djangoapps.django_comment_common.comment_client.thread import Thread +from openedx.core.djangoapps.django_comment_common.comment_client.user import User from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory diff --git a/lms/djangoapps/discussion/rest_api/tests/test_serializers.py b/lms/djangoapps/discussion/rest_api/tests/test_serializers.py index c6dca7f414ee..ecbe02b58f74 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_serializers.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_serializers.py @@ -14,9 +14,9 @@ CommentsServiceMockMixin, make_minimal_cs_comment, make_minimal_cs_thread, ) from lms.djangoapps.discussion.django_comment_client.tests.utils import ForumsEnableMixin -from django_comment_common.comment_client.comment import Comment -from django_comment_common.comment_client.thread import Thread -from django_comment_common.models import ( +from openedx.core.djangoapps.django_comment_common.comment_client.comment import Comment +from openedx.core.djangoapps.django_comment_common.comment_client.thread import Thread +from openedx.core.djangoapps.django_comment_common.models import ( FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_MODERATOR, diff --git a/lms/djangoapps/discussion/rest_api/tests/test_views.py b/lms/djangoapps/discussion/rest_api/tests/test_views.py index a1e7cd3f740e..8fd9dab22a80 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_views.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_views.py @@ -32,8 +32,8 @@ from lms.djangoapps.discussion.django_comment_client.tests.utils import ( ForumsEnableMixin, config_course_discussions, topic_name_to_id, ) -from django_comment_common.models import CourseDiscussionSettings, Role -from django_comment_common.utils import seed_permissions_roles +from openedx.core.djangoapps.django_comment_common.models import CourseDiscussionSettings, Role +from openedx.core.djangoapps.django_comment_common.utils import seed_permissions_roles from openedx.core.djangoapps.course_groups.tests.helpers import config_course_cohorts from openedx.core.djangoapps.oauth_dispatch.jwt import create_jwt_for_user from openedx.core.djangoapps.user_api.accounts.image_helpers import get_profile_image_storage diff --git a/lms/djangoapps/discussion/rest_api/views.py b/lms/djangoapps/discussion/rest_api/views.py index a6889465a4aa..d1725a925b06 100644 --- a/lms/djangoapps/discussion/rest_api/views.py +++ b/lms/djangoapps/discussion/rest_api/views.py @@ -17,10 +17,6 @@ from rest_framework.viewsets import ViewSet from six import text_type -from django_comment_common import comment_client -from django_comment_common.models import Role -from django_comment_common.utils import get_course_discussion_settings, set_course_discussion_settings - from instructor.access import update_forum_role from discussion.views import get_divided_discussions from lms.djangoapps.discussion.django_comment_client.utils import available_division_schemes @@ -52,6 +48,11 @@ from openedx.core.lib.api.authentication import OAuth2AuthenticationAllowInactiveUser from openedx.core.lib.api.parsers import MergePatchParser from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes +from openedx.core.djangoapps.django_comment_common import comment_client +from openedx.core.djangoapps.django_comment_common.models import Role +from openedx.core.djangoapps.django_comment_common.utils import ( + get_course_discussion_settings, set_course_discussion_settings, +) from openedx.core.djangoapps.user_api.accounts.permissions import CanReplaceUsername, CanRetireUser from openedx.core.djangoapps.user_api.models import UserRetirementStatus from util.json_request import JsonResponse diff --git a/lms/djangoapps/discussion/signals/handlers.py b/lms/djangoapps/discussion/signals/handlers.py index 41f0b47c6b16..81195c700e16 100644 --- a/lms/djangoapps/discussion/signals/handlers.py +++ b/lms/djangoapps/discussion/signals/handlers.py @@ -6,8 +6,8 @@ from django.conf import settings from django.dispatch import receiver -from django_comment_common import signals from lms.djangoapps.discussion import tasks +from openedx.core.djangoapps.django_comment_common import signals from opaque_keys.edx.locator import LibraryLocator from openedx.core.djangoapps.site_configuration.models import SiteConfiguration from openedx.core.djangoapps.theming.helpers import get_current_site diff --git a/lms/djangoapps/discussion/tasks.py b/lms/djangoapps/discussion/tasks.py index 28598b0d7061..cdf056bdc40b 100644 --- a/lms/djangoapps/discussion/tasks.py +++ b/lms/djangoapps/discussion/tasks.py @@ -11,8 +11,6 @@ from django.contrib.sites.models import Site from celery_utils.logged_task import LoggedTask -import django_comment_common.comment_client as cc -from django_comment_common.models import DiscussionsIdMapping from edx_ace import ace from edx_ace.utils import date from edx_ace.recipient import Recipient @@ -22,9 +20,11 @@ ) from opaque_keys.edx.keys import CourseKey -from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.ace_common.template_context import get_base_template_context from openedx.core.djangoapps.ace_common.message import BaseMessageType +from openedx.core.djangoapps.content.course_overviews.models import CourseOverview +import openedx.core.djangoapps.django_comment_common.comment_client as cc +from openedx.core.djangoapps.django_comment_common.models import DiscussionsIdMapping from openedx.core.lib.celery.task_utils import emulate_http_request from track import segment diff --git a/lms/djangoapps/discussion/tests/test_signals.py b/lms/djangoapps/discussion/tests/test_signals.py index 02b757604511..63786cd82fde 100644 --- a/lms/djangoapps/discussion/tests/test_signals.py +++ b/lms/djangoapps/discussion/tests/test_signals.py @@ -1,9 +1,9 @@ from django.test import TestCase import mock -from django_comment_common import signals, models from edx_django_utils.cache import RequestCache from lms.djangoapps.discussion.signals.handlers import ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY +from openedx.core.djangoapps.django_comment_common import signals, models from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory, SiteConfigurationFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory diff --git a/lms/djangoapps/discussion/tests/test_tasks.py b/lms/djangoapps/discussion/tests/test_tasks.py index 06c8de6d9539..c22855f25641 100644 --- a/lms/djangoapps/discussion/tests/test_tasks.py +++ b/lms/djangoapps/discussion/tests/test_tasks.py @@ -9,18 +9,17 @@ from django.contrib.sites.models import Site import mock -import django_comment_common.comment_client as cc - -from django_comment_common.models import ForumsConfig -from django_comment_common.signals import comment_created from edx_ace.recipient import Recipient from edx_ace.renderers import EmailRenderer from edx_ace.channel import ChannelType, get_channel_for_message from edx_ace.utils import date from lms.djangoapps.discussion.signals.handlers import ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY from lms.djangoapps.discussion.tasks import _should_send_message, _track_notification_sent -from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangoapps.ace_common.template_context import get_base_template_context +from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory +import openedx.core.djangoapps.django_comment_common.comment_client as cc +from openedx.core.djangoapps.django_comment_common.models import ForumsConfig +from openedx.core.djangoapps.django_comment_common.signals import comment_created from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory from openedx.core.lib.celery.task_utils import emulate_http_request from student.tests.factories import CourseEnrollmentFactory, UserFactory diff --git a/lms/djangoapps/discussion/tests/test_views.py b/lms/djangoapps/discussion/tests/test_views.py index 1538a4640166..2452a871d3d9 100644 --- a/lms/djangoapps/discussion/tests/test_views.py +++ b/lms/djangoapps/discussion/tests/test_views.py @@ -29,13 +29,6 @@ topic_name_to_id ) from lms.djangoapps.discussion.django_comment_client.utils import strip_none -from django_comment_common.comment_client.utils import CommentClientPaginatedResult -from django_comment_common.models import ( - CourseDiscussionSettings, - ForumsConfig, - FORUM_ROLE_STUDENT, -) -from django_comment_common.utils import ThreadContext, seed_permissions_roles from lms.djangoapps.courseware.exceptions import CourseAccessRedirect from lms.djangoapps.discussion import views from lms.djangoapps.discussion.views import _get_discussion_default_topic_id @@ -44,6 +37,13 @@ from openedx.core.djangoapps.course_groups.models import CourseUserGroup from openedx.core.djangoapps.course_groups.tests.helpers import config_course_cohorts from openedx.core.djangoapps.course_groups.tests.test_views import CohortViewsTestCase +from openedx.core.djangoapps.django_comment_common.comment_client.utils import CommentClientPaginatedResult +from openedx.core.djangoapps.django_comment_common.models import ( + CourseDiscussionSettings, + ForumsConfig, + FORUM_ROLE_STUDENT, +) +from openedx.core.djangoapps.django_comment_common.utils import ThreadContext, seed_permissions_roles from openedx.core.djangoapps.util.testing import ContentGroupTestCase from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES from openedx.features.content_type_gating.models import ContentTypeGatingConfig @@ -559,7 +559,7 @@ def test_html(self, mock_request): self.assertRegexpMatches(html, r'"group_name": "student_cohort"') -@patch('django_comment_common.comment_client.utils.requests.request', autospec=True) +@patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) class SingleThreadAccessTestCase(CohortedTestCase): def call_view(self, mock_request, commentable_id, user, group_id, thread_group_id=None, pass_group_id=True): @@ -647,7 +647,7 @@ def test_moderator_different_cohort(self, mock_request): self.assertEqual(resp.status_code, 200) -@patch('django_comment_common.comment_client.utils.requests.request', autospec=True) +@patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) class SingleThreadGroupIdTestCase(CohortedTestCase, GroupIdAssertionMixin): cs_endpoint = "/threads/dummy_thread_id" @@ -888,7 +888,7 @@ def test_standalone_context_respected(self, mock_request): self.assert_can_access(self.beta_user, self.alpha_module.discussion_id, thread_id, True) -@patch('django_comment_common.comment_client.utils.requests.request', autospec=True) +@patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) class InlineDiscussionContextTestCase(ForumsEnableMixin, ModuleStoreTestCase): def setUp(self): @@ -925,7 +925,7 @@ def test_context_can_be_standalone(self, mock_request): self.assertEqual(json_response['discussion_data'][0]['context'], ThreadContext.STANDALONE) -@patch('django_comment_common.comment_client.utils.requests.request', autospec=True) +@patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) class InlineDiscussionGroupIdTestCase( CohortedTestCase, CohortedTopicGroupIdTestMixin, @@ -976,7 +976,7 @@ def test_group_info_in_ajax_response(self, mock_request): ) -@patch('django_comment_common.comment_client.utils.requests.request', autospec=True) +@patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) class ForumFormDiscussionGroupIdTestCase(CohortedTestCase, CohortedTopicGroupIdTestMixin): cs_endpoint = "/threads" @@ -1022,7 +1022,7 @@ def test_group_info_in_ajax_response(self, mock_request): ) -@patch('django_comment_common.comment_client.utils.requests.request', autospec=True) +@patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) class UserProfileDiscussionGroupIdTestCase(CohortedTestCase, CohortedTopicGroupIdTestMixin): cs_endpoint = "/active_threads" @@ -1183,7 +1183,7 @@ def verify_group_id_not_present(profiled_user, pass_group_id, requested_cohort=s verify_group_id_not_present(profiled_user=self.moderator, pass_group_id=False) -@patch('django_comment_common.comment_client.utils.requests.request', autospec=True) +@patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) class FollowedThreadsDiscussionGroupIdTestCase(CohortedTestCase, CohortedTopicGroupIdTestMixin): cs_endpoint = "/subscribed_threads" @@ -1220,7 +1220,7 @@ def test_group_info_in_ajax_response(self, mock_request): ) -@patch('django_comment_common.comment_client.utils.requests.request', autospec=True) +@patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) class InlineDiscussionTestCase(ForumsEnableMixin, ModuleStoreTestCase): def setUp(self): @@ -1480,7 +1480,7 @@ def setUpTestData(cls): def setUp(self): super(InlineDiscussionUnicodeTestCase, self).setUp() - @patch('django_comment_common.comment_client.utils.requests.request', autospec=True) + @patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) def _test_unicode_data(self, text, mock_request): mock_request.side_effect = make_mock_request_impl(course=self.course, text=text) request = RequestFactory().get("dummy_url") @@ -1513,7 +1513,7 @@ def setUpTestData(cls): def setUp(self): super(ForumFormDiscussionUnicodeTestCase, self).setUp() - @patch('django_comment_common.comment_client.utils.requests.request', autospec=True) + @patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) def _test_unicode_data(self, text, mock_request): mock_request.side_effect = make_mock_request_impl(course=self.course, text=text) request = RequestFactory().get("dummy_url") @@ -1528,7 +1528,7 @@ def _test_unicode_data(self, text, mock_request): @ddt.ddt -@patch('django_comment_common.comment_client.utils.requests.request', autospec=True) +@patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) class ForumDiscussionXSSTestCase(ForumsEnableMixin, UrlResetMixin, ModuleStoreTestCase): @patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) @@ -1601,7 +1601,7 @@ def setUpTestData(cls): def setUp(self): super(ForumDiscussionSearchUnicodeTestCase, self).setUp() - @patch('django_comment_common.comment_client.utils.requests.request', autospec=True) + @patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) def _test_unicode_data(self, text, mock_request): mock_request.side_effect = make_mock_request_impl(course=self.course, text=text) data = { @@ -1637,7 +1637,7 @@ def setUpTestData(cls): def setUp(self): super(SingleThreadUnicodeTestCase, self).setUp() - @patch('django_comment_common.comment_client.utils.requests.request', autospec=True) + @patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) def _test_unicode_data(self, text, mock_request): thread_id = "test_thread_id" mock_request.side_effect = make_mock_request_impl(course=self.course, text=text, thread_id=thread_id) @@ -1670,7 +1670,7 @@ def setUpTestData(cls): def setUp(self): super(UserProfileUnicodeTestCase, self).setUp() - @patch('django_comment_common.comment_client.utils.requests.request', autospec=True) + @patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) def _test_unicode_data(self, text, mock_request): mock_request.side_effect = make_mock_request_impl(course=self.course, text=text) request = RequestFactory().get("dummy_url") @@ -1702,7 +1702,7 @@ def setUpTestData(cls): def setUp(self): super(FollowedThreadsUnicodeTestCase, self).setUp() - @patch('django_comment_common.comment_client.utils.requests.request', autospec=True) + @patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) def _test_unicode_data(self, text, mock_request): mock_request.side_effect = make_mock_request_impl(course=self.course, text=text) request = RequestFactory().get("dummy_url") @@ -1729,7 +1729,7 @@ def setUp(self): self.student = UserFactory.create() @patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) - @patch('django_comment_common.comment_client.utils.requests.request', autospec=True) + @patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) def test_unenrolled(self, mock_request): mock_request.side_effect = make_mock_request_impl(course=self.course, text='dummy') request = RequestFactory().get('dummy_url') @@ -2111,7 +2111,7 @@ def setUp(self): self.client.login(username=self.student.username, password=PASSWORD) @patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) - @patch('django_comment_common.comment_client.utils.perform_request') + @patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.perform_request') def test_thread_viewed_event(self, mock_perform_request): mock_perform_request.side_effect = make_mock_perform_request_impl( course=self.course, diff --git a/lms/djangoapps/discussion/views.py b/lms/djangoapps/discussion/views.py index 5cef3fd0fa0b..400b181b2e18 100644 --- a/lms/djangoapps/discussion/views.py +++ b/lms/djangoapps/discussion/views.py @@ -26,9 +26,6 @@ from courseware.access import has_access from courseware.courses import get_course_with_access from courseware.views.views import CourseTabView -import django_comment_common.comment_client as cc -from django_comment_common.models import CourseDiscussionSettings -from django_comment_common.utils import ThreadContext, get_course_discussion_settings, set_course_discussion_settings import lms.djangoapps.discussion.django_comment_client.utils as utils from lms.djangoapps.discussion.django_comment_client.base.views import track_thread_viewed_event from lms.djangoapps.discussion.django_comment_client.constants import TYPE_ENTRY @@ -45,6 +42,11 @@ strip_none ) from lms.djangoapps.experiments.utils import get_experiment_user_metadata_context +import openedx.core.djangoapps.django_comment_common.comment_client as cc +from openedx.core.djangoapps.django_comment_common.models import CourseDiscussionSettings +from openedx.core.djangoapps.django_comment_common.utils import ( + ThreadContext, get_course_discussion_settings, set_course_discussion_settings, +) from openedx.core.djangoapps.plugin_api.views import EdxFragmentView from openedx.features.course_duration_limits.access import generate_course_expired_fragment from student.models import CourseEnrollment diff --git a/lms/djangoapps/experiments/utils.py b/lms/djangoapps/experiments/utils.py index 520a73e3a576..5ce047395a39 100644 --- a/lms/djangoapps/experiments/utils.py +++ b/lms/djangoapps/experiments/utils.py @@ -7,7 +7,6 @@ import logging from decimal import Decimal from student.models import CourseEnrollment -from django_comment_common.models import Role from django.utils.timezone import now from lms.djangoapps.commerce.utils import EcommerceService from course_modes.models import get_cosmetic_verified_display_price, format_course_price @@ -17,6 +16,7 @@ from opaque_keys.edx.keys import CourseKey from opaque_keys import InvalidKeyError from openedx.core.djangoapps.catalog.utils import get_programs +from openedx.core.djangoapps.django_comment_common.models import Role from openedx.core.djangoapps.waffle_utils import WaffleFlag, WaffleFlagNamespace diff --git a/lms/djangoapps/instructor/access.py b/lms/djangoapps/instructor/access.py index eb38818e967f..064f9fe987dd 100644 --- a/lms/djangoapps/instructor/access.py +++ b/lms/djangoapps/instructor/access.py @@ -11,7 +11,7 @@ import logging -from django_comment_common.models import Role +from openedx.core.djangoapps.django_comment_common.models import Role from lms.djangoapps.instructor.enrollment import enroll_email, get_email_params from student.roles import CourseBetaTesterRole, CourseCcxCoachRole, CourseInstructorRole, CourseStaffRole diff --git a/lms/djangoapps/instructor/tests/test_access.py b/lms/djangoapps/instructor/tests/test_access.py index 19493950ad13..4a8423f65d73 100644 --- a/lms/djangoapps/instructor/tests/test_access.py +++ b/lms/djangoapps/instructor/tests/test_access.py @@ -4,9 +4,9 @@ import pytest -from django_comment_common.models import FORUM_ROLE_MODERATOR, Role from lms.djangoapps.instructor.access import allow_access, list_with_level, revoke_access, update_forum_role from openedx.core.djangoapps.ace_common.tests.mixins import EmailTemplateTagMixin +from openedx.core.djangoapps.django_comment_common.models import FORUM_ROLE_MODERATOR, Role from student.roles import CourseBetaTesterRole, CourseCcxCoachRole, CourseStaffRole from student.tests.factories import UserFactory from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase diff --git a/lms/djangoapps/instructor/tests/test_api.py b/lms/djangoapps/instructor/tests/test_api.py index f7b045b6caa0..b66fd8635a28 100644 --- a/lms/djangoapps/instructor/tests/test_api.py +++ b/lms/djangoapps/instructor/tests/test_api.py @@ -42,8 +42,6 @@ UserProfileFactory ) from courseware.tests.helpers import LoginEnrollmentTestCase -from django_comment_common.models import FORUM_ROLE_COMMUNITY_TA -from django_comment_common.utils import seed_permissions_roles from lms.djangoapps.certificates.models import CertificateStatuses from lms.djangoapps.certificates.tests.factories import GeneratedCertificateFactory from lms.djangoapps.instructor.tests.utils import FakeContentTask, FakeEmail, FakeEmailInfo @@ -59,6 +57,8 @@ generate_already_running_error_message ) from openedx.core.djangoapps.course_groups.cohorts import set_course_cohorted +from openedx.core.djangoapps.django_comment_common.models import FORUM_ROLE_COMMUNITY_TA +from openedx.core.djangoapps.django_comment_common.utils import seed_permissions_roles from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin from openedx.core.lib.xblock_utils import grade_histogram diff --git a/lms/djangoapps/instructor/views/api.py b/lms/djangoapps/instructor/views/api.py index c462bd9300eb..ee76af354b23 100644 --- a/lms/djangoapps/instructor/views/api.py +++ b/lms/djangoapps/instructor/views/api.py @@ -54,13 +54,6 @@ get_group_name, has_forum_access ) -from django_comment_common.models import ( - FORUM_ROLE_ADMINISTRATOR, - FORUM_ROLE_COMMUNITY_TA, - FORUM_ROLE_GROUP_MODERATOR, - FORUM_ROLE_MODERATOR, - Role -) from edxmako.shortcuts import render_to_string from lms.djangoapps.certificates import api as certs_api from lms.djangoapps.certificates.models import ( @@ -86,6 +79,13 @@ from lms.djangoapps.instructor_task.models import ReportStore from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.course_groups.cohorts import is_course_cohorted +from openedx.core.djangoapps.django_comment_common.models import ( + FORUM_ROLE_ADMINISTRATOR, + FORUM_ROLE_COMMUNITY_TA, + FORUM_ROLE_GROUP_MODERATOR, + FORUM_ROLE_MODERATOR, + Role +) from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.user_api.preferences.api import get_user_preference, set_user_preference from openedx.core.djangolib.markup import HTML, Text diff --git a/lms/djangoapps/instructor/views/instructor_dashboard.py b/lms/djangoapps/instructor/views/instructor_dashboard.py index c1f1b12239ac..0dcd471ba9b6 100644 --- a/lms/djangoapps/instructor/views/instructor_dashboard.py +++ b/lms/djangoapps/instructor/views/instructor_dashboard.py @@ -31,7 +31,6 @@ from courseware.access import has_access from courseware.courses import get_course_by_id, get_studio_url from lms.djangoapps.discussion.django_comment_client.utils import available_division_schemes, has_forum_access -from django_comment_common.models import FORUM_ROLE_ADMINISTRATOR, CourseDiscussionSettings from edxmako.shortcuts import render_to_response from edx_when.api import is_enabled_for_course from lms.djangoapps.certificates import api as certs_api @@ -46,6 +45,7 @@ from lms.djangoapps.courseware.module_render import get_module_by_usage_id from lms.djangoapps.grades.config.waffle import WRITABLE_GRADEBOOK, waffle_flags from openedx.core.djangoapps.course_groups.cohorts import DEFAULT_COHORT_NAME, get_course_cohorts, is_course_cohorted +from openedx.core.djangoapps.django_comment_common.models import FORUM_ROLE_ADMINISTRATOR, CourseDiscussionSettings from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.verified_track_content.models import VerifiedTrackCohortedCourse from openedx.core.djangolib.markup import HTML, Text diff --git a/lms/djangoapps/teams/models.py b/lms/djangoapps/teams/models.py index 43dcaf517424..4028fefca931 100644 --- a/lms/djangoapps/teams/models.py +++ b/lms/djangoapps/teams/models.py @@ -15,7 +15,7 @@ from model_utils import FieldTracker from opaque_keys.edx.django.models import CourseKeyField -from django_comment_common.signals import ( +from openedx.core.djangoapps.django_comment_common.signals import ( comment_created, comment_deleted, comment_edited, diff --git a/lms/djangoapps/teams/tests/test_models.py b/lms/djangoapps/teams/tests/test_models.py index a23a2c166709..5dca2f1be554 100644 --- a/lms/djangoapps/teams/tests/test_models.py +++ b/lms/djangoapps/teams/tests/test_models.py @@ -9,7 +9,7 @@ from mock import Mock from opaque_keys.edx.keys import CourseKey -from django_comment_common.signals import ( +from openedx.core.djangoapps.django_comment_common.signals import ( comment_created, comment_deleted, comment_edited, diff --git a/lms/djangoapps/teams/tests/test_views.py b/lms/djangoapps/teams/tests/test_views.py index c0394f970bc7..74f65258ae3b 100644 --- a/lms/djangoapps/teams/tests/test_views.py +++ b/lms/djangoapps/teams/tests/test_views.py @@ -18,8 +18,8 @@ from common.test.utils import skip_signal from courseware.tests.factories import StaffFactory -from django_comment_common.models import FORUM_ROLE_COMMUNITY_TA, Role -from django_comment_common.utils import seed_permissions_roles +from openedx.core.djangoapps.django_comment_common.models import FORUM_ROLE_COMMUNITY_TA, Role +from openedx.core.djangoapps.django_comment_common.utils import seed_permissions_roles from student.models import CourseEnrollment from student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory from util.testing import EventTestMixin diff --git a/lms/envs/common.py b/lms/envs/common.py index 172aab6919d3..124388c1f117 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -2123,7 +2123,7 @@ def _make_locale_paths(settings): 'openedx.core.djangoapps.util.apps.UtilConfig', # Discussion forums - 'django_comment_common', + 'openedx.core.djangoapps.django_comment_common', # Notes 'notes', diff --git a/lms/urls.py b/lms/urls.py index 5be7a50ea053..955ff38962e5 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -18,7 +18,6 @@ from courseware.views.index import CoursewareIndex from courseware.views.views import CourseTabView, EnrollStaffView, StaticCourseTabView from debug import views as debug_views -from django_comment_common.models import ForumsConfig from lms.djangoapps.certificates import views as certificates_views from lms.djangoapps.discussion import views as discussion_views from lms.djangoapps.discussion.notification_prefs import views as notification_prefs_views @@ -33,6 +32,7 @@ from openedx.core.djangoapps.cors_csrf import views as cors_csrf_views from openedx.core.djangoapps.course_groups import views as course_groups_views from openedx.core.djangoapps.debug import views as openedx_debug_views +from openedx.core.djangoapps.django_comment_common.models import ForumsConfig from openedx.core.djangoapps.lang_pref import views as lang_pref_views from openedx.core.djangoapps.password_policy import compliance as password_policy_compliance from openedx.core.djangoapps.password_policy.forms import PasswordPolicyAwareAdminAuthForm diff --git a/openedx/core/djangoapps/course_groups/tests/helpers.py b/openedx/core/djangoapps/course_groups/tests/helpers.py index b3d27db08a70..47d506242f16 100644 --- a/openedx/core/djangoapps/course_groups/tests/helpers.py +++ b/openedx/core/djangoapps/course_groups/tests/helpers.py @@ -10,8 +10,8 @@ from factory.django import DjangoModelFactory from opaque_keys.edx.locator import CourseLocator -from django_comment_common.models import CourseDiscussionSettings -from django_comment_common.utils import set_course_discussion_settings +from openedx.core.djangoapps.django_comment_common.models import CourseDiscussionSettings +from openedx.core.djangoapps.django_comment_common.utils import set_course_discussion_settings from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore diff --git a/openedx/core/djangoapps/course_groups/tests/test_views.py b/openedx/core/djangoapps/course_groups/tests/test_views.py index f158670ffe63..56d53c115e54 100644 --- a/openedx/core/djangoapps/course_groups/tests/test_views.py +++ b/openedx/core/djangoapps/course_groups/tests/test_views.py @@ -15,8 +15,8 @@ from django.test.client import RequestFactory from opaque_keys.edx.locator import CourseLocator -from django_comment_common.models import CourseDiscussionSettings -from django_comment_common.utils import get_course_discussion_settings +from openedx.core.djangoapps.django_comment_common.models import CourseDiscussionSettings +from openedx.core.djangoapps.django_comment_common.utils import get_course_discussion_settings from lms.djangoapps.courseware.tests.factories import InstructorFactory, StaffFactory from student.models import CourseEnrollment from student.tests.factories import UserFactory diff --git a/common/djangoapps/django_comment_common/README.rst b/openedx/core/djangoapps/django_comment_common/README.rst similarity index 100% rename from common/djangoapps/django_comment_common/README.rst rename to openedx/core/djangoapps/django_comment_common/README.rst diff --git a/common/djangoapps/django_comment_common/__init__.py b/openedx/core/djangoapps/django_comment_common/__init__.py similarity index 100% rename from common/djangoapps/django_comment_common/__init__.py rename to openedx/core/djangoapps/django_comment_common/__init__.py diff --git a/common/djangoapps/django_comment_common/admin.py b/openedx/core/djangoapps/django_comment_common/admin.py similarity index 100% rename from common/djangoapps/django_comment_common/admin.py rename to openedx/core/djangoapps/django_comment_common/admin.py diff --git a/common/djangoapps/django_comment_common/comment_client/README.rst b/openedx/core/djangoapps/django_comment_common/comment_client/README.rst similarity index 100% rename from common/djangoapps/django_comment_common/comment_client/README.rst rename to openedx/core/djangoapps/django_comment_common/comment_client/README.rst diff --git a/common/djangoapps/django_comment_common/comment_client/__init__.py b/openedx/core/djangoapps/django_comment_common/comment_client/__init__.py similarity index 75% rename from common/djangoapps/django_comment_common/comment_client/__init__.py rename to openedx/core/djangoapps/django_comment_common/comment_client/__init__.py index bd8187ecfca8..6f0222e54d91 100644 --- a/common/djangoapps/django_comment_common/comment_client/__init__.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/__init__.py @@ -1,3 +1,4 @@ +# pylint: disable=missing-docstring,wildcard-import from .comment_client import * from .utils import ( CommentClientError, CommentClientRequestError, diff --git a/common/djangoapps/django_comment_common/comment_client/comment.py b/openedx/core/djangoapps/django_comment_common/comment_client/comment.py similarity index 91% rename from common/djangoapps/django_comment_common/comment_client/comment.py rename to openedx/core/djangoapps/django_comment_common/comment_client/comment.py index 377079a996f0..4dd5bb58e079 100644 --- a/common/djangoapps/django_comment_common/comment_client/comment.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/comment.py @@ -1,4 +1,5 @@ -from django_comment_common.comment_client import models, settings +# pylint: disable=missing-docstring,protected-access +from openedx.core.djangoapps.django_comment_common.comment_client import models, settings from .thread import Thread, _url_for_flag_abuse_thread, _url_for_unflag_abuse_thread from .utils import CommentClientRequestError, perform_request @@ -42,14 +43,16 @@ def context(self): return self.thread.context @classmethod - def url_for_comments(cls, params={}): - if params.get('parent_id'): + def url_for_comments(cls, params=None): + if params and params.get('parent_id'): return _url_for_comment(params['parent_id']) else: return _url_for_thread_comments(params['thread_id']) @classmethod - def url(cls, action, params={}): + def url(cls, action, params=None): + if params is None: + params = {} if action in ['post']: return cls.url_for_comments(params) else: diff --git a/common/djangoapps/django_comment_common/comment_client/comment_client.py b/openedx/core/djangoapps/django_comment_common/comment_client/comment_client.py similarity index 100% rename from common/djangoapps/django_comment_common/comment_client/comment_client.py rename to openedx/core/djangoapps/django_comment_common/comment_client/comment_client.py diff --git a/common/djangoapps/django_comment_common/comment_client/commentable.py b/openedx/core/djangoapps/django_comment_common/comment_client/commentable.py similarity index 80% rename from common/djangoapps/django_comment_common/comment_client/commentable.py rename to openedx/core/djangoapps/django_comment_common/comment_client/commentable.py index f86760d316c5..76ef5d23c0ef 100644 --- a/common/djangoapps/django_comment_common/comment_client/commentable.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/commentable.py @@ -1,5 +1,6 @@ +# pylint: disable=missing-docstring """Provides base Commentable model class""" -from django_comment_common.comment_client import models, settings +from openedx.core.djangoapps.django_comment_common.comment_client import models, settings class Commentable(models.Model): diff --git a/common/djangoapps/django_comment_common/comment_client/models.py b/openedx/core/djangoapps/django_comment_common/comment_client/models.py similarity index 92% rename from common/djangoapps/django_comment_common/comment_client/models.py rename to openedx/core/djangoapps/django_comment_common/comment_client/models.py index 35a781bb07b0..7b0d2e2cd9a9 100644 --- a/common/djangoapps/django_comment_common/comment_client/models.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/models.py @@ -1,3 +1,4 @@ +# pylint: disable=missing-docstring,unused-argument import logging from .utils import CommentClientRequestError, extract, perform_request @@ -94,7 +95,7 @@ def _metric_tags(self): return tags @classmethod - def find(cls, id): + def find(cls, id): # pylint: disable=redefined-builtin return cls(id=id) def _update_from_response(self, response_data): @@ -160,19 +161,25 @@ def delete(self): self._update_from_response(response) @classmethod - def url_with_id(cls, params={}): + def url_with_id(cls, params=None): + if params is None: + params = {} return cls.base_url + '/' + str(params['id']) @classmethod - def url_without_id(cls, params={}): + def url_without_id(cls, params=None): return cls.base_url @classmethod - def url(cls, action, params={}): + def url(cls, action, params=None): + if params is None: + params = {} if cls.base_url is None: raise CommentClientRequestError("Must provide base_url when using default url function") if action not in cls.DEFAULT_ACTIONS: - raise ValueError(u"Invalid action {0}. The supported action must be in {1}".format(action, str(cls.DEFAULT_ACTIONS))) + raise ValueError( + u"Invalid action {0}. The supported action must be in {1}".format(action, str(cls.DEFAULT_ACTIONS)) + ) elif action in cls.DEFAULT_ACTIONS_WITH_ID: try: return cls.url_with_id(params) diff --git a/common/djangoapps/django_comment_common/comment_client/requirements.txt b/openedx/core/djangoapps/django_comment_common/comment_client/requirements.txt similarity index 100% rename from common/djangoapps/django_comment_common/comment_client/requirements.txt rename to openedx/core/djangoapps/django_comment_common/comment_client/requirements.txt diff --git a/common/djangoapps/django_comment_common/comment_client/settings.py b/openedx/core/djangoapps/django_comment_common/comment_client/settings.py similarity index 85% rename from common/djangoapps/django_comment_common/comment_client/settings.py rename to openedx/core/djangoapps/django_comment_common/comment_client/settings.py index f64726335f6e..1d3f224b410a 100644 --- a/common/djangoapps/django_comment_common/comment_client/settings.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/settings.py @@ -1,3 +1,4 @@ +# pylint: disable=missing-docstring from django.conf import settings if hasattr(settings, "COMMENTS_SERVICE_URL"): diff --git a/common/djangoapps/django_comment_common/comment_client/thread.py b/openedx/core/djangoapps/django_comment_common/comment_client/thread.py similarity index 91% rename from common/djangoapps/django_comment_common/comment_client/thread.py rename to openedx/core/djangoapps/django_comment_common/comment_client/thread.py index a73c6f5ec792..d45a385f9e06 100644 --- a/common/djangoapps/django_comment_common/comment_client/thread.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/thread.py @@ -1,11 +1,11 @@ +# pylint: disable=missing-docstring,protected-access import logging -import settings - -import models from eventtracking import tracker +from . import models +from . import settings +from . import utils -import utils log = logging.getLogger(__name__) @@ -93,7 +93,8 @@ def search(cls, query_params): } ) log.info( - u'forum_text_search query="{search_query}" corrected_text="{corrected_text}" course_id={course_id} group_id={group_id} page={requested_page} total_results={total_results}'.format( + u'forum_text_search query="{search_query}" corrected_text="{corrected_text}" course_id={course_id} ' + u'group_id={group_id} page={requested_page} total_results={total_results}'.format( search_query=search_query, corrected_text=corrected_text, course_id=course_id, @@ -112,23 +113,27 @@ def search(cls, query_params): ) @classmethod - def url_for_threads(cls, params={}): - if params.get('commentable_id'): - return u"{prefix}/{commentable_id}/threads".format(prefix=settings.PREFIX, commentable_id=params['commentable_id']) + def url_for_threads(cls, params=None): + if params and params.get('commentable_id'): + return u"{prefix}/{commentable_id}/threads".format( + prefix=settings.PREFIX, + commentable_id=params['commentable_id'], + ) else: return u"{prefix}/threads".format(prefix=settings.PREFIX) @classmethod - def url_for_search_threads(cls, params={}): + def url_for_search_threads(cls): return "{prefix}/search/threads".format(prefix=settings.PREFIX) @classmethod - def url(cls, action, params={}): - + def url(cls, action, params=None): + if params is None: + params = {} if action in ['get_all', 'post']: return cls.url_for_threads(params) elif action == 'search': - return cls.url_for_search_threads(params) + return cls.url_for_search_threads() else: return super(Thread, cls).url(action, params) @@ -159,8 +164,6 @@ def _retrieve(self, *args, **kwargs): def flagAbuse(self, user, voteable): if voteable.type == 'thread': url = _url_for_flag_abuse_thread(voteable.id) - elif voteable.type == 'comment': - url = _url_for_flag_comment(voteable.id) else: raise utils.CommentClientRequestError("Can only flag/unflag threads or comments") params = {'user_id': user.id} @@ -176,8 +179,6 @@ def flagAbuse(self, user, voteable): def unFlagAbuse(self, user, voteable, removeAll): if voteable.type == 'thread': url = _url_for_unflag_abuse_thread(voteable.id) - elif voteable.type == 'comment': - url = _url_for_unflag_comment(voteable.id) else: raise utils.CommentClientRequestError("Can only flag/unflag for threads or comments") params = {'user_id': user.id} diff --git a/common/djangoapps/django_comment_common/comment_client/user.py b/openedx/core/djangoapps/django_comment_common/comment_client/user.py similarity index 93% rename from common/djangoapps/django_comment_common/comment_client/user.py rename to openedx/core/djangoapps/django_comment_common/comment_client/user.py index a007bd1d7512..d6b68914546c 100644 --- a/common/djangoapps/django_comment_common/comment_client/user.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/user.py @@ -1,9 +1,10 @@ +# pylint: disable=missing-docstring,protected-access """ User model wrapper for comment service""" from six import text_type -import settings -import models -import utils +from . import models +from . import settings +from . import utils class User(models.Model): @@ -46,7 +47,7 @@ def read(self, source): def follow(self, source): params = {'source_type': source.type, 'source_id': source.id} - response = utils.perform_request( + utils.perform_request( 'post', _url_for_subscription(self.id), params, @@ -56,7 +57,7 @@ def follow(self, source): def unfollow(self, source): params = {'source_type': source.type, 'source_id': source.id} - response = utils.perform_request( + utils.perform_request( 'delete', _url_for_subscription(self.id), params, @@ -98,7 +99,9 @@ def unvote(self, voteable): ) voteable._update_from_response(response) - def active_threads(self, query_params={}): + def active_threads(self, query_params=None): + if query_params is None: + query_params = {} if not self.course_id: raise utils.CommentClientRequestError("Must provide course_id when retrieving active threads for the user") url = _url_for_user_active_threads(self.id) @@ -114,9 +117,13 @@ def active_threads(self, query_params={}): ) return response.get('collection', []), response.get('page', 1), response.get('num_pages', 1) - def subscribed_threads(self, query_params={}): + def subscribed_threads(self, query_params=None): + if query_params is None: + query_params = {} if not self.course_id: - raise utils.CommentClientRequestError("Must provide course_id when retrieving subscribed threads for the user") + raise utils.CommentClientRequestError( + "Must provide course_id when retrieving subscribed threads for the user", + ) url = _url_for_user_subscribed_threads(self.id) params = {'course_id': text_type(self.course_id)} params.update(query_params) diff --git a/common/djangoapps/django_comment_common/comment_client/utils.py b/openedx/core/djangoapps/django_comment_common/comment_client/utils.py similarity index 95% rename from common/djangoapps/django_comment_common/comment_client/utils.py rename to openedx/core/djangoapps/django_comment_common/comment_client/utils.py index 86e3b8c65ef0..dfa4712c8cea 100644 --- a/common/djangoapps/django_comment_common/comment_client/utils.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/utils.py @@ -1,7 +1,6 @@ +# pylint: disable=missing-docstring,unused-argument,broad-except """" Common utilities for comment client wrapper """ import logging -from contextlib import contextmanager -from time import time from uuid import uuid4 import requests @@ -32,7 +31,7 @@ def extract(dic, keys): def perform_request(method, url, data_or_params=None, raw=False, metric_action=None, metric_tags=None, paged_results=False): # To avoid dependency conflict - from django_comment_common.models import ForumsConfig + from openedx.core.djangoapps.django_comment_common.models import ForumsConfig config = ForumsConfig.current() if not config.enabled: @@ -135,7 +134,7 @@ def check_forum_heartbeat(): This function can be connected to the LMS heartbeat checker through the HEARTBEAT_CHECKS variable. """ # To avoid dependency conflict - from django_comment_common.models import ForumsConfig + from openedx.core.djangoapps.django_comment_common.models import ForumsConfig config = ForumsConfig.current() if not config.enabled: diff --git a/common/djangoapps/django_comment_common/migrations/0001_initial.py b/openedx/core/djangoapps/django_comment_common/migrations/0001_initial.py similarity index 100% rename from common/djangoapps/django_comment_common/migrations/0001_initial.py rename to openedx/core/djangoapps/django_comment_common/migrations/0001_initial.py diff --git a/common/djangoapps/django_comment_common/migrations/0002_forumsconfig.py b/openedx/core/djangoapps/django_comment_common/migrations/0002_forumsconfig.py similarity index 94% rename from common/djangoapps/django_comment_common/migrations/0002_forumsconfig.py rename to openedx/core/djangoapps/django_comment_common/migrations/0002_forumsconfig.py index c4c24e8586c6..797506dab55b 100644 --- a/common/djangoapps/django_comment_common/migrations/0002_forumsconfig.py +++ b/openedx/core/djangoapps/django_comment_common/migrations/0002_forumsconfig.py @@ -26,6 +26,7 @@ class Migration(migrations.Migration): options={ 'ordering': ('-change_date',), 'abstract': False, + 'db_table': 'django_comment_common_forumsconfig', }, ), ] diff --git a/common/djangoapps/django_comment_common/migrations/0003_enable_forums.py b/openedx/core/djangoapps/django_comment_common/migrations/0003_enable_forums.py similarity index 100% rename from common/djangoapps/django_comment_common/migrations/0003_enable_forums.py rename to openedx/core/djangoapps/django_comment_common/migrations/0003_enable_forums.py diff --git a/common/djangoapps/django_comment_common/migrations/0004_auto_20161117_1209.py b/openedx/core/djangoapps/django_comment_common/migrations/0004_auto_20161117_1209.py similarity index 100% rename from common/djangoapps/django_comment_common/migrations/0004_auto_20161117_1209.py rename to openedx/core/djangoapps/django_comment_common/migrations/0004_auto_20161117_1209.py diff --git a/common/djangoapps/django_comment_common/migrations/0005_coursediscussionsettings.py b/openedx/core/djangoapps/django_comment_common/migrations/0005_coursediscussionsettings.py similarity index 90% rename from common/djangoapps/django_comment_common/migrations/0005_coursediscussionsettings.py rename to openedx/core/djangoapps/django_comment_common/migrations/0005_coursediscussionsettings.py index 0b8eca433679..f75e0baa89ee 100644 --- a/common/djangoapps/django_comment_common/migrations/0005_coursediscussionsettings.py +++ b/openedx/core/djangoapps/django_comment_common/migrations/0005_coursediscussionsettings.py @@ -21,5 +21,8 @@ class Migration(migrations.Migration): ('_divided_discussions', models.TextField(null=True, db_column=b'divided_discussions', blank=True)), ('division_scheme', models.CharField(default=b'none', max_length=20, choices=[(b'none', b'None'), (b'cohort', b'Cohort'), (b'enrollment_track', b'Enrollment Track')])), ], + options={ + 'db_table': 'django_comment_common_coursediscussionsettings', + }, ), ] diff --git a/common/djangoapps/django_comment_common/migrations/0006_coursediscussionsettings_discussions_id_map.py b/openedx/core/djangoapps/django_comment_common/migrations/0006_coursediscussionsettings_discussions_id_map.py similarity index 100% rename from common/djangoapps/django_comment_common/migrations/0006_coursediscussionsettings_discussions_id_map.py rename to openedx/core/djangoapps/django_comment_common/migrations/0006_coursediscussionsettings_discussions_id_map.py diff --git a/common/djangoapps/django_comment_common/migrations/0007_discussionsidmapping.py b/openedx/core/djangoapps/django_comment_common/migrations/0007_discussionsidmapping.py similarity index 87% rename from common/djangoapps/django_comment_common/migrations/0007_discussionsidmapping.py rename to openedx/core/djangoapps/django_comment_common/migrations/0007_discussionsidmapping.py index c41d9cebe33d..b82c062f63ba 100644 --- a/common/djangoapps/django_comment_common/migrations/0007_discussionsidmapping.py +++ b/openedx/core/djangoapps/django_comment_common/migrations/0007_discussionsidmapping.py @@ -20,5 +20,8 @@ class Migration(migrations.Migration): ('course_id', opaque_keys.edx.django.models.CourseKeyField(db_index=True, max_length=255, primary_key=True, serialize=False)), ('mapping', jsonfield.fields.JSONField(help_text=b'Key/value store mapping discussion IDs to discussion XBlock usage keys.')), ], + options={ + 'db_table': 'django_comment_common_discussionsidmapping', + }, ), ] diff --git a/common/djangoapps/django_comment_common/migrations/0008_role_user_index.py b/openedx/core/djangoapps/django_comment_common/migrations/0008_role_user_index.py similarity index 78% rename from common/djangoapps/django_comment_common/migrations/0008_role_user_index.py rename to openedx/core/djangoapps/django_comment_common/migrations/0008_role_user_index.py index 5624c9b9186f..0fe8bc784a68 100644 --- a/common/djangoapps/django_comment_common/migrations/0008_role_user_index.py +++ b/openedx/core/djangoapps/django_comment_common/migrations/0008_role_user_index.py @@ -12,6 +12,7 @@ class Migration(migrations.Migration): operations = [ migrations.RunSQL( - 'CREATE INDEX dcc_role_users_user_role_idx ON django_comment_client_role_users(user_id, role_id);' + 'CREATE INDEX dcc_role_users_user_role_idx ON django_comment_client_role_users(user_id, role_id);', + reverse_sql=migrations.RunSQL.noop, ), ] diff --git a/common/djangoapps/django_comment_common/migrations/__init__.py b/openedx/core/djangoapps/django_comment_common/migrations/__init__.py similarity index 100% rename from common/djangoapps/django_comment_common/migrations/__init__.py rename to openedx/core/djangoapps/django_comment_common/migrations/__init__.py diff --git a/common/djangoapps/django_comment_common/models.py b/openedx/core/djangoapps/django_comment_common/models.py similarity index 90% rename from common/djangoapps/django_comment_common/models.py rename to openedx/core/djangoapps/django_comment_common/models.py index 5e761fa660fa..9d3e347ef930 100644 --- a/common/djangoapps/django_comment_common/models.py +++ b/openedx/core/djangoapps/django_comment_common/models.py @@ -1,3 +1,4 @@ +# pylint: disable=missing-docstring,unused-argument,model-missing-unicode import json import logging @@ -60,7 +61,7 @@ def assign_role(course_id, user, rolename): """ role, created = Role.objects.get_or_create(course_id=course_id, name=rolename) if created: - logging.info("EDUCATOR-1635: Created role {} for course {}".format(role, course_id)) + logging.info(u"EDUCATOR-1635: Created role {} for course {}".format(role, course_id)) user.roles.add(role) @@ -82,7 +83,6 @@ class Meta(object): db_table = 'django_comment_client_role' def __unicode__(self): - # pylint: disable=no-member return self.name + " for " + (text_type(self.course_id) if self.course_id else "all courses") # TODO the name of this method is a little bit confusing, @@ -94,7 +94,7 @@ def inherit_permissions(self, role): """ if role.course_id and role.course_id != self.course_id: logging.warning( - "%s cannot inherit permissions from %s due to course_id inconsistency", + u"%s cannot inherit permissions from %s due to course_id inconsistency", self, role, ) @@ -157,7 +157,7 @@ def permission_blacked_out(course, role_names, permission_name): ) -def all_permissions_for_user_in_course(user, course_id): # pylint: disable=invalid-name +def all_permissions_for_user_in_course(user, course_id): """ Returns all the permissions the user has in the given course. """ @@ -181,7 +181,7 @@ def all_permissions_for_user_in_course(user, course_id): # pylint: disable=inva permission_names.add(permission.name) # Prevent a circular import - from django_comment_common.utils import GLOBAL_STAFF_ROLE_PERMISSIONS + from openedx.core.djangoapps.django_comment_common.utils import GLOBAL_STAFF_ROLE_PERMISSIONS if GlobalStaff().has_user(user): for permission in GLOBAL_STAFF_ROLE_PERMISSIONS: @@ -202,6 +202,10 @@ class ForumsConfig(ConfigurationModel): help_text="Seconds to wait when trying to connect to the comment service.", ) + class Meta(ConfigurationModel.Meta): + # use existing table that was originally created from django_comment_common app + db_table = 'django_comment_common_forumsconfig' + @property def api_key(self): """The API key used to authenticate to the comments service.""" @@ -240,6 +244,10 @@ class CourseDiscussionSettings(models.Model): ASSIGNMENT_TYPE_CHOICES = ((NONE, 'None'), (COHORT, 'Cohort'), (ENROLLMENT_TRACK, 'Enrollment Track')) division_scheme = models.CharField(max_length=20, choices=ASSIGNMENT_TYPE_CHOICES, default=NONE) + class Meta(object): + # use existing table that was originally created from django_comment_common app + db_table = 'django_comment_common_coursediscussionsettings' + @property def divided_discussions(self): """ @@ -266,6 +274,10 @@ class DiscussionsIdMapping(models.Model): help_text="Key/value store mapping discussion IDs to discussion XBlock usage keys.", ) + class Meta(object): + # use existing table that was originally created from django_comment_common app + db_table = 'django_comment_common_discussionsidmapping' + @classmethod def update_mapping(cls, course_key, discussions_id_map): """Update the mapping of discussions IDs to XBlock usage key strings.""" diff --git a/common/djangoapps/django_comment_common/signals.py b/openedx/core/djangoapps/django_comment_common/signals.py similarity index 100% rename from common/djangoapps/django_comment_common/signals.py rename to openedx/core/djangoapps/django_comment_common/signals.py diff --git a/common/djangoapps/django_comment_common/tests.py b/openedx/core/djangoapps/django_comment_common/tests.py similarity index 95% rename from common/djangoapps/django_comment_common/tests.py rename to openedx/core/djangoapps/django_comment_common/tests.py index 23ef3e05e597..a951d5b5844d 100644 --- a/common/djangoapps/django_comment_common/tests.py +++ b/openedx/core/djangoapps/django_comment_common/tests.py @@ -1,12 +1,14 @@ +# pylint: disable=missing-docstring from django.test import TestCase from opaque_keys.edx.locator import CourseLocator from six import text_type -from django_comment_common.models import Role -from models import CourseDiscussionSettings from openedx.core.djangoapps.course_groups.cohorts import CourseCohortsSettings +from openedx.core.djangoapps.django_comment_common.models import Role, CourseDiscussionSettings +from openedx.core.djangoapps.django_comment_common.utils import ( + get_course_discussion_settings, set_course_discussion_settings, +) from student.models import CourseEnrollment, User -from utils import get_course_discussion_settings, set_course_discussion_settings from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase diff --git a/common/djangoapps/django_comment_common/utils.py b/openedx/core/djangoapps/django_comment_common/utils.py similarity index 95% rename from common/djangoapps/django_comment_common/utils.py rename to openedx/core/djangoapps/django_comment_common/utils.py index 06b73fc5e5b7..552ab4d0c549 100644 --- a/common/djangoapps/django_comment_common/utils.py +++ b/openedx/core/djangoapps/django_comment_common/utils.py @@ -1,8 +1,9 @@ +# pylint: disable=missing-docstring """ Common comment client utility functions. """ -from django_comment_common.models import ( +from openedx.core.djangoapps.django_comment_common.models import ( CourseDiscussionSettings, FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, @@ -89,7 +90,7 @@ def are_permissions_roles_seeded(course_id): moderator_role = Role.objects.get(name=FORUM_ROLE_MODERATOR, course_id=course_id) group_moderator_role = Role.objects.get(name=FORUM_ROLE_GROUP_MODERATOR, course_id=course_id) student_role = Role.objects.get(name=FORUM_ROLE_STUDENT, course_id=course_id) - except: + except: # pylint: disable=bare-except return False for per in STUDENT_ROLE_PERMISSIONS: @@ -153,7 +154,7 @@ def set_course_discussion_settings(course_key, **kwargs): for field, field_type in fields.items(): if field in kwargs: if not isinstance(kwargs[field], field_type): - raise ValueError("Incorrect field type for `{}`. Type must be `{}`".format(field, field_type.__name__)) + raise ValueError(u"Incorrect field type for `{}`. Type must be `{}`".format(field, field_type.__name__)) setattr(course_discussion_settings, field, kwargs[field]) course_discussion_settings.save() diff --git a/openedx/core/djangoapps/user_api/tests/test_views.py b/openedx/core/djangoapps/user_api/tests/test_views.py index 130c82c99ab4..6cb70d45ca23 100644 --- a/openedx/core/djangoapps/user_api/tests/test_views.py +++ b/openedx/core/djangoapps/user_api/tests/test_views.py @@ -19,7 +19,7 @@ from six import text_type from social_django.models import UserSocialAuth, Partial -from django_comment_common import models +from openedx.core.djangoapps.django_comment_common import models from openedx.core.djangoapps.site_configuration.helpers import get_value from openedx.core.lib.api.test_utils import ApiTestCase, TEST_API_KEY from openedx.core.lib.time_zone_utils import get_display_time_zone diff --git a/openedx/core/djangoapps/user_api/views.py b/openedx/core/djangoapps/user_api/views.py index fa526482ff44..bc7078ae4f0d 100644 --- a/openedx/core/djangoapps/user_api/views.py +++ b/openedx/core/djangoapps/user_api/views.py @@ -15,12 +15,13 @@ from rest_framework.permissions import IsAuthenticated from six import text_type -import accounts -from django_comment_common.models import Role from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser from opaque_keys import InvalidKeyError from opaque_keys.edx import locator from opaque_keys.edx.keys import CourseKey + +from openedx.core.djangoapps.django_comment_common.models import Role +from openedx.core.djangoapps.user_api import accounts from openedx.core.djangoapps.user_api.accounts.api import check_account_exists from openedx.core.djangoapps.user_api.api import ( RegistrationFormFactory, diff --git a/openedx/core/djangoapps/user_authn/views/auto_auth.py b/openedx/core/djangoapps/user_authn/views/auto_auth.py index 69ba2d6775f1..9bd095f9ef8b 100644 --- a/openedx/core/djangoapps/user_authn/views/auto_auth.py +++ b/openedx/core/djangoapps/user_authn/views/auto_auth.py @@ -12,10 +12,10 @@ from django.shortcuts import redirect from django.template.context_processors import csrf from django.utils.translation import ugettext as _ -from django_comment_common.models import assign_role from lms.djangoapps.verify_student.models import ManualVerification from opaque_keys.edx.locator import CourseLocator +from openedx.core.djangoapps.django_comment_common.models import assign_role from openedx.core.djangoapps.user_api.accounts.utils import generate_password from openedx.features.course_experience import course_home_url_name from student.forms import AccountCreationForm diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_auto_auth.py b/openedx/core/djangoapps/user_authn/views/tests/test_auto_auth.py index 78b34ba6a2d4..fadf004b734d 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_auto_auth.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_auto_auth.py @@ -9,10 +9,10 @@ from mock import patch, Mock from opaque_keys.edx.locator import CourseLocator -from django_comment_common.models import ( +from openedx.core.djangoapps.django_comment_common.models import ( Role, FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, FORUM_ROLE_STUDENT ) -from django_comment_common.utils import seed_permissions_roles +from openedx.core.djangoapps.django_comment_common.utils import seed_permissions_roles from student.models import anonymous_id_for_user, CourseAccessRole, CourseEnrollment, UserProfile from util.testing import UrlResetMixin diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_register.py b/openedx/core/djangoapps/user_authn/views/tests/test_register.py index 1da4cad5bde3..cfc78fa353c4 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_register.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_register.py @@ -16,12 +16,8 @@ from django.test.utils import override_settings from django.contrib.auth.hashers import make_password -from django_comment_common.models import ForumsConfig from lms.djangoapps.discussion.notification_prefs import NOTIFICATION_PREF_KEY -from openedx.core.djangoapps.user_authn.views.register import ( - REGISTRATION_AFFILIATE_ID, REGISTRATION_UTM_CREATED_AT, REGISTRATION_UTM_PARAMETERS, - _skip_activation_email, -) +from openedx.core.djangoapps.django_comment_common.models import ForumsConfig from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin from openedx.core.djangoapps.user_api.accounts import ( @@ -29,6 +25,10 @@ ) from openedx.core.djangoapps.user_api.config.waffle import PREVENT_AUTH_USER_WRITES, waffle from openedx.core.djangoapps.user_api.preferences.api import get_user_preference +from openedx.core.djangoapps.user_authn.views.register import ( + REGISTRATION_AFFILIATE_ID, REGISTRATION_UTM_CREATED_AT, REGISTRATION_UTM_PARAMETERS, + _skip_activation_email, +) from student.models import UserAttribute from student.tests.factories import UserFactory from third_party_auth.tests import factories as third_party_auth_factory @@ -768,9 +768,9 @@ def assert_extra_field_error(): @mock.patch.dict("student.models.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) -@mock.patch("django_comment_common.comment_client.User.base_url", TEST_CS_URL) +@mock.patch("openedx.core.djangoapps.django_comment_common.comment_client.User.base_url", TEST_CS_URL) @mock.patch( - "django_comment_common.comment_client.utils.requests.request", + "openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request", return_value=mock.Mock(status_code=200, text='{}') ) class TestCreateCommentsServiceUser(TransactionTestCase): diff --git a/openedx/core/djangoapps/util/testing.py b/openedx/core/djangoapps/util/testing.py index 6719c7076cbb..c7c15a8ffc04 100644 --- a/openedx/core/djangoapps/util/testing.py +++ b/openedx/core/djangoapps/util/testing.py @@ -3,8 +3,8 @@ from datetime import datetime from pytz import UTC -from django_comment_common.models import Role -from django_comment_common.utils import seed_permissions_roles +from openedx.core.djangoapps.django_comment_common.models import Role +from openedx.core.djangoapps.django_comment_common.utils import seed_permissions_roles from openedx.core.djangoapps.course_groups.models import CourseUserGroupPartitionGroup from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory from openedx.core.djangoapps.user_api.tests.factories import UserCourseTagFactory diff --git a/openedx/features/content_type_gating/tests/test_access.py b/openedx/features/content_type_gating/tests/test_access.py index b7895d2013ce..dd769c6e7a86 100644 --- a/openedx/features/content_type_gating/tests/test_access.py +++ b/openedx/features/content_type_gating/tests/test_access.py @@ -12,13 +12,6 @@ from mock import patch from course_api.blocks.api import get_blocks -from django_comment_common.models import ( - FORUM_ROLE_ADMINISTRATOR, - FORUM_ROLE_MODERATOR, - FORUM_ROLE_GROUP_MODERATOR, - FORUM_ROLE_COMMUNITY_TA, - Role -) from lms.djangoapps.discussion.django_comment_client.tests.factories import RoleFactory from course_modes.tests.factories import CourseModeFactory from experiments.models import ExperimentData, ExperimentKeyValue @@ -33,6 +26,13 @@ OrgInstructorFactory, GlobalStaffFactory, ) +from openedx.core.djangoapps.django_comment_common.models import ( + FORUM_ROLE_ADMINISTRATOR, + FORUM_ROLE_MODERATOR, + FORUM_ROLE_GROUP_MODERATOR, + FORUM_ROLE_COMMUNITY_TA, + Role +) from openedx.core.djangoapps.user_api.tests.factories import UserCourseTagFactory from openedx.core.djangoapps.util.testing import TestConditionalContent from openedx.core.lib.url_utils import quote_slashes @@ -50,14 +50,6 @@ UserFactory, TEST_PASSWORD ) -from lms.djangoapps.courseware.tests.factories import ( - InstructorFactory, - StaffFactory, - BetaTesterFactory, - OrgStaffFactory, - OrgInstructorFactory, - GlobalStaffFactory, -) from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory diff --git a/openedx/features/course_duration_limits/tests/test_course_expiration.py b/openedx/features/course_duration_limits/tests/test_course_expiration.py index 44925d796f4b..1a2cdc0df9cb 100644 --- a/openedx/features/course_duration_limits/tests/test_course_expiration.py +++ b/openedx/features/course_duration_limits/tests/test_course_expiration.py @@ -12,12 +12,6 @@ from course_modes.models import CourseMode from lms.djangoapps.discussion.django_comment_client.tests.factories import RoleFactory -from django_comment_common.models import ( - FORUM_ROLE_ADMINISTRATOR, - FORUM_ROLE_MODERATOR, - FORUM_ROLE_GROUP_MODERATOR, - FORUM_ROLE_COMMUNITY_TA -) from experiments.models import ExperimentData from lms.djangoapps.courseware.tests.factories import ( InstructorFactory, @@ -28,6 +22,12 @@ GlobalStaffFactory, ) from openedx.core.djangoapps.content.course_overviews.models import CourseOverview +from openedx.core.djangoapps.django_comment_common.models import ( + FORUM_ROLE_ADMINISTRATOR, + FORUM_ROLE_MODERATOR, + FORUM_ROLE_GROUP_MODERATOR, + FORUM_ROLE_COMMUNITY_TA +) from openedx.core.djangoapps.schedules.tests.factories import ScheduleFactory from openedx.features.content_type_gating.helpers import CONTENT_GATING_PARTITION_ID, CONTENT_TYPE_GATE_GROUP_IDS from openedx.features.course_duration_limits.access import get_user_course_expiration_date, MIN_DURATION, MAX_DURATION diff --git a/openedx/tests/settings.py b/openedx/tests/settings.py index 1fe06b2d7d21..8bfca798f777 100644 --- a/openedx/tests/settings.py +++ b/openedx/tests/settings.py @@ -60,12 +60,12 @@ FEATURES = {} INSTALLED_APPS = ( - 'django_comment_common', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'djcelery', + 'openedx.core.djangoapps.django_comment_common', 'openedx.core.djangoapps.video_config', 'openedx.core.djangoapps.video_pipeline', 'openedx.core.djangoapps.bookmarks.apps.BookmarksConfig',