mirror of
https://github.com/outline/outline.git
synced 2026-11-28 16:19:46 +03:00
fix: Scope events.list results by collection visibility
This commit is contained in:
2 files changed
+48
-1
No files matched your search
@@ -8,6 +8,7 @@ import {
|
||||
buildCollection,
|
||||
buildDocument,
|
||||
buildEvent,
|
||||
buildPersonalCollection,
|
||||
buildUser,
|
||||
buildUserPasskey,
|
||||
buildWebhookSubscription,
|
||||
@@ -484,6 +485,35 @@ describe("#events.list", () => {
|
||||
expect(eventIds).toContain(draftEvent.id);
|
||||
});
|
||||
|
||||
it("should not return events in other users' personal collections to admins", async () => {
|
||||
const user = await buildUser();
|
||||
const admin = await buildAdmin({ teamId: user.teamId });
|
||||
const collection = await buildPersonalCollection(user);
|
||||
const ownEvent = await buildEvent({
|
||||
name: "collections.create",
|
||||
collectionId: (await buildPersonalCollection(admin)).id,
|
||||
teamId: user.teamId,
|
||||
actorId: admin.id,
|
||||
});
|
||||
const otherEvent = await buildEvent({
|
||||
name: "documents.delete",
|
||||
collectionId: collection.id,
|
||||
teamId: user.teamId,
|
||||
actorId: user.id,
|
||||
});
|
||||
|
||||
for (const auditLog of [false, true]) {
|
||||
const res = await server.post("/api/events.list", admin, {
|
||||
body: { auditLog },
|
||||
});
|
||||
const body = await res.json();
|
||||
expect(res.status).toEqual(200);
|
||||
const eventIds = body.data.map((e: { id: string }) => e.id);
|
||||
expect(eventIds).toContain(ownEvent.id);
|
||||
expect(eventIds).not.toContain(otherEvent.id);
|
||||
}
|
||||
});
|
||||
|
||||
it("should allow non-admins to list events when collectionId is specified", async () => {
|
||||
const user = await buildUser();
|
||||
const collection = await buildCollection({
|
||||
|
||||
@@ -81,7 +81,18 @@ router.post(
|
||||
}
|
||||
|
||||
const loadedEvents = await Event.findAll({
|
||||
where,
|
||||
where: {
|
||||
[Op.and]: [
|
||||
where,
|
||||
// Exclude events in the personal collections of other users.
|
||||
{
|
||||
[Op.or]: [
|
||||
{ "$collection.ownerId$": null },
|
||||
{ "$collection.ownerId$": user.id },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
order: [[sort, direction]],
|
||||
include: [
|
||||
{
|
||||
@@ -89,6 +100,12 @@ router.post(
|
||||
as: "actor",
|
||||
paranoid: false,
|
||||
},
|
||||
{
|
||||
model: Collection.unscoped(),
|
||||
as: "collection",
|
||||
attributes: [],
|
||||
paranoid: false,
|
||||
},
|
||||
],
|
||||
offset: ctx.state.pagination.offset,
|
||||
limit: ctx.state.pagination.limit,
|
||||
|
||||
Reference in new issue
Block a user