diff --git a/server/models/Collection.ts b/server/models/Collection.ts index effd67e915..b4e0de4f55 100644 --- a/server/models/Collection.ts +++ b/server/models/Collection.ts @@ -74,6 +74,7 @@ type AdditionalFindOptions = { userId?: string; includeDocumentStructure?: boolean; includeOwner?: boolean; + includeArchivedBy?: boolean; rejectOnEmpty?: boolean | Error; }; @@ -551,7 +552,13 @@ class Collection extends ParanoidModel< return null; } - const { includeDocumentStructure, includeOwner, userId, ...rest } = options; + const { + includeDocumentStructure, + includeOwner, + includeArchivedBy, + userId, + ...rest + } = options; const scopes: (string | ScopeOptions)[] = [ includeDocumentStructure ? "withDocumentStructure" : "defaultScope", @@ -563,6 +570,9 @@ class Collection extends ParanoidModel< if (includeOwner) { scopes.push("withUser"); } + if (includeArchivedBy) { + scopes.push("withArchivedBy"); + } const scope = this.scope(scopes); diff --git a/server/routes/api/collections/collections.test.ts b/server/routes/api/collections/collections.test.ts index c78fb39990..885dbb6df8 100644 --- a/server/routes/api/collections/collections.test.ts +++ b/server/routes/api/collections/collections.test.ts @@ -1188,6 +1188,25 @@ describe("#collections.info", () => { expect(body.data.id).toEqual(collection.id); }); + it("should work when passing urlId to id parameter", async () => { + const team = await buildTeam(); + const user = await buildUser({ teamId: team.id }); + const collection = await buildCollection({ + userId: user.id, + teamId: team.id, + }); + const res = await server.post("/api/collections.info", { + body: { + token: user.getJwtToken(), + id: `any-slug-${collection.urlId}`, + }, + }); + const body = await res.json(); + expect(res.status).toEqual(200); + expect(body.data.id).toEqual(collection.id); + expect(body.data.urlId).toEqual(collection.urlId); + }); + it("should require user member of collection", async () => { const team = await buildTeam(); const user = await buildUser({ teamId: team.id }); diff --git a/server/routes/api/collections/collections.ts b/server/routes/api/collections/collections.ts index b65c88d812..b4812287b3 100644 --- a/server/routes/api/collections/collections.ts +++ b/server/routes/api/collections/collections.ts @@ -118,14 +118,10 @@ router.post( async (ctx: APIContext) => { const { id } = ctx.input.body; const { user } = ctx.state.auth; - const collection = await Collection.scope([ - "defaultScope", - "withArchivedBy", - { - method: ["withMembership", user.id], - }, - ]).findOne({ - where: { id }, + const collection = await Collection.findByPk(id, { + userId: user.id, + includeArchivedBy: true, + rejectOnEmpty: true, }); authorize(user, "read", collection);