Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@ BACKEND_ROLES=
DOMAIN_NAME=
WORKFLOW_WORKER_NAME=worker1
WORKFLOW_QUEUES=workflow

4 changes: 2 additions & 2 deletions .github/workflows/other.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: CI for all commits

on:
push:
branches-ignore:
pull_request:
branches:
- main

jobs:
Expand Down
10 changes: 8 additions & 2 deletions workflow/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,15 @@ def authenticate_credentials(self, key, request=None):
# Was in use when we have poor invites implementation
# Now is not need
try:
username = userinfo["preferred_username"]
is_admin = username == settings.ADMIN_USERNAME
password = settings.ADMIN_PASSWORD if is_admin else generate_random_string(12)

user = User.objects.create_user(
username=userinfo["preferred_username"],
password=generate_random_string(12),
username=username,
password=password,
is_staff=is_admin,
is_superuser=is_admin,
)

except Exception:
Expand Down
46 changes: 46 additions & 0 deletions workflow/middleware.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import logging

from django.conf import settings
from django.db import connection

from workflow.utils import schema_exists

logger = logging.getLogger(__name__)


# Very Important Middleware
# It sets the PostgreSQL search path to the tenant's schema
Expand Down Expand Up @@ -58,3 +63,44 @@ def __call__(self, request):
cursor.execute("SET search_path TO public;")

return response


class SentryContextMiddleware:
"""
Middleware that adds realm_code, space_code and domain to Sentry scope.
Must be placed after RealmAndSpaceMiddleware in MIDDLEWARE list.
"""

def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
# Set Sentry context from request attributes
# These attributes are set by RealmAndSpaceMiddleware
try:
import sentry_sdk

with sentry_sdk.configure_scope() as scope:
# Add realm_code
realm_code = getattr(request, "realm_code", None)
if realm_code:
scope.set_tag("realm_code", realm_code)
scope.set_context("realm", {"code": realm_code})

# Add space_code
space_code = getattr(request, "space_code", None)
if space_code:
scope.set_tag("space_code", space_code)
scope.set_context("space", {"code": space_code})

# Add domain
domain = settings.DOMAIN_NAME
if domain:
scope.set_tag("domain", domain)
scope.set_context("domain", {"name": domain})

except Exception as e:
logger.debug(f"Failed to set Sentry context: {e}")

response = self.get_response(request)
return response
17 changes: 9 additions & 8 deletions workflow_app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@

MIDDLEWARE = [
"workflow.middleware.RealmAndSpaceMiddleware", # do not delete, required for all requests
"workflow.middleware.SentryContextMiddleware",
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
Expand Down Expand Up @@ -421,10 +422,12 @@
ENV_STR('DB_NAME', None))
CELERY_ENABLE_UTC = True
CELERY_TIMEZONE = 'UTC'
CELERY_TASK_TIME_LIMIT = ENV_INT('CELERY_TASK_TIME_LIMIT', 86400)
CELERY_TASK_TIME_LIMIT = ENV_INT('CELERY_TASK_TIME_LIMIT', 90000)
CELERY_TASK_SOFT_TIME_LIMIT = ENV_INT('CELERY_TASK_SOFT_TIME_LIMIT', 86400)
CELERY_BEAT_SCHEDULER = 'workflow.schedulers:DatabaseScheduler'

CELERY_TASK_DEFAULT_QUEUE = ENV_STR('WORKFLOW_QUEUES', "workflow")

DJANGO_CELERY_RESULTS_TASK_ID_MAX_LENGTH = 191

CELERY_BROKER_TRANSPORT_OPTIONS = {
Expand Down Expand Up @@ -535,15 +538,13 @@
if SERVER_TYPE != "local" and SENTRY_DSN:
sentry_sdk.init(
dsn=SENTRY_DSN,
integrations=[DjangoIntegration()],
environment=SERVER_TYPE,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
# We recommend adjusting this value in production.
traces_sample_rate=1.0,

# If you wish to associate users to errors (assuming you are using
# django.contrib.auth) you may enable sending PII data.
send_default_pii=True,
before_send=filter_sentry_events,
profiles_sample_rate=1.0,
)

EDITION_TYPE = ENV_STR("EDITION_TYPE", "entreprise")
ADMIN_USERNAME = ENV_STR("ADMIN_USERNAME", "admin")
ADMIN_PASSWORD = ENV_STR("ADMIN_PASSWORD", "password")