mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
feat(cloud): MFA notice escalates in the last three days, a one-time toast per deadline, badge in the members list
This commit is contained in:
@@ -81,6 +81,8 @@ it.each(['owner', 'admin'] as const)('shows the MFA column to an %s', (viewerRol
|
||||
container.querySelector(`[data-team-row="${key}"] [data-team-mfa]`)!
|
||||
expect(cell('member:u-neil').textContent).toBe('MFA on')
|
||||
expect(cell('member:u-grace').textContent).toBe('MFA due Nov 24')
|
||||
// A small muted badge, not bare text.
|
||||
expect(cell('member:u-neil').querySelector('[data-slot="badge"]')).not.toBeNull()
|
||||
// Invites keep an empty cell so the role column stays aligned.
|
||||
expect(cell('invite:alex@acme.dev').textContent).toBe('')
|
||||
})
|
||||
|
||||
@@ -25,7 +25,6 @@ import {
|
||||
SelectValue
|
||||
} from '@/components/ui/select'
|
||||
import { LoadingSpinner } from '@/components/LoadingSpinner'
|
||||
import { cn } from '@/lib/class-names'
|
||||
import { useIntlLocale, useTranslate } from '@/i18n/use-translate'
|
||||
import type { OrcaOrgMember, OrcaOrgRole } from '../../../../../shared/orca-profiles'
|
||||
import { PersonAvatar } from './TeamAvatar'
|
||||
@@ -307,14 +306,11 @@ export function TeamMemberList(props: TeamMemberListProps): React.JSX.Element {
|
||||
// Rendered for every row, invites included, so the role column stays aligned.
|
||||
<span
|
||||
data-team-mfa={row.kind === 'member' ? (row.member.mfa ?? '') : ''}
|
||||
className={cn(
|
||||
'w-24 shrink-0 truncate text-xs',
|
||||
row.kind === 'member' && row.member.mfa === 'on'
|
||||
? 'text-muted-foreground'
|
||||
: 'text-foreground'
|
||||
)}
|
||||
className="flex w-28 shrink-0"
|
||||
>
|
||||
{row.kind === 'member' ? memberMfaLabel(row.member, locale, t) : null}
|
||||
{row.kind === 'member' && memberMfaLabel(row.member, locale, t) ? (
|
||||
<Badge variant="tag">{memberMfaLabel(row.member, locale, t)}</Badge>
|
||||
) : null}
|
||||
</span>
|
||||
) : null}
|
||||
{row.kind === 'member' ? (
|
||||
|
||||
@@ -3,6 +3,7 @@ import type {
|
||||
OrcaTeamMfaPendingMember,
|
||||
OrcaTeamMfaPolicy
|
||||
} from '../../../../shared/orca-team-mfa-policy'
|
||||
import { CloudToastCard } from '@/components/orca-cloud/cloud-toast-stack'
|
||||
import { RequireMfaRow, type RequireMfaRowProps } from './RequireMfaRow'
|
||||
import { TeamMfaBanner } from './TeamMfaBanner'
|
||||
import { TeamMfaBlockedScreen } from './TeamMfaBlockedScreen'
|
||||
@@ -58,12 +59,33 @@ const sidebar = (daysLeft: number, sidebarWidth: number) =>
|
||||
})
|
||||
|
||||
export const sidebarTwoWeeks = sidebar(14, 280)
|
||||
/** Three days or fewer: the warning look. */
|
||||
export const sidebarThreeDays = sidebar(3, 280)
|
||||
export const sidebarOneDay = sidebar(1, 280)
|
||||
/** After the deadline: no access until set up. */
|
||||
export const sidebarBlocked = sidebar(-2, 280)
|
||||
/** The narrowest sidebar. */
|
||||
export const sidebarBlockedNarrow = sidebar(-2, 220)
|
||||
|
||||
// ---- The one-time toast, for people who keep the sidebar collapsed ----
|
||||
|
||||
export const toast = frame(
|
||||
<CloudToastCard
|
||||
view={{
|
||||
priority: 'action',
|
||||
lines: [
|
||||
{
|
||||
key: 'mfa',
|
||||
text: 'Acme Engineering requires MFA from December 2, 2026.',
|
||||
action: { label: 'Set up MFA', primary: true, link: setupUrl, onClick: noop }
|
||||
}
|
||||
]
|
||||
}}
|
||||
onDismiss={noop}
|
||||
/>,
|
||||
420
|
||||
)
|
||||
|
||||
// ---- Blocked screen: after the deadline ----
|
||||
|
||||
const blocked = (props: { checking?: boolean; stillMissing?: boolean; personal?: boolean }) =>
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import { useEffect } from 'react'
|
||||
import { hideCloudToast, showCloudToast } from '@/components/orca-cloud/cloud-toast-stack'
|
||||
import { useIntlLocale, useTranslate } from '@/i18n/use-translate'
|
||||
import { claimMfaToast, mfaDeadlineDate } from './team-mfa-copy'
|
||||
import { useTeamMfaGate } from './TeamMfaGate'
|
||||
|
||||
/**
|
||||
@@ -10,7 +14,56 @@ import { useTeamMfaGate } from './TeamMfaGate'
|
||||
* team resource shows TeamMfaRefused in its own place whether or not the sidebar is visible.
|
||||
*/
|
||||
export function TeamMfaSidebarBanner(): React.JSX.Element | null {
|
||||
return useTeamMfaGate().sidebarBanner
|
||||
const gate = useTeamMfaGate()
|
||||
const t = useTranslate()
|
||||
const locale = useIntlLocale()
|
||||
const toast = gate.pendingToast
|
||||
const orgId = toast?.orgId
|
||||
const enforceAt = toast?.enforceAt
|
||||
// One toast per team and deadline, for people who keep the sidebar collapsed. Not tied to any
|
||||
// workspace, so it shows wherever they are; the sidebar card stays as the lasting reminder.
|
||||
useEffect(() => {
|
||||
if (!toast || orgId === undefined || enforceAt === undefined) {
|
||||
return
|
||||
}
|
||||
if (!claimMfaToast(readLocalStorage(), orgId, enforceAt)) {
|
||||
return
|
||||
}
|
||||
const id = `team-mfa:${orgId}`
|
||||
showCloudToast(id, {
|
||||
priority: 'action',
|
||||
lines: [
|
||||
{
|
||||
key: 'mfa',
|
||||
text: t('auto.components.teamMfa.toast', '{{value0}} requires MFA from {{value1}}.', {
|
||||
value0: toast.teamName,
|
||||
value1: mfaDeadlineDate(enforceAt, locale)
|
||||
}),
|
||||
action: {
|
||||
label: t('auto.components.teamMfa.setUp', 'Set up MFA'),
|
||||
primary: true,
|
||||
// Opens the account page in the browser, so the chevron offers Copy link.
|
||||
link: toast.setupUrl,
|
||||
onClick: () => {
|
||||
void window.api.shell.openUrl(toast.setupUrl)
|
||||
hideCloudToast(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
// Deliberately keyed on the team and deadline only: copy or locale changes must not re-show.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [orgId, enforceAt])
|
||||
return gate.sidebarBanner
|
||||
}
|
||||
|
||||
function readLocalStorage(): Storage | null {
|
||||
try {
|
||||
return window.localStorage
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,8 @@ import { InlineError } from '@/components/ui/inline-error'
|
||||
import { cn } from '@/lib/class-names'
|
||||
import { OpenExternalSplitButton } from '@/components/open-external/OpenExternalSplitButton'
|
||||
import { useIntlLocale, useTranslate } from '@/i18n/use-translate'
|
||||
import { mfaCountdownLabel, mfaDeadlineDate } from './team-mfa-copy'
|
||||
import { BANNER_BODY_TEXT, BANNER_TONE } from '@/components/ui/banner-tone'
|
||||
import { mfaCountdownLabel, mfaDeadlineDate, mfaSoonTitle, mfaUrgency } from './team-mfa-copy'
|
||||
|
||||
export type TeamMfaBannerProps = {
|
||||
teamName: string
|
||||
@@ -35,7 +36,10 @@ export function TeamMfaBanner({
|
||||
}: TeamMfaBannerProps): React.JSX.Element {
|
||||
const t = useTranslate()
|
||||
const locale = useIntlLocale()
|
||||
const title = blocked
|
||||
const urgency = mfaUrgency(enforceAt, now, blocked)
|
||||
const title = urgency === 'soon'
|
||||
? mfaSoonTitle(teamName, enforceAt, now, t)
|
||||
: blocked
|
||||
? t(
|
||||
'auto.components.teamMfa.bannerBlockedTitle',
|
||||
'{{value0}} requires two-factor authentication',
|
||||
@@ -67,10 +71,16 @@ export function TeamMfaBanner({
|
||||
return (
|
||||
<section
|
||||
role={blocked ? 'alert' : 'status'}
|
||||
data-team-mfa-banner={blocked ? 'blocked' : 'pending'}
|
||||
data-team-mfa-banner={urgency}
|
||||
className={cn(
|
||||
'mx-2 mb-2 shrink-0 rounded-md border bg-worktree-sidebar-accent/40 p-2.5 text-worktree-sidebar-foreground',
|
||||
blocked ? 'border-destructive/50' : 'border-border',
|
||||
'mx-2 mb-2 shrink-0 rounded-md border p-2.5 text-worktree-sidebar-foreground',
|
||||
// Quiet with time to spare; the shared warning look in the last three days; the
|
||||
// destructive border of a real block after the deadline.
|
||||
urgency === 'soon'
|
||||
? cn(BANNER_TONE.warning.surface, BANNER_TONE.warning.border)
|
||||
: 'bg-worktree-sidebar-accent/40',
|
||||
urgency === 'blocked' && 'border-destructive/50',
|
||||
urgency === 'quiet' && 'border-border',
|
||||
className
|
||||
)}
|
||||
>
|
||||
@@ -78,13 +88,24 @@ export function TeamMfaBanner({
|
||||
<ShieldAlert
|
||||
className={cn(
|
||||
'mt-px size-3.5 shrink-0',
|
||||
blocked ? 'text-destructive' : 'text-muted-foreground'
|
||||
urgency === 'blocked'
|
||||
? 'text-destructive'
|
||||
: urgency === 'soon'
|
||||
? BANNER_TONE.warning.icon
|
||||
: 'text-muted-foreground'
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<div className="min-w-0 flex-1 space-y-1.5">
|
||||
<p className="text-xs font-semibold leading-snug">{title}</p>
|
||||
<p className="text-xs leading-snug text-muted-foreground">{detail}</p>
|
||||
<p
|
||||
className={cn(
|
||||
'text-xs leading-snug',
|
||||
urgency === 'soon' ? BANNER_BODY_TEXT : 'text-muted-foreground'
|
||||
)}
|
||||
>
|
||||
{detail}
|
||||
</p>
|
||||
{action}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -21,6 +21,8 @@ export function useTeamMfaGate(options: { forceBlocked?: boolean } = {}): {
|
||||
blocked: React.JSX.Element | null
|
||||
/** The sidebar notice: the countdown, or "no access" once blocked. */
|
||||
sidebarBanner: React.JSX.Element | null
|
||||
/** Set while the member still has time: what the one-time toast needs. */
|
||||
pendingToast: { orgId: string; teamName: string; enforceAt: number; setupUrl: string } | null
|
||||
} {
|
||||
const cloud = useAppStore((state) => state.orcaProfileAuthStatus?.cloud)
|
||||
const selectOrg = useAppStore((state) => state.selectOrcaProfileOrg)
|
||||
@@ -31,7 +33,7 @@ export function useTeamMfaGate(options: { forceBlocked?: boolean } = {}): {
|
||||
const [stillMissing, setStillMissing] = useState(false)
|
||||
|
||||
if (!orgId || !policy?.policy) {
|
||||
return { banner: null, blocked: null, sidebarBanner: null }
|
||||
return { banner: null, blocked: null, sidebarBanner: null, pendingToast: null }
|
||||
}
|
||||
const surface = teamMfaSurface(policy)
|
||||
const openSetup = (): void => {
|
||||
@@ -56,6 +58,7 @@ export function useTeamMfaGate(options: { forceBlocked?: boolean } = {}): {
|
||||
return {
|
||||
banner: null,
|
||||
sidebarBanner: line(true, 'sidebar'),
|
||||
pendingToast: null,
|
||||
blocked: (
|
||||
<TeamMfaBlockedScreen
|
||||
teamName={teamName}
|
||||
@@ -79,6 +82,9 @@ export function useTeamMfaGate(options: { forceBlocked?: boolean } = {}): {
|
||||
return {
|
||||
banner: pending ? line(false) : null,
|
||||
sidebarBanner: pending ? line(false, 'sidebar') : null,
|
||||
pendingToast: pending
|
||||
? { orgId, teamName, enforceAt: policy.policy.enforceAt, setupUrl: policy.setupUrl }
|
||||
: null,
|
||||
blocked: null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,63 @@ export function teamMfaSurface(policy: OrcaTeamMfaPolicy | null): 'none' | 'bann
|
||||
return policy.self === 'pending' ? 'banner' : 'none'
|
||||
}
|
||||
|
||||
/** From this many days before the deadline the notice stops being quiet (design-squad). */
|
||||
export const MFA_URGENT_DAYS = 3
|
||||
|
||||
/**
|
||||
* How loud the notice is: quiet with more than three days left, a warning in the last three,
|
||||
* and blocked only on the server's word (never from the clock).
|
||||
*/
|
||||
export type TeamMfaUrgency = 'quiet' | 'soon' | 'blocked'
|
||||
|
||||
export function mfaUrgency(enforceAt: number, now: number, blocked: boolean): TeamMfaUrgency {
|
||||
if (blocked) {
|
||||
return 'blocked'
|
||||
}
|
||||
return mfaDaysLeft(enforceAt, now) <= MFA_URGENT_DAYS ? 'soon' : 'quiet'
|
||||
}
|
||||
|
||||
/** "Acme requires MFA in 2 days": the title once the deadline is close. */
|
||||
export function mfaSoonTitle(teamName: string, enforceAt: number, now: number, t: Translate): string {
|
||||
const days = mfaDaysLeft(enforceAt, now)
|
||||
if (days <= 0) {
|
||||
return t('auto.components.teamMfa.soonTitleNow', '{{value0}} requires MFA now', {
|
||||
value0: teamName
|
||||
})
|
||||
}
|
||||
return t('auto.components.teamMfa.soonTitle', '{{value0}} requires MFA in {{count}} days', {
|
||||
value0: teamName,
|
||||
count: days,
|
||||
defaultValue_one: '{{value0}} requires MFA in {{count}} day'
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* The one-time toast is shown once per team and deadline, so a changed date announces itself
|
||||
* again and a restart does not repeat it.
|
||||
*/
|
||||
export function mfaToastSeenKey(orgId: string, enforceAt: number): string {
|
||||
return `orca.teamMfa.toastSeen:${orgId}:${enforceAt}`
|
||||
}
|
||||
|
||||
/** True the first time for a deadline; records it. A storage failure shows it rather than hide it. */
|
||||
export function claimMfaToast(
|
||||
storage: Pick<Storage, 'getItem' | 'setItem'> | null,
|
||||
orgId: string,
|
||||
enforceAt: number
|
||||
): boolean {
|
||||
const key = mfaToastSeenKey(orgId, enforceAt)
|
||||
try {
|
||||
if (storage?.getItem(key) === '1') {
|
||||
return false
|
||||
}
|
||||
storage?.setItem(key, '1')
|
||||
} catch {
|
||||
// Private mode or a full quota: showing it again next launch is the lesser problem.
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/** "6 days left", "1 day left", "Due now". i18next plurals, never ternaries on the count. */
|
||||
export function mfaCountdownLabel(enforceAt: number, now: number, t: Translate): string {
|
||||
const days = mfaDaysLeft(enforceAt, now)
|
||||
|
||||
@@ -6,7 +6,14 @@ import type { OrcaTeamMfaPolicy } from '../../../../shared/orca-team-mfa-policy'
|
||||
import { RequireMfaRow, type RequireMfaRowProps } from './RequireMfaRow'
|
||||
import { TeamMfaBanner } from './TeamMfaBanner'
|
||||
import { TeamMfaBlockedScreen } from './TeamMfaBlockedScreen'
|
||||
import { mfaCountdownLabel, mfaDaysLeft, teamMfaSurface } from './team-mfa-copy'
|
||||
import {
|
||||
claimMfaToast,
|
||||
mfaCountdownLabel,
|
||||
mfaDaysLeft,
|
||||
mfaSoonTitle,
|
||||
mfaUrgency,
|
||||
teamMfaSurface
|
||||
} from './team-mfa-copy'
|
||||
import { describeError, describeInlineError } from '../cloud-workspaces/cloud-workspace-errors'
|
||||
|
||||
afterEach(cleanup)
|
||||
@@ -239,3 +246,69 @@ describe('banner after the deadline', () => {
|
||||
expect(getByRole('button', { name: 'Set up MFA' })).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
||||
describe('escalation', () => {
|
||||
it('is quiet with more than three days left, a warning in the last three, blocked on the server', () => {
|
||||
expect(mfaUrgency(NOW + 14 * DAY, NOW, false)).toBe('quiet')
|
||||
expect(mfaUrgency(NOW + 3 * DAY + 1, NOW, false)).toBe('quiet')
|
||||
expect(mfaUrgency(NOW + 3 * DAY, NOW, false)).toBe('soon')
|
||||
expect(mfaUrgency(NOW + DAY, NOW, false)).toBe('soon')
|
||||
// Past the deadline by the clock but not blocked by the server: still only a warning.
|
||||
expect(mfaUrgency(NOW - DAY, NOW, false)).toBe('soon')
|
||||
expect(mfaUrgency(NOW + 14 * DAY, NOW, true)).toBe('blocked')
|
||||
})
|
||||
|
||||
it('names the days in the title once it is close', () => {
|
||||
expect(mfaSoonTitle('Acme', NOW + 2 * DAY, NOW, translate)).toBe('Acme requires MFA in 2 days')
|
||||
expect(mfaSoonTitle('Acme', NOW + DAY, NOW, translate)).toBe('Acme requires MFA in 1 day')
|
||||
expect(mfaSoonTitle('Acme', NOW - 1, NOW, translate)).toBe('Acme requires MFA now')
|
||||
})
|
||||
|
||||
it('marks the sidebar card with its urgency', () => {
|
||||
const card = (daysLeft: number, blocked = false): string | null | undefined =>
|
||||
render(
|
||||
<TeamMfaBanner
|
||||
variant="sidebar"
|
||||
teamName="Acme"
|
||||
enforceAt={NOW + daysLeft * DAY}
|
||||
now={NOW}
|
||||
setupUrl={setupUrl}
|
||||
onSetUp={() => {}}
|
||||
blocked={blocked}
|
||||
/>
|
||||
)
|
||||
.container.querySelector('[data-team-mfa-banner]')
|
||||
?.getAttribute('data-team-mfa-banner')
|
||||
expect(card(14)).toBe('quiet')
|
||||
cleanup()
|
||||
expect(card(2)).toBe('soon')
|
||||
cleanup()
|
||||
expect(card(-2, true)).toBe('blocked')
|
||||
})
|
||||
})
|
||||
|
||||
describe('one-time toast', () => {
|
||||
const memory = (): Pick<Storage, 'getItem' | 'setItem'> => {
|
||||
const map = new Map<string, string>()
|
||||
return { getItem: (key) => map.get(key) ?? null, setItem: (key, value) => void map.set(key, value) }
|
||||
}
|
||||
|
||||
it('shows once per team and deadline, and again when the date changes', () => {
|
||||
const storage = memory()
|
||||
expect(claimMfaToast(storage, 'org_1', 100)).toBe(true)
|
||||
expect(claimMfaToast(storage, 'org_1', 100)).toBe(false)
|
||||
expect(claimMfaToast(storage, 'org_1', 200)).toBe(true)
|
||||
expect(claimMfaToast(storage, 'org_2', 100)).toBe(true)
|
||||
})
|
||||
|
||||
it('shows rather than hides when storage is unavailable', () => {
|
||||
expect(claimMfaToast(null, 'org_1', 100)).toBe(true)
|
||||
const broken = {
|
||||
getItem: () => {
|
||||
throw new Error('denied')
|
||||
},
|
||||
setItem: () => {}
|
||||
}
|
||||
expect(claimMfaToast(broken, 'org_1', 100)).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -21712,6 +21712,10 @@
|
||||
"bannerTitle": "{{value0}} requires two-factor authentication. {{value1}}.",
|
||||
"bannerBody": "Set it up by {{value0}}. After that you can’t use this team’s workspaces until you do.",
|
||||
"bannerBlockedTitle": "{{value0}} requires two-factor authentication",
|
||||
"soonTitleNow": "{{value0}} requires MFA now",
|
||||
"soonTitle_one": "{{value0}} requires MFA in {{count}} day",
|
||||
"soonTitle_other": "{{value0}} requires MFA in {{count}} days",
|
||||
"toast": "{{value0}} requires MFA from {{value1}}.",
|
||||
"bannerBlockedBody": "You can’t use this team’s workspaces until you set it up. Your personal account is not affected.",
|
||||
"setUp": "Set up MFA",
|
||||
"blockedTitle": "Set up two-factor authentication to use {{value0}}",
|
||||
|
||||
Reference in New Issue
Block a user