Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cms/djangoapps/contentstore/courseware_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def indexing_is_enabled():
"""
Checks to see if the indexing feature is enabled
"""
return settings.FEATURES.get('ENABLE_COURSEWARE_INDEX', False)
return settings.ENABLE_COURSEWARE_INDEX


class SearchIndexingError(Exception):
Expand Down
4 changes: 2 additions & 2 deletions cms/djangoapps/contentstore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,7 @@ def format_in_process_course_view(uca):
}

courses_iter, in_process_course_actions = get_courses_accessible_to_user(request)
split_archived = settings.FEATURES.get('ENABLE_SEPARATE_ARCHIVED_COURSES', False)
split_archived = settings.ENABLE_SEPARATE_ARCHIVED_COURSES
active_courses, archived_courses = _process_courses_list(courses_iter, in_process_course_actions, split_archived)
in_process_course_actions = [format_in_process_course_view(uca) for uca in in_process_course_actions]
return active_courses, archived_courses, in_process_course_actions
Expand Down Expand Up @@ -1864,7 +1864,7 @@ def _get_course_index_context(request, course_key, course_block):

lms_link = get_lms_link_for_item(course_block.location)
reindex_link = None
if settings.FEATURES.get('ENABLE_COURSEWARE_INDEX', False):
if settings.ENABLE_COURSEWARE_INDEX:
if GlobalStaff().has_user(request.user):
reindex_link = f"/course/{str(course_key)}/search_reindex"
sections = course_block.get_children()
Expand Down
4 changes: 2 additions & 2 deletions cms/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@
name='export_git')
]

if settings.FEATURES.get('ENABLE_SERVICE_STATUS'):
if settings.ENABLE_SERVICE_STATUS:
urlpatterns.append(path('status/', include('openedx.core.djangoapps.service_status.urls')))

# The password pages in the admin tool are disabled so that all password
# changes go through our user portal and follow complexity requirements.
if not settings.FEATURES.get('ENABLE_CHANGE_USER_PASSWORD_ADMIN'):
if not settings.ENABLE_CHANGE_USER_PASSWORD_ADMIN:
urlpatterns.append(re_path(r'^admin/auth/user/\d+/password/$', handler404))
urlpatterns.append(path('admin/password_change/', handler404))
urlpatterns.append(
Expand Down
2 changes: 1 addition & 1 deletion common/djangoapps/student/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ class UserChangeForm(BaseUserChangeForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

if not settings.FEATURES.get('ENABLE_CHANGE_USER_PASSWORD_ADMIN'):
if not settings.ENABLE_CHANGE_USER_PASSWORD_ADMIN:
self.fields["password"] = ReadOnlyPasswordHashField(
label=_("Password"),
help_text=_(
Expand Down
3 changes: 1 addition & 2 deletions common/djangoapps/student/tests/test_enrollment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import ddt
import pytest
from django.conf import settings
from django.test import override_settings
from django.urls import reverse
from openedx_events.testing import OpenEdxEventsTestMixin
Expand Down Expand Up @@ -178,7 +177,7 @@ def test_enrollment_properties_in_segment_traits(self):
assert traits['mode'] == 'verified'
assert traits['email'] == self.EMAIL

@patch.dict(settings.FEATURES, {'ENABLE_MKTG_EMAIL_OPT_IN': True})
@override_settings(ENABLE_MKTG_EMAIL_OPT_IN=True)
@patch('openedx.core.djangoapps.user_api.preferences.api.update_email_opt_in')
@ddt.data(
([], 'true'),
Expand Down
2 changes: 1 addition & 1 deletion common/djangoapps/student/views/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def change_enrollment(request, check_access=True):
return HttpResponseBadRequest(_("Course id is invalid"))

# Record the user's email opt-in preference
if settings.FEATURES.get('ENABLE_MKTG_EMAIL_OPT_IN'):
if getattr(settings, 'ENABLE_MKTG_EMAIL_OPT_IN', False):
_update_email_opt_in(request, course_id.org)

available_modes = CourseMode.modes_for_course_dict(course_id)
Expand Down
4 changes: 2 additions & 2 deletions lms/djangoapps/courseware/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3180,7 +3180,7 @@ def setUp(self):
(CourseMode.MASTERS, True),
)
@ddt.unpack
@patch.dict('django.conf.settings.FEATURES', {'ENABLE_COURSEWARE_SEARCH_VERIFIED_ENROLLMENT_REQUIRED': True})
@override_settings(ENABLE_COURSEWARE_SEARCH_VERIFIED_ENROLLMENT_REQUIRED=True)
def test_courseware_mfe_search_verified_only(self, mode, expected_enabled):
"""
Only verified enrollees may use Courseware Search if ENABLE_COURSEWARE_SEARCH_VERIFIED_ENROLLMENT_REQUIRED
Expand All @@ -3196,7 +3196,7 @@ def test_courseware_mfe_search_verified_only(self, mode, expected_enabled):
self.assertEqual(response.status_code, 200) # noqa: PT009
self.assertEqual(body, {'enabled': expected_enabled}) # noqa: PT009

@patch.dict('django.conf.settings.FEATURES', {'ENABLE_COURSEWARE_SEARCH_VERIFIED_ENROLLMENT_REQUIRED': True})
@override_settings(ENABLE_COURSEWARE_SEARCH_VERIFIED_ENROLLMENT_REQUIRED=True)
def test_courseware_mfe_search_staff_access(self):
"""
Staff users may use Courseware Search regardless of their enrollment status.
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/courseware/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2353,7 +2353,7 @@ def courseware_mfe_search_enabled(request, course_id=None):
user = request.user

has_required_enrollment = False
if settings.FEATURES.get('ENABLE_COURSEWARE_SEARCH_VERIFIED_ENROLLMENT_REQUIRED'):
if settings.ENABLE_COURSEWARE_SEARCH_VERIFIED_ENROLLMENT_REQUIRED:
enrollment_mode, _ = CourseEnrollment.enrollment_mode_for_user(user, course_key)
if (
auth.user_has_role(user, CourseStaffRole(CourseKey.from_string(course_id)))
Expand Down
10 changes: 5 additions & 5 deletions lms/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
RENDER_VIDEO_XBLOCK_EMBED_NAME = 'render_public_video_xblock_embed'
COURSE_PROGRESS_NAME = 'progress'

if settings.DEBUG or settings.FEATURES.get('ENABLE_DJANGO_ADMIN_SITE'):
if settings.DEBUG or settings.ENABLE_DJANGO_ADMIN_SITE:
django_autodiscover()
admin.site.site_header = _('LMS Administration')
admin.site.site_title = admin.site.site_header
Expand Down Expand Up @@ -789,7 +789,7 @@
),
]

if settings.FEATURES.get('ENABLE_STUDENT_HISTORY_VIEW'):
if settings.ENABLE_STUDENT_HISTORY_VIEW:
urlpatterns += [
re_path(
r'^courses/{}/submission_history/(?P<learner_identifier>[^/]*)/(?P<location>.*?)$'.format( # noqa: UP032
Expand All @@ -800,14 +800,14 @@
),
]

if settings.DEBUG or settings.FEATURES.get('ENABLE_DJANGO_ADMIN_SITE'):
if settings.DEBUG or settings.ENABLE_DJANGO_ADMIN_SITE:
# Jasmine and admin

# The password pages in the admin tool are disabled so that all password
# changes go through our user portal and follow complexity requirements.
# The form to change another user's password is conditionally enabled
# for backwards compatibility.
if not settings.FEATURES.get('ENABLE_CHANGE_USER_PASSWORD_ADMIN'):
if not settings.ENABLE_CHANGE_USER_PASSWORD_ADMIN:
urlpatterns += [
re_path(r'^admin/auth/user/\d+/password/$', handler404),
]
Expand Down Expand Up @@ -848,7 +848,7 @@
path('_o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
]

if settings.FEATURES.get('ENABLE_SERVICE_STATUS'):
if settings.ENABLE_SERVICE_STATUS:
urlpatterns += [
path('status/', include('openedx.core.djangoapps.service_status.urls')),
]
Expand Down
10 changes: 5 additions & 5 deletions openedx/core/djangoapps/cors_csrf/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class CorsCSRFMiddleware(CsrfViewMiddleware, MiddlewareMixin):

def __init__(self, *args, **kwargs):
"""Disable the middleware if the feature flag is disabled. """
if not settings.FEATURES.get('ENABLE_CORS_HEADERS'):
if not settings.ENABLE_CORS_HEADERS:
raise MiddlewareNotUsed()
super().__init__(*args, **kwargs)

Expand All @@ -85,7 +85,7 @@ class CsrfCrossDomainCookieMiddleware(MiddlewareMixin):
2) Set `CROSS_DOMAIN_CSRF_COOKIE_NAME` and `CROSS_DOMAIN_CSRF_COOKIE_DOMAIN`
in settings.
3) Add the domain to `CORS_ORIGIN_WHITELIST`
4) Enable `FEATURES['ENABLE_CROSS_DOMAIN_CSRF_COOKIE']`
4) Enable `ENABLE_CROSS_DOMAIN_CSRF_COOKIE`

For testing, it is often easier to relax the security checks by setting:
* `CORS_ALLOW_INSECURE = True`
Expand All @@ -95,19 +95,19 @@ class CsrfCrossDomainCookieMiddleware(MiddlewareMixin):

def __init__(self, *args, **kwargs):
"""Disable the middleware if the feature is not enabled. """
if not settings.FEATURES.get('ENABLE_CROSS_DOMAIN_CSRF_COOKIE'):
if not settings.ENABLE_CROSS_DOMAIN_CSRF_COOKIE:
raise MiddlewareNotUsed()

if not getattr(settings, 'CROSS_DOMAIN_CSRF_COOKIE_NAME', ''):
raise ImproperlyConfigured(
"You must set `CROSS_DOMAIN_CSRF_COOKIE_NAME` when "
"`FEATURES['ENABLE_CROSS_DOMAIN_CSRF_COOKIE']` is True."
"`ENABLE_CROSS_DOMAIN_CSRF_COOKIE` is True."
)

if not getattr(settings, 'CROSS_DOMAIN_CSRF_COOKIE_DOMAIN', ''):
raise ImproperlyConfigured(
"You must set `CROSS_DOMAIN_CSRF_COOKIE_DOMAIN` when "
"`FEATURES['ENABLE_CROSS_DOMAIN_CSRF_COOKIE']` is True."
"`ENABLE_CROSS_DOMAIN_CSRF_COOKIE` is True."
)
super().__init__(*args, **kwargs)

Expand Down
14 changes: 7 additions & 7 deletions openedx/core/djangoapps/cors_csrf/tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_request(self, is_secure, http_referer):
request.is_secure = lambda: is_secure
return request

@override_settings(FEATURES={'ENABLE_CORS_HEADERS': True})
@override_settings(ENABLE_CORS_HEADERS=True)
def setUp(self):
super().setUp()
self.middleware = CorsCSRFMiddleware(get_response=lambda request: None)
Expand Down Expand Up @@ -78,8 +78,8 @@ def test_enabled(self, http_referer):
self.check_enabled(request)

@override_settings(
FEATURES={'ENABLE_CORS_HEADERS': False},
CORS_ORIGIN_WHITELIST=['https://foo.com']
ENABLE_CORS_HEADERS=False,
CORS_ORIGIN_WHITELIST=['https://foo.com'],
)
def test_disabled_no_cors_headers(self):
with pytest.raises(MiddlewareNotUsed):
Expand Down Expand Up @@ -116,23 +116,23 @@ class TestCsrfCrossDomainCookieMiddleware(TestCase):
COOKIE_DOMAIN = '.edx.org'

@override_settings(
FEATURES={'ENABLE_CROSS_DOMAIN_CSRF_COOKIE': True},
ENABLE_CROSS_DOMAIN_CSRF_COOKIE=True,
CROSS_DOMAIN_CSRF_COOKIE_NAME=COOKIE_NAME,
CROSS_DOMAIN_CSRF_COOKIE_DOMAIN=COOKIE_DOMAIN
CROSS_DOMAIN_CSRF_COOKIE_DOMAIN=COOKIE_DOMAIN,
)
def setUp(self):
super().setUp()
self.middleware = CsrfCrossDomainCookieMiddleware(get_response=lambda request: None)

@override_settings(FEATURES={'ENABLE_CROSS_DOMAIN_CSRF_COOKIE': False})
@override_settings(ENABLE_CROSS_DOMAIN_CSRF_COOKIE=False)
def test_disabled_by_feature_flag(self):
with pytest.raises(MiddlewareNotUsed):
CsrfCrossDomainCookieMiddleware(get_response=lambda request: None)

@ddt.data('CROSS_DOMAIN_CSRF_COOKIE_NAME', 'CROSS_DOMAIN_CSRF_COOKIE_DOMAIN')
def test_improperly_configured(self, missing_setting):
settings = {
'FEATURES': {'ENABLE_CROSS_DOMAIN_CSRF_COOKIE': True},
'ENABLE_CROSS_DOMAIN_CSRF_COOKIE': True,
'CROSS_DOMAIN_CSRF_COOKIE_NAME': self.COOKIE_NAME,
'CROSS_DOMAIN_CSRF_COOKIE_DOMAIN': self.COOKIE_DOMAIN
}
Expand Down
15 changes: 4 additions & 11 deletions openedx/core/djangoapps/enrollments/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import ddt
import httpretty
import pytest
from django.conf import settings
from django.core.cache import cache
from django.core.exceptions import ImproperlyConfigured
from django.core.handlers.wsgi import WSGIRequest
Expand Down Expand Up @@ -1433,22 +1432,16 @@ def test_embargo_change_enrollment_allow(self):

def cross_domain_config(func):
"""Decorator for configuring a cross-domain request. """
feature_flag_decorator = patch.dict(settings.FEATURES, {
'ENABLE_CORS_HEADERS': True,
'ENABLE_CROSS_DOMAIN_CSRF_COOKIE': True
})
settings_decorator = override_settings(
ENABLE_CORS_HEADERS=True,
ENABLE_CROSS_DOMAIN_CSRF_COOKIE=True,
CORS_ORIGIN_WHITELIST=["https://www.edx.org"],
CROSS_DOMAIN_CSRF_COOKIE_NAME="prod-edx-csrftoken",
CROSS_DOMAIN_CSRF_COOKIE_DOMAIN=".edx.org"
CROSS_DOMAIN_CSRF_COOKIE_DOMAIN=".edx.org",
)
is_secure_decorator = patch.object(WSGIRequest, 'is_secure', return_value=True)

return feature_flag_decorator(
settings_decorator(
is_secure_decorator(func)
)
)
return settings_decorator(is_secure_decorator(func))


@skip_unless_lms
Expand Down
Loading