extract necessary user bindings and add types
This commit is contained in:
parent
d7d7ae9d75
commit
09695fabd6
|
@ -13,7 +13,6 @@ import {
|
|||
UserCtx,
|
||||
DeleteAutomationResponse,
|
||||
FetchAutomationResponse,
|
||||
User,
|
||||
} from "@budibase/types"
|
||||
import { getActionDefinitions as actionDefs } from "../../automations/actions"
|
||||
import sdk from "../../sdk"
|
||||
|
@ -160,7 +159,7 @@ export async function trigger(ctx: UserCtx) {
|
|||
automation,
|
||||
{
|
||||
fields: ctx.request.body.fields,
|
||||
user: ctx.user as User,
|
||||
user: sdk.users.getUserContextBindings(ctx.user),
|
||||
timeout:
|
||||
ctx.request.body.timeout * 1000 || env.AUTOMATION_THREAD_TIMEOUT,
|
||||
},
|
||||
|
@ -185,7 +184,7 @@ export async function trigger(ctx: UserCtx) {
|
|||
await triggers.externalTrigger(automation, {
|
||||
...ctx.request.body,
|
||||
appId: ctx.appId,
|
||||
user: ctx.user as User,
|
||||
user: sdk.users.getUserContextBindings(ctx.user),
|
||||
})
|
||||
ctx.body = {
|
||||
message: `Automation ${automation._id} has been triggered.`,
|
||||
|
@ -215,7 +214,7 @@ export async function test(ctx: UserCtx) {
|
|||
{
|
||||
...testInput,
|
||||
appId: ctx.appId,
|
||||
user: ctx.user,
|
||||
user: sdk.users.getUserContextBindings(ctx.user),
|
||||
},
|
||||
{ getResponses: true }
|
||||
)
|
||||
|
|
|
@ -71,7 +71,7 @@ export async function patch(
|
|||
row,
|
||||
table,
|
||||
oldRow,
|
||||
ctx.user
|
||||
sdk.users.getUserContextBindings(ctx.user)
|
||||
)
|
||||
ctx.message = `${table.name} updated successfully.`
|
||||
ctx.body = row
|
||||
|
@ -104,7 +104,14 @@ export const save = async (ctx: UserCtx<Row, Row>) => {
|
|||
)
|
||||
ctx.status = 200
|
||||
ctx.eventEmitter &&
|
||||
ctx.eventEmitter.emitRow(`row:save`, appId, row, table, null, ctx.user)
|
||||
ctx.eventEmitter.emitRow(
|
||||
`row:save`,
|
||||
appId,
|
||||
row,
|
||||
table,
|
||||
null,
|
||||
sdk.users.getUserContextBindings(ctx.user)
|
||||
)
|
||||
ctx.message = `${table.name} saved successfully`
|
||||
// prefer squashed for response
|
||||
ctx.body = row || squashed
|
||||
|
@ -177,7 +184,14 @@ async function deleteRows(ctx: UserCtx<DeleteRowRequest>) {
|
|||
|
||||
for (let row of rows) {
|
||||
ctx.eventEmitter &&
|
||||
ctx.eventEmitter.emitRow(`row:delete`, appId, row, null, null, ctx.user)
|
||||
ctx.eventEmitter.emitRow(
|
||||
`row:delete`,
|
||||
appId,
|
||||
row,
|
||||
null,
|
||||
null,
|
||||
sdk.users.getUserContextBindings(ctx.user)
|
||||
)
|
||||
gridSocket?.emitRowDeletion(ctx, row)
|
||||
}
|
||||
|
||||
|
@ -200,7 +214,7 @@ async function deleteRow(ctx: UserCtx<DeleteRowRequest>) {
|
|||
resp.row,
|
||||
null,
|
||||
null,
|
||||
ctx.user
|
||||
sdk.users.getUserContextBindings(ctx.user)
|
||||
)
|
||||
gridSocket?.emitRowDeletion(ctx, resp.row)
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ import {
|
|||
AutomationStoppedReason,
|
||||
AutomationStatus,
|
||||
AutomationRowEvent,
|
||||
User,
|
||||
UserBindings,
|
||||
} from "@budibase/types"
|
||||
import { executeInThread } from "../threads/automation"
|
||||
import { dataFilters, sdk } from "@budibase/shared-core"
|
||||
|
@ -145,11 +145,10 @@ export async function externalTrigger(
|
|||
fields: Record<string, any>
|
||||
timeout?: number
|
||||
appId?: string
|
||||
user?: User
|
||||
user?: UserBindings | undefined
|
||||
},
|
||||
{ getResponses }: { getResponses?: boolean } = {}
|
||||
): Promise<any> {
|
||||
console.log("user: " + params.user)
|
||||
if (automation.disabled) {
|
||||
throw new Error("Automation is disabled")
|
||||
}
|
||||
|
@ -196,7 +195,6 @@ export async function externalTrigger(
|
|||
appId: context.getAppId(),
|
||||
automation,
|
||||
}
|
||||
console.log(data)
|
||||
return executeInThread({ data } as AutomationJob)
|
||||
} else {
|
||||
return automationQueue.add(data, JOB_OPTS)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { AutomationResults, LoopStepType, User } from "@budibase/types"
|
||||
import { AutomationResults, LoopStepType, UserBindings } from "@budibase/types"
|
||||
|
||||
export interface LoopInput {
|
||||
option: LoopStepType
|
||||
|
@ -18,6 +18,6 @@ export interface AutomationContext extends AutomationResults {
|
|||
stepsById: Record<string, any>
|
||||
stepsByName: Record<string, any>
|
||||
env?: Record<string, string>
|
||||
user?: User
|
||||
user?: UserBindings
|
||||
trigger: any
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import {
|
|||
UserMetadata,
|
||||
Database,
|
||||
ContextUserMetadata,
|
||||
UserBindings,
|
||||
} from "@budibase/types"
|
||||
|
||||
export function combineMetadataAndUser(
|
||||
|
@ -125,7 +126,7 @@ export async function syncGlobalUsers() {
|
|||
}
|
||||
}
|
||||
|
||||
export function getUserContextBindings(user: ContextUser) {
|
||||
export function getUserContextBindings(user: ContextUser): UserBindings {
|
||||
if (!user) {
|
||||
return {}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import {
|
|||
BranchStep,
|
||||
LoopStep,
|
||||
SearchFilters,
|
||||
User,
|
||||
UserBindings,
|
||||
} from "@budibase/types"
|
||||
import { AutomationContext, TriggerOutput } from "../definitions/automations"
|
||||
import { WorkerCallback } from "./definitions"
|
||||
|
@ -76,7 +76,7 @@ class Orchestrator {
|
|||
private loopStepOutputs: LoopStep[]
|
||||
private stopped: boolean
|
||||
private executionOutput: Omit<AutomationContext, "stepsByName" | "stepsById">
|
||||
private currentUser: User | undefined
|
||||
private currentUser: UserBindings | undefined
|
||||
|
||||
constructor(job: AutomationJob) {
|
||||
let automation = job.data.automation
|
||||
|
|
|
@ -68,6 +68,16 @@ export interface User extends Document {
|
|||
appSort?: string
|
||||
}
|
||||
|
||||
export interface UserBindings extends Document {
|
||||
firstName?: string
|
||||
lastName?: string
|
||||
email?: string
|
||||
status?: string
|
||||
roleId?: string | undefined | null
|
||||
globalId?: string
|
||||
userId?: string
|
||||
}
|
||||
|
||||
export enum UserStatus {
|
||||
ACTIVE = "active",
|
||||
INACTIVE = "inactive",
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
import { Automation, AutomationMetadata, Row, User } from "../../documents"
|
||||
import {
|
||||
Automation,
|
||||
AutomationMetadata,
|
||||
Row,
|
||||
UserBindings,
|
||||
} from "../../documents"
|
||||
import { Job } from "bull"
|
||||
|
||||
export interface AutomationDataEvent {
|
||||
|
@ -8,7 +13,7 @@ export interface AutomationDataEvent {
|
|||
timeout?: number
|
||||
row?: Row
|
||||
oldRow?: Row
|
||||
user?: User
|
||||
user?: UserBindings
|
||||
}
|
||||
|
||||
export interface AutomationData {
|
||||
|
|
Loading…
Reference in New Issue