posthog icon indicating copy to clipboard operation
posthog copied to clipboard

feat: add is_active to organizations

Open ReeceJones opened this issue 1 month ago • 14 comments

Problem

It is not possible to temporarily disable access to an organization. The current workaround is to disable all users in the organization by setting is_active = False for these users.

Changes

  • Add is_active and is_not_active_reason to organization model
  • Add migration for ^
  • Add ActiveOrganization middleware to enforce that users are member of an active organization and the current organization in the session is active
  • Update organization switcher to disable selecting is_active = False organizations.
  • Update some data loaders to only load data when the current session has an organization set (current organization).

How did you test this code?

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

  1. Manual testing - loom demo
  2. Unit tests

Changelog: (features only) Is this feature complete?

ReeceJones avatar Dec 06 '25 01:12 ReeceJones

Docs from this PR will be published at posthog.com

Project Deployment Preview Updated (UTC)
posthog.com 🤷 Unknown Preview Dec 8, 2025, 11:04 PM

Preview will be ready in ~10 minutes. Click Preview link above to access docs at /handbook/engineering/

github-actions[bot] avatar Dec 08 '25 23:12 github-actions[bot]

Wiz Scan Summary

Scanner Findings
Vulnerability Finding Vulnerabilities -
Data Finding Sensitive Data -
Secret Finding Secrets -
IaC Misconfiguration IaC Misconfigurations -
SAST Finding SAST Findings -
Total -

View scan details in Wiz

To detect these findings earlier in the dev lifecycle, try using Wiz Code VS Code Extension.

wiz-7ad640923b[bot] avatar Dec 08 '25 23:12 wiz-7ad640923b[bot]

Migration SQL Changes

Hey đź‘‹, we've detected some migrations on this PR. Here's the SQL output for each migration, make sure they make sense:

posthog/migrations/0938_organization_is_active_and_more.py

BEGIN;
--
-- Add field is_active to organization
--
ALTER TABLE "posthog_organization" ADD COLUMN "is_active" boolean DEFAULT true NULL;
ALTER TABLE "posthog_organization" ALTER COLUMN "is_active" DROP DEFAULT;
--
-- Add field is_not_active_reason to organization
--
ALTER TABLE "posthog_organization" ADD COLUMN "is_not_active_reason" text NULL;
COMMIT;

Last updated: 2025-12-10 15:41 UTC (bfffa9c)

github-actions[bot] avatar Dec 08 '25 23:12 github-actions[bot]

Size Change: +533 B (+0.01%)

Total Size: 3.66 MB

ℹ️ View Unchanged
Filename Size Change
frontend/dist/toolbar.js 3.66 MB +533 B (+0.01%)

compressed-size-action

github-actions[bot] avatar Dec 08 '25 23:12 github-actions[bot]

🔍 Migration Risk Analysis

We've analyzed your migrations for potential risks.

Summary: 1 Safe | 0 Needs Review | 0 Blocked

âś… Safe

Brief or no lock, backwards compatible

posthog.0938_organization_is_active_and_more
  └─ #1 ✅ AddField
     Adding nullable field requires brief lock
     model: organization, field: is_active
  └─ #2 ✅ AddField
     Adding nullable field requires brief lock
     model: organization, field: is_not_active_reason

📚 How to Deploy These Changes Safely

AddField:

This operation acquires a brief lock but doesn't rewrite the table.

Deployment uses lock timeouts with automatic retries, so lock contention will cause retries rather than connection pile-up.

Last updated: 2025-12-10 15:41 UTC (bfffa9c)

github-actions[bot] avatar Dec 08 '25 23:12 github-actions[bot]

Query snapshots: Backend query snapshots updated

Changes: 9 snapshots (9 modified, 0 added, 0 deleted)

What this means:

  • Query snapshots have been automatically updated to match current output
  • These changes reflect modifications to database queries or schema

Next steps:

  • Review the query changes to ensure they're intentional
  • If unexpected, investigate what caused the query to change

Review snapshot changes →

posthog-bot avatar Dec 08 '25 23:12 posthog-bot

⏭️ Skipped snapshot commit because branch advanced to 581dd20 while workflow was testing 97402f7.

The new commit will trigger its own snapshot update workflow.

If you expected this workflow to succeed: This can happen due to concurrent commits. To get a fresh workflow run, either:

  • Merge master into your branch, or
  • Push an empty commit: git commit --allow-empty -m 'trigger CI' && git push

posthog-bot avatar Dec 08 '25 23:12 posthog-bot

Query snapshots: Backend query snapshots updated

Changes: 3 snapshots (3 modified, 0 added, 0 deleted)

What this means:

  • Query snapshots have been automatically updated to match current output
  • These changes reflect modifications to database queries or schema

Next steps:

  • Review the query changes to ensure they're intentional
  • If unexpected, investigate what caused the query to change

Review snapshot changes →

posthog-bot avatar Dec 09 '25 00:12 posthog-bot

⏭️ Skipped snapshot commit because branch advanced to 07d77af while workflow was testing 851aa0b.

The new commit will trigger its own snapshot update workflow.

If you expected this workflow to succeed: This can happen due to concurrent commits. To get a fresh workflow run, either:

  • Merge master into your branch, or
  • Push an empty commit: git commit --allow-empty -m 'trigger CI' && git push

posthog-bot avatar Dec 09 '25 00:12 posthog-bot

Visual regression: Storybook UI snapshots updated

Changes: 20 snapshots (20 modified, 0 added, 0 deleted)

What this means:

  • Snapshots have been automatically updated to match current rendering
  • Next CI run will switch to CHECK mode to verify stability
  • If snapshots change again, CHECK mode will fail (indicates flapping)

Next steps:

  • Review the changes to ensure they're intentional
  • Approve if changes match your expectations
  • If unexpected, investigate component rendering

Review snapshot changes →

posthog-bot avatar Dec 09 '25 01:12 posthog-bot

Visual regression: Storybook UI snapshots updated

Changes: 5 snapshots (5 modified, 0 added, 0 deleted)

What this means:

  • Snapshots have been automatically updated to match current rendering
  • Next CI run will switch to CHECK mode to verify stability
  • If snapshots change again, CHECK mode will fail (indicates flapping)

Next steps:

  • Review the changes to ensure they're intentional
  • Approve if changes match your expectations
  • If unexpected, investigate component rendering

Review snapshot changes →

posthog-bot avatar Dec 09 '25 14:12 posthog-bot

Visual regression: Storybook UI snapshots updated

Changes: 1 snapshots (1 modified, 0 added, 0 deleted)

What this means:

  • Snapshots have been automatically updated to match current rendering
  • Next CI run will switch to CHECK mode to verify stability
  • If snapshots change again, CHECK mode will fail (indicates flapping)

Next steps:

  • Review the changes to ensure they're intentional
  • Approve if changes match your expectations
  • If unexpected, investigate component rendering

Review snapshot changes →

posthog-bot avatar Dec 09 '25 21:12 posthog-bot

Query snapshots: Backend query snapshots updated

Changes: 2 snapshots (2 modified, 0 added, 0 deleted)

What this means:

  • Query snapshots have been automatically updated to match current output
  • These changes reflect modifications to database queries or schema

Next steps:

  • Review the query changes to ensure they're intentional
  • If unexpected, investigate what caused the query to change

Review snapshot changes →

posthog-bot avatar Dec 10 '25 10:12 posthog-bot

Query snapshots: Backend query snapshots updated

Changes: 2 snapshots (2 modified, 0 added, 0 deleted)

What this means:

  • Query snapshots have been automatically updated to match current output
  • These changes reflect modifications to database queries or schema

Next steps:

  • Review the query changes to ensure they're intentional
  • If unexpected, investigate what caused the query to change

Review snapshot changes →

posthog-bot avatar Dec 10 '25 12:12 posthog-bot