Remove usercontroller dependency from internal
This commit is contained in:
parent
940da62b98
commit
77b3547af7
|
@ -7,21 +7,7 @@ import { Ctx, UserCtx } from "@budibase/types"
|
||||||
import sdk from "../../sdk"
|
import sdk from "../../sdk"
|
||||||
|
|
||||||
export async function fetchMetadata(ctx: Ctx) {
|
export async function fetchMetadata(ctx: Ctx) {
|
||||||
const global = await getGlobalUsers()
|
const users = await sdk.users.fetchMetadata()
|
||||||
const metadata = await sdk.users.rawUserMetadata()
|
|
||||||
const users = []
|
|
||||||
for (let user of global) {
|
|
||||||
// find the metadata that matches up to the global ID
|
|
||||||
const info = metadata.find(meta => meta._id.includes(user._id))
|
|
||||||
// remove these props, not for the correct DB
|
|
||||||
users.push({
|
|
||||||
...user,
|
|
||||||
...info,
|
|
||||||
tableId: InternalTables.USER_METADATA,
|
|
||||||
// make sure the ID is always a local ID, not a global one
|
|
||||||
_id: generateUserMetadataID(user._id),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
ctx.body = users
|
ctx.body = users
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import {
|
||||||
} from "../../../../db/utils"
|
} from "../../../../db/utils"
|
||||||
import { getGlobalUsersFromMetadata } from "../../../../utilities/global"
|
import { getGlobalUsersFromMetadata } from "../../../../utilities/global"
|
||||||
import { outputProcessing } from "../../../../utilities/rowProcessor"
|
import { outputProcessing } from "../../../../utilities/rowProcessor"
|
||||||
import { Ctx, Database, Row, UserCtx } from "@budibase/types"
|
import { Ctx, Database, Row } from "@budibase/types"
|
||||||
import { cleanExportRows } from "../utils"
|
import { cleanExportRows } from "../utils"
|
||||||
import {
|
import {
|
||||||
Format,
|
Format,
|
||||||
|
@ -17,7 +17,6 @@ import {
|
||||||
jsonWithSchema,
|
jsonWithSchema,
|
||||||
} from "../../../../api/controllers/view/exporters"
|
} from "../../../../api/controllers/view/exporters"
|
||||||
import { apiFileReturn } from "../../../../utilities/fileSystem"
|
import { apiFileReturn } from "../../../../utilities/fileSystem"
|
||||||
import * as userController from "../../../../api/controllers/user"
|
|
||||||
import * as inMemoryViews from "../../../../db/inMemoryView"
|
import * as inMemoryViews from "../../../../db/inMemoryView"
|
||||||
import {
|
import {
|
||||||
migrateToInMemoryView,
|
migrateToInMemoryView,
|
||||||
|
@ -25,6 +24,7 @@ import {
|
||||||
getFromDesignDoc,
|
getFromDesignDoc,
|
||||||
getFromMemoryDoc,
|
getFromMemoryDoc,
|
||||||
} from "../../../../api/controllers/view/utils"
|
} from "../../../../api/controllers/view/utils"
|
||||||
|
import sdk from "src/sdk"
|
||||||
|
|
||||||
export async function search(ctx: Ctx) {
|
export async function search(ctx: Ctx) {
|
||||||
// Fetch the whole table when running in cypress, as search doesn't work
|
// Fetch the whole table when running in cypress, as search doesn't work
|
||||||
|
@ -126,15 +126,14 @@ export async function fetch(ctx: Ctx) {
|
||||||
|
|
||||||
const tableId = ctx.params.tableId
|
const tableId = ctx.params.tableId
|
||||||
let table = await db.get(tableId)
|
let table = await db.get(tableId)
|
||||||
let rows = await getRawTableData(ctx, db, tableId)
|
let rows = await getRawTableData(db, tableId)
|
||||||
return outputProcessing(table, rows)
|
return outputProcessing(table, rows)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getRawTableData(ctx: Ctx, db: Database, tableId: string) {
|
async function getRawTableData(db: Database, tableId: string) {
|
||||||
let rows
|
let rows
|
||||||
if (tableId === InternalTables.USER_METADATA) {
|
if (tableId === InternalTables.USER_METADATA) {
|
||||||
await userController.fetchMetadata(ctx)
|
rows = await sdk.users.fetchMetadata()
|
||||||
rows = ctx.body
|
|
||||||
} else {
|
} else {
|
||||||
const response = await db.allDocs(
|
const response = await db.allDocs(
|
||||||
getRowParams(tableId, null, {
|
getRowParams(tableId, null, {
|
||||||
|
@ -166,7 +165,7 @@ export async function fetchView(ctx: Ctx) {
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
const tableId = viewInfo.meta.tableId
|
const tableId = viewInfo.meta.tableId
|
||||||
const data = await getRawTableData(ctx, db, tableId)
|
const data = await getRawTableData(db, tableId)
|
||||||
response = await inMemoryViews.runView(
|
response = await inMemoryViews.runView(
|
||||||
viewInfo,
|
viewInfo,
|
||||||
calculation as string,
|
calculation as string,
|
||||||
|
|
|
@ -64,6 +64,25 @@ export async function rawUserMetadata(db?: Database) {
|
||||||
).rows.map(row => row.doc)
|
).rows.map(row => row.doc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function fetchMetadata() {
|
||||||
|
const global = await getGlobalUsers()
|
||||||
|
const metadata = await rawUserMetadata()
|
||||||
|
const users = []
|
||||||
|
for (let user of global) {
|
||||||
|
// find the metadata that matches up to the global ID
|
||||||
|
const info = metadata.find(meta => meta._id.includes(user._id))
|
||||||
|
// remove these props, not for the correct DB
|
||||||
|
users.push({
|
||||||
|
...user,
|
||||||
|
...info,
|
||||||
|
tableId: InternalTables.USER_METADATA,
|
||||||
|
// make sure the ID is always a local ID, not a global one
|
||||||
|
_id: generateUserMetadataID(user._id),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return users
|
||||||
|
}
|
||||||
|
|
||||||
export async function syncGlobalUsers() {
|
export async function syncGlobalUsers() {
|
||||||
// sync user metadata
|
// sync user metadata
|
||||||
const dbs = [context.getDevAppDB(), context.getProdAppDB()]
|
const dbs = [context.getDevAppDB(), context.getProdAppDB()]
|
||||||
|
|
Loading…
Reference in New Issue