diff --git a/.env.sample b/.env.sample index 6dce8aa..3a7dece 100644 --- a/.env.sample +++ b/.env.sample @@ -34,4 +34,3 @@ BACKEND_ROLES= DOMAIN_NAME= WORKFLOW_WORKER_NAME=worker1 WORKFLOW_QUEUES=workflow - diff --git a/.github/workflows/other.yml b/.github/workflows/other.yml index 6557d83..0ba8403 100644 --- a/.github/workflows/other.yml +++ b/.github/workflows/other.yml @@ -1,8 +1,8 @@ name: CI for all commits on: - push: - branches-ignore: + pull_request: + branches: - main jobs: diff --git a/workflow/authentication.py b/workflow/authentication.py index d11bfb7..fa5f20a 100644 --- a/workflow/authentication.py +++ b/workflow/authentication.py @@ -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: diff --git a/workflow/middleware.py b/workflow/middleware.py index 7408b7f..0897935 100644 --- a/workflow/middleware.py +++ b/workflow/middleware.py @@ -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 @@ -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 diff --git a/workflow_app/settings.py b/workflow_app/settings.py index bccd406..84956c8 100644 --- a/workflow_app/settings.py +++ b/workflow_app/settings.py @@ -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', @@ -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 = { @@ -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")