: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(today): rebuild the access control panel in quill (#119076)
Adam Leitha2e287db732a
diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAccessControlMembers.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAccessControlMembers.tsxnew file mode 100644index 000000000000..4fe214d800e4--- /dev/null+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAccessControlMembers.tsx@@ -0,0 +1,125 @@+import { useAsyncActions, useValues } from 'kea'++import { Item, ItemActions, ItemContent, ItemDescription, ItemMedia, ItemTitle } from '@posthog/quill'++import { fullName } from 'lib/utils/strings'+import { userLogic } from 'scenes/userLogic'++import {+ AccessControlLevel,+ AccessControlTypeMember,+ AccessControlTypeOrganizationAdmins,+ AvailableFeature,+ OrganizationMemberType,+} from '~/types'++import { QuillPeopleAvatars } from '../../../components/QuillPeopleAvatars'+import { QuillPersonAvatar } from '../../../components/QuillPersonAvatar'+import { accessControlLogic } from '../accessControlLogic'+import { QuillAccessLevelSelect } from './QuillAccessLevelSelect'+import { QuillAccessSection } from './QuillAccessSection'+import { QuillRemoveAccessButton } from './QuillRemoveAccessButton'++export function QuillAccessControlMembers(): JSX.Element | null {+ const { user } = useValues(userLogic)+ const { resource, membersById, addableMembers, accessControlMembers, availableLevels, accessControlsLoading } =+ useValues(accessControlLogic)+ // Each change saves the whole list, so a second change before the first lands could overwrite it.+ const savingReason = accessControlsLoading ? 'Saving…' : undefined+ const { updateAccessControlMembers } = useAsyncActions(accessControlLogic)++ if (!user) {+ return null+ }++ // TODO(@zach): show project admins (that are not organization admins) in the list+ const rows = accessControlMembers.map((ac: AccessControlTypeMember | AccessControlTypeOrganizationAdmins) => {+ if (ac.resource === 'organization') {+ const admins = (ac as AccessControlTypeOrganizationAdmins).organization_admin_members ?? []+ return (+ <Item key="organization-admins" size="sm" variant="outline">+ <ItemMedia>+ <QuillPeopleAvatars+ people={admins.map((id) => ({+ email: membersById[id]?.user.email,+ name: fullName(membersById[id]?.user),+ }))}+ />+ </ItemMedia>+ <ItemContent className="min-w-0">+ <ItemDescription>+ {admins.length > 1+ ? 'have access as organization admins'+ : 'has access as an organization admin'}+ </ItemDescription>+ </ItemContent>+ <ItemActions>+ {/* Shown as disabled for visibility */}+ <QuillAccessLevelSelect+ level={resource === 'project' ? AccessControlLevel.Admin : AccessControlLevel.Editor}+ disabled+ levels={availableLevels}+ onChange={() => {}}+ />+ </ItemActions>+ </Item>+ )+ }++ const memberAc = ac as AccessControlTypeMember+ const member: OrganizationMemberType | undefined = membersById[memberAc.organization_member]+ const name = fullName(member?.user)+ return (+ <Item key={memberAc.organization_member} size="sm" variant="outline">+ <ItemMedia>+ <QuillPersonAvatar name={name} email={member?.user.email} />+ </ItemMedia>+ <ItemContent className="ph-no-capture min-w-0">+ <ItemTitle className="w-full">+ <span className="truncate">{member?.user.uuid == user.uuid ? `${name} (you)` : name}</span>+ </ItemTitle>+ <ItemDescription className="truncate">{member?.user.email}</ItemDescription>+ </ItemContent>+ <ItemActions>+ <QuillAccessLevelSelect+ level={memberAc.access_level}+ levels={availableLevels}+ disabledReason={savingReason}+ onChange={(level) =>+ void updateAccessControlMembers([{ member: memberAc.organization_member as string, level }])+ }+ />+ <QuillRemoveAccessButton+ subject="member"+ disabledReason={savingReason}+ onConfirm={() =>+ void updateAccessControlMembers([+ { member: memberAc.organization_member as string, level: null },+ ])+ }+ />+ </ItemActions>+ </Item>+ )+ })++ return (+ <QuillAccessSection+ title="Members"+ subject="member"+ emptyText="No members have their own access rule yet."+ feature={AvailableFeature.ACCESS_CONTROL}+ placeholder="Search for team members to add…"+ nothingToAddText="No members left to add."+ onAdd={(keys, level) => updateAccessControlMembers(keys.map((member) => ({ member, level })))}+ options={addableMembers.map((member: OrganizationMemberType) => ({+ key: member.id,+ searchLabel: `${fullName(member.user)} ${member.user.email}`,+ name: fullName(member.user),+ email: member.user.email,+ }))}+ >+ {rows}+ </QuillAccessSection>+ )+}diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAccessControlObject.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAccessControlObject.tsxnew file mode 100644index 000000000000..d7480347a0cf--- /dev/null+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAccessControlObject.tsx@@ -0,0 +1,98 @@+import { BindLogic, useValues } from 'kea'++import { IconInfo, IconLock } from '@posthog/icons'+import {+ Button,+ Heading,+ Item,+ ItemContent,+ ItemDescription,+ ItemMedia,+ ItemTitle,+ Text,+ Tooltip,+ TooltipContent,+ TooltipTrigger,+} from '@posthog/quill'++import { PayGateMini } from 'lib/components/PayGateMini/PayGateMini'+import { getAccessControlTooltip } from 'lib/utils/accessControlUtils'++import { AvailableFeature } from '~/types'++import { AccessControlLogicProps, accessControlLogic } from '../accessControlLogic'+import { QuillAccessControlDefaults } from './QuillAccessControlDefaults'+import { QuillAccessControlMembers } from './QuillAccessControlMembers'+import { QuillAccessControlRoles } from './QuillAccessControlRoles'++export function QuillAccessControlObject(props: AccessControlLogicProps): JSX.Element {+ const { canEditAccessControls, humanReadableResource, resource } = useValues(accessControlLogic(props))++ const suffix = `this ${humanReadableResource}`+ const tooltipText = getAccessControlTooltip(resource)++ return (+ <BindLogic logic={accessControlLogic} props={props}>+ <div className="flex flex-col gap-6">+ <div className="flex flex-col gap-1">+ <div className="flex items-center gap-1">+ <Heading size="base" render={<h2 className="m-0" />}>+ {props.title}+ </Heading>+ {tooltipText && (+ <Tooltip>+ <TooltipTrigger+ delay={0}+ render={<Button size="icon-xs" aria-label="About object permissions" />}+ >+ <IconInfo />+ </TooltipTrigger>+ <TooltipContent>{tooltipText}</TooltipContent>+ </Tooltip>+ )}+ </div>+ <Text size="xs" variant="muted">+ {props.description}+ </Text>+ </div>+ <PayGateMini feature={AvailableFeature.ACCESS_CONTROL} featureDetail="access-control-object-settings">+ <div className="flex flex-col gap-6">+ {canEditAccessControls === false && (+ <Item variant="outline" tone="warning" size="sm">+ <ItemMedia variant="icon">+ <IconLock />+ </ItemMedia>+ <ItemContent>+ <ItemTitle>Permission required</ItemTitle>+ <ItemDescription>+ Only the creator of {suffix}, project admins, organization admins, or people+ with manager access to it can change its access.+ </ItemDescription>+ </ItemContent>+ </Item>+ )}++ <section className="flex flex-col gap-2">+ <Heading size="sm" render={<h3 className="m-0" />}>+ Default access to {suffix}+ </Heading>+ <div>+ <QuillAccessControlDefaults />+ </div>+ </section>++ <QuillAccessControlMembers />++ {/* Inside the access control gate, so the two pay gates never show at once */}+ <PayGateMini+ feature={AvailableFeature.ROLE_BASED_ACCESS}+ featureDetail="access-control-object-roles"+ >+ <QuillAccessControlRoles />+ </PayGateMini>+ </div>+ </PayGateMini>+ </div>+ </BindLogic>+ )+}diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAccessControlPanel.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAccessControlPanel.tsxnew file mode 100644index 000000000000..5e3acb39672f--- /dev/null+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAccessControlPanel.tsx@@ -0,0 +1,57 @@+import { useValues } from 'kea'+import { useEffect } from 'react'++import { IconLock } from '@posthog/icons'+import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@posthog/quill'++import { captureAccessControlEvent, resourceTypeToString } from 'lib/utils/accessControlUtils'++import { AccessControlResourceType } from '~/types'++import { sidePanelContextLogic } from '../../../sidePanelContextLogic'+import { QuillAccessControlObject } from './QuillAccessControlObject'++export function QuillAccessControlPanel(): JSX.Element {+ const { sceneSidePanelContext } = useValues(sidePanelContextLogic)+ const { access_control_resource: resource, access_control_resource_id: resourceId } = sceneSidePanelContext++ useEffect(() => {+ if (!resource || !resourceId) {+ return+ }+ // pinned: analytics event name, shared with the flag-off panel+ captureAccessControlEvent('access_control_side_panel_viewed', {+ resource,+ resource_id: resourceId,+ })+ }, [resource, resourceId])++ if (!resource || !resourceId) {+ return (+ <Empty className="flex-1">+ <EmptyHeader>+ <EmptyMedia variant="icon">+ <IconLock />+ </EmptyMedia>+ <EmptyTitle>Access control isn't available here</EmptyTitle>+ <EmptyDescription>+ Open a dashboard, insight, or another saved object to manage who can access it.+ </EmptyDescription>+ </EmptyHeader>+ </Empty>+ )+ }++ return (+ <div className="min-h-0 flex-1 overflow-y-auto scroll-mask-y-4 scroll-py-4">+ <div className="flex flex-col p-4">+ <QuillAccessControlObject+ resource={resource}+ resource_id={resourceId}+ title="Object permissions"+ description={`Use object permissions to assign access for individuals and roles to this ${resourceTypeToString(resource as AccessControlResourceType)}.`}+ />+ </div>+ </div>+ )+}diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAccessControlRoles.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAccessControlRoles.tsxnew file mode 100644index 000000000000..9095112891c8--- /dev/null+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAccessControlRoles.tsx@@ -0,0 +1,83 @@+import { useAsyncActions, useValues } from 'kea'++import { Item, ItemActions, ItemContent, ItemDescription, ItemTitle } from '@posthog/quill'++import { Link } from 'lib/lemon-ui/Link'+import { fullName } from 'lib/utils/strings'+import { urls } from 'scenes/urls'++import { AvailableFeature, RoleMemberType, RoleType } from '~/types'++import { QuillPeopleAvatars } from '../../../components/QuillPeopleAvatars'+import { accessControlLogic } from '../accessControlLogic'+import { QuillAccessLevelSelect } from './QuillAccessLevelSelect'+import { QuillAccessSection } from './QuillAccessSection'+import { QuillRemoveAccessButton } from './QuillRemoveAccessButton'++export function QuillAccessControlRoles(): JSX.Element {+ const { accessControlRoles, addableRoles, rolesById, availableLevels, accessControlsLoading } =+ useValues(accessControlLogic)+ // Each change saves the whole list, so a second change before the first lands could overwrite it.+ const savingReason = accessControlsLoading ? 'Saving…' : undefined+ const { updateAccessControlRoles } = useAsyncActions(accessControlLogic)++ const rows = accessControlRoles.map(({ role, access_level }) => {+ const members: RoleMemberType[] = rolesById[role]?.members ?? []+ return (+ <Item key={role} size="sm" variant="outline">+ <ItemContent className="min-w-0">+ <ItemTitle className="w-full">+ <Link+ to={urls.settings('organization-roles') + `#role=${role}`}+ className="truncate text-foreground"+ >+ {rolesById[role]?.name}+ </Link>+ </ItemTitle>+ {members.length ? (+ <QuillPeopleAvatars+ people={members.map((member) => ({+ email: member.user.email,+ name: fullName(member.user),+ }))}+ />+ ) : (+ <ItemDescription>No members</ItemDescription>+ )}+ </ItemContent>+ <ItemActions>+ <QuillAccessLevelSelect+ level={access_level}+ levels={availableLevels}+ disabledReason={savingReason}+ onChange={(level) => void updateAccessControlRoles([{ role, level }])}+ />+ <QuillRemoveAccessButton+ subject="role"+ disabledReason={savingReason}+ onConfirm={() => void updateAccessControlRoles([{ role, level: null }])}+ />+ </ItemActions>+ </Item>+ )+ })++ return (+ <QuillAccessSection+ title="Roles"+ subject="role"+ emptyText="No roles have their own access rule yet."+ feature={AvailableFeature.ROLE_BASED_ACCESS}+ placeholder="Search for roles to add…"+ nothingToAddText="No roles left to add. Create roles in organization settings."+ onAdd={(keys, level) => updateAccessControlRoles(keys.map((role) => ({ role, level })))}+ options={addableRoles.map((role: RoleType) => ({+ key: role.id,+ searchLabel: role.name,+ name: role.name,+ }))}+ >+ {rows}+ </QuillAccessSection>+ )+}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.tsxindex 7422abc50bf7..0bd4e4637572 100644--- 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@@ -20,11 +20,18 @@ import { accessControlLogic } from '../accessControlLogic'interface QuillRemoveAccessButtonProps {onConfirm: () => voidsubject: 'member' | 'role'+ /** Set while another access change is saving, so removals and level changes never overlap. */+ disabledReason?: string}-export function QuillRemoveAccessButton({ onConfirm, subject }: QuillRemoveAccessButtonProps): JSX.Element {+export function QuillRemoveAccessButton({+ onConfirm,+ subject,+ disabledReason: reasonFromCaller,+}: QuillRemoveAccessButtonProps): JSX.Element {const { canEditAccessControls } = useValues(accessControlLogic)const [confirmOpen, setConfirmOpen] = useState(false)+ const disabledReason = canEditAccessControls ? reasonFromCaller : 'You cannot edit this'return (<>@@ -35,7 +42,7 @@ export function QuillRemoveAccessButton({ onConfirm, subject }: QuillRemoveAcces<Buttonsize="icon"aria-label="Remove access"- disabled={!canEditAccessControls}+ disabled={!!disabledReason}onClick={() => setConfirmOpen(true)}data-attr={`access-control-remove-${subject}`}/>@@ -43,7 +50,7 @@ export function QuillRemoveAccessButton({ onConfirm, subject }: QuillRemoveAcces><IconTrash /></TooltipTrigger>- <TooltipContent>{canEditAccessControls ? 'Remove access' : 'You cannot edit this'}</TooltipContent>+ <TooltipContent>{disabledReason ?? 'Remove access'}</TooltipContent></Tooltip><AlertDialog open={confirmOpen} onOpenChange={setConfirmOpen}><AlertDialogContent>diff --git a/frontend/src/layout/today/TodayContextPanelContent.tsx b/frontend/src/layout/today/TodayContextPanelContent.tsxindex 681e2045da21..93e9265e265a 100644--- a/frontend/src/layout/today/TodayContextPanelContent.tsx+++ b/frontend/src/layout/today/TodayContextPanelContent.tsx@@ -20,6 +20,11 @@ const QUILL_TAB_PANELS: Partial<Record<SidePanelTab, ComponentType>> = {[SidePanelTab.Support]: lazyWithRetry(() =>import('./TodaySupportPanel').then((m) => ({ default: m.TodaySupportPanel }))),+ [SidePanelTab.AccessControl]: lazyWithRetry(() =>+ import('~/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAccessControlPanel').then((m) => ({+ default: m.QuillAccessControlPanel,+ }))+ ),}type SwitchDirection = 'forward' | 'backward'