mirror of
https://github.com/outline/outline.git
synced 2026-11-30 00:50:41 +03:00
fix: Tighten document policy checks for drafts (#14786)
This commit is contained in:
1 parent
139f511056
commit
3d5e9c1da1
2 files changed
+120
-2
No files matched your search
@@ -405,6 +405,119 @@ describe("duplicate", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("draft in collection", () => {
|
||||
it("should allow no permissions for another collection member", async () => {
|
||||
const team = await buildTeam();
|
||||
const author = await buildUser({ teamId: team.id });
|
||||
const user = await buildUser({ teamId: team.id });
|
||||
const collection = await buildCollection({
|
||||
teamId: team.id,
|
||||
permission: CollectionPermission.ReadWrite,
|
||||
});
|
||||
const doc = await buildDraftDocument({
|
||||
teamId: team.id,
|
||||
userId: author.id,
|
||||
collectionId: collection.id,
|
||||
});
|
||||
const document = await Document.findByPk(doc.id, { userId: user.id });
|
||||
const abilities = serialize(user, document);
|
||||
expect(abilities.read).toEqual(false);
|
||||
expect(abilities.update).toEqual(false);
|
||||
expect(abilities.publish).toEqual(false);
|
||||
expect(abilities.delete).toEqual(false);
|
||||
expect(abilities.move).toEqual(false);
|
||||
expect(abilities.share).toEqual(false);
|
||||
expect(abilities.manageUsers).toEqual(false);
|
||||
});
|
||||
|
||||
it("should allow no permissions for a workspace admin", async () => {
|
||||
const team = await buildTeam();
|
||||
const author = await buildUser({ teamId: team.id });
|
||||
const user = await buildAdmin({ teamId: team.id });
|
||||
const collection = await buildCollection({
|
||||
teamId: team.id,
|
||||
permission: CollectionPermission.ReadWrite,
|
||||
});
|
||||
const doc = await buildDraftDocument({
|
||||
teamId: team.id,
|
||||
userId: author.id,
|
||||
collectionId: collection.id,
|
||||
});
|
||||
const document = await Document.findByPk(doc.id, { userId: user.id });
|
||||
const abilities = serialize(user, document);
|
||||
expect(abilities.read).toEqual(false);
|
||||
expect(abilities.update).toEqual(false);
|
||||
expect(abilities.delete).toEqual(false);
|
||||
});
|
||||
|
||||
it("should allow access for the creator", 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 buildDraftDocument({
|
||||
teamId: team.id,
|
||||
userId: user.id,
|
||||
collectionId: collection.id,
|
||||
});
|
||||
const document = await Document.findByPk(doc.id, { userId: user.id });
|
||||
const abilities = serialize(user, document);
|
||||
expect(abilities.read).toBeTruthy();
|
||||
expect(abilities.update).toBeTruthy();
|
||||
expect(abilities.publish).toBeTruthy();
|
||||
expect(abilities.delete).toBeTruthy();
|
||||
});
|
||||
|
||||
it("should allow access for a member with a direct membership", async () => {
|
||||
const team = await buildTeam();
|
||||
const author = await buildUser({ teamId: team.id });
|
||||
const user = await buildUser({ teamId: team.id });
|
||||
const collection = await buildCollection({
|
||||
teamId: team.id,
|
||||
permission: CollectionPermission.ReadWrite,
|
||||
});
|
||||
const doc = await buildDraftDocument({
|
||||
teamId: team.id,
|
||||
userId: author.id,
|
||||
collectionId: collection.id,
|
||||
});
|
||||
await UserMembership.create({
|
||||
createdById: author.id,
|
||||
documentId: doc.id,
|
||||
userId: user.id,
|
||||
permission: DocumentPermission.ReadWrite,
|
||||
});
|
||||
const document = await Document.findByPk(doc.id, { userId: user.id });
|
||||
const abilities = serialize(user, document);
|
||||
expect(abilities.read).toBeTruthy();
|
||||
expect(abilities.update).toBeTruthy();
|
||||
});
|
||||
|
||||
it("should not allow another collection member to restore", async () => {
|
||||
const team = await buildTeam();
|
||||
const author = await buildUser({ teamId: team.id });
|
||||
const user = await buildUser({ teamId: team.id });
|
||||
const collection = await buildCollection({
|
||||
teamId: team.id,
|
||||
permission: CollectionPermission.ReadWrite,
|
||||
});
|
||||
const doc = await buildDraftDocument({
|
||||
teamId: team.id,
|
||||
userId: author.id,
|
||||
collectionId: collection.id,
|
||||
});
|
||||
await doc.destroy();
|
||||
const document = await Document.findByPk(doc.id, {
|
||||
userId: user.id,
|
||||
paranoid: false,
|
||||
});
|
||||
const abilities = serialize(user, document);
|
||||
expect(abilities.restore).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("no collection", () => {
|
||||
it("should allow no permissions for team member", async () => {
|
||||
const team = await buildTeam();
|
||||
|
||||
@@ -39,7 +39,9 @@ allow(User, "read", Document, (actor, document) =>
|
||||
DocumentPermission.Admin,
|
||||
]),
|
||||
and(!!document?.isDraft, actor.id === document?.createdById),
|
||||
can(actor, "readDocument", document?.collection)
|
||||
|
||||
// Drafts are not shared through the collection.
|
||||
and(!document?.isDraft, can(actor, "readDocument", document?.collection))
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -231,7 +233,10 @@ allow(User, "restore", Document, (actor, document) =>
|
||||
DocumentPermission.ReadWrite,
|
||||
DocumentPermission.Admin,
|
||||
]),
|
||||
can(actor, "updateDocument", document?.collection),
|
||||
and(
|
||||
!document?.isDraft,
|
||||
can(actor, "updateDocument", document?.collection)
|
||||
),
|
||||
and(!!document?.isDraft && actor.id === document?.createdById)
|
||||
)
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user