chore: Bringing across edits from enterprise codebase

This commit is contained in:
Tom Moor
2022-04-16 19:46:01 -07:00
parent 0b5e48621a
commit b1aba32b62
7 changed files with 13 additions and 11 deletions

View File

@@ -1,4 +1,5 @@
import chalk from "chalk"; import chalk from "chalk";
import { isEmpty } from "lodash";
import winston from "winston"; import winston from "winston";
import env from "@server/env"; import env from "@server/env";
import Metrics from "@server/logging/metrics"; import Metrics from "@server/logging/metrics";
@@ -32,10 +33,10 @@ class Logger {
: winston.format.combine( : winston.format.combine(
winston.format.colorize(), winston.format.colorize(),
winston.format.printf( winston.format.printf(
({ message, level, label }) => ({ message, level, label, ...extra }) =>
`${level}: ${ `${level}: ${
label ? chalk.bold("[" + label + "] ") : "" label ? chalk.bold("[" + label + "] ") : ""
}${message}` }${message} ${isEmpty(extra) ? "" : JSON.stringify(extra)}`
) )
), ),
}) })

View File

@@ -1,7 +1,7 @@
import { Event } from "@server/types"; import { Event } from "@server/types";
export default abstract class BaseProcessor { export default abstract class BaseProcessor {
static applicableEvents: Event["name"][] = []; static applicableEvents: (Event["name"] | "*")[] = [];
public abstract perform(event: Event): Promise<void>; public abstract perform(event: Event): Promise<void>;
} }

View File

@@ -294,7 +294,7 @@ export default class WebsocketsProcessor {
} }
case "collections.add_group": { case "collections.add_group": {
const group = await Group.findByPk(event.data.groupId); const group = await Group.findByPk(event.modelId);
if (!group) { if (!group) {
return; return;
} }
@@ -320,7 +320,7 @@ export default class WebsocketsProcessor {
} }
case "collections.remove_group": { case "collections.remove_group": {
const group = await Group.findByPk(event.data.groupId); const group = await Group.findByPk(event.modelId);
if (!group) { if (!group) {
return; return;
} }

View File

@@ -2,14 +2,12 @@ import { subDays } from "date-fns";
import { Op } from "sequelize"; import { Op } from "sequelize";
import { sequelize } from "@server/database/sequelize"; import { sequelize } from "@server/database/sequelize";
import InviteReminderEmail from "@server/emails/templates/InviteReminderEmail"; import InviteReminderEmail from "@server/emails/templates/InviteReminderEmail";
import { APM } from "@server/logging/tracing";
import { User } from "@server/models"; import { User } from "@server/models";
import { UserFlag } from "@server/models/User"; import { UserFlag } from "@server/models/User";
import BaseTask, { TaskPriority } from "./BaseTask"; import BaseTask, { TaskPriority } from "./BaseTask";
type Props = undefined; type Props = undefined;
@APM.trace()
export default class InviteReminderTask extends BaseTask<Props> { export default class InviteReminderTask extends BaseTask<Props> {
public async perform() { public async perform() {
const users = await User.scope("invited").findAll({ const users = await User.scope("invited").findAll({

View File

@@ -194,9 +194,9 @@ router.post("collections.add_group", auth(), async (ctx) => {
collectionId: collection.id, collectionId: collection.id,
teamId: collection.teamId, teamId: collection.teamId,
actorId: ctx.state.user.id, actorId: ctx.state.user.id,
modelId: groupId,
data: { data: {
name: group.name, name: group.name,
groupId,
}, },
ip: ctx.request.ip, ip: ctx.request.ip,
}); });
@@ -229,9 +229,9 @@ router.post("collections.remove_group", auth(), async (ctx) => {
collectionId: collection.id, collectionId: collection.id,
teamId: collection.teamId, teamId: collection.teamId,
actorId: ctx.state.user.id, actorId: ctx.state.user.id,
modelId: groupId,
data: { data: {
name: group.name, name: group.name,
groupId,
}, },
ip: ctx.request.ip, ip: ctx.request.ip,
}); });

View File

@@ -46,7 +46,10 @@ export default function init() {
// websockets are a special case on their own queue because they must // websockets are a special case on their own queue because they must
// only be consumed by the websockets service rather than workers. // only be consumed by the websockets service rather than workers.
await websocketQueue.add(job.data); await websocketQueue.add(job.data);
} else if (ProcessorClass.applicableEvents.includes(event.name)) { } else if (
ProcessorClass.applicableEvents.includes(event.name) ||
ProcessorClass.applicableEvents.includes("*")
) {
await processorEventQueue.add({ event, name }); await processorEventQueue.add({ event, name });
} }
} catch (error) { } catch (error) {

View File

@@ -174,9 +174,9 @@ export type CollectionEvent =
collectionId: string; collectionId: string;
teamId: string; teamId: string;
actorId: string; actorId: string;
modelId: string;
data: { data: {
name: string; name: string;
groupId: string;
}; };
ip: string; ip: string;
} }