refactor: [FC-0031] Move get_profile_image method to api
This commit is contained in:
committed by
Glib Glugovskiy
parent
ae3830b023
commit
da9266e31d
@@ -41,8 +41,8 @@ from openedx.core.djangoapps.django_comment_common.comment_client.thread import
|
||||
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()
|
||||
|
||||
@@ -588,7 +588,7 @@ class CommentSerializer(_ContentSerializer):
|
||||
|
||||
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):
|
||||
"""
|
||||
|
||||
@@ -33,6 +33,8 @@ from openedx.core.djangoapps.user_api.errors import (
|
||||
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
|
||||
@@ -524,6 +526,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.
|
||||
|
||||
Reference in New Issue
Block a user