Complete processing pipeline for Signal

This commit is contained in:
2025-02-07 20:59:39 +00:00
parent dec9d28803
commit 9b3f28c631
42 changed files with 2879 additions and 0 deletions

0
app/__init__.py Normal file
View File

16
app/asgi.py Normal file
View File

@@ -0,0 +1,16 @@
"""
ASGI config for app project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")
application = get_asgi_application()

48
app/local_settings.py Normal file
View File

@@ -0,0 +1,48 @@
from os import getenv
trues = ("t", "true", "yes", "y", "1")
# URLs
DOMAIN = getenv("DOMAIN", "example.com")
URL = getenv("URL", f"https://{DOMAIN}")
# Access control
ALLOWED_HOSTS = getenv("ALLOWED_HOSTS", f"127.0.0.1,{DOMAIN}").split(",")
# CSRF
CSRF_TRUSTED_ORIGINS = getenv("CSRF_TRUSTED_ORIGINS", URL).split(",")
# Stripe
BILLING_ENABLED = getenv("BILLING_ENABLED", "false").lower() in trues
STRIPE_TEST = getenv("STRIPE_TEST", "true") in trues
STRIPE_API_KEY_TEST = getenv("STRIPE_API_KEY_TEST", "")
STRIPE_PUBLIC_API_KEY_TEST = getenv("STRIPE_PUBLIC_API_KEY_TEST", "")
STRIPE_API_KEY_PROD = getenv("STRIPE_API_KEY_PROD", "")
STRIPE_PUBLIC_API_KEY_PROD = getenv("STRIPE_PUBLIC_API_KEY_PROD", "")
STRIPE_ENDPOINT_SECRET = getenv("STRIPE_ENDPOINT_SECRET", "")
STATIC_ROOT = getenv("STATIC_ROOT", "")
SECRET_KEY = getenv("SECRET_KEY", "")
STRIPE_ADMIN_COUPON = getenv("STRIPE_ADMIN_COUPON", "")
REGISTRATION_OPEN = getenv("REGISTRATION_OPEN", "false").lower() in trues
LAGO_API_KEY = getenv("LAGO_API_KEY", "")
LAGO_ORG_ID = getenv("LAGO_ORG_ID", "")
LAGO_URL = getenv("LAGO_URL", "")
DEBUG = getenv("DEBUG", "false") in trues
PROFILER = getenv("PROFILER", "false") in trues
if DEBUG:
import socket # only if you haven't already imported this
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS = [ip[: ip.rfind(".")] + ".1" for ip in ips] + [
"127.0.0.1",
"10.0.2.2",
]
SETTINGS_EXPORT = ["BILLING_ENABLED"]

229
app/settings.py Normal file
View File

@@ -0,0 +1,229 @@
"""
Django settings for app project.
Generated by 'django-admin startproject' using Django 4.0.6.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.0/ref/settings/
"""
import os
from pathlib import Path
# 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/4.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
# MOVED TO local_settings.py
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
"core",
"django.contrib.admin",
# 'core.apps.LibraryAdminConfig', # our custom OTP'ed admin
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"debug_toolbar",
"template_profiler_panel",
"django_htmx",
"crispy_forms",
"crispy_bulma",
# "django_tables2",
# "django_tables2_bulma_template",
"django_otp",
"django_otp.plugins.otp_totp",
# "django_otp.plugins.otp_email",
# 'django_otp.plugins.otp_hotp',
"django_otp.plugins.otp_static",
"two_factor",
# "two_factor.plugins.phonenumber",
# "two_factor.plugins.email",
# "two_factor.plugins.yubikey",
# "otp_yubikey",
"mixins",
"cachalot",
]
# Performance optimisations
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
# "LOCATION": "unix:///var/run/socks/redis.sock",
# "LOCATION": f"redis://{REDIS_HOST}:{REDIS_PORT}",
"LOCATION": "unix:///var/run/gia-redis.sock",
"OPTIONS": {
"db": 10,
# "parser_class": "django_redis.cache.RedisCache",
# "PASSWORD": REDIS_PASSWORD,
"pool_class": "redis.BlockingConnectionPool",
},
}
}
# CACHE_MIDDLEWARE_ALIAS = 'default'
# CACHE_MIDDLEWARE_SECONDS = '600'
# CACHE_MIDDLEWARE_KEY_PREFIX = ''
CRISPY_TEMPLATE_PACK = "bulma"
CRISPY_ALLOWED_TEMPLATE_PACKS = ("bulma",)
DJANGO_TABLES2_TEMPLATE = "django-tables2/bulma.html"
MIDDLEWARE = [
"debug_toolbar.middleware.DebugToolbarMiddleware",
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
# 'django.middleware.cache.UpdateCacheMiddleware',
"django.middleware.common.CommonMiddleware",
# 'django.middleware.cache.FetchFromCacheMiddleware',
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django_otp.middleware.OTPMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django_htmx.middleware.HtmxMiddleware",
]
ROOT_URLCONF = "app.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(BASE_DIR, "core/templates")],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"core.util.django_settings_export.settings_export",
],
},
},
]
WSGI_APPLICATION = "app.wsgi.application"
# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": "/conf/db.sqlite3",
}
}
# Password validation
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{"NAME": f"django.contrib.auth.password_validation.{name}"}
for name in [
"UserAttributeSimilarityValidator",
"MinimumLengthValidator",
"CommonPasswordValidator",
"NumericPasswordValidator",
]
]
# Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/
LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/
STATIC_URL = "static/"
# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
AUTH_USER_MODEL = "core.User"
LOGIN_REDIRECT_URL = "home"
LOGOUT_REDIRECT_URL = "home"
# 2FA
LOGIN_URL = "two_factor:login"
# LOGIN_REDIRECT_URL = 'two_factor:profile'
# ALLOWED_PAYMENT_METHODS = ["bacs_debit", "card"]
ALLOWED_PAYMENT_METHODS = ["card"]
REST_FRAMEWORK = {
"DEFAULT_PARSER_CLASSES": [
"rest_framework.parsers.JSONParser",
]
}
INTERNAL_IPS = [
"127.0.0.1",
"10.1.10.11",
]
DEBUG_TOOLBAR_PANELS = [
"template_profiler_panel.panels.template.TemplateProfilerPanel",
"debug_toolbar.panels.history.HistoryPanel",
"debug_toolbar.panels.versions.VersionsPanel",
"debug_toolbar.panels.timer.TimerPanel",
"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",
"cachalot.panels.CachalotPanel",
]
from app.local_settings import * # noqa
if PROFILER: # noqa - trust me its there
import pyroscope
pyroscope.configure(
application_name="neptune",
server_address="http://pyroscope:4040",
auth_token=os.getenv("PYROSCOPE_AUTH_TOKEN", ""),
# tags = {
# "region": f'{os.getenv("REGION")}',
# }
)
def show_toolbar(request):
return DEBUG # noqa: from local imports
DEBUG_TOOLBAR_CONFIG = {
"SHOW_TOOLBAR_CALLBACK": show_toolbar,
}

210
app/urls.py Normal file
View File

@@ -0,0 +1,210 @@
"""app URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.auth.views import LogoutView
from django.urls import include, path
from django.views.generic import TemplateView
from two_factor.urls import urlpatterns as tf_urls
from core.views import base, notifications, signal, people, ais, groups, personas, manipulations, identifiers, sessions, messages
urlpatterns = [
path("__debug__/", include("debug_toolbar.urls")),
path("", base.Home.as_view(), name="home"),
path("admin/", admin.site.urls),
# 2FA login urls
path("", include(tf_urls)),
path("accounts/signup/", base.Signup.as_view(), name="signup"),
path("accounts/logout/", LogoutView.as_view(), name="logout"),
# Notifications
path(
"notifications/<str:type>/update/",
notifications.NotificationsUpdate.as_view(),
name="notifications_update",
),
path(
"services/signal/",
signal.Signal.as_view(),
name="signal",
),
path(
"services/signal/<str:type>/",
signal.SignalAccounts.as_view(),
name="signal_accounts",
),
path(
"services/signal/<str:type>/contacts/<str:pk>/",
signal.SignalContactsList.as_view(),
name="signal_contacts",
),
path(
"services/signal/<str:type>/chats/<str:pk>/",
signal.SignalChatsList.as_view(),
name="signal_chats",
),
path(
"services/signal/<str:type>/messages/<str:pk>/<str:chat_id>/",
signal.SignalMessagesList.as_view(),
name="signal_messages",
),
path(
"services/signal/<str:type>/add/",
signal.SignalAccountAdd.as_view(),
name="signal_account_add",
),
# AIs
path(
"ai/<str:type>/",
ais.AIList.as_view(),
name="ais",
),
path(
"ai/<str:type>/create/",
ais.AICreate.as_view(),
name="ai_create",
),
path(
"ai/<str:type>/update/<str:pk>/",
ais.AIUpdate.as_view(),
name="ai_update",
),
path(
"ai/<str:type>/delete/<str:pk>/",
ais.AIDelete.as_view(),
name="ai_delete",
),
# People
path(
"person/<str:type>/",
people.PersonList.as_view(),
name="people",
),
path(
"person/<str:type>/create/",
people.PersonCreate.as_view(),
name="person_create",
),
path(
"person/<str:type>/update/<str:pk>/",
people.PersonUpdate.as_view(),
name="person_update",
),
path(
"person/<str:type>/delete/<str:pk>/",
people.PersonDelete.as_view(),
name="person_delete",
),
# Groups
path(
"group/<str:type>/",
groups.GroupList.as_view(),
name="groups",
),
path(
"group/<str:type>/create/",
groups.GroupCreate.as_view(),
name="group_create",
),
path(
"group/<str:type>/update/<str:pk>/",
groups.GroupUpdate.as_view(),
name="group_update",
),
path(
"group/<str:type>/delete/<str:pk>/",
groups.GroupDelete.as_view(),
name="group_delete",
),
# Personas
path(
"persona/<str:type>/",
personas.PersonaList.as_view(),
name="personas",
),
path(
"persona/<str:type>/create/",
personas.PersonaCreate.as_view(),
name="persona_create",
),
path(
"persona/<str:type>/update/<str:pk>/",
personas.PersonaUpdate.as_view(),
name="persona_update",
),
path(
"persona/<str:type>/delete/<str:pk>/",
personas.PersonaDelete.as_view(),
name="persona_delete",
),
# Manipulations
path(
"manipulation/<str:type>/",
manipulations.ManipulationList.as_view(),
name="manipulations",
),
path(
"manipulation/<str:type>/create/",
manipulations.ManipulationCreate.as_view(),
name="manipulation_create",
),
path(
"manipulation/<str:type>/update/<str:pk>/",
manipulations.ManipulationUpdate.as_view(),
name="manipulation_update",
),
path(
"manipulation/<str:type>/delete/<str:pk>/",
manipulations.ManipulationDelete.as_view(),
name="manipulation_delete",
),
# Sessions
path(
"session/<str:type>/",
sessions.SessionList.as_view(),
name="sessions",
),
path(
"session/<str:type>/create/",
sessions.SessionCreate.as_view(),
name="session_create",
),
path(
"session/<str:type>/update/<str:pk>/",
sessions.SessionUpdate.as_view(),
name="session_update",
),
path(
"session/<str:type>/delete/<str:pk>/",
sessions.SessionDelete.as_view(),
name="session_delete",
),
# Identifiers
path("person/<str:type>/identifiers/<str:person>/", identifiers.PersonIdentifierList.as_view(), name="person_identifiers"),
path("person/<str:type>/identifiers/create/<str:person>", identifiers.PersonIdentifierCreate.as_view(), name="person_identifier_create"),
path("person/<str:type>/identifiers/update/<str:person>/<str:pk>/", identifiers.PersonIdentifierUpdate.as_view(), name="person_identifier_update"),
path("person/<str:type>/identifiers/delete/<str:person>/<str:pk>/", identifiers.PersonIdentifierDelete.as_view(), name="person_identifier_delete"),
# Messages
path("session/<str:type>/messages/<str:session>/", messages.MessageList.as_view(), name="messages"),
path("session/<str:type>/messages/create/<str:session>", messages.MessageCreate.as_view(), name="message_create"),
path("session/<str:type>/messages/update/<str:session>/<str:pk>/", messages.MessageUpdate.as_view(), name="message_update"),
path("session/<str:type>/messages/delete/<str:session>/<str:pk>/", messages.MessageDelete.as_view(), name="message_delete"),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

16
app/wsgi.py Normal file
View File

@@ -0,0 +1,16 @@
"""
WSGI config for app project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")
application = get_wsgi_application()