mirror of
https://github.com/outline/outline.git
synced 2026-11-22 14:01:41 +03:00
fix: Allow adding yourself as a collection owner, include collection owners in MCP exact match
This commit is contained in:
4 files changed
+46
-7
No files matched your search
@@ -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 }
|
||||
|
||||
@@ -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 });
|
||||
|
||||
@@ -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 });
|
||||
|
||||
Reference in new issue
Block a user