mirror of
https://github.com/outline/outline.git
synced 2025-12-30 15:30:12 -06:00
fix: withCollection scopes on UserPermission, GroupPermission
This commit is contained in:
29
server/models/GroupPermission.test.ts
Normal file
29
server/models/GroupPermission.test.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { buildCollection, buildGroup, buildUser } from "@server/test/factories";
|
||||
import GroupPermission from "./GroupPermission";
|
||||
|
||||
describe("GroupPermission", () => {
|
||||
describe("withCollection scope", () => {
|
||||
it("should return the collection", async () => {
|
||||
const collection = await buildCollection();
|
||||
const group = await buildGroup();
|
||||
const user = await buildUser({ teamId: group.teamId });
|
||||
|
||||
await GroupPermission.create({
|
||||
createdById: user.id,
|
||||
groupId: group.id,
|
||||
collectionId: collection.id,
|
||||
});
|
||||
|
||||
const permission = await GroupPermission.scope("withCollection").findOne({
|
||||
where: {
|
||||
groupId: group.id,
|
||||
collectionId: collection.id,
|
||||
},
|
||||
});
|
||||
|
||||
expect(permission).toBeDefined();
|
||||
expect(permission?.collection).toBeDefined();
|
||||
expect(permission?.collection?.id).toEqual(collection.id);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -26,15 +26,14 @@ import Fix from "./decorators/Fix";
|
||||
],
|
||||
},
|
||||
withCollection: {
|
||||
where: {
|
||||
collectionId: {
|
||||
[Op.ne]: null,
|
||||
},
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Collection,
|
||||
as: "collection",
|
||||
where: {
|
||||
collectionId: {
|
||||
[Op.ne]: null,
|
||||
},
|
||||
},
|
||||
association: "collection",
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
28
server/models/UserPermission.test.ts
Normal file
28
server/models/UserPermission.test.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { buildCollection, buildUser } from "@server/test/factories";
|
||||
import UserPermission from "./UserPermission";
|
||||
|
||||
describe("UserPermission", () => {
|
||||
describe("withCollection scope", () => {
|
||||
it("should return the collection", async () => {
|
||||
const collection = await buildCollection();
|
||||
const user = await buildUser({ teamId: collection.teamId });
|
||||
|
||||
await UserPermission.create({
|
||||
createdById: user.id,
|
||||
userId: user.id,
|
||||
collectionId: collection.id,
|
||||
});
|
||||
|
||||
const permission = await UserPermission.scope("withCollection").findOne({
|
||||
where: {
|
||||
userId: user.id,
|
||||
collectionId: collection.id,
|
||||
},
|
||||
});
|
||||
|
||||
expect(permission).toBeDefined();
|
||||
expect(permission?.collection).toBeDefined();
|
||||
expect(permission?.collection?.id).toEqual(collection.id);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -25,15 +25,14 @@ import Fix from "./decorators/Fix";
|
||||
],
|
||||
},
|
||||
withCollection: {
|
||||
where: {
|
||||
collectionId: {
|
||||
[Op.ne]: null,
|
||||
},
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Collection,
|
||||
as: "collection",
|
||||
where: {
|
||||
collectionId: {
|
||||
[Op.ne]: null,
|
||||
},
|
||||
},
|
||||
association: "collection",
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user