mirror of
https://github.com/outline/outline.git
synced 2026-12-03 01:59:03 +03:00
fix(policies): let guests with edit rights duplicate documents again (#13717)
#13198 (9796407) moved the duplicate gate to team-level createDocument,
which guests and viewers can never hold - so the policy change silently
removed duplicate for guests with edit rights on the source document.
Allow duplicate when the actor can createDocument at team level
(members, preserves #13198) OR update the source (guests, the pre-1.10
capability); the destination collection is still authorized separately
in documents.duplicate. Includes the #13198 regression guard plus
guest positive/negative cases.
Fixes #13715.
Co-authored-by: Instinct Agent <agent@instinct.com>
This commit is contained in:
1 parent
07aab19000
commit
0e054da71d
2 files changed
+94
-1
No files matched your search
@@ -317,6 +317,93 @@ describe("membership ids", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("duplicate", () => {
|
||||
it("should allow members to duplicate from a read-write collection", async () => {
|
||||
const team = await buildTeam();
|
||||
const user = await buildUser({ teamId: team.id });
|
||||
const collection = await buildCollection({
|
||||
teamId: team.id,
|
||||
permission: CollectionPermission.ReadWrite,
|
||||
});
|
||||
const doc = await buildDocument({
|
||||
teamId: team.id,
|
||||
collectionId: collection.id,
|
||||
});
|
||||
const document = await Document.findByPk(doc.id, { userId: user.id });
|
||||
const abilities = serialize(user, document);
|
||||
expect(abilities.duplicate).toBeTruthy();
|
||||
});
|
||||
|
||||
it("should allow members to duplicate from a read-only collection", async () => {
|
||||
const team = await buildTeam();
|
||||
const user = await buildUser({ teamId: team.id });
|
||||
const collection = await buildCollection({
|
||||
teamId: team.id,
|
||||
permission: CollectionPermission.Read,
|
||||
});
|
||||
const doc = await buildDocument({
|
||||
teamId: team.id,
|
||||
collectionId: collection.id,
|
||||
});
|
||||
const document = await Document.findByPk(doc.id, { userId: user.id });
|
||||
const abilities = serialize(user, document);
|
||||
expect(abilities.duplicate).toBeTruthy();
|
||||
});
|
||||
|
||||
it("should allow guests to duplicate documents they can update", async () => {
|
||||
const team = await buildTeam();
|
||||
const user = await buildUser({
|
||||
teamId: team.id,
|
||||
role: UserRole.Guest,
|
||||
});
|
||||
const collection = await buildCollection({
|
||||
teamId: team.id,
|
||||
permission: null,
|
||||
});
|
||||
const doc = await buildDocument({
|
||||
teamId: team.id,
|
||||
collectionId: collection.id,
|
||||
});
|
||||
await UserMembership.create({
|
||||
documentId: doc.id,
|
||||
userId: user.id,
|
||||
createdById: user.id,
|
||||
permission: DocumentPermission.ReadWrite,
|
||||
});
|
||||
const document = await Document.findByPk(doc.id, { userId: user.id });
|
||||
const abilities = serialize(user, document);
|
||||
expect(abilities.update).toBeTruthy();
|
||||
expect(abilities.duplicate).toBeTruthy();
|
||||
});
|
||||
|
||||
it("should not allow guests to duplicate read-only documents", async () => {
|
||||
const team = await buildTeam();
|
||||
const user = await buildUser({
|
||||
teamId: team.id,
|
||||
role: UserRole.Guest,
|
||||
});
|
||||
const collection = await buildCollection({
|
||||
teamId: team.id,
|
||||
permission: null,
|
||||
});
|
||||
const doc = await buildDocument({
|
||||
teamId: team.id,
|
||||
collectionId: collection.id,
|
||||
});
|
||||
await UserMembership.create({
|
||||
documentId: doc.id,
|
||||
userId: user.id,
|
||||
createdById: user.id,
|
||||
permission: DocumentPermission.Read,
|
||||
});
|
||||
const document = await Document.findByPk(doc.id, { userId: user.id });
|
||||
const abilities = serialize(user, document);
|
||||
expect(abilities.read).toBeTruthy();
|
||||
expect(abilities.update).toEqual(false);
|
||||
expect(abilities.duplicate).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("no collection", () => {
|
||||
it("should allow no permissions for team member", async () => {
|
||||
const team = await buildTeam();
|
||||
|
||||
@@ -129,7 +129,13 @@ allow(User, "duplicate", Document, (actor, document) =>
|
||||
!!document?.isActive,
|
||||
isTeamMutable(actor),
|
||||
can(actor, "read", document),
|
||||
can(actor, "createDocument", actor.team)
|
||||
or(
|
||||
can(actor, "createDocument", actor.team),
|
||||
// Guests and viewers are never team-level creators (see createDocument
|
||||
// on Team above), but may duplicate documents they can update - the
|
||||
// destination is still authorized separately in documents.duplicate.
|
||||
can(actor, "update", document)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
Reference in new issue
Block a user