Skip to content

Commit

Permalink
Merge pull request #1108 from uktrade/develop
Browse files Browse the repository at this point in the history
Merge develop into main
  • Loading branch information
LuptonM authored Jul 3, 2023
2 parents 3ef1a50 + cf2c69d commit a6f21f1
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 33 deletions.
1 change: 1 addition & 0 deletions conf/env/dev
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ ACTIVITY_STREAM_SECRET_ACCESS_KEY=123-secret-key
FEATURE_ENFORCE_STAFF_SSO_ENABLED=false
USERS_REQUEST_ACCESS_PREVENT_RESUBMISSION=false
STATICFILES_STORAGE=django.contrib.staticfiles.storage.StaticFilesStorage
FEATURE_DIRECTORY_CMS_OPENAPI_ENABLED=true
12 changes: 12 additions & 0 deletions conf/preprocessors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def preprocessing_filter_admin_spec(endpoints):
"""
Filters all Wagtail Admin API endpoints from the Open API schema generated by drf-spectacular. Spec generated at
/openui/ui/.
"""

filtered = []
for path, path_regex, method, callback in endpoints:
# Remove all Wagtail admin endpoints
if not path.startswith('/admin/'):
filtered.append((path, path_regex, method, callback))
return filtered
21 changes: 20 additions & 1 deletion conf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
'django_filters',
'authbroker_client',
'django_celery_beat',
'drf_spectacular',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -429,7 +430,10 @@
else:
LOGIN_URL = '/admin/login/'

REST_FRAMEWORK = {'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',)}
REST_FRAMEWORK = {
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',)
}

if FEATURE_FLAGS['DEBUG_TOOLBAR_ON']:
INSTALLED_APPS += ['debug_toolbar']
Expand Down Expand Up @@ -475,3 +479,18 @@
FOREIGN_DIRECT_INVESTMENT_SNIPPET_LABEL = env.str(
'FOREIGN_DIRECT_INVESTMENT_SNIPPET_LABEL', FOREIGN_DIRECT_INVESTMENT_SNIPPET_LABEL_DEFAULT
)


# Resolves DEFAULT_AUTO_FIELD warnings on Django 3.2 and above
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

# OpenAPI
FEATURE_DIRECTORY_CMS_OPENAPI_ENABLED = env.bool('FEATURE_DIRECTORY_CMS_OPENAPI_ENABLED', False)

SPECTACULAR_SETTINGS = {
'TITLE': 'Directory CMS API',
'DESCRIPTION': 'Directory CMS API - the Department for Business and Trade (DBT)',
'VERSION': os.environ.get('GIT_TAG', 'dev'),
'SERVE_INCLUDE_SCHEMA': False,
'PREPROCESSING_HOOKS': ['conf.preprocessors.preprocessing_filter_admin_spec'],
}
21 changes: 21 additions & 0 deletions conf/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import RedirectView
from django.urls import path, re_path
from drf_spectacular.views import (
SpectacularAPIView,
SpectacularRedocView,
SpectacularSwaggerView,
)

import core.views
from groups.views import GroupInfoModalView
Expand Down Expand Up @@ -100,3 +105,19 @@
urlpatterns = [
re_path(r'^__debug__/', include(debug_toolbar.urls)),
] + urlpatterns


if settings.FEATURE_DIRECTORY_CMS_OPENAPI_ENABLED:
urlpatterns = [
path('openapi/', SpectacularAPIView.as_view(), name='schema'),
path(
'openapi/ui/',
login_required(SpectacularSwaggerView.as_view(url_name='schema'), login_url='admin:login'),
name='swagger-ui',
),
path(
'openapi/ui/redoc/',
login_required(SpectacularRedocView.as_view(url_name='schema'), login_url='admin:login'),
name='redoc',
),
] + urlpatterns
Binary file modified core/static/core/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ _Tick or delete as appropriate:_
- [ ] Upgraded any vulnerable dependencies.
- [ ] I have updated security dependencies
- [ ] Python requirements have been re-compiled.
- [ ] I have checked that my PR is using the latest package versions of: sigauth, directory-healthcheck, directory-components,directory-constants, django-staff-sso-client

### Merging

Expand Down
3 changes: 2 additions & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ django-filter>=2.4.0
django-redis
celery[redis]
django-celery-beat==2.5.0
kombu==5.3.0
kombu==5.3.1
requests[security]>=2.31.0
markdown==2.*
bleach==3.*
Expand All @@ -39,3 +39,4 @@ psycogreen==1.0.2
wagtailmedia==0.14.*
cryptography==41.*
oauthlib==3.2.*
drf-spectacular
36 changes: 24 additions & 12 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ botocore==1.27.96
# via
# boto3
# s3transfer
celery[redis]==5.3.0
celery[redis]==5.3.1
# via
# -r requirements.in
# django-celery-beat
Expand All @@ -55,11 +55,11 @@ click-didyoumean==0.3.0
# via celery
click-plugins==1.1.1
# via celery
click-repl==0.2.0
click-repl==0.3.0
# via celery
cron-descriptor==1.4.0
# via django-celery-beat
cryptography==41.0.0
cryptography==41.0.1
# via -r requirements.in
directory-components==39.1.2
# via -r requirements.in
Expand Down Expand Up @@ -88,8 +88,10 @@ django==4.1.9
# django-staff-sso-client
# django-storages
# django-taggit
# django-timezone-field
# django-treebeard
# djangorestframework
# drf-spectacular
# sigauth
# wagtail
# wagtail-modeltranslation
Expand All @@ -114,21 +116,22 @@ django-permissionedforms==0.1
# via wagtail
django-pglocks==1.0.4
# via -r requirements.in
django-redis==5.2.0
django-redis==5.3.0
# via -r requirements.in
django-staff-sso-client==4.2.0
# via -r requirements.in
django-storages==1.13.2
# via -r requirements.in
django-taggit==3.1.0
# via wagtail
django-timezone-field==5.0
django-timezone-field==5.1
# via django-celery-beat
django-treebeard==4.7
# via wagtail
djangorestframework==3.14.0
# via
# -r requirements.in
# drf-spectacular
# sigauth
# wagtail
docopt==0.6.2
Expand All @@ -137,6 +140,8 @@ docopt==0.6.2
# num2words
draftjs-exporter==2.1.7
# via wagtail
drf-spectacular==0.26.3
# via -r requirements.in
ecs-logging==2.0.2
# via elastic-apm
elastic-apm==6.16.2
Expand All @@ -155,13 +160,17 @@ html5lib==1.1
# via wagtail
idna==3.4
# via requests
inflection==0.5.1
# via drf-spectacular
jmespath==1.0.1
# via
# boto3
# botocore
jsonschema==3.2.0
# via directory-components
kombu==5.3.0
# via
# directory-components
# drf-spectacular
kombu==5.3.1
# via
# -r requirements.in
# celery
Expand Down Expand Up @@ -214,7 +223,9 @@ pytz==2023.3
# django-timezone-field
# djangorestframework
# l18n
redis==4.5.5
pyyaml==6.0
# via drf-spectacular
redis==4.6.0
# via
# celery
# django-redis
Expand All @@ -228,14 +239,13 @@ requests-oauthlib==1.3.1
# via django-staff-sso-client
s3transfer==0.6.1
# via boto3
sentry-sdk==1.25.1
sentry-sdk==1.26.0
# via -r requirements.in
sigauth==5.2.0
# via -r requirements.in
six==1.16.0
# via
# bleach
# click-repl
# django-pglocks
# html5lib
# jsonschema
Expand All @@ -249,7 +259,7 @@ sqlparse==0.4.4
# via django
telepath==0.3.1
# via wagtail
typing-extensions==4.6.3
typing-extensions==4.7.0
# via
# asgiref
# dj-database-url
Expand All @@ -259,6 +269,8 @@ tzdata==2023.3
# via
# celery
# django-celery-beat
uritemplate==4.1.1
# via drf-spectacular
urllib3==1.26.16
# via
# -r requirements.in
Expand Down Expand Up @@ -294,7 +306,7 @@ willow==1.4.1
# via wagtail
wrapt==1.15.0
# via elastic-apm
zope-event==4.6
zope-event==5.0
# via gevent
zope-interface==6.0
# via gevent
Expand Down
2 changes: 1 addition & 1 deletion requirements_test.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ wagtail-factories==2.0.1
django-debug-toolbar==3.2.*
pip-tools
pytest-codecov
GitPython
GitPython
Loading

0 comments on commit a6f21f1

Please sign in to comment.