Skip to content

Commit

Permalink
refactor: [FC-0031] Move get_profile_image method to api
Browse files Browse the repository at this point in the history
  • Loading branch information
KyryloKireiev authored and OmarIthawi committed May 31, 2024
1 parent da93542 commit 7798746
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lms/djangoapps/discussion/rest_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
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.models import CourseDiscussionSettings
from openedx.core.djangoapps.user_api.accounts.api import get_profile_images
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 @@ -589,7 +589,7 @@ def get_abuse_flagged_any_user(self, obj):

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

def validate(self, attrs):
"""
Expand Down
15 changes: 15 additions & 0 deletions openedx/core/djangoapps/user_api/accounts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
AccountValidationError,
PreferenceValidationError
)
from openedx.core.djangoapps.user_api.accounts.image_helpers import get_profile_image_urls_for_user
from openedx.core.djangoapps.user_api.accounts.serializers import PROFILE_IMAGE_KEY_PREFIX
from openedx.core.djangoapps.user_api.preferences.api import update_user_preferences
from openedx.core.djangoapps.user_authn.utils import check_pwned_password
from openedx.core.djangoapps.user_authn.views.registration_form import validate_name, validate_username
Expand Down Expand Up @@ -510,6 +512,19 @@ def get_email_existence_validation_error(email):
return _validate(_validate_email_doesnt_exist, errors.AccountEmailAlreadyExists, email)


def get_profile_images(user_profile, user, request=None):
"""
Returns metadata about a user's profile image.
"""
data = {'has_image': user_profile.has_profile_image}
urls = get_profile_image_urls_for_user(user, request)
data.update({
f'{PROFILE_IMAGE_KEY_PREFIX}_{size_display_name}': url
for size_display_name, url in urls.items()
})
return data


def _get_user_and_profile(username):
"""
Helper method to return the legacy user and profile objects based on username.
Expand Down

0 comments on commit 7798746

Please sign in to comment.