generated from ocadotechnology/codeforlife-template-backend
-
Notifications
You must be signed in to change notification settings - Fork 24
/
settings.py
312 lines (279 loc) · 10.6 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
"""
Django settings for service project.
Generated by 'django-admin startproject' using Django 3.2.18.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
import os
from pathlib import Path
from codeforlife import set_up_settings
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent
secrets = set_up_settings(BASE_DIR, service_name="portal")
# ------------------------------------------------------------------------------
# TODO: Clean settings below
# ------------------------------------------------------------------------------
EMAIL_VERIFICATION_TIMEOUT = 60 * 60 * 24
# ⚠️ The template keys must match their names on Dotdigital.
DOTDIGITAL_CAMPAIGN_IDS = {
"Verify new user email - first reminder": 1557170,
"Verify new user email - second reminder": 1557173,
"Verify new user email": 1551577,
"Verify new user email - parents": 1551587,
"Verify released student email": 1580574,
"Reset password": 1557153,
"Student join request accepted": 1605779,
"Student join request rejected": 1569470,
"Student join request notification": 1569486,
"Student join request sent": 1569477,
"Admin given": 1569057,
"Admin revoked": 1569071,
"Invite teacher - account doesn't exist": 1569607,
"Invite teacher - account exists": 1569599,
"User already registered": 1569539,
"Teacher released from school": 1569537,
"Email change notification": 1551600,
"Verify changed user email": 1551594,
"Account deletion": 1567477,
"Inactive users on website - first reminder": 1604381,
"Inactive users on website - second reminder": 1606208,
"Inactive users on website - final reminder": 1606215,
}
# Custom
LOGIN_REDIRECT_URL = "/teach/dashboard/"
SILENCED_SYSTEM_CHECKS = ["captcha.recaptcha_test_key_error"]
RECAPTCHA_DOMAIN = "www.recaptcha.net"
PASSWORD_RESET_TIMEOUT = 3600
# This is used in common to enable/disable the OneTrust cookie management script
COOKIE_MANAGEMENT_ENABLED = False
SITE_ID = 1
FRONTEND_URL = os.getenv("FRONTEND_URL", "http://localhost:3000")
MODULE_NAME = os.getenv("MODULE_NAME", "local")
"""RAPID ROUTER SETTINGS"""
# TODO: The settings in this section are needed for the old Rapid Router
# package. Remove once RR has moved to the new system.
MESSAGE_STORAGE = "django.contrib.messages.storage.session.SessionStorage"
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
PIPELINE_ENABLED = False # True if assets should be compressed, False if not.
PIPELINE = {}
if os.environ.get("STATIC_MODE", "") == "pipeline":
STATICFILES_FINDERS = ["pipeline.finders.PipelineFinder"]
STATICFILES_STORAGE = "pipeline.storage.PipelineStorage"
PIPELINE = {
"COMPILERS": ("portal.pipeline_compilers.LibSassCompiler",),
"STYLESHEETS": {
"css": {
"source_filenames": (
os.path.join(BASE_DIR, "static/portal/sass/bootstrap.scss"),
os.path.join(BASE_DIR, "static/portal/sass/colorbox.scss"),
os.path.join(BASE_DIR, "static/portal/sass/styles.scss"),
os.path.join(
BASE_DIR, "static/game/css/level_selection.css"
),
os.path.join(BASE_DIR, "static/game/css/backgrounds.css"),
),
"output_filename": "portal.css",
},
"game-scss": {
"source_filenames": (
os.path.join(BASE_DIR, "static/game/sass/game.scss"),
),
"output_filename": "game.css",
},
"popup": {
"source_filenames": (
os.path.join(
BASE_DIR, "static/portal/sass/partials/_popup.scss"
),
),
"output_filename": "popup.css",
},
},
"CSS_COMPRESSOR": None,
"SASS_ARGUMENTS": "--quiet",
}
else:
STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
"django.contrib.staticfiles.finders.FileSystemFinder",
]
# pylint: disable-next=pointless-string-statement
"""END OF RAPID ROUTER SETTINGS"""
# Domain
# TODO: Check if CSP still needs it after it's revisited
def domain():
"""
Returns the full domain depending on whether it's local, dev, staging or
prod.
"""
domain_name = "https://www.codeforlife.education"
if MODULE_NAME == "local":
domain_name = "localhost:8000"
elif MODULE_NAME == "staging":
domain_name = "https://staging-dot-decent-digit-629.appspot.com"
elif MODULE_NAME == "development":
domain_name = (
"https://development-portal-dot-decent-digit-629.appspot.com"
)
return domain_name
# CSP
# TODO: A lot of the links mentioned in the CSP will not be relevant with the
# new system anymore. Update and clean the CSP settings once the frontend
# has been done. Currently still needed for RR.
CSP_DEFAULT_SRC = ("self",)
CSP_CONNECT_SRC = (
"'self'",
"https://api.pwnedpasswords.com",
"https://*.onetrust.com/",
"https://euc-widget.freshworks.com/",
"https://codeforlife.freshdesk.com/",
"https://api.iconify.design/",
"https://api.simplesvg.com/",
"https://api.unisvg.com/",
"https://www.google-analytics.com/",
"https://region1.google-analytics.com/g/",
"https://pyodide-cdn2.iodide.io/v0.15.0/full/",
"https://crowdin.com/",
"https://o2.mouseflow.com/",
"https://stats.g.doubleclick.net/",
f"wss://{MODULE_NAME}-aimmo.codeforlife.education/",
f"https://{MODULE_NAME}-aimmo.codeforlife.education/",
)
CSP_FONT_SRC = (
"'self'",
"https://fonts.gstatic.com/",
"https://fonts.googleapis.com/",
"https://use.typekit.net/",
)
CSP_SCRIPT_SRC = (
"'self'",
"'unsafe-inline'",
"'unsafe-eval'",
"https://cdn.crowdin.com/",
"https://*.onetrust.com/",
"https://code.jquery.com/",
"https://euc-widget.freshworks.com/",
"https://cdn-ukwest.onetrust.com/",
"https://code.iconify.design/2/2.0.3/iconify.min.js",
"https://www.googletagmanager.com/",
"https://www.google-analytics.com/analytics.js",
"https://cdn.mouseflow.com/",
"https://www.recaptcha.net/",
"https://www.google.com/recaptcha/",
"https://www.gstatic.com/recaptcha/",
"https://use.typekit.net/mrl4ieu.js",
"https://pyodide-cdn2.iodide.io/v0.15.0/full/",
f"{domain()}/static/portal/",
f"{domain()}/static/common/",
"https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/crypto-js.min.js",
)
CSP_STYLE_SRC = (
"'self'",
"'unsafe-inline'",
"https://euc-widget.freshworks.com/",
"https://cdn-ukwest.onetrust.com/",
"https://fonts.googleapis.com/",
"https://code.jquery.com/ui/1.13.1/themes/base/jquery-ui.css",
"https://cdn.crowdin.com/",
f"{domain()}/static/portal/",
)
CSP_FRAME_SRC = (
"https://storage.googleapis.com/",
"https://www.youtube-nocookie.com/",
"https://www.recaptcha.net/",
"https://www.google.com/recaptcha/",
"https://crowdin.com/",
f"{domain()}/static/common/img/",
f"{domain()}/static/game/image/",
)
CSP_IMG_SRC = (
"https://storage.googleapis.com/codeforlife-assets/images/",
"https://cdn-ukwest.onetrust.com/",
"https://p.typekit.net/",
"https://cdn.crowdin.com/",
"https://crowdin-static.downloads.crowdin.com/",
"https://www.google-analytics.com/",
"data:",
f"{domain()}/static/portal/img/",
f"{domain()}/static/portal/static/portal/img/",
f"{domain()}/static/portal/img/",
f"{domain()}/favicon.ico",
f"{domain()}/img/",
f"{domain()}/account/two_factor/qrcode/",
f"{domain()}/static/",
f"{domain()}/static/game/image/",
f"{domain()}/static/game/raphael_image/",
f"{domain()}/static/game/js/blockly/media/",
f"{domain()}/static/icons/",
)
CSP_OBJECT_SRC = (
f"{domain()}/static/common/img/",
f"{domain()}/static/game/image/",
)
CSP_MEDIA_SRC = (
f"{domain()}/static/react/",
f"{domain()}/static/game/sound/",
f"{domain()}/static/game/js/blockly/media/",
f"{domain()}/static/portal/video/",
)
CSP_MANIFEST_SRC = (f"{domain()}/static/manifest.json",)
# ------------------------------------------------------------------------------
# TODO: Clean settings above
# ------------------------------------------------------------------------------
# pylint: disable-next=wrong-import-position,wildcard-import,unused-wildcard-import
from codeforlife.settings import *
ROOT_URLCONF = "src.urls"
# TODO: Go through the commented out middleware and decide if we still need them
MIDDLEWARE = [
*MIDDLEWARE,
# "deploy.middleware.admin_access.AdminAccessMiddleware",
# "deploy.middleware.security.CustomSecurityMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
# "deploy.middleware.session_timeout.SessionTimeoutMiddleware",
# "deploy.middleware.exceptionlogging.ExceptionLoggingMiddleware",
# "django_otp.middleware.OTPMiddleware",
"csp.middleware.CSPMiddleware",
# "deploy.middleware.screentime_warning.ScreentimeWarningMiddleware",
]
INSTALLED_APPS = [
"src.api",
"src.sso",
"src.rapid_router",
"pipeline",
"captcha",
"import_export",
"sekizai", # for javascript and css management
"treebeard",
*INSTALLED_APPS,
]
INSTALLED_APPS.remove("api")
# Frontend pages.
PAGE_TEACHER_LOGIN = f"{SERVICE_SITE_URL}/login/teacher"
PAGE_INDY_LOGIN = f"{SERVICE_SITE_URL}/login/independent"
PAGE_TEACHER_DASHBOARD_SCHOOL = f"{SERVICE_SITE_URL}/teacher/dashboard/school"
PAGE_REGISTER = f"{SERVICE_SITE_URL}/register"
PAGE_STUDENT_LOGIN = f"{SERVICE_SITE_URL}/login/student"
"""RAPID ROUTER SETTINGS"""
# TODO: The settings in this section are needed for the old Rapid Router
# package. Remove once RR has moved to the new system.
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.contrib.auth.context_processors.auth",
"django.template.context_processors.request",
"django.contrib.messages.context_processors.messages",
"sekizai.context_processors.sekizai",
# TODO: replace in new system and remove here
# "common.context_processors.module_name",
# "common.context_processors.cookie_management_enabled",
# TODO: use when integrating dotmailer
# "portal.context_processors.process_newsletter_form",
]
},
}
]