fix: Scope events.list results by collection visibility

This commit is contained in:
Tom Moor committed 2026-11-26 19:28:29 -05:00
1 parent 13c6c7718f
commit 4b430243c7
2 files changed
+48 -1

No files matched your search

+30
View File
@@ -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({
+18 -1
View File
@@ -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,