mirror of
https://github.com/outline/outline.git
synced 2026-12-05 18:55:10 +03:00
fix: Regression in collections.info endpoint disallowed find by urlId (#9423)
This commit is contained in:
1 parent
554c7a8111
commit
0f4c1d7db5
3 files changed
+34
-9
No files matched your search
@@ -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);
|
||||
|
||||
|
||||
@@ -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 });
|
||||
|
||||
@@ -118,14 +118,10 @@ router.post(
|
||||
async (ctx: APIContext<T.CollectionsInfoReq>) => {
|
||||
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);
|
||||
|
||||
Reference in new issue
Block a user