Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cherry pick mobile apis #29

Merged
merged 24 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e193555
feat: [AXIM-44] Adapt Delete Account to Bearer Authorization
Sep 8, 2023
a677b68
fix: (review) Add comment to Delete Account view
KyryloKireiev Sep 25, 2023
0a5110c
fix: [AXIM-50] Fix count items in pagination
Sep 12, 2023
9060663
feat: list courses details by keys
yusuf-musleh Jun 26, 2023
b7f4923
fix: [FC-0031] Add limit the number of returned results for mobile_se…
KyryloKireiev Nov 1, 2023
1100983
feat: [AXIM-6] Add DefaultPagination for UserCourseEnrollmentsList v3
KyryloKireiev Sep 12, 2023
51f0ebe
docs: add docstring for the paginator property override
GlugovGrGlib Nov 20, 2023
b739c00
fix: remove trailing whitespace failing quality check
GlugovGrGlib Nov 20, 2023
25577e2
feat: add tracking event for following post
Oct 4, 2023
8b94c2c
feat: added edit_by_label and closed_by_label in threads response (#3…
muhammadadeeltajamul Apr 19, 2023
da93542
feat: [AXIM-20] Add profile_image to API CommentViewSet
KyryloKireiev Sep 13, 2023
7798746
refactor: [FC-0031] Move get_profile_image method to api
KyryloKireiev Nov 8, 2023
e0b4d50
fix: remove duplicate implementation and correct the docstring
GlugovGrGlib Nov 13, 2023
f37ddd3
feat: [AXIM-26] Extended BlocksInCourseView API
KyryloKireiev Sep 15, 2023
3bb8ebc
fix: [FC-0031] Add parameters description, refactor list method
KyryloKireiev Oct 30, 2023
462c780
refactor: [FC-0031] Use serializer instead of custom function
KyryloKireiev Dec 15, 2023
fd3d355
docs: [FC-0031] Update docstring
GlugovGrGlib Dec 19, 2023
4d179d6
feat: [FC-0031] Add optional field 'is_enrolled' to course detail view
KyryloKireiev Oct 31, 2023
5c1fff6
fix: [FC-0031] Restrict access to is_enrolled field
GlugovGrGlib Dec 15, 2023
8a43fac
feat(mobile_api): Add course access object to mobile course info API …
GlugovGrGlib Apr 25, 2024
fb0f16a
fix: discussion tab should be None if discussion tab is disabled (#33…
muhammadadeeltajamul Dec 11, 2023
79756e8
feat: Added upgrade deadline in blocks api (#34750)
jawad-khan May 9, 2024
37b7549
feat: Add course price in mobile enrollment api (#34255)
jawad-khan Feb 19, 2024
83ead13
temp: fix TestDiscussionCourseEnrollmentSerializer.test_discussion_ta…
OmarIthawi Jun 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: discussion tab should be None if discussion tab is disabled (ope…
  • Loading branch information
muhammadadeeltajamul authored and OmarIthawi committed May 31, 2024
commit fb0f16a1336b6d3a9ec7b4f76afa70cd34677ec4
3 changes: 1 addition & 2 deletions lms/djangoapps/mobile_api/users/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def to_representation(self, course_overview): # lint-amnesty, pylint: disable=a
request = self.context.get('request')
api_version = self.context.get('api_version')
enrollment = CourseEnrollment.get_enrollment(user=self.context.get('request').user, course_key=course_id)

return {
# identifiers
'id': course_id,
Expand Down Expand Up @@ -74,7 +73,7 @@ def to_representation(self, course_overview): # lint-amnesty, pylint: disable=a
'discussion_course',
kwargs={'course_id': course_id},
request=request,
) if course_overview.is_discussion_tab_enabled() else None,
) if course_overview.is_discussion_tab_enabled(request.user) else None,

# This is an old API that was removed as part of DEPR-4. We keep the
# field present in case API parsers expect it, but this API is now
Expand Down
49 changes: 49 additions & 0 deletions lms/djangoapps/mobile_api/users/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
)
from lms.djangoapps.mobile_api.utils import API_V1, API_V05, API_V2, API_V3
from openedx.core.lib.courses import course_image_url
from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration
from openedx.features.course_duration_limits.models import CourseDurationLimitConfig
from openedx.features.course_experience.tests.views.helpers import add_course_mode
from xmodule.course_block import DEFAULT_START_DATE # lint-amnesty, pylint: disable=wrong-import-order
Expand Down Expand Up @@ -713,3 +714,51 @@ def test_with_display_overrides(self, api_version):
assert serialized['course']['number'] == self.course.display_coursenumber
assert serialized['course']['org'] == self.course.display_organization
self._expiration_in_response(serialized, api_version)


@ddt.ddt
class TestDiscussionCourseEnrollmentSerializer(UrlResetMixin, MobileAPITestCase, MilestonesTestCaseMixin):
"""
Tests discussion data in course enrollment serializer
"""

def setUp(self):
"""
Setup data for test
"""
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_DISCUSSION_SERVICE': True}):
super().setUp()
self.login_and_enroll()
self.request = RequestFactory().get('/')
self.request.user = self.user

def get_serialized_data(self, api_version):
"""
Return data from CourseEnrollmentSerializer
"""
if api_version == API_V05:
serializer = CourseEnrollmentSerializerv05
else:
serializer = CourseEnrollmentSerializer

return serializer(
CourseEnrollment.enrollments_for_user(self.user)[0],
context={'request': self.request, 'api_version': api_version},
).data

@ddt.data(True, False)
def test_discussion_tab_url(self, discussion_tab_enabled):
"""
Tests discussion tab url is None if tab is disabled
"""
config, _ = DiscussionsConfiguration.objects.get_or_create(context_key=self.course.id)
config.enabled = discussion_tab_enabled
config.save()
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_DISCUSSION_SERVICE': True}):
serialized = self.get_serialized_data(API_V2)
discussion_url = serialized["course"]["discussion_url"]
if discussion_tab_enabled:
assert discussion_url is not None
assert isinstance(discussion_url, str)
else:
assert discussion_url is None
9 changes: 5 additions & 4 deletions openedx/core/djangoapps/content/course_overviews/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from opaque_keys.edx.django.models import CourseKeyField, UsageKeyField
from simple_history.models import HistoricalRecords

from lms.djangoapps.discussion import django_comment_client
from openedx.core.djangoapps.catalog.models import CatalogIntegration
from openedx.core.djangoapps.lang_pref.api import get_closest_released_language
from openedx.core.djangoapps.models.course_details import CourseDetails
Expand Down Expand Up @@ -702,15 +701,17 @@ def get_all_course_keys(cls):
"""
return CourseOverview.objects.values_list('id', flat=True)

def is_discussion_tab_enabled(self):
def is_discussion_tab_enabled(self, user=None):
"""
Returns True if course has discussion tab and is enabled
"""
# Importing here to avoid circular import
from lms.djangoapps.discussion.plugins import DiscussionTab
tabs = self.tab_set.all()
# creates circular import; hence explicitly referenced is_discussion_enabled
for tab in tabs:
if tab.tab_id == "discussion" and django_comment_client.utils.is_discussion_enabled(self.id):
return True
if tab.tab_id == "discussion":
return DiscussionTab.is_enabled(self, user)
return False

@property
Expand Down
Loading