Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean settings #320

Merged
merged 17 commits into from
May 15, 2024
4 changes: 2 additions & 2 deletions backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ name = "pypi"
# 5. Run `pipenv install --dev` in your terminal.

[packages]
codeforlife = {ref = "v0.16.2", git = "https://github.com/ocadotechnology/codeforlife-package-python.git"}
codeforlife = {ref = "v0.16.4", git = "https://github.com/ocadotechnology/codeforlife-package-python.git"}
# 🚫 Don't add [packages] below that are inhertited from the CFL package.
# TODO: check if we need the below packages
whitenoise = "==6.5.0"
Expand All @@ -47,7 +47,7 @@ google-cloud-container = "==2.3.0"
# "django-anymail[amazon_ses]" = "==7.0.*"

[dev-packages]
codeforlife = {ref = "v0.16.2", git = "https://github.com/ocadotechnology/codeforlife-package-python.git", extras = ["dev"]}
codeforlife = {ref = "v0.16.4", git = "https://github.com/ocadotechnology/codeforlife-package-python.git", extras = ["dev"]}
# codeforlife = {file = "../../codeforlife-package-python", editable = true, extras = ["dev"]}
# 🚫 Don't add [dev-packages] below that are inhertited from the CFL package.
# TODO: check if we need the below packages
Expand Down
15 changes: 8 additions & 7 deletions backend/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

144 changes: 81 additions & 63 deletions backend/service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,8 @@
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

ALLOWED_HOSTS = ["*"]

# Application definition

MIDDLEWARE = [
# "deploy.middleware.admin_access.AdminAccessMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.locale.LocaleMiddleware",
"corsheaders.middleware.CorsMiddleware",
"django.middleware.common.CommonMiddleware",
# "django.middleware.csrf.CsrfViewMiddleware",
# "deploy.middleware.security.CustomSecurityMiddleware",
# "whitenoise.middleware.WhiteNoiseMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
# "deploy.middleware.session_timeout.SessionTimeoutMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
# "deploy.middleware.exceptionlogging.ExceptionLoggingMiddleware",
# "django_otp.middleware.OTPMiddleware",
"preventconcurrentlogins.middleware.PreventConcurrentLoginsMiddleware",
"csp.middleware.CSPMiddleware",
# "deploy.middleware.screentime_warning.ScreentimeWarningMiddleware",
]

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",
"common.context_processors.module_name",
"common.context_processors.cookie_management_enabled",
# TODO: use when integrating dotmailer
# "portal.context_processors.process_newsletter_form",
]
},
}
]

# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

Expand All @@ -79,48 +35,92 @@
STATIC_URL = "/static/"
STATICFILES_DIRS = [BASE_DIR / "portal/static"]
STATICFILES_FINDERS = [
"pipeline.finders.PipelineFinder",
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
]
# STATICFILES_STORAGE = "pipeline.storage.PipelineStorage"
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"

# Custom
MEDIA_ROOT = os.path.join(STATIC_ROOT, "email_media/")
LOGIN_REDIRECT_URL = "/teach/dashboard/"
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
SILENCED_SYSTEM_CHECKS = ["captcha.recaptcha_test_key_error"]
MESSAGE_STORAGE = "django.contrib.messages.storage.session.SessionStorage"


CODEFORLIFE_WEBSITE = "www.codeforlife.education"
CLOUD_STORAGE_PREFIX = "https://storage.googleapis.com/codeforlife-assets/"
# TODO: assess if still need and trim fat if not.
# RAPID_ROUTER_EARLY_ACCESS_FUNCTION_NAME = "portal.beta.has_beta_access"
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_BROWSER_XSS_FILTER = True
SECURE_REFERRER_POLICY = "strict-origin-when-cross-origin"
RECAPTCHA_DOMAIN = "www.recaptcha.net"

PASSWORD_RESET_TIMEOUT = 3600

PIPELINE_ENABLED = False

# This is used in common to enable/disable the OneTrust cookie management script
COOKIE_MANAGEMENT_ENABLED = False

AUTOCONFIG_INDEX_VIEW = "home"
SITE_ID = 1

PIPELINE = {} # type: ignore[var-annotated]

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.
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",
]
},
}
]

MESSAGE_STORAGE = "django.contrib.messages.storage.session.SessionStorage"
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

rel = lambda rel_path: os.path.join(BASE_DIR, rel_path)

STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATICFILES_FINDERS += ["pipeline.finders.PipelineFinder"]
STATICFILES_STORAGE = "pipeline.storage.PipelineStorage"

PIPELINE_ENABLED = False # True if assets should be compressed, False if not.

PIPELINE = {
"COMPILERS": ("portal.pipeline_compilers.LibSassCompiler",),
"STYLESHEETS": {
"css": {
"source_filenames": (
rel("static/portal/sass/bootstrap.scss"),
rel("static/portal/sass/colorbox.scss"),
rel("static/portal/sass/styles.scss"),
rel("static/game/css/level_selection.css"),
rel("static/game/css/backgrounds.css"),
),
"output_filename": "portal.css",
},
"game-scss": {
"source_filenames": (rel("static/game/sass/game.scss"),),
"output_filename": "game.css",
},
"popup": {
"source_filenames": (
rel("static/portal/sass/partials/_popup.scss"),
),
"output_filename": "popup.css",
},
},
"CSS_COMPRESSOR": None,
"SASS_ARGUMENTS": "--quiet",
}
"""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
Expand All @@ -140,6 +140,10 @@ def domain():
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'",
Expand Down Expand Up @@ -241,6 +245,20 @@ def domain():
# pylint: disable-next=wrong-import-position,wildcard-import,unused-wildcard-import
from codeforlife.settings import *

# 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",
"preventconcurrentlogins.middleware.PreventConcurrentLoginsMiddleware",
"csp.middleware.CSPMiddleware",
# "deploy.middleware.screentime_warning.ScreentimeWarningMiddleware",
]

INSTALLED_APPS = [
"api",
"aimmo",
Expand Down
2 changes: 1 addition & 1 deletion backend/service/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
name="kurono",
),
*service_urlpatterns(
frontend_template_name="portal.html", # TODO: standardize name
frontend_template_name="portal.html", # TODO: update, removed bundling
include_user_urls=False,
),
path(
Expand Down
74 changes: 0 additions & 74 deletions frontend/djangoBundler.js

This file was deleted.

5 changes: 1 addition & 4 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"@types/crypto-js": "^4.1.1",
"@types/js-cookie": "^3.0.3",
"@types/node": "^17.0.45",
"@types/parcel-bundler": "^1.12.5",
"@types/react": "^18.0.28",
"@types/react-copy-to-clipboard": "^5.0.4",
"@types/react-dom": "^18.0.11",
Expand All @@ -67,12 +66,10 @@
"eslint-plugin-n": "^15.6.1",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-react": "^7.32.2",
"handlebars": "^4.7.7",
"parcel-bundler": "^1.12.5",
"serve": "^14.2.0",
"typescript": "^4.9.5"
},
"nyc": {
"exclude": []
}
}
}
Loading