fix: Cannot mention users that have been explicitly added to document

This commit is contained in:
Tom Moor
2024-05-14 19:36:09 -04:00
parent 8120407bf3
commit 2ecc9009f0
3 changed files with 126 additions and 25 deletions

View File

@@ -4,6 +4,7 @@ import {
CollectionPermission,
DocumentPermission,
StatusFilter,
UserRole,
} from "@shared/types";
import {
Document,
@@ -3912,6 +3913,64 @@ describe("#documents.users", () => {
expect(memberIds).toContain(user.id);
});
it("should return collection users when collection is private", async () => {
const user = await buildUser();
const collection = await buildCollection({
teamId: user.teamId,
userId: user.id,
permission: null,
});
const document = await buildDocument({
collectionId: collection.id,
userId: user.id,
teamId: user.teamId,
});
const [alan, ken] = await Promise.all([
buildUser({
name: "Alan Kay",
teamId: user.teamId,
}),
buildUser({
name: "Ken",
teamId: user.teamId,
}),
buildUser({
name: "Bret Victor",
teamId: user.teamId,
}),
]);
await UserMembership.create({
createdById: alan.id,
collectionId: collection.id,
userId: alan.id,
permission: CollectionPermission.ReadWrite,
});
await UserMembership.create({
createdById: ken.id,
documentId: document.id,
userId: ken.id,
permission: CollectionPermission.ReadWrite,
});
const res = await server.post("/api/documents.users", {
body: {
token: user.getJwtToken(),
id: document.id,
},
});
const body = await res.json();
expect(res.status).toBe(200);
expect(body.data.length).toBe(2);
const memberIds = body.data.map((u: User) => u.id);
expect(memberIds).toContain(alan.id);
expect(memberIds).toContain(ken.id);
});
it("should return document users with names matching the search query", async () => {
const user = await buildUser({
// Ensure the generated name doesn't match
@@ -4028,7 +4087,7 @@ describe("#documents.users", () => {
expect(memberNames).toContain(jamie.name);
});
it("should not return suspended users", async () => {
it("should not return suspended or guest users", async () => {
const user = await buildUser();
const collection = await buildCollection({
teamId: user.teamId,
@@ -4053,6 +4112,11 @@ describe("#documents.users", () => {
name: "Ken Thompson",
teamId: user.teamId,
}),
buildUser({
name: "Guest",
teamId: user.teamId,
role: UserRole.Guest,
}),
]);
// add people to collection