mirror of
https://github.com/outline/outline.git
synced 2026-11-27 07:58:51 +03:00
fix: Prevent removing document member with inherited access (#13408)
Memberships that originate from a parent document (sourceId set) can no longer be removed directly, on both the client and server.
This commit is contained in:
1 parent
7d353dc4da
commit
f6514719dc
3 files changed
+75
-9
No files matched your search
@@ -43,6 +43,9 @@ const DocumentMemberListItem = ({
|
||||
[onRemove, onUpdate]
|
||||
);
|
||||
|
||||
// Access inherited from a parent document cannot be removed here.
|
||||
const canRemove = !membership?.sourceId;
|
||||
|
||||
const permissions: Permission[] = [
|
||||
{
|
||||
label: t("View only"),
|
||||
@@ -56,11 +59,15 @@ const DocumentMemberListItem = ({
|
||||
label: t("Manage"),
|
||||
value: DocumentPermission.Admin,
|
||||
},
|
||||
{
|
||||
divider: true,
|
||||
label: t("Remove"),
|
||||
value: EmptySelectValue,
|
||||
},
|
||||
...(canRemove
|
||||
? ([
|
||||
{
|
||||
divider: true,
|
||||
label: t("Remove"),
|
||||
value: EmptySelectValue,
|
||||
},
|
||||
] satisfies Permission[])
|
||||
: []),
|
||||
];
|
||||
|
||||
const currentPermission = permissions.find(
|
||||
@@ -105,10 +112,14 @@ const DocumentMemberListItem = ({
|
||||
onLeave
|
||||
? [
|
||||
currentPermission,
|
||||
{
|
||||
label: `${t("Leave")}…`,
|
||||
value: EmptySelectValue,
|
||||
},
|
||||
...(canRemove
|
||||
? ([
|
||||
{
|
||||
label: `${t("Leave")}…`,
|
||||
value: EmptySelectValue,
|
||||
},
|
||||
] satisfies Permission[])
|
||||
: []),
|
||||
]
|
||||
: permissions
|
||||
}
|
||||
|
||||
@@ -5570,6 +5570,55 @@ describe("#documents.remove_user", () => {
|
||||
expect(res.status).toEqual(200);
|
||||
expect(users.length).toEqual(0);
|
||||
});
|
||||
|
||||
it("should not remove user with access inherited from a parent", async () => {
|
||||
const user = await buildUser();
|
||||
const collection = await buildCollection({
|
||||
teamId: user.teamId,
|
||||
createdById: user.id,
|
||||
permission: null,
|
||||
});
|
||||
const parentDocument = await buildDocument({
|
||||
collectionId: collection.id,
|
||||
createdById: user.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
const document = await buildDocument({
|
||||
collectionId: collection.id,
|
||||
parentDocumentId: parentDocument.id,
|
||||
createdById: user.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
const member = await buildUser({
|
||||
teamId: user.teamId,
|
||||
});
|
||||
const sourceMembership = await UserMembership.create({
|
||||
createdById: user.id,
|
||||
documentId: parentDocument.id,
|
||||
userId: member.id,
|
||||
permission: DocumentPermission.ReadWrite,
|
||||
});
|
||||
await UserMembership.create({
|
||||
createdById: user.id,
|
||||
documentId: document.id,
|
||||
userId: member.id,
|
||||
permission: DocumentPermission.ReadWrite,
|
||||
sourceId: sourceMembership.id,
|
||||
});
|
||||
|
||||
const res = await server.post("/api/documents.remove_user", user, {
|
||||
body: {
|
||||
id: document.id,
|
||||
userId: member.id,
|
||||
},
|
||||
});
|
||||
expect(res.status).toEqual(400);
|
||||
expect(
|
||||
await UserMembership.count({
|
||||
where: { documentId: document.id, userId: member.id },
|
||||
})
|
||||
).not.toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#documents.add_group", () => {
|
||||
|
||||
@@ -1873,6 +1873,12 @@ router.post(
|
||||
rejectOnEmpty: true,
|
||||
});
|
||||
|
||||
if (membership.sourceId) {
|
||||
throw ValidationError(
|
||||
"Cannot remove access that is inherited from a parent document"
|
||||
);
|
||||
}
|
||||
|
||||
await membership.destroy(ctx.context);
|
||||
|
||||
ctx.body = {
|
||||
|
||||
Reference in new issue
Block a user