Skip to content

Commit

Permalink
fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
domdinicola committed May 2, 2024
1 parent 3413d63 commit 743c23e
Show file tree
Hide file tree
Showing 49 changed files with 524 additions and 487 deletions.
26 changes: 26 additions & 0 deletions src/aurora/config/fragments/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from .ad import *
from .admin_sync import *
from .anymail import *
from .azure_graph_api import *
from .capcha import *
from .channels import *
from .concurrency import *
from .constance import *
from .cors import *
from .csp import *
from .dbtemplate import *
from .django_toolbar import *
from .flags import *
from .front_door import *
from .hijack import *
from .json_editor import *
from .matomo import *
from .mdeditor import *
from .rest_framework import *
from .reversion import *
from .sentry import *
from .smart_admin import *
from .social_auth import *
from .strategy import *
from .sysinfo import *
from .translator import *
4 changes: 4 additions & 0 deletions src/aurora/config/fragments/ad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .. import env

AZURE_CLIENT_ID = env("AZURE_CLIENT_ID")
AZURE_CLIENT_SECRET = env("AZURE_CLIENT_SECRET")
9 changes: 9 additions & 0 deletions src/aurora/config/fragments/admin_sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from .. import env

ADMIN_SYNC_CONFIG = env("ADMIN_SYNC_CONFIG")
ADMIN_SYNC_RESPONSE_HEADER = None
# these are actually used only in local development
ADMIN_SYNC_REMOTE_SERVER = env("ADMIN_SYNC_REMOTE_SERVER", default="")
ADMIN_SYNC_REMOTE_ADMIN_URL = env("ADMIN_SYNC_REMOTE_ADMIN_URL", default="")
ADMIN_SYNC_LOCAL_ADMIN_URL = env("ADMIN_SYNC_LOCAL_ADMIN_URL", default="")
# ADMIN_SYNC_USE_REVERSION=
3 changes: 3 additions & 0 deletions src/aurora/config/fragments/anymail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .. import env

ANYMAIL = {"MAILJET_API_KEY": env("MAILJET_API_KEY"), "MAILJET_SECRET_KEY": env("MAILJET_SECRET_KEY")}
4 changes: 4 additions & 0 deletions src/aurora/config/fragments/azure_graph_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Graph API
AZURE_GRAPH_API_BASE_URL = "https://graph.microsoft.com"
AZURE_GRAPH_API_VERSION = "v1.0"
AZURE_TOKEN_URL = "https://login.microsoftonline.com/unicef.org/oauth2/token"
10 changes: 10 additions & 0 deletions src/aurora/config/fragments/capcha.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .. import env

# CAPTCHA_IMAGE_SIZE = 300,200
CAPTCHA_FONT_SIZE = 40
CAPTCHA_CHALLENGE_FUNCT = "captcha.helpers.random_char_challenge"
CAPTCHA_TEST_MODE = env("CAPTCHA_TEST_MODE")
CAPTCHA_GET_FROM_POOL = True


# CAPTCHA_CHALLENGE_FUNCT = 'captcha.helpers.math_challenge'
10 changes: 10 additions & 0 deletions src/aurora/config/fragments/channels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .. import env

CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [env("CHANNEL_LAYER")],
},
},
}
1 change: 1 addition & 0 deletions src/aurora/config/fragments/concurrency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONCURRENCY_ENABLED = False
40 changes: 40 additions & 0 deletions src/aurora/config/fragments/constance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from collections import OrderedDict

from .. import env

CONSTANCE_ADDITIONAL_FIELDS = {
"html_minify_select": [
"bitfield.forms.BitFormField",
{"initial": 0, "required": False, "choices": (("html", "HTML"), ("line", "NEWLINE"), ("space", "SPACES"))},
],
}
CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend"
CONSTANCE_DATABASE_CACHE_BACKEND = env("CONSTANCE_DATABASE_CACHE_BACKEND")
CONSTANCE_CONFIG = OrderedDict(
{
"CACHE_FORMS": (False, "", bool),
"CACHE_VERSION": (1, "", int),
"HOME_PAGE_REGISTRATIONS": ("", "", str),
"SMART_ADMIN_BOOKMARKS": (
"",
"",
str,
),
"LOGIN_LOCAL": (True, "Enable local accounts login", bool),
"LOGIN_SSO": (True, "Enable SSO logon", bool),
"ADMIN_SYNC_REMOTE_SERVER": ("", "production server url", str),
"ADMIN_SYNC_REMOTE_ADMIN_URL": ("/admin/", "", str),
"ADMIN_SYNC_LOCAL_ADMIN_URL": ("/admin/", "", str),
"ADMIN_SYNC_USE_REVERSION": (False, "", bool),
"LOG_POST_ERRORS": (False, "", bool),
"MINIFY_RESPONSE": (0, "select yes or no", "html_minify_select"),
"MINIFY_IGNORE_PATH": (r"", "regex for ignored path", str),
"BASE_TEMPLATE": ("base_lean.html", "Default base template", str),
"HOME_TEMPLATE": ("home.html", "Default home.html", str),
"QRCODE": (True, "Enable QRCode generation", bool),
"SHOW_REGISTER_ANOTHER": (True, "Enable QRCode generation", bool),
"MAINTENANCE_MODE": (False, "set maintenance mode On/Off", bool),
"WAF_REGISTRATION_ALLOWED_HOSTNAMES": (".*", "public website hostname (regex)", str),
"WAF_ADMIN_ALLOWED_HOSTNAMES": ("", "admin website hostname (regex)", str),
}
)
12 changes: 12 additions & 0 deletions src/aurora/config/fragments/cors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from .. import env

CORS_ALLOWED_ORIGINS = [
"https://excubo.unicef.io",
"http://localhost:8000",
"https://browser.sentry-cdn.com",
"https://cdnjs.cloudflare.com",
"https://login.microsoftonline.com",
] + env("CORS_ALLOWED_ORIGINS")

CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
62 changes: 62 additions & 0 deletions src/aurora/config/fragments/csp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
SOURCES = (
"'self'",
"inline",
"unsafe-inline",
"data:",
"blob:",
"'unsafe-inline'",
"localhost:8000",
"unpkg.com",
"browser.sentry-cdn.com",
"cdnjs.cloudflare.com",
"unisitetracker.unicef.io",
"cdn.jsdelivr.net",
"register.unicef.org",
"uni-hope-ukr-sr.azurefd.net",
"uni-hope-ukr-sr-dev.azurefd.net",
"uni-hope-ukr-sr-dev.unitst.org",
)

CSP_DEFAULT_SRC = SOURCES
CSP_FRAME_ANCESTORS = ("'self'",)
# CSP_SCRIPT_SRC = SOURCES
# CSP_STYLE_SRC = (
# "'self'",
# "'data'",
# "'unsafe-inline'",
# "https://unpkg.com",
# "http://localhost:8000",
# "https://cdnjs.cloudflare.com",
# "http://cdnjs.cloudflare.com",
#
# )
# CSP_OBJECT_SRC = ("self",)
# CSP_BASE_URI = ("self", "http://localhost:8000",)
# CSP_CONNECT_SRC = ("self",)
# CSP_FONT_SRC = ("self",)
# CSP_FRAME_SRC = ("self",)
# CSP_IMG_SRC = ("self", "data")
# CSP_MANIFEST_SRC = ("self",)
# CSP_MEDIA_SRC = ("self",)
# CSP_REPORT_URI = ("https://624948b721ea44ac2a6b4de4.endpoint.csper.io/?v=0;",)
# CSP_WORKER_SRC = ("self",)
# """default-src 'self';
# script-src 'report-sample' 'self';
# style-src 'report-sample' 'self';
# object-src 'none';
#
# base-uri 'self';
# connect-src 'self';
# font-src 'self';
# frame-src 'self';
# img-src 'self';
# manifest-src 'self';
# media-src 'self';
# report-uri https://624948b721ea44ac2a6b4de4.endpoint.csper.io/?v=0;
# worker-src 'none';
# """

# CSP_INCLUDE_NONCE_IN = env("CSP_INCLUDE_NONCE_IN")
# CSP_REPORT_ONLY = env("CSP_REPORT_ONLY")
# CSP_DEFAULT_SRC = env("CSP_DEFAULT_SRC")
# CSP_SCRIPT_SRC = env("CSP_SCRIPT_SRC")
2 changes: 2 additions & 0 deletions src/aurora/config/fragments/dbtemplate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DBTEMPLATES_USE_REVERSION = True
DBTEMPLATES_USE_CODEMIRROR = True
38 changes: 38 additions & 0 deletions src/aurora/config/fragments/django_toolbar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from django_regex.utils import RegexList


def show_ddt(request): # pragma: no-cover
from flags.state import flag_enabled

if request.path in RegexList(("/tpl/.*", "/api/.*", "/dal/.*")): # pragma: no cache
return False
return flag_enabled("DEVELOP_DEBUG_TOOLBAR", request=request)


DEBUG_TOOLBAR_CONFIG = {
"SHOW_TOOLBAR_CALLBACK": show_ddt,
"JQUERY_URL": "",
"INSERT_BEFORE": "</head>",
"SHOW_TEMPLATE_CONTEXT": True,
}

DEBUG_TOOLBAR_PANELS = [
"debug_toolbar.panels.history.HistoryPanel",
# "debug_toolbar.panels.versions.VersionsPanel",
"aurora.ddt_panels.StatePanel",
"aurora.ddt_panels.MigrationPanel",
"debug_toolbar.panels.timer.TimerPanel",
"flags.panels.FlagsPanel",
"flags.panels.FlagChecksPanel",
"debug_toolbar.panels.settings.SettingsPanel",
"debug_toolbar.panels.headers.HeadersPanel",
"debug_toolbar.panels.request.RequestPanel",
"debug_toolbar.panels.sql.SQLPanel",
"debug_toolbar.panels.staticfiles.StaticFilesPanel",
"debug_toolbar.panels.templates.TemplatesPanel",
"debug_toolbar.panels.cache.CachePanel",
"debug_toolbar.panels.signals.SignalsPanel",
"debug_toolbar.panels.logging.LoggingPanel",
"debug_toolbar.panels.redirects.RedirectsPanel",
"debug_toolbar.panels.profiling.ProfilingPanel",
]
10 changes: 10 additions & 0 deletions src/aurora/config/fragments/flags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from ..settings import DEBUG

FLAGS_STATE_LOGGING = DEBUG

FLAGS = {
"DEVELOP_DEVELOPER": [],
"DEVELOP_DEBUG_TOOLBAR": [],
"SENTRY_JAVASCRIPT": [],
"I18N_COLLECT_MESSAGES": [],
}
22 changes: 22 additions & 0 deletions src/aurora/config/fragments/front_door.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from .. import env

FRONT_DOOR_CONFIG = "front_door.conf.DjangoConstance"
FRONT_DOOR_ENABLED = env("FRONT_DOOR_ENABLED")
FRONT_DOOR_ALLOWED_PATHS = env("FRONT_DOOR_ALLOWED_PATHS")
FRONT_DOOR_TOKEN = env("FRONT_DOOR_TOKEN")
FRONT_DOOR_HEADER = "x-aurora"
FRONT_DOOR_COOKIE_NAME = "x-aurora"
FRONT_DOOR_COOKIE_PATTERN = ".*"
# FRONT_DOOR_ERROR_CODE = 404
# FRONT_DOOR_REDIR_URL = "https://www.sosbob.com/"
FRONT_DOOR_LOG_LEVEL = env("FRONT_DOOR_LOG_LEVEL") # LOG_RULE_FAIL
FRONT_DOOR_RULES = [
# "front_door.rules.internal_ip", # grant access to settings.INTERNAL_IPS
# "front_door.rules.forbidden_path", # DENY access to FORBIDDEN_PATHS
"front_door.rules.allowed_path", # grant access to ALLOWED_PATHS
"front_door.rules.allowed_ip", # grant access to ALLOWED_IPS
"front_door.rules.special_header", # grant access if request has Header[HEADER] == TOKEN
# "front_door.rules.has_header", # grant access if request has HEADER
"front_door.rules.cookie_value", # grant access if request.COOKIES[COOKIE_NAME]
# "front_door.rules.cookie_exists", # grant access ir COOKIE_NAME in request.COOKIES
]
1 change: 1 addition & 0 deletions src/aurora/config/fragments/hijack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HIJACK_PERMISSION_CHECK = "aurora.administration.hijack.can_impersonate"
4 changes: 4 additions & 0 deletions src/aurora/config/fragments/json_editor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
JSON_EDITOR_JS = "https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/8.6.4/jsoneditor.js"
JSON_EDITOR_CSS = "https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/8.6.4/jsoneditor.css"
JSON_EDITOR_INIT_JS = "django-jsoneditor/jsoneditor-init.min.js"
JSON_EDITOR_ACE_OPTIONS_JS = "django-jsoneditor/ace_options.min.js"
4 changes: 4 additions & 0 deletions src/aurora/config/fragments/matomo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .. import env

MATOMO_SITE = env("MATOMO_SITE", default="https://unisitetracker.unicef.io/")
MATOMO_ID = env("MATOMO_ID", default="N/A")
64 changes: 64 additions & 0 deletions src/aurora/config/fragments/mdeditor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
MDEDITOR_CONFIGS = {
"default": {
"width": "100% ", # Custom edit box width
"height": 200, # Custom edit box height
"toolbar": [
"undo",
"redo",
"|",
"bold",
"del",
"italic",
"quote",
"ucwords",
"uppercase",
"lowercase",
"|",
"h1",
"h2",
"h3",
"h5",
"h6",
"|",
"list-ul",
"list-ol",
"hr",
"|",
"link",
"reference-link",
"image",
"code",
"preformatted-text",
"code-block",
"table",
"datetime",
"emoji",
"html-entities",
"pagebreak",
"goto-line",
"|",
"help",
"info",
"||",
"preview",
"watch",
"fullscreen",
], # custom edit box toolbar
# image upload format type
# 'upload_image_formats': ["jpg", "jpeg", "gif", "png", "bmp", "webp", "svg"],
# 'image_folder': 'editor', # image save the folder name
"theme": "default", # edit box theme, dark / default
"preview_theme": "default", # Preview area theme, dark / default
"editor_theme": "default", # edit area theme, pastel-on-dark / default
"toolbar_autofixed": False, # Whether the toolbar capitals
"search_replace": True, # Whether to open the search for replacement
"emoji": True, # whether to open the expression function
"tex": True, # whether to open the tex chart function
"flow_chart": True, # whether to open the flow chart function
"sequence": True, # Whether to open the sequence diagram function
"watch": True, # Live preview
"lineWrapping": True, # lineWrapping
"lineNumbers": True, # lineNumbers
"language": "en", # zh / en / es
}
}
19 changes: 19 additions & 0 deletions src/aurora/config/fragments/rest_framework.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
REST_FRAMEWORK = {
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
"DEFAULT_VERSIONING_CLASS": "rest_framework.versioning.NamespaceVersioning",
"DEFAULT_FILTER_BACKENDS": ("django_filters.rest_framework.DjangoFilterBackend",),
"DEFAULT_RENDERER_CLASSES": (
"rest_framework.renderers.JSONRenderer",
"rest_framework.renderers.BrowsableAPIRenderer",
"rest_framework_datatables.renderers.DatatablesRenderer",
),
"PAGE_SIZE": 30,
"DEFAULT_AUTHENTICATION_CLASSES": [
"rest_framework.authentication.BasicAuthentication",
"rest_framework.authentication.SessionAuthentication",
"rest_framework.authentication.TokenAuthentication",
],
"DEFAULT_PERMISSION_CLASSES": [
"rest_framework.permissions.DjangoModelPermissions",
],
}
5 changes: 5 additions & 0 deletions src/aurora/config/fragments/reversion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Add reversion models to admin interface:
ADD_REVERSION_ADMIN = True
# optional settings:
REVERSION_COMPARE_FOREIGN_OBJECTS_AS_ID = False
REVERSION_COMPARE_IGNORE_NOT_REGISTERED = False
27 changes: 27 additions & 0 deletions src/aurora/config/fragments/sentry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import logging

import aurora

from .. import env

SENTRY_DSN = env("SENTRY_DSN")
SENTRY_PROJECT = env("SENTRY_PROJECT")
if SENTRY_DSN:
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.logging import LoggingIntegration

sentry_logging = LoggingIntegration(
level=logging.INFO, # Capture info and above as breadcrumbs
event_level=logging.ERROR, # Send errors as events
)
sentry_sdk.init(
dsn=SENTRY_DSN,
environment=env("SENTRY_ENVIRONMENT", default=None),
integrations=[
DjangoIntegration(transaction_style="url"),
sentry_logging,
],
release=aurora.VERSION,
send_default_pii=True,
)
Loading

0 comments on commit 743c23e

Please sign in to comment.