mirror of
https://github.com/outline/outline.git
synced 2026-12-03 18:10:36 +03:00
fix: Document list results
This commit is contained in:
5 files changed
+92
-2
No files matched your search
@@ -2,6 +2,7 @@ import { DirectionFilter, DocumentPermission, SortFilter } from "@shared/types";
|
||||
import {
|
||||
buildDocument,
|
||||
buildDraftDocument,
|
||||
buildPersonalDocument,
|
||||
buildCollection,
|
||||
buildTeam,
|
||||
buildUser,
|
||||
@@ -955,6 +956,54 @@ describe("PostgresSearchProvider", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("personal document visibility", () => {
|
||||
it.each([false, true])(
|
||||
"should require sharing to search personal documents created for another owner (shared: %s)",
|
||||
async (shared) => {
|
||||
const creator = await buildUser();
|
||||
const owner = await buildUser({ teamId: creator.teamId });
|
||||
const document = await buildPersonalDocument({
|
||||
teamId: creator.teamId,
|
||||
userId: creator.id,
|
||||
personalOwnerId: owner.id,
|
||||
title: "personal test",
|
||||
});
|
||||
|
||||
if (shared) {
|
||||
await UserMembership.create({
|
||||
documentId: document.id,
|
||||
userId: creator.id,
|
||||
createdById: owner.id,
|
||||
permission: DocumentPermission.Read,
|
||||
});
|
||||
}
|
||||
|
||||
const { results } = await provider.searchForUser(creator, {
|
||||
query: "personal test",
|
||||
});
|
||||
const titles = await provider.searchTitlesForUser(creator, {
|
||||
query: "personal test",
|
||||
});
|
||||
const expectedIds = shared ? [document.id] : [];
|
||||
expect(results.map((result) => result.document.id)).toEqual(
|
||||
expectedIds
|
||||
);
|
||||
expect(titles.map((result) => result.id)).toEqual(expectedIds);
|
||||
|
||||
const ownerResults = await provider.searchForUser(owner, {
|
||||
query: "personal test",
|
||||
});
|
||||
const ownerTitles = await provider.searchTitlesForUser(owner, {
|
||||
query: "personal test",
|
||||
});
|
||||
expect(
|
||||
ownerResults.results.map((result) => result.document.id)
|
||||
).toEqual([document.id]);
|
||||
expect(ownerTitles.map((result) => result.id)).toEqual([document.id]);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe("#searchTitlesForUser", () => {
|
||||
it("should return search results from collections", async () => {
|
||||
const team = await buildTeam();
|
||||
|
||||
@@ -681,6 +681,7 @@ export default class PostgresSearchProvider extends BaseSearchProvider {
|
||||
where[Op.or].push({
|
||||
createdById: model.id,
|
||||
collectionId: { [Op.is]: null },
|
||||
personalOwnerId: { [Op.is]: null },
|
||||
});
|
||||
if (collectionIds.length) {
|
||||
where[Op.or].push(
|
||||
|
||||
@@ -836,6 +836,46 @@ describe("#documents.export", () => {
|
||||
});
|
||||
|
||||
describe("#documents.list", () => {
|
||||
it("should not expose a document moved to another user's personal space", async () => {
|
||||
const creator = await buildUser();
|
||||
const owner = await buildUser({ teamId: creator.teamId });
|
||||
const collection = await buildCollection({
|
||||
teamId: owner.teamId,
|
||||
userId: owner.id,
|
||||
});
|
||||
const document = await buildDocument({
|
||||
teamId: creator.teamId,
|
||||
userId: creator.id,
|
||||
collectionId: collection.id,
|
||||
});
|
||||
|
||||
const move = await server.post("/api/documents.move", owner, {
|
||||
body: { id: document.id, personalOwnerId: owner.id },
|
||||
});
|
||||
expect(move.status).toEqual(200);
|
||||
|
||||
const info = await server.post("/api/documents.info", creator, {
|
||||
body: { id: document.id },
|
||||
});
|
||||
expect(info.status).toEqual(403);
|
||||
|
||||
const creatorList = await server.post("/api/documents.list", creator, {
|
||||
body: {},
|
||||
});
|
||||
expect(creatorList.status).toEqual(200);
|
||||
const creatorBody = await creatorList.json();
|
||||
expect(creatorBody.data).toEqual([]);
|
||||
|
||||
const ownerList = await server.post("/api/documents.list", owner, {
|
||||
body: {},
|
||||
});
|
||||
expect(ownerList.status).toEqual(200);
|
||||
const ownerBody = await ownerList.json();
|
||||
expect(ownerBody.data).toEqual([
|
||||
expect.objectContaining({ id: document.id }),
|
||||
]);
|
||||
});
|
||||
|
||||
it("should fail for invalid userId", async () => {
|
||||
const user = await buildUser();
|
||||
const res = await server.post("/api/documents.list", user, {
|
||||
|
||||
@@ -331,7 +331,7 @@ router.post(
|
||||
where[Op.and].push({
|
||||
[Op.or]: [
|
||||
{ collectionId: collectionIds },
|
||||
{ collectionId: null, createdById: user.id },
|
||||
{ collectionId: null, personalOwnerId: null, createdById: user.id },
|
||||
// a document in the user's own personal space carries access on
|
||||
// itself, whoever created it
|
||||
{ personalOwnerId: user.id },
|
||||
|
||||
@@ -61,7 +61,6 @@
|
||||
"Development": "Development",
|
||||
"Open document": "Open document",
|
||||
"New draft": "New draft",
|
||||
"New doc": "New doc",
|
||||
"Nested document": "Nested document",
|
||||
"Before": "Before",
|
||||
"After": "After",
|
||||
@@ -622,6 +621,7 @@
|
||||
"Collapse sidebar": "Collapse sidebar",
|
||||
"Archived collections": "Archived collections",
|
||||
"Empty": "Empty",
|
||||
"New doc": "New doc",
|
||||
"New nested document": "New nested document",
|
||||
"No collections": "No collections",
|
||||
"Hide": "Hide",
|
||||
|
||||
Reference in new issue
Block a user