Repository navigation
feat(workflows): sandbox tenant mirror, org block and tier exclusion #128411
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
Closed
Silthus
wants to merge
6
commits into
workflows-sandbox-safety/caps
from
workflows-sandbox-safety/django
+655
−53
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bbf56be
feat(workflows): sandbox tenant mirror, org block and tier exclusion
Silthus 175e462
chore(workflows): merge safety/caps and master into this layer
Silthus ffd5304
Merge branch 'workflows-sandbox-safety/caps' into workflows-sandbox-s…
Silthus 7bc0be5
Merge branch 'workflows-sandbox-safety/caps' into workflows-sandbox-s…
Silthus cf32b69
chore(workflows): merge the layer below into workflows-sandbox-safety…
Silthus 9ce0beb
Merge branch 'workflows-sandbox-safety/caps' into workflows-sandbox-s…
Silthus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
products/workflows/backend/admin/sandbox_sender_organization_block_admin.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| from typing import cast | ||
|
|
||
| from django.contrib import admin | ||
| from django.forms import ModelForm | ||
| from django.http import HttpRequest | ||
|
|
||
| from posthog.models.user import User | ||
|
|
||
| from products.workflows.backend.models import SandboxSenderOrganizationBlock | ||
|
|
||
|
|
||
| @admin.register(SandboxSenderOrganizationBlock) | ||
| class SandboxSenderOrganizationBlockAdmin(admin.ModelAdmin): | ||
| list_display = ("organization", "reason", "created_by", "created_at") | ||
| fields = ("organization", "reason", "created_by", "created_at") | ||
| readonly_fields = ("created_by", "created_at") | ||
| raw_id_fields = ("organization",) | ||
| search_fields = ("organization__id", "organization__name", "reason") | ||
| list_select_related = ("organization", "created_by") | ||
| ordering = ("-created_at",) | ||
|
|
||
| def save_model( | ||
| self, | ||
| request: HttpRequest, | ||
| obj: SandboxSenderOrganizationBlock, | ||
| form: ModelForm | None, | ||
| change: bool, | ||
| ) -> None: | ||
| if not change: | ||
| obj.created_by = cast(User, request.user) | ||
| super().save_model(request, obj, form, change) |
32 changes: 32 additions & 0 deletions
32
products/workflows/backend/migrations/0041_sandbox_sender_tenant_state.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Generated by Django 6.1.2 on 2026-11-03 14:30 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("workflows", "0040_team_workflows_config_frequency_cap_hold"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name="SandboxSenderTenantState", | ||
| fields=[ | ||
| ( | ||
| "id", | ||
| models.BigAutoField( | ||
| auto_created=True, | ||
| primary_key=True, | ||
| serialize=False, | ||
| verbose_name="ID", | ||
| ), | ||
| ), | ||
| ("tenant_name", models.CharField(max_length=64, unique=True)), | ||
| ( | ||
| "sending_status", | ||
| models.CharField(blank=True, db_default="", default="", max_length=32), | ||
| ), | ||
| ("synced_at", models.DateTimeField(blank=True, null=True)), | ||
| ], | ||
| ), | ||
| ] |
52 changes: 52 additions & 0 deletions
52
products/workflows/backend/migrations/0042_sandbox_sender_organization_block.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # Generated by Django 6.1.2 on 2026-11-03 14:30 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.conf import settings | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("posthog", "1411_personalapikey_expires_at"), | ||
| ("workflows", "0041_sandbox_sender_tenant_state"), | ||
| migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name="SandboxSenderOrganizationBlock", | ||
| fields=[ | ||
| ( | ||
| "id", | ||
| models.BigAutoField( | ||
| auto_created=True, | ||
| primary_key=True, | ||
| serialize=False, | ||
| verbose_name="ID", | ||
| ), | ||
| ), | ||
| ("reason", models.TextField()), | ||
| ("created_at", models.DateTimeField(auto_now_add=True)), | ||
| ( | ||
| "created_by", | ||
| models.ForeignKey( | ||
| blank=True, | ||
| db_constraint=False, | ||
| null=True, | ||
| on_delete=django.db.models.deletion.SET_NULL, | ||
| related_name="+", | ||
| to=settings.AUTH_USER_MODEL, | ||
| ), | ||
| ), | ||
| ( | ||
| "organization", | ||
| models.OneToOneField( | ||
| db_constraint=False, | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| related_name="+", | ||
| to="posthog.organization", | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0040_team_workflows_config_frequency_cap_hold | ||
| 0042_sandbox_sender_organization_block |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
products/workflows/backend/models/sandbox_sender_organization_block.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| from django.db import models | ||
|
|
||
|
|
||
| class SandboxSenderOrganizationBlock(models.Model): | ||
| organization = models.OneToOneField( | ||
| "posthog.Organization", on_delete=models.CASCADE, db_constraint=False, related_name="+" | ||
| ) | ||
| reason = models.TextField() | ||
| created_by = models.ForeignKey( | ||
| "posthog.User", on_delete=models.SET_NULL, null=True, blank=True, db_constraint=False, related_name="+" | ||
| ) | ||
| created_at = models.DateTimeField(auto_now_add=True) | ||
|
|
||
| def __str__(self) -> str: | ||
| return self.organization.name |
9 changes: 9 additions & 0 deletions
9
products/workflows/backend/models/sandbox_sender_tenant_state.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| from django.db import models | ||
|
|
||
|
|
||
| class SandboxSenderTenantState(models.Model): | ||
| """Instance-level mirror of the shared sandbox SES tenant; platform state, not tenant data, so no team_id.""" | ||
|
|
||
| tenant_name = models.CharField(max_length=64, unique=True) | ||
| sending_status = models.CharField(max_length=32, blank=True, default="", db_default="") | ||
| synced_at = models.DateTimeField(null=True, blank=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2 · Wire the sandbox reload message to a worker consumer
When reconciliation records
DISABLED, this publishes to a channel that no worker subscribes to. Workers also never readSandboxSenderTenantState;SandboxEmailSender.canSenddepends only on configuration, so they continue attempting sends against the paused tenant. Add a worker state reader and subscriber, and enforce that state before sending.