Skip to content

: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.

feat(today): add quill access control building blocks (#119075)

Adam Leithf28881f5ff06
diff --git a/frontend/src/layout/navigation-3000/sidepanel/components/QuillPeopleAvatars.tsx b/frontend/src/layout/navigation-3000/sidepanel/components/QuillPeopleAvatars.tsx
new file mode 100644
index 000000000000..0ceff2d7b45f
--- /dev/null
+++ b/frontend/src/layout/navigation-3000/sidepanel/components/QuillPeopleAvatars.tsx
@@ -0,0 +1,38 @@
+import { AvatarGroup, Text, Tooltip, TooltipContent, TooltipTrigger } from '@posthog/quill'
+
+import { QuillPersonAvatar } from './QuillPersonAvatar'
+
+interface QuillPeopleAvatarsProps {
+ people: { name: string; email: string }[]
+ limit?: number
+}
+
+export function QuillPeopleAvatars({ people, limit = 3 }: QuillPeopleAvatarsProps): JSX.Element | null {
+ if (!people.length) {
+ return null
+ }
+ const overflow = people.length - limit
+
+ return (
+ <Tooltip>
+ <TooltipTrigger
+ delay={200}
+ render={<span className="ph-no-capture inline-flex items-center gap-1" tabIndex={0} />}
+ >
+ <AvatarGroup stacked size="xs">
+ {people.slice(0, limit).map((person) => (
+ <QuillPersonAvatar key={person.email} name={person.name} email={person.email} size="xs" />
+ ))}
+ </AvatarGroup>
+ {overflow > 0 && (
+ <Text size="xs" variant="muted" render={<span />}>
+ +{overflow}
+ </Text>
+ )}
+ </TooltipTrigger>
+ <TooltipContent className="ph-no-capture">
+ {people.map((person) => person.name || person.email).join(', ')}
+ </TooltipContent>
+ </Tooltip>
+ )
+}
diff --git a/frontend/src/layout/navigation-3000/sidepanel/components/QuillPersonAvatar.tsx b/frontend/src/layout/navigation-3000/sidepanel/components/QuillPersonAvatar.tsx
new file mode 100644
index 000000000000..b8ffd1de07c0
--- /dev/null
+++ b/frontend/src/layout/navigation-3000/sidepanel/components/QuillPersonAvatar.tsx
@@ -0,0 +1,30 @@
+import { IconLogomark } from '@posthog/icons'
+import { Avatar, AvatarFallback, AvatarImage } from '@posthog/quill'
+
+import { gravatarUrl } from 'lib/utils/gravatar'
+
+interface QuillPersonAvatarProps {
+ name: string
+ email?: string
+ size?: 'xs' | 'sm' | 'default'
+ /** PostHog itself, or staff acting as the user, rather than a person. */
+ system?: boolean
+}
+
+export function QuillPersonAvatar({ name, email, size = 'sm', system }: QuillPersonAvatarProps): JSX.Element {
+ if (system) {
+ return (
+ <Avatar size={size}>
+ <AvatarFallback>
+ <IconLogomark />
+ </AvatarFallback>
+ </Avatar>
+ )
+ }
+ return (
+ <Avatar size={size} className="ph-no-capture">
+ {email && <AvatarImage src={gravatarUrl(email)} alt="" />}
+ <AvatarFallback>{(name || email || '?').charAt(0).toUpperCase()}</AvatarFallback>
+ </Avatar>
+ )
+}
diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAccessControlDefaults.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAccessControlDefaults.tsx
new file mode 100644
index 000000000000..d5b557067058
--- /dev/null
+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAccessControlDefaults.tsx
@@ -0,0 +1,39 @@
+import { useActions, useValues } from 'kea'
+
+import { Skeleton } from '@posthog/quill'
+
+import { upgradeModalLogic } from 'lib/components/UpgradeModal/upgradeModalLogic'
+
+import { AvailableFeature } from '~/types'
+
+import { accessControlLogic } from '../accessControlLogic'
+import { QuillAccessLevelSelect } from './QuillAccessLevelSelect'
+
+export function QuillAccessControlDefaults(): JSX.Element {
+ const { accessControlDefault, accessControls, accessControlsLoading, availableLevelsWithNone, inheritedAccess } =
+ useValues(accessControlLogic)
+ const { updateAccessControlDefault } = useActions(accessControlLogic)
+ const { guardAvailableFeature } = useValues(upgradeModalLogic)
+
+ if (!accessControls) {
+ // A null level is a real state ("No override") for this select, so it can't double as the loading state.
+ return <Skeleton className="h-7 w-40" />
+ }
+
+ return (
+ <QuillAccessLevelSelect
+ // A null level renders as the "No override" option, which only exists when there is
+ // an inherited tier. With nothing to inherit (project/organization), a missing row
+ // means the built-in default applies, so show that rather than an empty selection.
+ level={accessControlDefault?.access_level ?? (inheritedAccess ? null : accessControls.default_access_level)}
+ levels={availableLevelsWithNone}
+ inherited={inheritedAccess}
+ disabledReason={accessControlsLoading ? 'Loading…' : undefined}
+ onChange={(newValue) => {
+ guardAvailableFeature(AvailableFeature.ACCESS_CONTROL, () => {
+ updateAccessControlDefault(newValue)
+ })
+ }}
+ />
+ )
+}
diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAccessLevelSelect.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAccessLevelSelect.tsx
new file mode 100644
index 000000000000..189a617515cb
--- /dev/null
+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAccessLevelSelect.tsx
@@ -0,0 +1,146 @@
+import { useValues } from 'kea'
+
+import {
+ Select,
+ SelectContent,
+ SelectGroup,
+ SelectItem,
+ SelectSeparator,
+ SelectTrigger,
+ SelectValue,
+ Text,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+} from '@posthog/quill'
+
+import { AccessControlLevel } from '~/types'
+
+import { InheritedAccess, accessControlLogic } from '../accessControlLogic'
+import { humanizeAccessControlLevel } from '../ResourceAccessControlsV2/helpers'
+
+export interface QuillAccessLevelSelectProps {
+ /** The subject's own saved rule; null means no rule ("No override"). */
+ level: AccessControlLevel | null
+ levels: AccessControlLevel[]
+ onChange: (newValue: AccessControlLevel | null) => void
+ disabled?: boolean
+ disabledReason?: string
+ /**
+ * What applies when there is no rule. Passing it offers "No override" as a way back,
+ * rendered as `No override · <level>` with the reason in the tooltip and menu entry.
+ * Only the object default sets it. Member and role rows are removed with their own button.
+ */
+ inherited?: InheritedAccess | null
+}
+
+type LevelItem = { value: AccessControlLevel | null; label: string }
+
+export function QuillAccessLevelSelect({
+ level,
+ levels,
+ onChange,
+ disabled,
+ disabledReason: reasonFromCaller,
+ inherited,
+}: QuillAccessLevelSelectProps): JSX.Element {
+ const { canEditAccessControls, minimumAccessLevel: minimumLevel } = useValues(accessControlLogic)
+ // The permission gate wins over any caller-supplied reason, so a reason passed for
+ // some other purpose can never re-enable the control for someone who cannot edit
+ const disabledReason = !canEditAccessControls || disabled ? 'You cannot edit this' : reasonFromCaller
+ const minimumIndex = minimumLevel ? levels.indexOf(minimumLevel) : -1
+ const items: LevelItem[] = [
+ ...(inherited ? [{ value: null, label: 'No override' }] : []),
+ ...levels.map((value) => ({ value, label: humanizeAccessControlLevel(value) })),
+ ]
+
+ // The trigger and the menu entry read identically, so what you pick is what you end up looking at.
+ // The inherited half drops to a muted color so it reads as a consequence, not a second value.
+ const noOverrideLabel = inherited ? (
+ <span className="whitespace-nowrap">
+ No override <span className="text-muted-foreground">· {inherited.label}</span>
+ </span>
+ ) : (
+ 'No override'
+ )
+
+ // A disabled control explains itself through disabledReason; adding the inherited
+ // reason on top reads as two unrelated sentences
+ const tooltip =
+ disabledReason ??
+ (!inherited
+ ? undefined
+ : level === null
+ ? inherited.reason
+ : `Overrides ${inherited.label}. ${inherited.reason}.`)
+
+ const value = (
+ <SelectValue>
+ {(selected: AccessControlLevel | null) =>
+ selected === null ? (
+ inherited ? (
+ noOverrideLabel
+ ) : (
+ <span className="text-muted-foreground">Select level…</span>
+ )
+ ) : (
+ humanizeAccessControlLevel(selected)
+ )
+ }
+ </SelectValue>
+ )
+
+ return (
+ <Select<AccessControlLevel | null>
+ items={items}
+ value={level}
+ onValueChange={(next) => onChange(next as AccessControlLevel | null)}
+ disabled={!!disabledReason}
+ >
+ {tooltip ? (
+ <Tooltip>
+ <TooltipTrigger delay={0} render={<SelectTrigger className="shrink-0" />}>
+ {value}
+ </TooltipTrigger>
+ <TooltipContent>{tooltip}</TooltipContent>
+ </Tooltip>
+ ) : (
+ <SelectTrigger className="shrink-0">{value}</SelectTrigger>
+ )}
+ <SelectContent>
+ {inherited && (
+ <>
+ <SelectGroup>
+ <SelectItem value={null}>
+ <span className="flex flex-col items-start gap-1 py-1">
+ {noOverrideLabel}
+ <Text size="xs" variant="muted" render={<span className="whitespace-nowrap" />}>
+ {inherited.reason}
+ </Text>
+ </span>
+ </SelectItem>
+ </SelectGroup>
+ <SelectSeparator />
+ </>
+ )}
+ <SelectGroup>
+ {levels.map((option, index) => {
+ const unavailable = index < minimumIndex
+ return (
+ <SelectItem key={option} value={option} disabled={unavailable}>
+ <span className="flex flex-col items-start gap-0.5">
+ {humanizeAccessControlLevel(option)}
+ {unavailable && (
+ <Text size="xs" variant="muted" render={<span />}>
+ Not available for this resource type
+ </Text>
+ )}
+ </span>
+ </SelectItem>
+ )
+ })}
+ </SelectGroup>
+ </SelectContent>
+ </Select>
+ )
+}
diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAccessSection.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAccessSection.tsx
new file mode 100644
index 000000000000..7c9fc79d4a10
--- /dev/null
+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAccessSection.tsx
@@ -0,0 +1,95 @@
+import { useValues } from 'kea'
+import { useState } from 'react'
+
+import { IconPlus } from '@posthog/icons'
+import { Button, Heading, ItemGroup, Skeleton, Text, Tooltip, TooltipContent, TooltipTrigger } from '@posthog/quill'
+
+import { upgradeModalLogic } from 'lib/components/UpgradeModal/upgradeModalLogic'
+
+import { AccessControlLevel, AvailableFeature } from '~/types'
+
+import { accessControlLogic } from '../accessControlLogic'
+import { AddAccessOption, QuillAddAccessDialog } from './QuillAddAccessDialog'
+
+interface QuillAccessSectionProps {
+ title: string
+ /** Feeds the add button's data-attr, e.g. "member" → `access-control-add-member`. */
+ subject: 'member' | 'role'
+ emptyText: string
+ children: React.ReactNode[]
+ feature: AvailableFeature
+ placeholder: string
+ nothingToAddText: string
+ options: AddAccessOption[]
+ onAdd: (keys: string[], level: AccessControlLevel) => Promise<void>
+}
+
+export function QuillAccessSection({
+ title,
+ subject,
+ emptyText,
+ children,
+ feature,
+ placeholder,
+ nothingToAddText,
+ options,
+ onAdd,
+}: QuillAccessSectionProps): JSX.Element {
+ const { canEditAccessControls, accessControlsLoading: loading } = useValues(accessControlLogic)
+ const { guardAvailableFeature } = useValues(upgradeModalLogic)
+ const [dialogOpen, setDialogOpen] = useState(false)
+ const addDisabledReason = canEditAccessControls ? undefined : 'You cannot edit this'
+ const onAddClick = (): void => setDialogOpen(true)
+
+ return (
+ <section className="flex flex-col gap-1">
+ <div className="flex items-center justify-between gap-2">
+ <Heading size="sm" render={<h3 className="m-0" />}>
+ {title}
+ </Heading>
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <Button
+ variant="outline"
+ disabled={!!addDisabledReason}
+ onClick={onAddClick}
+ data-attr={`access-control-add-${subject}`}
+ />
+ }
+ >
+ <IconPlus />
+ Add
+ </TooltipTrigger>
+ {addDisabledReason && <TooltipContent>{addDisabledReason}</TooltipContent>}
+ </Tooltip>
+ </div>
+ {loading && !children.length ? (
+ <div className="flex flex-col gap-1">
+ <Skeleton className="h-11" />
+ <Skeleton className="h-11 opacity-70" />
+ </div>
+ ) : !children.length ? (
+ <Text size="xs" variant="muted">
+ {emptyText}
+ </Text>
+ ) : (
+ <ItemGroup combined>{children}</ItemGroup>
+ )}
+ <QuillAddAccessDialog
+ open={dialogOpen}
+ onOpenChange={setDialogOpen}
+ pickerLabel={title}
+ placeholder={placeholder}
+ emptyText={nothingToAddText}
+ options={options}
+ onAdd={async (keys, level) => {
+ if (guardAvailableFeature(feature)) {
+ await onAdd(keys, level)
+ setDialogOpen(false)
+ }
+ }}
+ />
+ </section>
+ )
+}
diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAddAccessDialog.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAddAccessDialog.tsx
new file mode 100644
index 000000000000..884c5537c127
--- /dev/null
+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAddAccessDialog.tsx
@@ -0,0 +1,218 @@
+import { useValues } from 'kea'
+import { useEffect, useId, useState } from 'react'
+
+import {
+ Button,
+ Combobox,
+ ComboboxChip,
+ ComboboxChips,
+ ComboboxChipsInput,
+ ComboboxContent,
+ ComboboxEmpty,
+ ComboboxItem,
+ ComboboxList,
+ ComboboxValue,
+ Dialog,
+ DialogBody,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ Field,
+ FieldGroup,
+ FieldLabel,
+ FieldTitle,
+ Text,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+ useComboboxAnchor,
+} from '@posthog/quill'
+
+import { AccessControlLevel } from '~/types'
+
+import { QuillPersonAvatar } from '../../../components/QuillPersonAvatar'
+import { accessControlLogic } from '../accessControlLogic'
+import { QuillAccessLevelSelect } from './QuillAccessLevelSelect'
+
+// The same cap as the LemonUI member picker.
+const MAX_PICKER_RESULTS = 100
+
+export interface AddAccessOption {
+ key: string
+ /** What the search matches against. */
+ searchLabel: string
+ name: string
+ /** Set for members, so their row shows an avatar and email. */
+ email?: string
+}
+
+interface QuillAddAccessDialogProps {
+ open: boolean
+ onOpenChange: (open: boolean) => void
+ pickerLabel: string
+ placeholder: string
+ emptyText: string
+ onAdd: (newValues: string[], level: AccessControlLevel) => Promise<void>
+ options: AddAccessOption[]
+}
+
+export function QuillAddAccessDialog(props: QuillAddAccessDialogProps): JSX.Element {
+ const { availableLevels, canEditAccessControls } = useValues(accessControlLogic)
+ const [items, setItems] = useState<string[]>([])
+ const [level, setLevel] = useState<AccessControlLevel | null>(availableLevels[0] ?? null)
+ const [submitting, setSubmitting] = useState(false)
+ const pickerId = useId()
+
+ useEffect(() => {
+ setLevel(availableLevels[0] ?? null)
+ }, [availableLevels])
+
+ const optionsByKey = Object.fromEntries(props.options.map((option) => [option.key, option]))
+ const disabledReason = !canEditAccessControls
+ ? 'You cannot edit this'
+ : !items.length || !level
+ ? 'Choose who to add and at what level'
+ : undefined
+
+ const onSubmit = (): void => {
+ if (!items.length || !level) {
+ return
+ }
+ setSubmitting(true)
+ void props
+ .onAdd(items, level)
+ .then(() => {
+ setItems([])
+ setLevel(availableLevels[0] ?? null)
+ })
+ .finally(() => setSubmitting(false))
+ }
+
+ return (
+ <Dialog open={props.open} onOpenChange={props.onOpenChange}>
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>Add access</DialogTitle>
+ <DialogDescription>Allow other users or roles to access this resource</DialogDescription>
+ </DialogHeader>
+ <DialogBody>
+ <FieldGroup>
+ <Field>
+ <FieldLabel htmlFor={pickerId}>{props.pickerLabel}</FieldLabel>
+ <Combobox<string, true>
+ multiple
+ autoHighlight
+ items={props.options.map((option) => option.key)}
+ // Large organizations have thousands of members, so the list shows the top matches only.
+ limit={MAX_PICKER_RESULTS}
+ itemToStringLabel={(key: string) => optionsByKey[key]?.searchLabel ?? key}
+ value={items}
+ onValueChange={(next: string[]) => setItems(next ?? [])}
+ disabled={!canEditAccessControls}
+ >
+ <AddAccessPicker
+ id={pickerId}
+ placeholder={props.placeholder}
+ emptyText={props.options.length ? 'No matches' : props.emptyText}
+ optionsByKey={optionsByKey}
+ disabled={!canEditAccessControls}
+ />
+ </Combobox>
+ </Field>
+ <Field>
+ <FieldTitle>Access level</FieldTitle>
+ <div>
+ <QuillAccessLevelSelect levels={availableLevels} level={level} onChange={setLevel} />
+ </div>
+ </Field>
+ </FieldGroup>
+ </DialogBody>
+ <DialogFooter>
+ <Button variant="outline" onClick={() => props.onOpenChange(false)}>
+ Cancel
+ </Button>
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <Button
+ variant="primary"
+ loading={submitting}
+ disabled={!!disabledReason}
+ onClick={onSubmit}
+ data-attr="access-control-add-submit"
+ />
+ }
+ >
+ Add
+ </TooltipTrigger>
+ {disabledReason && <TooltipContent>{disabledReason}</TooltipContent>}
+ </Tooltip>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ )
+}
+
+function AddAccessPicker({
+ id,
+ placeholder,
+ emptyText,
+ optionsByKey,
+ disabled,
+}: {
+ id: string
+ placeholder: string
+ emptyText: string
+ optionsByKey: Record<string, AddAccessOption>
+ disabled: boolean
+}): JSX.Element {
+ const anchor = useComboboxAnchor()
+
+ return (
+ <>
+ <ComboboxChips ref={anchor}>
+ <ComboboxValue>
+ {(values: string[]) => (
+ <>
+ {values.map((key) => (
+ <ComboboxChip key={key} title={optionsByKey[key]?.name}>
+ <span className="ph-no-capture">{optionsByKey[key]?.name ?? key}</span>
+ </ComboboxChip>
+ ))}
+ <ComboboxChipsInput
+ id={id}
+ placeholder={values.length ? '' : placeholder}
+ disabled={disabled}
+ />
+ </>
+ )}
+ </ComboboxValue>
+ </ComboboxChips>
+ <ComboboxContent anchor={anchor}>
+ <ComboboxEmpty>{emptyText}</ComboboxEmpty>
+ <ComboboxList>
+ {(key: string) => {
+ const option = optionsByKey[key]
+ return (
+ <ComboboxItem key={key} value={key}>
+ <span className="ph-no-capture flex min-w-0 items-center gap-2">
+ {option?.email !== undefined && (
+ <QuillPersonAvatar name={option.name} email={option.email} size="xs" />
+ )}
+ <span className="truncate">{option?.name ?? key}</span>
+ {option?.email && (
+ <Text size="xs" variant="muted" render={<span className="truncate" />}>
+ {option.email}
+ </Text>
+ )}
+ </span>
+ </ComboboxItem>
+ )
+ }}
+ </ComboboxList>
+ </ComboboxContent>
+ </>
+ )
+}
diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillRemoveAccessButton.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillRemoveAccessButton.tsx
new file mode 100644
index 000000000000..7422abc50bf7
--- /dev/null
+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillRemoveAccessButton.tsx
@@ -0,0 +1,74 @@
+import { useValues } from 'kea'
+import { useState } from 'react'
+
+import { IconTrash } from '@posthog/icons'
+import {
+ AlertDialog,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+ Button,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+} from '@posthog/quill'
+
+import { accessControlLogic } from '../accessControlLogic'
+
+interface QuillRemoveAccessButtonProps {
+ onConfirm: () => void
+ subject: 'member' | 'role'
+}
+
+export function QuillRemoveAccessButton({ onConfirm, subject }: QuillRemoveAccessButtonProps): JSX.Element {
+ const { canEditAccessControls } = useValues(accessControlLogic)
+ const [confirmOpen, setConfirmOpen] = useState(false)
+
+ return (
+ <>
+ <Tooltip>
+ <TooltipTrigger
+ delay={0}
+ render={
+ <Button
+ size="icon"
+ aria-label="Remove access"
+ disabled={!canEditAccessControls}
+ onClick={() => setConfirmOpen(true)}
+ data-attr={`access-control-remove-${subject}`}
+ />
+ }
+ >
+ <IconTrash />
+ </TooltipTrigger>
+ <TooltipContent>{canEditAccessControls ? 'Remove access' : 'You cannot edit this'}</TooltipContent>
+ </Tooltip>
+ <AlertDialog open={confirmOpen} onOpenChange={setConfirmOpen}>
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>Remove access</AlertDialogTitle>
+ <AlertDialogDescription>
+ Are you sure you want to remove this {subject}'s explicit access?
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <Button variant="outline" onClick={() => setConfirmOpen(false)}>
+ Cancel
+ </Button>
+ <Button
+ variant="destructive-outline"
+ onClick={() => {
+ setConfirmOpen(false)
+ onConfirm()
+ }}
+ >
+ Remove
+ </Button>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
+ </>
+ )
+}