Revert "feat: refactor country disable logic into the Embargo app (#36202)" (#36393)

This reverts commit 72959ad9d5.
This commit is contained in:
Ahtisham Shahid
2025-03-17 23:55:59 +05:00
committed by GitHub
parent f700c89357
commit e7100d813f
10 changed files with 62 additions and 212 deletions

View File

@@ -9,11 +9,10 @@ import re
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.core.validators import ValidationError, validate_email
from django.utils.translation import gettext as _
from django.utils.translation import override as override_language
from django.utils.translation import gettext as _
from eventtracking import tracker
from pytz import UTC
from common.djangoapps.student import views as student_views
from common.djangoapps.student.models import (
AccountRecovery,
@@ -26,7 +25,7 @@ from common.djangoapps.util.model_utils import emit_settings_changed_event
from common.djangoapps.util.password_policy_validators import validate_password
from lms.djangoapps.certificates.api import get_certificates_for_user
from lms.djangoapps.certificates.data import CertificateStatuses
from openedx.core.djangoapps.embargo.models import GlobalRestrictedCountry
from openedx.core.djangoapps.enrollments.api import get_verified_enrollments
from openedx.core.djangoapps.user_api import accounts, errors, helpers
from openedx.core.djangoapps.user_api.errors import (
@@ -40,7 +39,6 @@ from openedx.core.djangoapps.user_authn.views.registration_form import validate_
from openedx.core.lib.api.view_utils import add_serializer_errors
from openedx.features.enterprise_support.utils import get_enterprise_readonly_account_fields
from openedx.features.name_affirmation_api.utils import is_name_affirmation_installed
from .serializers import AccountLegacyProfileSerializer, AccountUserSerializer, UserReadOnlySerializer, _visible_fields
name_affirmation_installed = is_name_affirmation_installed()
@@ -153,10 +151,7 @@ def update_account_settings(requesting_user, update, username=None):
_validate_email_change(user, update, field_errors)
_validate_secondary_email(user, update, field_errors)
if (
settings.FEATURES.get('EMBARGO', False) and
GlobalRestrictedCountry.is_country_restricted(update.get('country', ''))
):
if update.get('country', '') in settings.DISABLED_COUNTRIES:
field_errors['country'] = {
'developer_message': 'Country is disabled for registration',
'user_message': 'This country cannot be selected for user registration'

View File

@@ -7,19 +7,18 @@ import datetime
import itertools
import unicodedata
from unittest.mock import Mock, patch
import ddt
import pytest
import ddt
from django.conf import settings
from django.contrib.auth.hashers import make_password
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
from django.http import HttpResponse
from django.test import TestCase
from django.test.client import RequestFactory
from django.test.utils import override_settings
from django.urls import reverse
from pytz import UTC
from social_django.models import UserSocialAuth
from common.djangoapps.student.models import (
AccountRecovery,
PendingEmailChange,
@@ -29,14 +28,14 @@ from common.djangoapps.student.models import (
from common.djangoapps.student.tests.factories import UserFactory
from common.djangoapps.student.tests.tests import UserSettingsEventTestMixin
from common.djangoapps.student.views.management import activate_secondary_email
from lms.djangoapps.certificates.data import CertificateStatuses
from openedx.core.djangoapps.ace_common.tests.mixins import EmailTemplateTagMixin
from openedx.core.djangoapps.embargo.models import Country, GlobalRestrictedCountry
from openedx.core.djangoapps.user_api.accounts import PRIVATE_VISIBILITY
from openedx.core.djangoapps.user_api.accounts.api import (
get_account_settings,
get_name_validation_error,
update_account_settings
update_account_settings,
get_name_validation_error
)
from openedx.core.djangoapps.user_api.accounts.tests.retirement_helpers import ( # pylint: disable=unused-import
RetirementTestCase,
@@ -575,14 +574,12 @@ class TestAccountApi(UserSettingsEventTestMixin, EmailTemplateTagMixin, CreateAc
assert account_settings['country'] is None
assert account_settings['state'] is None
@override_settings(DISABLED_COUNTRIES=['KP'])
def test_change_to_disabled_country(self):
"""
Test that changing the country to a disabled country is not allowed
"""
# First set the country and state
country = Country.objects.create(country="KP")
GlobalRestrictedCountry.objects.create(country=country)
update_account_settings(self.user, {"country": UserProfile.COUNTRY_WITH_STATES, "state": "MA"})
account_settings = get_account_settings(self.default_request)[0]
assert account_settings['country'] == UserProfile.COUNTRY_WITH_STATES