Merge pull request #14862 from Budibase/BUDI-8749/missing-old-row-on-automations
Missing old row on automations
This commit is contained in:
commit
ef2465635a
|
@ -11,6 +11,7 @@ import {
|
||||||
DeleteRow,
|
DeleteRow,
|
||||||
DeleteRowRequest,
|
DeleteRowRequest,
|
||||||
DeleteRows,
|
DeleteRows,
|
||||||
|
EventType,
|
||||||
ExportRowsRequest,
|
ExportRowsRequest,
|
||||||
ExportRowsResponse,
|
ExportRowsResponse,
|
||||||
FieldType,
|
FieldType,
|
||||||
|
@ -64,9 +65,9 @@ export async function patch(
|
||||||
ctx.throw(404, "Row not found")
|
ctx.throw(404, "Row not found")
|
||||||
}
|
}
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
ctx.eventEmitter &&
|
|
||||||
ctx.eventEmitter.emitRow({
|
ctx.eventEmitter?.emitRow({
|
||||||
eventName: `row:update`,
|
eventName: EventType.ROW_UPDATE,
|
||||||
appId,
|
appId,
|
||||||
row,
|
row,
|
||||||
table,
|
table,
|
||||||
|
@ -103,9 +104,9 @@ export const save = async (ctx: UserCtx<Row, Row>) => {
|
||||||
sdk.rows.save(sourceId, ctx.request.body, ctx.user?._id)
|
sdk.rows.save(sourceId, ctx.request.body, ctx.user?._id)
|
||||||
)
|
)
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
ctx.eventEmitter &&
|
|
||||||
ctx.eventEmitter.emitRow({
|
ctx.eventEmitter?.emitRow({
|
||||||
eventName: `row:save`,
|
eventName: EventType.ROW_SAVE,
|
||||||
appId,
|
appId,
|
||||||
row,
|
row,
|
||||||
table,
|
table,
|
||||||
|
@ -182,9 +183,8 @@ async function deleteRows(ctx: UserCtx<DeleteRowRequest>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let row of rows) {
|
for (let row of rows) {
|
||||||
ctx.eventEmitter &&
|
ctx.eventEmitter?.emitRow({
|
||||||
ctx.eventEmitter.emitRow({
|
eventName: EventType.ROW_DELETE,
|
||||||
eventName: `row:delete`,
|
|
||||||
appId,
|
appId,
|
||||||
row,
|
row,
|
||||||
user: sdk.users.getUserContextBindings(ctx.user),
|
user: sdk.users.getUserContextBindings(ctx.user),
|
||||||
|
@ -203,9 +203,8 @@ async function deleteRow(ctx: UserCtx<DeleteRowRequest>) {
|
||||||
await quotas.removeRow()
|
await quotas.removeRow()
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.eventEmitter &&
|
ctx.eventEmitter?.emitRow({
|
||||||
ctx.eventEmitter.emitRow({
|
eventName: EventType.ROW_DELETE,
|
||||||
eventName: `row:delete`,
|
|
||||||
appId,
|
appId,
|
||||||
row: resp.row,
|
row: resp.row,
|
||||||
user: sdk.users.getUserContextBindings(ctx.user),
|
user: sdk.users.getUserContextBindings(ctx.user),
|
||||||
|
|
|
@ -16,6 +16,7 @@ import {
|
||||||
BulkImportResponse,
|
BulkImportResponse,
|
||||||
CsvToJsonRequest,
|
CsvToJsonRequest,
|
||||||
CsvToJsonResponse,
|
CsvToJsonResponse,
|
||||||
|
EventType,
|
||||||
FetchTablesResponse,
|
FetchTablesResponse,
|
||||||
FieldType,
|
FieldType,
|
||||||
MigrateRequest,
|
MigrateRequest,
|
||||||
|
@ -129,8 +130,7 @@ export async function save(ctx: UserCtx<SaveTableRequest, SaveTableResponse>) {
|
||||||
}
|
}
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
ctx.message = `Table ${table.name} saved successfully.`
|
ctx.message = `Table ${table.name} saved successfully.`
|
||||||
ctx.eventEmitter &&
|
ctx.eventEmitter?.emitTable(EventType.TABLE_SAVE, appId, { ...savedTable })
|
||||||
ctx.eventEmitter.emitTable(`table:save`, appId, { ...savedTable })
|
|
||||||
ctx.body = savedTable
|
ctx.body = savedTable
|
||||||
|
|
||||||
savedTable = await processTable(savedTable)
|
savedTable = await processTable(savedTable)
|
||||||
|
@ -143,8 +143,8 @@ export async function destroy(ctx: UserCtx) {
|
||||||
await sdk.rowActions.deleteAll(tableId)
|
await sdk.rowActions.deleteAll(tableId)
|
||||||
const deletedTable = await pickApi({ tableId }).destroy(ctx)
|
const deletedTable = await pickApi({ tableId }).destroy(ctx)
|
||||||
await events.table.deleted(deletedTable)
|
await events.table.deleted(deletedTable)
|
||||||
ctx.eventEmitter &&
|
|
||||||
ctx.eventEmitter.emitTable(`table:delete`, appId, deletedTable)
|
ctx.eventEmitter?.emitTable(EventType.TABLE_DELETE, appId, deletedTable)
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
ctx.table = deletedTable
|
ctx.table = deletedTable
|
||||||
ctx.body = { message: `Table ${tableId} deleted.` }
|
ctx.body = { message: `Table ${tableId} deleted.` }
|
||||||
|
|
|
@ -17,6 +17,7 @@ import {
|
||||||
import { context, features } from "@budibase/backend-core"
|
import { context, features } from "@budibase/backend-core"
|
||||||
import {
|
import {
|
||||||
ContextUser,
|
ContextUser,
|
||||||
|
EventType,
|
||||||
FeatureFlag,
|
FeatureFlag,
|
||||||
FieldType,
|
FieldType,
|
||||||
LinkDocumentValue,
|
LinkDocumentValue,
|
||||||
|
@ -44,15 +45,7 @@ const INVALID_DISPLAY_COLUMN_TYPE = [
|
||||||
* This functionality makes sure that when rows with links are created, updated or deleted they are processed
|
* This functionality makes sure that when rows with links are created, updated or deleted they are processed
|
||||||
* correctly - making sure that no stale links are left around and that all links have been made successfully.
|
* correctly - making sure that no stale links are left around and that all links have been made successfully.
|
||||||
*/
|
*/
|
||||||
|
export { EventType } from "@budibase/types"
|
||||||
export const EventType = {
|
|
||||||
ROW_SAVE: "row:save",
|
|
||||||
ROW_UPDATE: "row:update",
|
|
||||||
ROW_DELETE: "row:delete",
|
|
||||||
TABLE_SAVE: "table:save",
|
|
||||||
TABLE_UPDATED: "table:updated",
|
|
||||||
TABLE_DELETE: "table:delete",
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearRelationshipFields(schema: TableSchema, rows: Row[]) {
|
function clearRelationshipFields(schema: TableSchema, rows: Row[]) {
|
||||||
for (let [key, field] of Object.entries(schema)) {
|
for (let [key, field] of Object.entries(schema)) {
|
||||||
|
|
|
@ -1,12 +1,20 @@
|
||||||
import { rowEmission, tableEmission } from "./utils"
|
import { rowEmission, tableEmission } from "./utils"
|
||||||
import mainEmitter from "./index"
|
import mainEmitter from "./index"
|
||||||
import env from "../environment"
|
import env from "../environment"
|
||||||
import { Table, Row, DocumentType, App } from "@budibase/types"
|
import {
|
||||||
|
Table,
|
||||||
|
Row,
|
||||||
|
DocumentType,
|
||||||
|
App,
|
||||||
|
ContextEmitter,
|
||||||
|
EventType,
|
||||||
|
UserBindings,
|
||||||
|
} from "@budibase/types"
|
||||||
import { context } from "@budibase/backend-core"
|
import { context } from "@budibase/backend-core"
|
||||||
|
|
||||||
const MAX_AUTOMATIONS_ALLOWED = 5
|
const MAX_AUTOMATIONS_ALLOWED = 5
|
||||||
|
|
||||||
class AutomationEmitter {
|
class AutomationEmitter implements ContextEmitter {
|
||||||
chainCount: number
|
chainCount: number
|
||||||
metadata: { automationChainCount: number }
|
metadata: { automationChainCount: number }
|
||||||
|
|
||||||
|
@ -36,11 +44,15 @@ class AutomationEmitter {
|
||||||
appId,
|
appId,
|
||||||
row,
|
row,
|
||||||
table,
|
table,
|
||||||
|
oldRow,
|
||||||
|
user,
|
||||||
}: {
|
}: {
|
||||||
eventName: string
|
eventName: EventType.ROW_SAVE | EventType.ROW_DELETE | EventType.ROW_UPDATE
|
||||||
appId: string
|
appId: string
|
||||||
row: Row
|
row: Row
|
||||||
table?: Table
|
table?: Table
|
||||||
|
oldRow?: Row
|
||||||
|
user: UserBindings
|
||||||
}) {
|
}) {
|
||||||
let MAX_AUTOMATION_CHAIN = await this.getMaxAutomationChain()
|
let MAX_AUTOMATION_CHAIN = await this.getMaxAutomationChain()
|
||||||
|
|
||||||
|
@ -54,7 +66,9 @@ class AutomationEmitter {
|
||||||
appId,
|
appId,
|
||||||
row,
|
row,
|
||||||
table,
|
table,
|
||||||
|
oldRow,
|
||||||
metadata: this.metadata,
|
metadata: this.metadata,
|
||||||
|
user,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
import { EventEmitter } from "events"
|
import { EventEmitter } from "events"
|
||||||
import { rowEmission, tableEmission } from "./utils"
|
import { rowEmission, tableEmission } from "./utils"
|
||||||
import { Table, Row, User } from "@budibase/types"
|
import {
|
||||||
|
Table,
|
||||||
|
Row,
|
||||||
|
UserBindings,
|
||||||
|
EventType,
|
||||||
|
ContextEmitter,
|
||||||
|
} from "@budibase/types"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* keeping event emitter in one central location as it might be used for things other than
|
* keeping event emitter in one central location as it might be used for things other than
|
||||||
|
@ -12,7 +18,7 @@ import { Table, Row, User } from "@budibase/types"
|
||||||
* Extending the standard emitter to some syntactic sugar and standardisation to the emitted event.
|
* Extending the standard emitter to some syntactic sugar and standardisation to the emitted event.
|
||||||
* This is specifically quite important for template strings used in automations.
|
* This is specifically quite important for template strings used in automations.
|
||||||
*/
|
*/
|
||||||
class BudibaseEmitter extends EventEmitter {
|
class BudibaseEmitter extends EventEmitter implements ContextEmitter {
|
||||||
emitRow({
|
emitRow({
|
||||||
eventName,
|
eventName,
|
||||||
appId,
|
appId,
|
||||||
|
@ -21,17 +27,17 @@ class BudibaseEmitter extends EventEmitter {
|
||||||
oldRow,
|
oldRow,
|
||||||
user,
|
user,
|
||||||
}: {
|
}: {
|
||||||
eventName: string
|
eventName: EventType.ROW_SAVE | EventType.ROW_DELETE | EventType.ROW_UPDATE
|
||||||
appId: string
|
appId: string
|
||||||
row: Row
|
row: Row
|
||||||
table?: Table
|
table?: Table
|
||||||
oldRow?: Row
|
oldRow?: Row
|
||||||
user: User
|
user: UserBindings
|
||||||
}) {
|
}) {
|
||||||
rowEmission({ emitter: this, eventName, appId, row, table, oldRow, user })
|
rowEmission({ emitter: this, eventName, appId, row, table, oldRow, user })
|
||||||
}
|
}
|
||||||
|
|
||||||
emitTable(eventName: string, appId: string, table?: Table) {
|
emitTable(eventName: EventType, appId: string, table?: Table) {
|
||||||
tableEmission({ emitter: this, eventName, appId, table })
|
tableEmission({ emitter: this, eventName, appId, table })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Table, Row, User } from "@budibase/types"
|
import { Table, Row, UserBindings } from "@budibase/types"
|
||||||
import BudibaseEmitter from "./BudibaseEmitter"
|
import BudibaseEmitter from "./BudibaseEmitter"
|
||||||
|
|
||||||
type BBEventOpts = {
|
type BBEventOpts = {
|
||||||
|
@ -9,7 +9,7 @@ type BBEventOpts = {
|
||||||
row?: Row
|
row?: Row
|
||||||
oldRow?: Row
|
oldRow?: Row
|
||||||
metadata?: any
|
metadata?: any
|
||||||
user?: User
|
user?: UserBindings
|
||||||
}
|
}
|
||||||
|
|
||||||
interface BBEventTable extends Table {
|
interface BBEventTable extends Table {
|
||||||
|
@ -25,7 +25,7 @@ type BBEvent = {
|
||||||
id?: string
|
id?: string
|
||||||
revision?: string
|
revision?: string
|
||||||
metadata?: any
|
metadata?: any
|
||||||
user?: User
|
user?: UserBindings
|
||||||
}
|
}
|
||||||
|
|
||||||
export function rowEmission({
|
export function rowEmission({
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
export const enum EventType {
|
||||||
|
ROW_SAVE = "row:save",
|
||||||
|
ROW_UPDATE = "row:update",
|
||||||
|
ROW_DELETE = "row:delete",
|
||||||
|
TABLE_SAVE = "table:save",
|
||||||
|
TABLE_UPDATED = "table:updated",
|
||||||
|
TABLE_DELETE = "table:delete",
|
||||||
|
}
|
|
@ -1 +1,2 @@
|
||||||
export * from "./installation"
|
export * from "./installation"
|
||||||
|
export * from "./events"
|
||||||
|
|
|
@ -1,7 +1,17 @@
|
||||||
import { Context, Request } from "koa"
|
import { Context, Request } from "koa"
|
||||||
import { User, Role, UserRoles, Account, ConfigType } from "../documents"
|
import {
|
||||||
|
User,
|
||||||
|
Role,
|
||||||
|
UserRoles,
|
||||||
|
Account,
|
||||||
|
ConfigType,
|
||||||
|
Row,
|
||||||
|
Table,
|
||||||
|
UserBindings,
|
||||||
|
} from "../documents"
|
||||||
import { FeatureFlag, License } from "../sdk"
|
import { FeatureFlag, License } from "../sdk"
|
||||||
import { Files } from "formidable"
|
import { Files } from "formidable"
|
||||||
|
import { EventType } from "../core"
|
||||||
|
|
||||||
export interface ContextUser extends Omit<User, "roles"> {
|
export interface ContextUser extends Omit<User, "roles"> {
|
||||||
globalId?: string
|
globalId?: string
|
||||||
|
@ -40,6 +50,7 @@ export interface UserCtx<RequestBody = any, ResponseBody = any>
|
||||||
extends Ctx<RequestBody, ResponseBody> {
|
extends Ctx<RequestBody, ResponseBody> {
|
||||||
user: ContextUser
|
user: ContextUser
|
||||||
roleId?: string
|
roleId?: string
|
||||||
|
eventEmitter?: ContextEmitter
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,3 +60,32 @@ export interface UserCtx<RequestBody = any, ResponseBody = any>
|
||||||
export interface BBContext extends Ctx {
|
export interface BBContext extends Ctx {
|
||||||
user?: ContextUser
|
user?: ContextUser
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ContextEmitter {
|
||||||
|
emitRow(values: {
|
||||||
|
eventName: EventType.ROW_SAVE
|
||||||
|
appId: string
|
||||||
|
row: Row
|
||||||
|
table: Table
|
||||||
|
user: UserBindings
|
||||||
|
}): void
|
||||||
|
emitRow(values: {
|
||||||
|
eventName: EventType.ROW_UPDATE
|
||||||
|
appId: string
|
||||||
|
row: Row
|
||||||
|
table: Table
|
||||||
|
oldRow: Row
|
||||||
|
user: UserBindings
|
||||||
|
}): void
|
||||||
|
emitRow(values: {
|
||||||
|
eventName: EventType.ROW_DELETE
|
||||||
|
appId: string
|
||||||
|
row: Row
|
||||||
|
user: UserBindings
|
||||||
|
}): void
|
||||||
|
emitTable(
|
||||||
|
eventName: EventType.TABLE_SAVE | EventType.TABLE_DELETE,
|
||||||
|
appId: string,
|
||||||
|
table?: Table
|
||||||
|
): void
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue