fix: Allow adding yourself as a collection owner, include collection owners in MCP exact match

This commit is contained in:
Tom Moor committed 2026-11-03 10:23:17 -05:00
1 parent 7c75680501
commit 0f2a1fae60
4 files changed
+46 -7

No files matched your search

+1 -6
View File
@@ -105,8 +105,7 @@ export async function updateCollectionOwners(
/**
* Gives users the manage permission on a collection when they are made
* owners. The acting user is skipped, as they can already manage the
* collection.
* owners.
*
* @param ctx the API context containing the acting user.
* @param collection the collection that the users own.
@@ -122,10 +121,6 @@ export async function grantCollectionOwnerAccess(
const { transaction } = ctx.state;
for (const userId of userIds) {
if (userId === user.id) {
continue;
}
const membership = await UserMembership.findOneForUpdate(
{ userId, collectionId: collection.id },
{ transaction }
+26
View File
@@ -178,6 +178,32 @@ describe("list_documents", () => {
expect(data[0].document.id).toEqual(document.id);
});
it("returns an exact match owned through its collection", async () => {
const { user, accessToken } = await buildOAuthUser();
const owner = await buildUser({ teamId: user.teamId });
const collection = await buildCollection({
teamId: user.teamId,
userId: user.id,
ownerIds: [owner.id],
});
const document = await buildDocument({
teamId: user.teamId,
userId: user.id,
collectionId: collection.id,
});
const res = await callMcpTool(server, accessToken, "list_documents", {
query: document.id,
ownerId: owner.id,
});
expect(res?.result?.isError).toBeUndefined();
const data = (res?.result?.content ?? []).map((c: { text: string }) =>
JSON.parse(c.text)
);
expect(data[0].document.id).toEqual(document.id);
});
it("returns documents shared directly with the user", async () => {
const { user, accessToken } = await buildOAuthUser();
const author = await buildUser({ teamId: user.teamId });
+4 -1
View File
@@ -189,7 +189,10 @@ export function documentTools(server: McpServer, scopes: string[]) {
(!collectionId ||
exactMatchCandidate.collectionId === collectionId) &&
(!input.ownerId ||
exactMatchCandidate.ownerIds?.includes(input.ownerId))
exactMatchCandidate.ownerIds?.includes(input.ownerId) ||
exactMatchCandidate.collection?.ownerIds?.includes(
input.ownerId
))
? exactMatchCandidate
: null;
@@ -3156,6 +3156,21 @@ describe("collection owners", () => {
expect(body.data.collections[0].ownerIds).toEqual([owner.id]);
});
it("should allow a user to add themselves as an owner", async () => {
const admin = await buildAdmin();
const collection = await buildCollection({ teamId: admin.teamId });
const res = await server.post("/api/collections.add_user", admin, {
body: { id: collection.id, userId: admin.id, owner: true },
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.memberships[0].permission).toEqual(
CollectionPermission.Admin
);
expect(body.data.collections[0].ownerIds).toEqual([admin.id]);
});
it("should add owners from concurrent invitations", async () => {
const admin = await buildAdmin();
const first = await buildUser({ teamId: admin.teamId });