Skip to content

Commit 0a7d894

Browse files
authored
feat: removed age restriction on profile image upload (#36857)
* feat: removed age restriction on profile image upload * test: updated test files * test: updated test files * fix: fixed lint issues * test: updated test files * fix: fixed lint issues
1 parent 714303d commit 0a7d894

4 files changed

Lines changed: 16 additions & 44 deletions

File tree

common/djangoapps/student/models/user.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -696,10 +696,6 @@ def user_profile_pre_save_callback(sender, **kwargs):
696696
"""
697697
user_profile = kwargs['instance']
698698

699-
# Remove profile images for users who require parental consent
700-
if user_profile.requires_parental_consent() and user_profile.has_profile_image:
701-
user_profile.profile_image_uploaded_at = None
702-
703699
# Cache "old" field values on the model instance so that they can be
704700
# retrieved in the post_save callback when we emit an event with new and
705701
# old field values.

common/djangoapps/student/tests/test_parental_controls.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,3 @@ def test_child_user(self):
6565
self.set_year_of_birth(current_year - 14)
6666
assert not self.profile.requires_parental_consent()
6767
assert not self.profile.requires_parental_consent(year=current_year)
68-
69-
def test_profile_image(self):
70-
"""Verify that a profile's image obeys parental controls."""
71-
72-
# Verify that an image cannot be set for a user with no year of birth set
73-
self.profile.profile_image_uploaded_at = now()
74-
self.profile.save()
75-
assert not self.profile.has_profile_image
76-
77-
# Verify that an image can be set for an adult user
78-
current_year = now().year
79-
self.set_year_of_birth(current_year - 20)
80-
self.profile.profile_image_uploaded_at = now()
81-
self.profile.save()
82-
assert self.profile.has_profile_image
83-
84-
# verify that a user's profile image is removed when they switch to requiring parental controls
85-
self.set_year_of_birth(current_year - 10)
86-
self.profile.save()
87-
assert not self.profile.has_profile_image

openedx/core/djangoapps/user_api/accounts/tests/test_views.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,17 +403,18 @@ def _verify_full_shareable_account_response(self, response, account_privacy=None
403403
assert data['social_links'] is not None
404404
assert data['time_zone'] is None
405405

406-
def _verify_private_account_response(self, response, requires_parental_consent=False):
406+
def _verify_private_account_response(self, response, requires_parental_consent=False, has_profile_image=True):
407407
"""
408408
Verify that only the public fields are returned if a user does not want to share account fields
409409
"""
410410
data = response.data
411411
assert 3 == len(data)
412412
assert PRIVATE_VISIBILITY == data['account_privacy']
413-
self._verify_profile_image_data(data, not requires_parental_consent)
413+
self._verify_profile_image_data(data, has_profile_image)
414414
assert self.user.username == data['username']
415415

416-
def _verify_full_account_response(self, response, requires_parental_consent=False, year_of_birth=2000):
416+
def _verify_full_account_response(self, response, requires_parental_consent=False,
417+
has_profile_image=True, year_of_birth=2000):
417418
"""
418419
Verify that all account fields are returned (even those that are not shareable).
419420
"""
@@ -426,7 +427,7 @@ def _verify_full_account_response(self, response, requires_parental_consent=Fals
426427
UserPreference.get_value(self.user, 'account_privacy')
427428
)
428429
assert expected_account_privacy == data['account_privacy']
429-
self._verify_profile_image_data(data, not requires_parental_consent)
430+
self._verify_profile_image_data(data, has_profile_image)
430431
assert self.user.username == data['username']
431432

432433
# additional shareable fields (8)
@@ -1271,11 +1272,11 @@ def test_parental_consent(self, api_client, requesting_username, has_full_access
12711272
assert data['requires_parental_consent']
12721273
assert PRIVATE_VISIBILITY == data['account_privacy']
12731274
else:
1274-
self._verify_private_account_response(response, requires_parental_consent=True)
1275+
self._verify_private_account_response(response, requires_parental_consent=True, has_profile_image=False)
12751276

12761277
# Verify that the shared view is still private
12771278
response = self.send_get(client, query_parameters='view=shared')
1278-
self._verify_private_account_response(response, requires_parental_consent=True)
1279+
self._verify_private_account_response(response, requires_parental_consent=True, has_profile_image=False)
12791280

12801281

12811282
@skip_unless_lms

openedx/core/djangoapps/user_authn/tests/test_cookies.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# pylint: disable=missing-docstring
22

33

4-
from datetime import date
4+
from datetime import date, datetime
55
import json
6+
from pytz import UTC
67
from unittest.mock import MagicMock, patch
78
from urllib.parse import urljoin
89
from django.conf import settings
@@ -20,13 +21,19 @@
2021
from openedx.core.djangoapps.profile_images.tests.helpers import make_image_file
2122
from openedx.core.djangoapps.profile_images.images import create_profile_images
2223
from openedx.core.djangoapps.user_api.accounts.image_helpers import get_profile_image_names
24+
from openedx.core.djangoapps.user_api.accounts.image_helpers import get_profile_image_urls_for_user
25+
26+
27+
TEST_PROFILE_IMAGE_UPLOAD_DT = datetime(2002, 1, 9, 15, 43, 1, tzinfo=UTC)
2328

2429

2530
class CookieTests(TestCase):
2631
def setUp(self):
2732
super().setUp()
2833
self.user = UserFactory.create()
2934
self.user.profile = UserProfileFactory.create(user=self.user)
35+
self.user.profile.profile_image_uploaded_at = TEST_PROFILE_IMAGE_UPLOAD_DT
36+
self.user.profile.save() # lint-amnesty, pylint: disable=no-member
3037
self.request = RequestFactory().get('/')
3138
self.request.user = self.user
3239
self.request.session = self._get_stub_session()
@@ -43,18 +50,6 @@ def _convert_to_absolute_uris(self, request, urls_obj):
4350

4451
return urls_obj
4552

46-
def _get_expected_image_urls(self):
47-
expected_image_urls = {
48-
'full': '/static/default_500.png',
49-
'large': '/static/default_120.png',
50-
'medium': '/static/default_50.png',
51-
'small': '/static/default_30.png'
52-
}
53-
54-
expected_image_urls = self._convert_to_absolute_uris(self.request, expected_image_urls)
55-
56-
return expected_image_urls
57-
5853
def _get_expected_header_urls(self):
5954
expected_header_urls = {
6055
'logout': reverse('logout'),
@@ -112,7 +107,7 @@ def test_get_user_info_cookie_data(self):
112107
'username': self.user.username,
113108
'email': self.user.email,
114109
'header_urls': self._get_expected_header_urls(),
115-
'user_image_urls': self._get_expected_image_urls(),
110+
'user_image_urls': get_profile_image_urls_for_user(self.user),
116111
}
117112

118113
self.assertDictEqual(actual, expected)

0 commit comments

Comments
 (0)