:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(flags): confirm before a save releases a flag to all users (#127717)
ruby childsb907ab160f53
diff --git a/frontend/src/scenes/feature-flags/ConfirmationModal.tsx b/frontend/src/scenes/feature-flags/ConfirmationModal.tsxindex 1980ed785d78..98d0e3da18f0 100644--- a/frontend/src/scenes/feature-flags/ConfirmationModal.tsx+++ b/frontend/src/scenes/feature-flags/ConfirmationModal.tsx@@ -1,3 +1,5 @@+import posthog from 'posthog-js'+import { IconWarning } from '@posthog/icons'import { LemonDialog, Link } from '@posthog/lemon-ui'@@ -19,10 +21,23 @@ interface ConfirmationModalProps {dependentFlags?: DependentFlag[] // Feature flags that depend on this flag (only shown when disabling)isBeingDisabled?: boolean // Whether the flag is being disabled (controls dependent flags warning)featureFlagConfirmationEnabled?: boolean // Whether the team has feature flag confirmation enabled in settings+ releasesToEveryone?: boolean // Whether saving turns the flag on for everyone (only for multi-changes type)onConfirm: () => voidonCancel?: () => void}+function WarningCallout({ title, children }: { title: string; children: React.ReactNode }): JSX.Element {+ return (+ <div className="mt-4 p-3 border border-warning bg-warning-highlight rounded">+ <p className="my-0 flex items-center gap-2">+ <IconWarning className="text-warning" />+ <strong>{title}</strong>+ </p>+ <p className="mb-0">{children}</p>+ </div>+ )+}+/*** Opens a confirmation dialog for feature flag changes.* This is used for confirming status changes, rollout changes, or multiple changes at once.@@ -36,6 +51,7 @@ export function openConfirmationModal({dependentFlags,isBeingDisabled = false,featureFlagConfirmationEnabled = false,+ releasesToEveryone = false,onConfirm,onCancel,}: ConfirmationModalProps): void {@@ -100,30 +116,30 @@ export function openConfirmationModal({<li key={index}>{change}</li>))}</ul>+ {releasesToEveryone && (+ <WarningCallout title="This releases the flag to all users">+ After you save, every user who evaluates <strong>{featureFlag.key}</strong> gets it+ immediately.+ </WarningCallout>+ )}{isBeingDisabled && dependentFlags && dependentFlags.length > 0 && (- <div className="mt-4 p-3 border border-warning bg-warning-highlight rounded">- <p className="my-0 flex items-center gap-2">- <IconWarning className="text-warning" />- <strong>Cannot disable this feature flag</strong>- </p>- <p className="mb-0">- This flag is referenced by {dependentFlags.length} other feature flag- {dependentFlags.length === 1 ? '' : 's'}:{' '}- {dependentFlags.map((flag, index) => (- <span key={flag.id}>- {index > 0 && (index === dependentFlags.length - 1 ? ' and ' : ', ')}- <Link- to={urls.featureFlag(flag.id)}- target="_blank"- aria-label={`Open ${flag.key}`}- >- <strong>{flag.key}</strong>- </Link>- </span>- ))}- . Please update or disable the dependent flags first.- </p>- </div>+ <WarningCallout title="Cannot disable this feature flag">+ This flag is referenced by {dependentFlags.length} other feature flag+ {dependentFlags.length === 1 ? '' : 's'}:{' '}+ {dependentFlags.map((flag, index) => (+ <span key={flag.id}>+ {index > 0 && (index === dependentFlags.length - 1 ? ' and ' : ', ')}+ <Link+ to={urls.featureFlag(flag.id)}+ target="_blank"+ aria-label={`Open ${flag.key}`}+ >+ <strong>{flag.key}</strong>+ </Link>+ </span>+ ))}+ . Please update or disable the dependent flags first.+ </WarningCallout>)}{allMessages.map((message, index) => (<p key={index} className="mt-4">@@ -138,6 +154,12 @@ export function openConfirmationModal({// Determine if the primary button should be disabledconst hasBlockingDependentFlags = isBeingDisabled && dependentFlags && dependentFlags.length > 0+ let confirmed = false++ if (releasesToEveryone) {+ // pinned: analytics event names+ posthog.capture('feature flag release to everyone confirmation shown')+ }LemonDialog.open({title,@@ -148,14 +170,27 @@ export function openConfirmationModal({? `${capitalizeFirstLetter(activeNewValue ? 'enable' : 'disable')} flag`: type === 'rollout'? 'Update conditions'- : 'Save changes',+ : releasesToEveryone+ ? 'Release to all users'+ : 'Save changes',status: type === 'flag-status' && !activeNewValue ? 'danger' : 'default',- onClick: hasBlockingDependentFlags ? undefined : onConfirm,+ onClick: hasBlockingDependentFlags+ ? undefined+ : () => {+ confirmed = true+ onConfirm()+ },disabled: hasBlockingDependentFlags,},secondaryButton: {children: 'Cancel',onClick: onCancel,},+ // Escape, the close icon and the overlay skip the Cancel button, so count every close without a confirm.+ onAfterClose: () => {+ if (releasesToEveryone && !confirmed) {+ posthog.capture('feature flag release to everyone confirmation canceled')+ }+ },})}diff --git a/frontend/src/scenes/feature-flags/featureFlagConfirmationLogic.ts b/frontend/src/scenes/feature-flags/featureFlagConfirmationLogic.tsindex 0f7905d6d4b3..3e95cfd3ee57 100644--- a/frontend/src/scenes/feature-flags/featureFlagConfirmationLogic.ts+++ b/frontend/src/scenes/feature-flags/featureFlagConfirmationLogic.ts@@ -114,10 +114,11 @@ export function checkFeatureFlagConfirmation(dependentFlags?: DependentFlag[],isBeingDisabled?: boolean,requireStatusConfirmation = false,- onDisableAndArchive?: () => void+ onDisableAndArchive?: () => void,+ releasesToEveryone = false): boolean {// Check if confirmation is needed- const needsConfirmation = !!updatedFlag.id && shouldDisplayConfirmation+ const needsConfirmation = !!updatedFlag.id && (shouldDisplayConfirmation || releasesToEveryone)if (needsConfirmation) {const changes = detectFeatureFlagChanges(originalFlag, updatedFlag)@@ -132,6 +133,7 @@ export function checkFeatureFlagConfirmation(dependentFlags: dependentFlags,isBeingDisabled: isBeingDisabled,featureFlagConfirmationEnabled: featureFlagConfirmationEnabled,+ releasesToEveryone: releasesToEveryone,onConfirm: onConfirm,})return true // Confirmation modal shown, don't proceed with savediff --git a/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts b/frontend/src/scenes/feature-flags/featureFlagLogic.test.tsindex d3be3a0feaa5..2d3f2a230407 100644--- a/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts+++ b/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts@@ -3890,6 +3890,103 @@ describe('featureFlagLogic', () => {})})+ describe('release to everyone confirmation', () => {+ const withRollout = (rollout_percentage: number): FeatureFlagType =>+ ({+ ...MOCK_FEATURE_FLAG,+ filters: {+ ...MOCK_FEATURE_FLAG.filters,+ groups: [{ properties: [], rollout_percentage, variant: null }],+ },+ }) as FeatureFlagType++ it('confirms a save that releases the flag to all users, even with team confirmation off', async () => {+ const dialogOpenSpy = jest.spyOn(LemonDialog, 'open').mockImplementation(() => {})+ logic.actions.setOriginalFeatureFlag(withRollout(50))+ logic.actions.setFeatureFlag(withRollout(100))++ await expectLogic(logic, () => logic.actions.submitFeatureFlagWithValidation(logic.values.featureFlag))+ .toNotHaveDispatchedActions(['saveFeatureFlag'])+ .toFinishAllListeners()++ expect(dialogOpenSpy).toHaveBeenCalledTimes(1)+ expect(dialogOpenSpy.mock.calls[0][0].primaryButton?.children).toBe('Release to all users')+ expect(capturesOf('feature flag release to everyone confirmation shown')).toHaveLength(1)+ dialogOpenSpy.mockRestore()+ })++ it('confirms turning on a disabled flag that is already at 100% of all users', async () => {+ const dialogOpenSpy = jest.spyOn(LemonDialog, 'open').mockImplementation(() => {})+ const disabledForEveryone = { ...withRollout(100), active: false }+ logic.actions.setOriginalFeatureFlag(disabledForEveryone)+ logic.actions.setFeatureFlag(disabledForEveryone)++ await expectLogic(logic, () => logic.actions.toggleFeatureFlagActive(true)).toFinishAllListeners()++ expect(dialogOpenSpy).toHaveBeenCalledTimes(1)+ expect(dialogOpenSpy.mock.calls[0][0].primaryButton?.children).toBe('Release to all users')+ expect(capturesOf('feature flag release to everyone confirmation shown')).toHaveLength(1)+ dialogOpenSpy.mockRestore()+ })++ it('keeps the usual save confirmation for a partial rollout when the team requires confirmation', async () => {+ teamLogic.actions.loadCurrentTeamSuccess({ ...MOCK_DEFAULT_TEAM, feature_flag_confirmation_enabled: true })+ const dialogOpenSpy = jest.spyOn(LemonDialog, 'open').mockImplementation(() => {})+ logic.actions.setOriginalFeatureFlag(withRollout(50))+ logic.actions.setFeatureFlag(withRollout(60))++ await expectLogic(logic, () => logic.actions.submitFeatureFlagWithValidation(logic.values.featureFlag))+ .toNotHaveDispatchedActions(['saveFeatureFlag'])+ .toFinishAllListeners()++ const dialogProps = dialogOpenSpy.mock.calls[0][0]+ expect(dialogProps.primaryButton?.children).toBe('Save changes')+ dialogProps.onAfterClose?.()+ expect(capturesOf('feature flag release to everyone confirmation shown')).toHaveLength(0)+ expect(capturesOf('feature flag release to everyone confirmation canceled')).toHaveLength(0)+ dialogOpenSpy.mockRestore()+ })++ it.each([+ { scenario: 'dismissed with Escape, the close icon or the overlay', confirm: false, canceled: 1 },+ { scenario: 'confirmed', confirm: true, canceled: 0 },+ ])('counts a cancellation only when the warning is $scenario', async ({ confirm, canceled }) => {+ const dialogOpenSpy = jest.spyOn(LemonDialog, 'open').mockImplementation(() => {})+ const update = jest.spyOn(api, 'update').mockResolvedValue(withRollout(100))+ logic.actions.setOriginalFeatureFlag(withRollout(50))+ logic.actions.setFeatureFlag(withRollout(100))+ await expectLogic(logic, () =>+ logic.actions.submitFeatureFlagWithValidation(logic.values.featureFlag)+ ).toFinishAllListeners()++ const dialogProps = dialogOpenSpy.mock.calls[0][0]+ if (confirm) {+ dialogProps.primaryButton?.onClick?.(undefined as any)+ }+ dialogProps.onAfterClose?.()+ await expectLogic(logic).toFinishAllListeners()++ expect(capturesOf('feature flag release to everyone confirmation canceled')).toHaveLength(canceled)+ expect(update).toHaveBeenCalledTimes(confirm ? 1 : 0)+ dialogOpenSpy.mockRestore()+ update.mockRestore()+ })++ it('saves a partial rollout change without asking', async () => {+ const dialogOpenSpy = jest.spyOn(LemonDialog, 'open').mockImplementation(() => {})+ jest.spyOn(api, 'update').mockResolvedValueOnce(withRollout(60))+ logic.actions.setOriginalFeatureFlag(withRollout(50))+ logic.actions.setFeatureFlag(withRollout(60))++ await expectLogic(logic, () => logic.actions.submitFeatureFlagWithValidation(logic.values.featureFlag))+ .toDispatchActions(['saveFeatureFlag'])+ .toFinishAllListeners()++ expect(dialogOpenSpy).not.toHaveBeenCalled()+ dialogOpenSpy.mockRestore()+ })+ })+describe('rollback reason question', () => {const rollbackReasonRequired = (): ApiError =>new ApiError(undefined, 409, undefined, {diff --git a/frontend/src/scenes/feature-flags/featureFlagLogic.ts b/frontend/src/scenes/feature-flags/featureFlagLogic.tsindex 6710e2ad09ca..a4e45f2759ac 100644--- a/frontend/src/scenes/feature-flags/featureFlagLogic.ts+++ b/frontend/src/scenes/feature-flags/featureFlagLogic.ts@@ -3452,6 +3452,8 @@ export const featureFlagLogic = kea<featureFlagLogicType>([}const shouldDisplayConfirmation = featureFlagConfirmationEnabled || dependentFlags.length > 0+ // Releasing an existing flag to everyone is always confirmed, whatever the team setting says.+ const releasesToEveryone = flagWentLive(originalFlag, updatedFlag as FeatureFlagType)const confirmationShown = checkFeatureFlagConfirmation(originalFlag,@@ -3463,7 +3465,8 @@ export const featureFlagLogic = kea<featureFlagLogicType>([dependentFlags,isBeingDisabled,requireStatusConfirmation,- onDisableAndArchive+ onDisableAndArchive,+ releasesToEveryone)// If no confirmation was shown, proceed immediately