Files
outline/app/components/Sharing/Collection/AccessControlList.tsx
T
Tom MoorandClaude 767758a1a8 feat: Document and collection owners (#14437)
* feat: Add document owners

Documents can now have owners, stored as an array of user IDs. Owners
must be active members or admins, and changing them requires the
existing manage users permission on the document, gated behind a new
DocumentOwners plan entitlement that is included in every plan.

- ownerIds accepted by documents.create and documents.update and
  returned by the document presenter
- ownerIds filter field (eq/in) for documents.list and documents.search
- ownerIds on the MCP create_document and update_document tools, and an
  ownerId filter on list_documents
- Owners section in the document Insights dialog to add and remove owners
- Owner filter on the search page
- In-app and email notification when a user is made an owner

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016MJXFdSZ39ZGPf31jyGcYz

* feat: Give document owners responsibility for their documents

- Access requests are routed to owners that can manage the document
  before falling back to document, collection and workspace admins
- Owners are subscribed to a document when they are added, respecting
  a previous unsubscribe
- Owners that can edit a document can also manage its access, owners
  and archive it; ownership never grants access on its own
- Owners are shown in the document byline, list items and search
  results, and document hover previews

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016MJXFdSZ39ZGPf31jyGcYz

* feat: Manage document owners from the share panel

- Owner is a role in the share panel permission menu and invite picker for
  individual users, adding an owner gives them the manage permission
- Lowering an owner's permission or removing their access removes the
  ownership
- Owners are sorted to the top of the member list
- Owners added through the API or MCP are given the manage permission
- Owners do not also receive the "added to document" notification
- Only added owners are validated, so suspended owners can still be removed
- Deleted users are removed from document owners
- Removes the owners section from Insights

* fix: Address review feedback on document owners

- Authorize owner changes before assigning owners on create
- Lock the document when adding an owner so concurrent invitations are kept
- Enforce the owner limit on every path
- Run MCP document updates in a transaction
- Broadcast owner removals to connected clients

* feat: Add collection owners

- Collections can have owners, who also own every document in the
  collection, shown first in document bylines
- Owner is a role in the collection share panel and invite picker for
  individual users, adding an owner gives them the manage permission
- Lowering an owner's permission or removing their access removes the
  ownership
- ownerIds on collections.create, collections.update and the MCP
  collection tools
- The document owner filter includes documents in owned collections
- Access requests go to document and collection owners together
- Collection owners are subscribed to the collection and notified when
  they are added
- Deleted users are removed from collection owners
- Renames the personal collection policy helper to
  isPersonalCollectionOwner

* feat: Show profile cards on owner names, hide inherited owners in collection lists

* fix: Allow adding yourself as a collection owner, include collection owners in MCP exact match

* fix: Correct singular owner translations

* feat: Allow users to make themselves a document owner

- The share panel suggests the current user when they can manage owners,
  and only offers the Owner permission for them
- documents.add_user accepts the actor's own ID when changing ownership,
  without changing their own access
- An owner's own row offers "Remove as owner", which keeps their access
- Hides the duplicate "You have full access" row when the current user is
  listed as a member

* fix: Restore singular owner translations

* fix: Limit owners to 5, use no key update locks when adding owners

* refactor: Move owner logic into Document and Collection model methods

- addOwner, removeOwner, grantOwnerAccess and setOwnerIds on both models,
  locking the row so concurrent owner changes are kept
- Owner events are created by an update hook from the change in ownerIds
- The manageOwners check runs at the route level when ownerIds is sent
- Removes the documentOwners and collectionOwners command modules
- Removes duplicate owner tests

* fix: Owner selection and membership edge cases

- Remove document owners from the legacy plan
- Selecting yourself in the share picker only suggests other users that can
  be owners, and you are not suggested next to groups or guests
- Users that make themselves an owner through the API get the manage
  permission, so they are listed in the share panel

* perf: Scope the collection owner filter subquery to the team

* chore: Drop redundant teamId UUID check

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-25 19:21:26 -05:00

341 lines
13 KiB
TypeScript

import { observer } from "mobx-react";
import { UserIcon } from "outline-icons";
import * as React from "react";
import { useTranslation } from "react-i18next";
import styled, { useTheme } from "styled-components";
import Squircle from "@shared/components/Squircle";
import { s } from "@shared/styles";
import { CollectionPermission } from "@shared/types";
import type Collection from "~/models/Collection";
import type Share from "~/models/Share";
import { Avatar, GroupAvatar, AvatarSize } from "~/components/Avatar";
import InputMemberPermissionSelect from "~/components/InputMemberPermissionSelect";
import { InputSelectPermission } from "~/components/InputSelectPermission";
import Scrollable from "~/components/Scrollable";
import useCurrentTeam from "~/hooks/useCurrentTeam";
import useMaxHeight from "~/hooks/useMaxHeight";
import usePolicy from "~/hooks/usePolicy";
import useStores from "~/hooks/useStores";
import type { Permission } from "~/types";
import { EmptySelectValue, OwnerSelectValue } from "~/types";
import { Separator, GroupMembersPopover } from "../components";
import { ListItem } from "../components/ListItem";
import { Placeholder } from "../components/Placeholder";
import { PublicAccess } from "./PublicAccess";
import Flex from "@shared/components/Flex";
import ButtonLink from "~/components/ButtonLink";
import { showErrorToast } from "../components/toasts";
type Props = {
/** Collection to which team members are supposed to be invited */
collection: Collection;
/** The existing share model, if any. */
share: Share | null | undefined;
/** Children to be rendered before the list of members */
children?: React.ReactNode;
/** List of users and groups that have been invited during the current editing session */
invitedInSession: string[];
/** Whether the popover is visible. */
visible: boolean;
/** Whether the share data is currently loading. */
loading: boolean;
};
export const AccessControlList = observer(
({ collection, share, invitedInSession, visible, loading }: Props) => {
const { memberships, groupMemberships } = useStores();
const team = useCurrentTeam();
const can = usePolicy(collection);
const { t } = useTranslation();
const theme = useTheme();
const collectionId = collection.id;
const groupMembershipsInCollection =
groupMemberships.inCollection(collectionId);
const membershipsInCollection = memberships.inCollection(collectionId);
const hasMemberships =
groupMembershipsInCollection.length > 0 ||
membershipsInCollection.length > 0;
const showLoading = !hasMemberships && loading;
const containerRef = React.useRef<HTMLDivElement | null>(null);
const publicAccessRef = React.useRef<HTMLDivElement | null>(null);
const publicAccessHeight = publicAccessRef.current?.clientHeight || 0;
const { maxHeight, calcMaxHeight } = useMaxHeight({
elementRef: containerRef,
maxViewportPercentage: 70,
margin: 24,
});
React.useEffect(() => {
calcMaxHeight();
});
const permissions = React.useMemo(
() =>
[
{
label: t("View only"),
value: CollectionPermission.Read,
},
{
label: t("Can edit"),
value: CollectionPermission.ReadWrite,
},
{
label: t("Manage"),
value: CollectionPermission.Admin,
},
{
divider: true,
label: t("Remove"),
value: EmptySelectValue,
},
] as Permission[],
[t]
);
// Owners are individual users, so the role is not offered for groups.
const userPermissions = React.useMemo(
() =>
[
...permissions.slice(0, -1),
{
label: t("Owner"),
value: OwnerSelectValue,
},
...permissions.slice(-1),
] as Permission[],
[t, permissions]
);
// Order owners first, then users added during the current session.
const sortKey = (userId: string, name: string) =>
(collection.ownerIds.includes(userId) ? "0" : "1") +
(invitedInSession.includes(userId) ? "_" : "") +
name;
return (
<Wrapper>
<ScrollableContainer
ref={containerRef}
hiddenScrollbars
style={{
maxHeight: maxHeight ? maxHeight - publicAccessHeight : undefined,
}}
>
<>
<ListItem
image={
<Squircle color={theme.accent} size={AvatarSize.Medium}>
<UserIcon color={theme.accentText} size={16} />
</Squircle>
}
title={t("All members")}
subtitle={t("Everyone in the workspace")}
actions={
<div style={{ marginRight: -8 }}>
<InputSelectPermission
onChange={(
value: CollectionPermission | typeof EmptySelectValue
) => {
void collection.save({
permission: value === EmptySelectValue ? null : value,
});
}}
disabled={!can.manageUsers}
value={collection?.permission}
labelHidden
nude
shrink
/>
</div>
}
/>
{showLoading ? (
<Placeholder />
) : (
<>
{groupMembershipsInCollection
.filter((membership) => membership.group)
.sort((a, b) =>
(
(invitedInSession.includes(a.group.id) ? "_" : "") +
a.group.name
).localeCompare(b.group.name)
)
.map((membership) => (
<ListItem
key={membership.id}
image={
<GroupAvatar
group={membership.group}
backgroundColor={theme.modalBackground}
/>
}
title={membership.group.name}
subtitle={
<GroupMembersPopover group={membership.group}>
<StyledButtonLink>
{t("{{ count }} member", {
count: membership.group.memberCount,
})}
</StyledButtonLink>
</GroupMembersPopover>
}
actions={
<div style={{ marginRight: -8 }}>
<InputMemberPermissionSelect
permissions={permissions}
onChange={async (
permission:
| CollectionPermission
| typeof EmptySelectValue
) => {
try {
if (permission === EmptySelectValue) {
await groupMemberships.delete({
collectionId: collection.id,
groupId: membership.groupId,
});
} else {
await groupMemberships.create({
collectionId: collection.id,
groupId: membership.groupId,
permission,
});
}
} catch (err) {
showErrorToast(err);
return false;
}
return true;
}}
disabled={!can.manageUsers}
value={membership.permission}
/>
</div>
}
/>
))}
{membershipsInCollection
.filter((membership) => membership.user)
.sort((a, b) =>
sortKey(a.user.id, a.user.name).localeCompare(
sortKey(b.user.id, b.user.name)
)
)
.map((membership) => {
const isOwner = collection.ownerIds.includes(
membership.userId
);
const canBeOwner =
!!can.manageOwners &&
(membership.user.isAdmin || membership.user.isMember) &&
!membership.user.isSuspended;
return (
<ListItem
key={membership.id}
image={
<Avatar
model={membership.user}
size={AvatarSize.Medium}
/>
}
title={membership.user.name}
subtitle={membership.user.email}
actions={
<div style={{ marginRight: -8 }}>
<InputMemberPermissionSelect
permissions={
isOwner || canBeOwner
? userPermissions
: permissions
}
onChange={async (
permission:
| CollectionPermission
| typeof EmptySelectValue
| typeof OwnerSelectValue
) => {
try {
if (permission === EmptySelectValue) {
await memberships.delete({
collectionId: collection.id,
userId: membership.userId,
});
} else if (permission === OwnerSelectValue) {
await memberships.create({
collectionId: collection.id,
userId: membership.userId,
permission: CollectionPermission.Admin,
owner: true,
});
} else {
await memberships.create({
collectionId: collection.id,
userId: membership.userId,
permission,
owner: false,
});
}
} catch (err) {
showErrorToast(err);
return false;
}
return true;
}}
disabled={!can.manageUsers}
value={
isOwner
? OwnerSelectValue
: membership.permission
}
/>
</div>
}
/>
);
})}
</>
)}
</>
</ScrollableContainer>
{team.sharing && can.share && collection.sharing && visible && (
<Sticky>
{collection.members.length ? <Separator /> : null}
<PublicAccess
ref={publicAccessRef}
collection={collection}
share={share}
/>
</Sticky>
)}
</Wrapper>
);
}
);
const StyledButtonLink = styled(ButtonLink)`
color: ${s("textTertiary")};
&:hover {
text-decoration: underline;
}
`;
const Wrapper = styled(Flex)`
flex-direction: column;
`;
const ScrollableContainer = styled(Scrollable)`
padding: 12px 24px;
margin: -12px -24px;
`;
const Sticky = styled.div`
background: ${s("menuBackground")};
position: sticky;
bottom: 0;
`;