Skip to content

Commit

Permalink
feat: [AXIM-20] Add profile_image to API CommentViewSet
Browse files Browse the repository at this point in the history
  • Loading branch information
KyryloKireiev authored and GlugovGrGlib committed Nov 14, 2023
1 parent 034d632 commit ae3830b
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lms/djangoapps/discussion/rest_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from openedx.core.djangoapps.django_comment_common.comment_client.utils import CommentClientRequestError
from openedx.core.djangoapps.django_comment_common.models import CourseDiscussionSettings
from openedx.core.lib.api.serializers import CourseKeyField
from openedx.core.djangoapps.user_api.accounts.serializers import AccountLegacyProfileSerializer

User = get_user_model()

Expand Down Expand Up @@ -502,6 +503,7 @@ class CommentSerializer(_ContentSerializer):
child_count = serializers.IntegerField(read_only=True)
children = serializers.SerializerMethodField(required=False)
abuse_flagged_any_user = serializers.SerializerMethodField(required=False)
profile_image = serializers.SerializerMethodField(read_only=True)

non_updatable_fields = NON_UPDATABLE_COMMENT_FIELDS

Expand Down Expand Up @@ -584,6 +586,10 @@ def get_abuse_flagged_any_user(self, obj):
if _validate_privileged_access(self.context):
return len(obj.get("abuse_flaggers", [])) > 0

def get_profile_image(self, obj):
request = self.context["request"]
return AccountLegacyProfileSerializer.get_profile_image(request.user.profile, request.user, request)

def validate(self, attrs):
"""
Ensure that parent_id identifies a comment that is actually in the
Expand Down
35 changes: 35 additions & 0 deletions lms/djangoapps/discussion/rest_api/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,13 @@ def test_discussion_content(self):
"anonymous_to_peers": False,
"last_edit": None,
"edit_by_label": None,
"profile_image": {
"has_image": False,
"image_url_full": "http://testserver/static/default_500.png",
"image_url_large": "http://testserver/static/default_120.png",
"image_url_medium": "http://testserver/static/default_50.png",
"image_url_small": "http://testserver/static/default_30.png",
},
},
{
"id": "test_comment_2",
Expand Down Expand Up @@ -1505,6 +1512,13 @@ def test_discussion_content(self):
"anonymous_to_peers": False,
"last_edit": None,
"edit_by_label": None,
"profile_image": {
"has_image": False,
"image_url_full": "http://testserver/static/default_500.png",
"image_url_large": "http://testserver/static/default_120.png",
"image_url_medium": "http://testserver/static/default_50.png",
"image_url_small": "http://testserver/static/default_30.png",
},
},
]
actual_comments = self.get_comment_list(
Expand Down Expand Up @@ -2252,6 +2266,13 @@ def test_success(self, parent_id, mock_emit):
"anonymous_to_peers": False,
"last_edit": None,
"edit_by_label": None,
"profile_image": {
"has_image": False,
"image_url_full": "http://testserver/static/default_500.png",
"image_url_large": "http://testserver/static/default_120.png",
"image_url_medium": "http://testserver/static/default_50.png",
"image_url_small": "http://testserver/static/default_30.png",
},
}
assert actual == expected
expected_url = (
Expand Down Expand Up @@ -2352,6 +2373,13 @@ def test_success_in_black_out_with_user_access(self, parent_id, mock_emit):
"anonymous_to_peers": False,
"last_edit": None,
"edit_by_label": None,
"profile_image": {
"has_image": False,
"image_url_full": "http://testserver/static/default_500.png",
"image_url_large": "http://testserver/static/default_120.png",
"image_url_medium": "http://testserver/static/default_50.png",
"image_url_small": "http://testserver/static/default_30.png",
},
}
assert actual == expected
expected_url = (
Expand Down Expand Up @@ -3188,6 +3216,13 @@ def test_basic(self, parent_id):
"can_delete": True,
"last_edit": None,
"edit_by_label": None,
"profile_image": {
"has_image": False,
"image_url_full": "http://testserver/static/default_500.png",
"image_url_large": "http://testserver/static/default_120.png",
"image_url_medium": "http://testserver/static/default_50.png",
"image_url_small": "http://testserver/static/default_30.png",
},
}
assert actual == expected
assert parsed_body(httpretty.last_request()) == {
Expand Down
7 changes: 7 additions & 0 deletions lms/djangoapps/discussion/rest_api/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,13 @@ def test_basic(self):
"can_delete": False,
"last_edit": None,
"edit_by_label": None,
"profile_image": {
"has_image": False,
"image_url_full": "http://testserver/static/default_500.png",
"image_url_large": "http://testserver/static/default_120.png",
"image_url_medium": "http://testserver/static/default_50.png",
"image_url_small": "http://testserver/static/default_30.png",
},
}

assert self.serialize(comment) == expected
Expand Down
28 changes: 28 additions & 0 deletions lms/djangoapps/discussion/rest_api/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1972,6 +1972,13 @@ def expected_response_comment(self, overrides=None):
"anonymous_to_peers": False,
"last_edit": None,
"edit_by_label": None,
"profile_image": {
"has_image": False,
"image_url_full": "http://testserver/static/default_500.png",
"image_url_large": "http://testserver/static/default_120.png",
"image_url_medium": "http://testserver/static/default_50.png",
"image_url_small": "http://testserver/static/default_30.png",
},
}
response_data.update(overrides or {})
return response_data
Expand Down Expand Up @@ -2398,6 +2405,13 @@ def test_basic(self):
"anonymous_to_peers": False,
"last_edit": None,
"edit_by_label": None,
"profile_image": {
"has_image": False,
"image_url_full": "http://testserver/static/default_500.png",
"image_url_large": "http://testserver/static/default_120.png",
"image_url_medium": "http://testserver/static/default_50.png",
"image_url_small": "http://testserver/static/default_30.png",
},
}
response = self.client.post(
self.url,
Expand Down Expand Up @@ -2490,6 +2504,13 @@ def expected_response_data(self, overrides=None):
"anonymous_to_peers": False,
"last_edit": None,
"edit_by_label": None,
"profile_image": {
"has_image": False,
"image_url_full": "http://testserver/static/default_500.png",
"image_url_large": "http://testserver/static/default_120.png",
"image_url_medium": "http://testserver/static/default_50.png",
"image_url_small": "http://testserver/static/default_30.png",
},
}
response_data.update(overrides or {})
return response_data
Expand Down Expand Up @@ -2680,6 +2701,13 @@ def test_basic(self):
"anonymous_to_peers": False,
"last_edit": None,
"edit_by_label": None,
"profile_image": {
"has_image": False,
"image_url_full": "http://testserver/static/default_500.png",
"image_url_large": "http://testserver/static/default_120.png",
"image_url_medium": "http://testserver/static/default_50.png",
"image_url_small": "http://testserver/static/default_30.png",
},
}

response = self.client.get(self.url)
Expand Down

0 comments on commit ae3830b

Please sign in to comment.