|
3 | 3 |
|
4 | 4 | from ansible_base.lib.cache.fallback_cache import FALLBACK_CACHE, PRIMARY_CACHE |
5 | 5 |
|
| 6 | +from .constants import api_documentation, rest_filters |
| 7 | + |
6 | 8 | # |
7 | 9 | # If you are adding a new dynamic setting: |
8 | 10 | # Please be sure to modify pyproject.toml with your new settings in tool.setuptools.dynamic |
|
11 | 13 |
|
12 | 14 |
|
13 | 15 | DEFAULT_AUTH_GROUP = 'auth.Group' |
14 | | -DEFAULT_SPECTACULAR_SETTINGS = { |
15 | | - 'TITLE': 'Open API', |
16 | | - 'DESCRIPTION': 'Open API', |
17 | | - 'VERSION': 'v1', |
18 | | - 'SCHEMA_PATH_PREFIX': '/api/v1/', |
19 | | - 'COMPONENT_NO_READ_ONLY_REQUIRED': True, |
20 | | -} |
21 | 16 | DEFAULT_ANSIBLE_BASE_AUTH = "ansible_base.authentication.backend.AnsibleBaseAuth" |
22 | 17 | DEFAULT_ANSIBLE_BASE_JWT_CONSUMER_APP_NAME = "ansible_base.jwt_consumer" |
23 | 18 | DEFAULT_ANSIBLE_BASE_RBAC_APP_NAME = "ansible_base.rbac" |
@@ -92,51 +87,22 @@ def get_mergeable_dab_settings(settings: dict) -> dict: # NOSONAR |
92 | 87 | # without enabling the ansible_base.rest_filters app explicitly |
93 | 88 | # we also apply this to views from other apps so we should always define it |
94 | 89 | if settings.get('ANSIBLE_BASE_REST_FILTERS_RESERVED_NAMES') is None: |
95 | | - dab_data['ANSIBLE_BASE_REST_FILTERS_RESERVED_NAMES'] = ( |
96 | | - 'page', |
97 | | - 'page_size', |
98 | | - 'format', |
99 | | - 'order', |
100 | | - 'order_by', |
101 | | - 'search', |
102 | | - 'type', |
103 | | - 'host_filter', |
104 | | - 'count_disabled', |
105 | | - 'no_truncate', |
106 | | - 'limit', |
107 | | - 'validate', |
108 | | - ) |
| 90 | + dab_data['ANSIBLE_BASE_REST_FILTERS_RESERVED_NAMES'] = rest_filters.reserved_names |
109 | 91 |
|
110 | 92 | # SPECTACULAR SETTINGS |
111 | | - if 'ansible_base.api_documentation' in installed_apps: |
112 | | - rest_framework.setdefault('DEFAULT_SCHEMA_CLASS', 'drf_spectacular.openapi.AutoSchema') |
113 | | - |
114 | | - if 'drf_spectacular' not in installed_apps: |
115 | | - installed_apps.append('drf_spectacular') |
116 | | - |
117 | | - for key, value in DEFAULT_SPECTACULAR_SETTINGS.items(): |
118 | | - if key not in spectacular_settings: |
119 | | - spectacular_settings[key] = value |
| 93 | + # NOTE: validators check default schema class and that drf_spectacular is installed |
120 | 94 |
|
121 | 95 | # General, factual, constant of all filters that ansible_base.rest_filters ships |
122 | | - dab_data['ANSIBLE_BASE_ALL_REST_FILTERS'] = ( |
123 | | - 'ansible_base.rest_filters.rest_framework.type_filter_backend.TypeFilterBackend', |
124 | | - 'ansible_base.rest_filters.rest_framework.field_lookup_backend.FieldLookupBackend', |
125 | | - 'rest_framework.filters.SearchFilter', |
126 | | - 'ansible_base.rest_filters.rest_framework.order_backend.OrderByBackend', |
127 | | - ) |
128 | | - if 'ansible_base.rest_filters' in installed_apps: |
129 | | - rest_framework['DEFAULT_FILTER_BACKENDS'] = dab_data['ANSIBLE_BASE_ALL_REST_FILTERS'] |
130 | | - else: |
| 96 | + dab_data['ANSIBLE_BASE_ALL_REST_FILTERS'] = rest_filters.dab_rest_filters |
| 97 | + if 'ansible_base.rest_filters' not in installed_apps: |
131 | 98 | # Explanation - these are the filters for views provided by DAB like /authenticators/ |
132 | 99 | # we want them to be enabled by default _even if_ the rest_filters app is not used |
133 | 100 | # so that clients have consistency, but if an app wants to turn them off, they can. |
134 | 101 | # these will be combined with the actual DRF defaults in our base view |
135 | 102 | dab_data['ANSIBLE_BASE_CUSTOM_VIEW_FILTERS'] = dab_data['ANSIBLE_BASE_ALL_REST_FILTERS'] |
136 | 103 |
|
137 | 104 | if 'ansible_base.authentication' in installed_apps: |
138 | | - if 'social_django' not in installed_apps: |
139 | | - installed_apps.append('social_django') |
| 105 | + # TODO: stop point for migrating modifications to validations |
140 | 106 | if DEFAULT_ANSIBLE_BASE_AUTH not in authentication_backends: |
141 | 107 | authentication_backends.append(DEFAULT_ANSIBLE_BASE_AUTH) |
142 | 108 |
|
|
0 commit comments