mirror of
https://github.com/outline/outline.git
synced 2026-11-25 23:24:06 +03:00
Fix TypeScript compilation errors in Mention model
- Replace authorize() with can() function for proper boolean return - Add missing createdAt property to documents.update events in tests - Add non-null assertions for required properties - Fix event type definitions to match DocumentEvent interface
This commit is contained in:
1 parent
94a8326c68
commit
ac2d3bf3cb
2 files changed
+59
-49
No files matched your search
@@ -7,6 +7,7 @@ import {
|
||||
Table,
|
||||
} from "sequelize-typescript";
|
||||
import { MentionType } from "@shared/types";
|
||||
import { can } from "@server/policies";
|
||||
import Document from "./Document";
|
||||
import User from "./User";
|
||||
import IdModel from "./base/IdModel";
|
||||
@@ -68,7 +69,7 @@ class Mention extends IdModel<
|
||||
const accessibleMentions = [];
|
||||
for (const mention of mentions) {
|
||||
if (mention.document) {
|
||||
const hasAccess = await mention.document.authorize(user, "read");
|
||||
const hasAccess = can(user, "read", mention.document);
|
||||
if (hasAccess) {
|
||||
accessibleMentions.push(mention);
|
||||
}
|
||||
|
||||
@@ -7,18 +7,18 @@ describe("MentionsProcessor", () => {
|
||||
const user = await buildUser();
|
||||
const mentionedUser = await buildUser({ teamId: user.teamId });
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
userId: user.id!,
|
||||
teamId: user.teamId!,
|
||||
text: `Hello @${mentionedUser.name}!`,
|
||||
});
|
||||
|
||||
const processor = new MentionsProcessor();
|
||||
await processor.perform({
|
||||
name: "documents.publish",
|
||||
documentId: document.id,
|
||||
collectionId: document.collectionId,
|
||||
teamId: document.teamId,
|
||||
actorId: user.id,
|
||||
documentId: document.id!,
|
||||
collectionId: document.collectionId!,
|
||||
teamId: document.teamId!,
|
||||
actorId: user.id!,
|
||||
data: {
|
||||
title: document.title,
|
||||
},
|
||||
@@ -38,8 +38,8 @@ describe("MentionsProcessor", () => {
|
||||
const user = await buildUser();
|
||||
const mentionedUser = await buildUser({ teamId: user.teamId });
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
userId: user.id!,
|
||||
teamId: user.teamId!,
|
||||
text: `Hello @${mentionedUser.name}!`,
|
||||
publishedAt: null,
|
||||
});
|
||||
@@ -47,12 +47,15 @@ describe("MentionsProcessor", () => {
|
||||
const processor = new MentionsProcessor();
|
||||
await processor.perform({
|
||||
name: "documents.update",
|
||||
documentId: document.id,
|
||||
collectionId: document.collectionId,
|
||||
teamId: document.teamId,
|
||||
actorId: user.id,
|
||||
documentId: document.id!,
|
||||
collectionId: document.collectionId!,
|
||||
teamId: document.teamId!,
|
||||
createdAt: new Date().toISOString(),
|
||||
actorId: user.id!,
|
||||
data: {
|
||||
title: document.title,
|
||||
autosave: false,
|
||||
done: true,
|
||||
},
|
||||
ip: "127.0.0.1",
|
||||
});
|
||||
@@ -71,18 +74,18 @@ describe("MentionsProcessor", () => {
|
||||
const mentionedUser = await buildUser({ teamId: user.teamId });
|
||||
const anotherMentionedUser = await buildUser({ teamId: user.teamId });
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
userId: user.id!,
|
||||
teamId: user.teamId!,
|
||||
text: `Hello @${mentionedUser.name}!`,
|
||||
});
|
||||
|
||||
const processor = new MentionsProcessor();
|
||||
await processor.perform({
|
||||
name: "documents.publish",
|
||||
documentId: document.id,
|
||||
collectionId: document.collectionId,
|
||||
teamId: document.teamId,
|
||||
actorId: user.id,
|
||||
documentId: document.id!,
|
||||
collectionId: document.collectionId!,
|
||||
teamId: document.teamId!,
|
||||
actorId: user.id!,
|
||||
data: {
|
||||
title: document.title,
|
||||
},
|
||||
@@ -95,12 +98,15 @@ describe("MentionsProcessor", () => {
|
||||
|
||||
await processor.perform({
|
||||
name: "documents.update",
|
||||
documentId: document.id,
|
||||
collectionId: document.collectionId,
|
||||
teamId: document.teamId,
|
||||
actorId: user.id,
|
||||
documentId: document.id!,
|
||||
collectionId: document.collectionId!,
|
||||
teamId: document.teamId!,
|
||||
actorId: user.id!,
|
||||
createdAt: new Date().toISOString(),
|
||||
data: {
|
||||
title: document.title,
|
||||
autosave: false,
|
||||
done: true,
|
||||
},
|
||||
ip: "127.0.0.1",
|
||||
});
|
||||
@@ -119,18 +125,18 @@ describe("MentionsProcessor", () => {
|
||||
const user = await buildUser();
|
||||
const mentionedUser = await buildUser({ teamId: user.teamId });
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
userId: user.id!,
|
||||
teamId: user.teamId!,
|
||||
text: `Hello @${mentionedUser.name}!`,
|
||||
});
|
||||
|
||||
const processor = new MentionsProcessor();
|
||||
await processor.perform({
|
||||
name: "documents.publish",
|
||||
documentId: document.id,
|
||||
collectionId: document.collectionId,
|
||||
teamId: document.teamId,
|
||||
actorId: user.id,
|
||||
documentId: document.id!,
|
||||
collectionId: document.collectionId!,
|
||||
teamId: document.teamId!,
|
||||
actorId: user.id!,
|
||||
data: {
|
||||
title: document.title,
|
||||
},
|
||||
@@ -151,18 +157,18 @@ describe("MentionsProcessor", () => {
|
||||
const mentionedUser = await buildUser({ teamId: user.teamId });
|
||||
const anotherMentionedUser = await buildUser({ teamId: user.teamId });
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
userId: user.id!,
|
||||
teamId: user.teamId!,
|
||||
text: `Hello @${mentionedUser.name} and @${anotherMentionedUser.name}!`,
|
||||
});
|
||||
|
||||
const processor = new MentionsProcessor();
|
||||
await processor.perform({
|
||||
name: "documents.publish",
|
||||
documentId: document.id,
|
||||
collectionId: document.collectionId,
|
||||
teamId: document.teamId,
|
||||
actorId: user.id,
|
||||
documentId: document.id!,
|
||||
collectionId: document.collectionId!,
|
||||
teamId: document.teamId!,
|
||||
actorId: user.id!,
|
||||
data: {
|
||||
title: document.title,
|
||||
},
|
||||
@@ -175,12 +181,15 @@ describe("MentionsProcessor", () => {
|
||||
|
||||
await processor.perform({
|
||||
name: "documents.update",
|
||||
documentId: document.id,
|
||||
collectionId: document.collectionId,
|
||||
teamId: document.teamId,
|
||||
actorId: user.id,
|
||||
documentId: document.id!,
|
||||
collectionId: document.collectionId!,
|
||||
teamId: document.teamId!,
|
||||
actorId: user.id!,
|
||||
createdAt: new Date().toISOString(),
|
||||
data: {
|
||||
title: document.title,
|
||||
autosave: false,
|
||||
done: true,
|
||||
},
|
||||
ip: "127.0.0.1",
|
||||
});
|
||||
@@ -199,18 +208,18 @@ describe("MentionsProcessor", () => {
|
||||
const user = await buildUser();
|
||||
const mentionedUser = await buildUser({ teamId: user.teamId });
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
userId: user.id!,
|
||||
teamId: user.teamId!,
|
||||
text: `Hello @${mentionedUser.name}!`,
|
||||
});
|
||||
|
||||
const processor = new MentionsProcessor();
|
||||
await processor.perform({
|
||||
name: "documents.publish",
|
||||
documentId: document.id,
|
||||
collectionId: document.collectionId,
|
||||
teamId: document.teamId,
|
||||
actorId: user.id,
|
||||
documentId: document.id!,
|
||||
collectionId: document.collectionId!,
|
||||
teamId: document.teamId!,
|
||||
actorId: user.id!,
|
||||
data: {
|
||||
title: document.title,
|
||||
},
|
||||
@@ -219,10 +228,10 @@ describe("MentionsProcessor", () => {
|
||||
|
||||
await processor.perform({
|
||||
name: "documents.delete",
|
||||
documentId: document.id,
|
||||
collectionId: document.collectionId,
|
||||
teamId: document.teamId,
|
||||
actorId: user.id,
|
||||
documentId: document.id!,
|
||||
collectionId: document.collectionId!,
|
||||
teamId: document.teamId!,
|
||||
actorId: user.id!,
|
||||
data: {
|
||||
title: document.title,
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user