Remove ContextUser usages in favor of just ids

This commit is contained in:
Adria Navarro 2024-10-09 12:47:43 +02:00
parent 47985748d2
commit 9d06c705ac
4 changed files with 14 additions and 17 deletions

View File

@ -33,7 +33,7 @@ export async function save(
try { try {
const { table } = await sdk.tables.internal.save(tableToSave, { const { table } = await sdk.tables.internal.save(tableToSave, {
user: ctx.user, userId: ctx.user._id,
rowsToImport: rows, rowsToImport: rows,
tableId: ctx.request.body._id, tableId: ctx.request.body._id,
renaming, renaming,
@ -72,7 +72,7 @@ export async function bulkImport(
await handleDataImport(table, { await handleDataImport(table, {
importRows: rows, importRows: rows,
identifierFields, identifierFields,
user: ctx.user, userId: ctx.user._id,
}) })
return table return table
} }

View File

@ -41,7 +41,7 @@ describe("utils", () => {
const data = [{ name: "Alice" }, { name: "Bob" }, { name: "Claire" }] const data = [{ name: "Alice" }, { name: "Bob" }, { name: "Claire" }]
const result = await importToRows(data, table, config.user) const result = await importToRows(data, table, config.user?._id)
expect(result).toEqual([ expect(result).toEqual([
expect.objectContaining({ expect.objectContaining({
autoId: 1, autoId: 1,

View File

@ -18,7 +18,6 @@ import { quotas } from "@budibase/pro"
import { events, context, features } from "@budibase/backend-core" import { events, context, features } from "@budibase/backend-core"
import { import {
AutoFieldSubType, AutoFieldSubType,
ContextUser,
Datasource, Datasource,
Row, Row,
SourceName, SourceName,
@ -122,7 +121,7 @@ export function makeSureTableUpToDate(table: Table, tableToSave: Table) {
export async function importToRows( export async function importToRows(
data: Row[], data: Row[],
table: Table, table: Table,
user?: ContextUser, userId?: string,
opts?: { keepCouchId: boolean } opts?: { keepCouchId: boolean }
) { ) {
const originalTable = table const originalTable = table
@ -136,7 +135,7 @@ export async function importToRows(
// We use a reference to table here and update it after input processing, // We use a reference to table here and update it after input processing,
// so that we can auto increment auto IDs in imported data properly // so that we can auto increment auto IDs in imported data properly
const processed = await inputProcessing(user?._id, table, row, { const processed = await inputProcessing(userId, table, row, {
noAutoRelationships: true, noAutoRelationships: true,
}) })
row = processed row = processed
@ -167,11 +166,10 @@ export async function importToRows(
export async function handleDataImport( export async function handleDataImport(
table: Table, table: Table,
opts?: { identifierFields?: string[]; user?: ContextUser; importRows?: Row[] } opts?: { identifierFields?: string[]; userId?: string; importRows?: Row[] }
) { ) {
const schema = table.schema const schema = table.schema
const identifierFields = opts?.identifierFields || [] const identifierFields = opts?.identifierFields || []
const user = opts?.user
const importRows = opts?.importRows const importRows = opts?.importRows
if (!importRows || !isRows(importRows) || !isSchema(schema)) { if (!importRows || !isRows(importRows) || !isSchema(schema)) {
@ -181,7 +179,7 @@ export async function handleDataImport(
const db = context.getAppDB() const db = context.getAppDB()
const data = parse(importRows, table) const data = parse(importRows, table)
const finalData = await importToRows(data, table, user, { const finalData = await importToRows(data, table, opts?.userId, {
keepCouchId: identifierFields.includes("_id"), keepCouchId: identifierFields.includes("_id"),
}) })
@ -282,22 +280,22 @@ export function checkStaticTables(table: Table) {
class TableSaveFunctions { class TableSaveFunctions {
db: Database db: Database
user?: ContextUser userId?: string
oldTable?: Table oldTable?: Table
importRows?: Row[] importRows?: Row[]
rows: Row[] rows: Row[]
constructor({ constructor({
user, userId,
oldTable, oldTable,
importRows, importRows,
}: { }: {
user?: ContextUser userId?: string
oldTable?: Table oldTable?: Table
importRows?: Row[] importRows?: Row[]
}) { }) {
this.db = context.getAppDB() this.db = context.getAppDB()
this.user = user this.userId = userId
this.oldTable = oldTable this.oldTable = oldTable
this.importRows = importRows this.importRows = importRows
// any rows that need updated // any rows that need updated
@ -329,7 +327,7 @@ class TableSaveFunctions {
table = await handleSearchIndexes(table) table = await handleSearchIndexes(table)
table = await handleDataImport(table, { table = await handleDataImport(table, {
importRows: this.importRows, importRows: this.importRows,
user: this.user, userId: this.userId,
}) })
if (await features.flags.isEnabled("SQS")) { if (await features.flags.isEnabled("SQS")) {
await sdk.tables.sqs.addTable(table) await sdk.tables.sqs.addTable(table)

View File

@ -5,7 +5,6 @@ import {
ViewStatisticsSchema, ViewStatisticsSchema,
ViewV2, ViewV2,
Row, Row,
ContextUser,
} from "@budibase/types" } from "@budibase/types"
import { import {
hasTypeChanged, hasTypeChanged,
@ -27,7 +26,7 @@ import { quotas } from "@budibase/pro"
export async function save( export async function save(
table: Table, table: Table,
opts?: { opts?: {
user?: ContextUser userId?: string
tableId?: string tableId?: string
rowsToImport?: Row[] rowsToImport?: Row[]
renaming?: RenameColumn renaming?: RenameColumn
@ -63,7 +62,7 @@ export async function save(
// saving a table is a complex operation, involving many different steps, this // saving a table is a complex operation, involving many different steps, this
// has been broken out into a utility to make it more obvious/easier to manipulate // has been broken out into a utility to make it more obvious/easier to manipulate
const tableSaveFunctions = new TableSaveFunctions({ const tableSaveFunctions = new TableSaveFunctions({
user: opts?.user, userId: opts?.userId,
oldTable, oldTable,
importRows: opts?.rowsToImport, importRows: opts?.rowsToImport,
}) })