From d585a8f71d357c0d58fd197202eb283741238821 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Tue, 17 Sep 2019 16:16:42 -0400 Subject: [PATCH] URLs and settings for OpenAPI generation API docs are now always available, no more toggle to enable them. --- cms/envs/common.py | 7 ++++--- cms/envs/devstack.py | 7 +++---- cms/envs/production.py | 3 +++ cms/urls.py | 19 +++++++++++++------ lms/envs/common.py | 6 +++--- lms/envs/devstack.py | 6 ++---- lms/envs/production.py | 3 +++ lms/envs/test.py | 2 -- lms/tests.py | 1 - lms/urls.py | 19 +++++++++++++------ 10 files changed, 44 insertions(+), 29 deletions(-) diff --git a/cms/envs/common.py b/cms/envs/common.py index fad19c78ea..93efbdb523 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -305,9 +305,6 @@ FEATURES = { # Prevent auto auth from creating superusers or modifying existing users 'RESTRICT_AUTOMATIC_AUTH': True, - - # Set this to true to make API docs available at /api-docs/. - 'ENABLE_API_DOCS': False, } ENABLE_JASMINE = False @@ -1802,6 +1799,10 @@ COURSE_ABOUT_VISIBILITY_PERMISSION = 'see_exists' DEFAULT_COURSE_VISIBILITY_IN_CATALOG = "both" DEFAULT_MOBILE_AVAILABLE = False + +# How long to cache OpenAPI schemas and UI, in seconds. +OPENAPI_CACHE_TIMEOUT = 0 + ################# Mobile URLS ########################## # These are URLs to the app store for mobile. diff --git a/cms/envs/devstack.py b/cms/envs/devstack.py index 67cde0116d..78b3939f7b 100644 --- a/cms/envs/devstack.py +++ b/cms/envs/devstack.py @@ -105,10 +105,6 @@ def should_show_debug_toolbar(request): return True -########################### API DOCS ################################# - -FEATURES['ENABLE_API_DOCS'] = True - ################################ MILESTONES ################################ FEATURES['MILESTONES_APP'] = True @@ -186,6 +182,9 @@ from openedx.core.djangoapps.plugins import constants as plugin_constants, plugi plugin_settings.add_plugins(__name__, plugin_constants.ProjectType.CMS, plugin_constants.SettingsType.DEVSTACK) + +OPENAPI_CACHE_TIMEOUT = 0 + ############################################################################### # See if the developer has any local overrides. if os.path.isfile(join(dirname(abspath(__file__)), 'private.py')): diff --git a/cms/envs/production.py b/cms/envs/production.py index 5fa8a79300..26e477c47a 100644 --- a/cms/envs/production.py +++ b/cms/envs/production.py @@ -135,6 +135,9 @@ DEFAULT_MOBILE_AVAILABLE = ENV_TOKENS.get( DEFAULT_MOBILE_AVAILABLE ) +# How long to cache OpenAPI schemas and UI, in seconds. +OPENAPI_CACHE_TIMEOUT = ENV_TOKENS.get('OPENAPI_CACHE_TIMEOUT', 60 * 60) + # MEDIA_ROOT specifies the directory where user-uploaded files are stored. MEDIA_ROOT = ENV_TOKENS.get('MEDIA_ROOT', MEDIA_ROOT) MEDIA_URL = ENV_TOKENS.get('MEDIA_URL', MEDIA_URL) diff --git a/cms/urls.py b/cms/urls.py index ab925b24d7..81cb89df43 100644 --- a/cms/urls.py +++ b/cms/urls.py @@ -270,12 +270,19 @@ urlpatterns += [ url(r'^500$', handler500), ] -if settings.FEATURES.get('ENABLE_API_DOCS'): - urlpatterns += [ - url(r'^swagger(?P\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'), - url(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), - url(r'^api-docs/$', schema_view.with_ui('swagger', cache_timeout=0)), - ] +# API docs. +urlpatterns += [ + url( + r'^swagger(?P\.json|\.yaml)$', + schema_view.without_ui(cache_timeout=settings.OPENAPI_CACHE_TIMEOUT), name='schema-json', + ), + url( + r'^swagger/$', + schema_view.with_ui('swagger', cache_timeout=settings.OPENAPI_CACHE_TIMEOUT), + name='schema-swagger-ui', + ), + url(r'^api-docs/$', schema_view.with_ui('swagger', cache_timeout=settings.OPENAPI_CACHE_TIMEOUT)), +] if 'openedx.testing.coverage_context_listener' in settings.INSTALLED_APPS: urlpatterns += [ diff --git a/lms/envs/common.py b/lms/envs/common.py index eadc7b842b..e286ae39c0 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -411,9 +411,6 @@ FEATURES = { # Sets the default browser support. For more information go to http://browser-update.org/customize.html 'UNSUPPORTED_BROWSER_ALERT_VERSIONS': "{i:10,f:-3,o:-3,s:-3,c:-3}", - # Set this to true to make API docs available at /api-docs/. - 'ENABLE_API_DOCS': False, - # Whether to display the account deletion section the account settings page 'ENABLE_ACCOUNT_DELETION': True, @@ -2530,6 +2527,9 @@ SWAGGER_SETTINGS = { 'DEFAULT_INFO': 'openedx.core.openapi.openapi_info', } +# How long to cache OpenAPI schemas and UI, in seconds. +OPENAPI_CACHE_TIMEOUT = 0 + ######################### MARKETING SITE ############################### EDXMKTG_LOGGED_IN_COOKIE_NAME = 'edxloggedin' EDXMKTG_USER_INFO_COOKIE_NAME = 'edx-user-info' diff --git a/lms/envs/devstack.py b/lms/envs/devstack.py index 4f8a9a7c53..c0043304b9 100644 --- a/lms/envs/devstack.py +++ b/lms/envs/devstack.py @@ -100,10 +100,6 @@ def should_show_debug_toolbar(request): return False return True -########################### API DOCS ################################# - -FEATURES['ENABLE_API_DOCS'] = True - ########################### PIPELINE ################################# PIPELINE['PIPELINE_ENABLED'] = False @@ -282,6 +278,8 @@ REST_FRAMEWORK['DEFAULT_RENDERER_CLASSES'] += ( 'rest_framework.renderers.BrowsableAPIRenderer', ) +OPENAPI_CACHE_TIMEOUT = 0 + ##################################################################### # See if the developer has any local overrides. if os.path.isfile(join(dirname(abspath(__file__)), 'private.py')): diff --git a/lms/envs/production.py b/lms/envs/production.py index 291e26dffd..554dccbed2 100644 --- a/lms/envs/production.py +++ b/lms/envs/production.py @@ -1051,6 +1051,9 @@ ICP_LICENSE_INFO = ENV_TOKENS.get('ICP_LICENSE_INFO', {}) ############## Settings for CourseGraph ############################ COURSEGRAPH_JOB_QUEUE = ENV_TOKENS.get('COURSEGRAPH_JOB_QUEUE', DEFAULT_PRIORITY_QUEUE) +# How long to cache OpenAPI schemas and UI, in seconds. +OPENAPI_CACHE_TIMEOUT = ENV_TOKENS.get('OPENAPI_CACHE_TIMEOUT', 60 * 60) + ########################## Parental controls config ####################### # The age at which a learner no longer requires parental consent, or None diff --git a/lms/envs/test.py b/lms/envs/test.py index 2557ebeb10..02954e2630 100644 --- a/lms/envs/test.py +++ b/lms/envs/test.py @@ -91,8 +91,6 @@ FEATURES['ENABLE_ENROLLMENT_TRACK_USER_PARTITION'] = True FEATURES['ENABLE_BULK_ENROLLMENT_VIEW'] = True -FEATURES['ENABLE_API_DOCS'] = True - DEFAULT_MOBILE_AVAILABLE = True # Need wiki for courseware views to work. TODO (vshnayder): shouldn't need it. diff --git a/lms/tests.py b/lms/tests.py index 3cf88ca084..dcca4359df 100644 --- a/lms/tests.py +++ b/lms/tests.py @@ -28,6 +28,5 @@ class LmsModuleTests(TestCase): """ Tests that requests to the `/api-docs/` endpoint do not raise an exception. """ - assert settings.FEATURES['ENABLE_API_DOCS'] response = self.client.get('/api-docs/') self.assertEqual(200, response.status_code) diff --git a/lms/urls.py b/lms/urls.py index bab81e9df0..e6c4c68de4 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -949,12 +949,19 @@ if settings.BRANCH_IO_KEY: url(r'^text-me-the-app', student_views.text_me_the_app, name='text_me_the_app'), ] -if settings.FEATURES.get('ENABLE_API_DOCS'): - urlpatterns += [ - url(r'^swagger(?P\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'), - url(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), - url(r'^api-docs/$', schema_view.with_ui('swagger', cache_timeout=0)), - ] +# API docs. +urlpatterns += [ + url( + r'^swagger(?P\.json|\.yaml)$', + schema_view.without_ui(cache_timeout=settings.OPENAPI_CACHE_TIMEOUT), name='schema-json', + ), + url( + r'^swagger/$', + schema_view.with_ui('swagger', cache_timeout=settings.OPENAPI_CACHE_TIMEOUT), + name='schema-swagger-ui', + ), + url(r'^api-docs/$', schema_view.with_ui('swagger', cache_timeout=settings.OPENAPI_CACHE_TIMEOUT)), +] # edx-drf-extensions csrf app urlpatterns += [