Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for user groups adding users to app user metadata tables #10120

Merged
merged 19 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c601b8b
Fix for app sync, base it on group roles, not just user roles - stops…
mike12345567 Mar 21, 2023
040c6de
Fixing some issues with test cases.
mike12345567 Mar 21, 2023
849a593
Updating Jest to latest 29.5.0 and then fixing snapshots to work with…
mike12345567 Mar 21, 2023
a35aa5a
Fix for currentapp build issue.
mike12345567 Mar 22, 2023
8d37172
Merge branch 'develop' of github.com:Budibase/budibase into fix/budi-…
mike12345567 Mar 27, 2023
7c7fb23
General fixes for open handles, attempting to find and close all issu…
mike12345567 Mar 27, 2023
793c4c1
Merge branch 'fix/budi-6657' of github.com:Budibase/budibase into fix…
mike12345567 Mar 27, 2023
e223c31
Removing test script changes.
mike12345567 Mar 27, 2023
8c170e7
Testing simplifying coverage (fix server issue).
mike12345567 Mar 27, 2023
c0a4526
Adding back backend-core and worker coverage.
mike12345567 Mar 27, 2023
33b13ee
Updating to codecov-action v3 as v1 deprecated.
mike12345567 Mar 27, 2023
9efaa46
Making sure server tests end correctly with forceExit.
mike12345567 Mar 27, 2023
49b1a39
adding force exit to all CI jobs.
mike12345567 Mar 27, 2023
26885ac
Removing files from coverage upload to see if it correctly resolves a…
mike12345567 Mar 27, 2023
f683eee
Removing spec.js/ts from coverage in server.
mike12345567 Mar 27, 2023
960cbd0
Splitting server tests out to run separately to main lerna thread.
mike12345567 Mar 27, 2023
00f8467
Running server tests first.
mike12345567 Mar 27, 2023
b94049a
Making sure client is built, before running server tests.
mike12345567 Mar 28, 2023
502a8b1
Upping memory limit for server tests.
mike12345567 Mar 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/backend-core/tests/jestEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ process.env.NODE_ENV = "jest"
process.env.MOCK_REDIS = "1"
process.env.LOG_LEVEL = process.env.LOG_LEVEL || "error"
process.env.ENABLE_4XX_HTTP_LOGGING = "0"
process.env.REDIS_PASSWORD = "budibase"
7 changes: 6 additions & 1 deletion packages/server/__mocks__/node-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module FetchMock {
// @ts-ignore
const fetch = jest.requireActual("node-fetch")
let failCount = 0
let mockSearch = false

const func = async (url: any, opts: any) => {
function json(body: any, status = 200) {
Expand Down Expand Up @@ -69,7 +70,7 @@ module FetchMock {
},
404
)
} else if (url.includes("_search")) {
} else if (mockSearch && url.includes("_search")) {
const body = opts.body
const parts = body.split("tableId:")
let tableId
Expand Down Expand Up @@ -192,5 +193,9 @@ module FetchMock {

func.Headers = fetch.Headers

func.mockSearch = () => {
mockSearch = true
}

module.exports = func
}
9 changes: 5 additions & 4 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"debug": "yarn build && node --expose-gc --inspect=9222 dist/index.js",
"postbuild": "copyfiles -u 1 src/**/*.svelte dist/ && copyfiles -u 1 src/**/*.hbs dist/ && copyfiles -u 1 src/**/*.json dist/",
"test": "bash scripts/test.sh",
"test:memory": "jest --maxWorkers=2 --logHeapUsage --forceExit",
"test:watch": "jest --watch",
"predocker": "copyfiles -f ../client/dist/budibase-client.js ../client/manifest.json client",
"build:docker": "yarn run predocker && docker build . -t app-service --label version=$BUDIBASE_RELEASE_VERSION",
Expand Down Expand Up @@ -125,7 +126,7 @@
"@babel/core": "7.17.4",
"@babel/preset-env": "7.16.11",
"@budibase/standard-components": "^0.9.139",
"@jest/test-sequencer": "24.9.0",
"@jest/test-sequencer": "29.5.0",
"@swc/core": "^1.3.25",
"@swc/jest": "^0.2.24",
"@trendyol/jest-testcontainers": "^2.1.1",
Expand All @@ -134,7 +135,7 @@
"@types/global-agent": "2.1.1",
"@types/google-spreadsheet": "3.1.5",
"@types/ioredis": "4.28.10",
"@types/jest": "27.5.1",
"@types/jest": "29.5.0",
"@types/koa": "2.13.4",
"@types/koa__router": "8.0.8",
"@types/lodash": "4.14.180",
Expand All @@ -154,7 +155,7 @@
"eslint": "6.8.0",
"ioredis-mock": "7.2.0",
"is-wsl": "2.2.0",
"jest": "28.1.1",
"jest": "29.5.0",
"jest-openapi": "0.14.2",
"jest-serial-runner": "^1.2.1",
"nodemon": "2.0.15",
Expand All @@ -166,7 +167,7 @@
"supertest": "6.2.2",
"swagger-jsdoc": "6.1.0",
"timekeeper": "2.2.0",
"ts-jest": "28.0.4",
"ts-jest": "29.0.5",
"ts-node": "10.8.1",
"tsconfig-paths": "4.0.0",
"typescript": "4.7.3",
Expand Down
10 changes: 5 additions & 5 deletions packages/server/scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
if [[ -n $CI ]]
then
# --runInBand performs better in ci where resources are limited
echo "jest --coverage --runInBand"
jest --coverage --runInBand
echo "jest --coverage --runInBand --forceExit --workerIdleMemoryLimit=1000MB"
jest --coverage --runInBand --forceExit --workerIdleMemoryLimit=1000MB
else
# --maxWorkers performs better in development
echo "jest --coverage --maxWorkers=2"
jest --coverage --maxWorkers=2
fi
echo "jest --coverage --maxWorkers=2 --forceExit --workerIdleMemoryLimit=1000MB"
jest --coverage --maxWorkers=2 --forceExit --workerIdleMemoryLimit=1000MB
fi
37 changes: 18 additions & 19 deletions packages/server/src/api/controllers/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import {
Layout,
Screen,
MigrationType,
BBContext,
Database,
UserCtx,
} from "@budibase/types"
Expand Down Expand Up @@ -74,14 +73,14 @@ async function getScreens() {
).rows.map((row: any) => row.doc)
}

function getUserRoleId(ctx: BBContext) {
function getUserRoleId(ctx: UserCtx) {
return !ctx.user?.role || !ctx.user.role._id
? roles.BUILTIN_ROLE_IDS.PUBLIC
: ctx.user.role._id
}

function checkAppUrl(
ctx: BBContext,
ctx: UserCtx,
apps: App[],
url: string,
currentAppId?: string
Expand All @@ -95,7 +94,7 @@ function checkAppUrl(
}

function checkAppName(
ctx: BBContext,
ctx: UserCtx,
apps: App[],
name: string,
currentAppId?: string
Expand Down Expand Up @@ -160,7 +159,7 @@ async function addDefaultTables(db: Database) {
await db.bulkDocs([...defaultDbDocs])
}

export async function fetch(ctx: BBContext) {
export async function fetch(ctx: UserCtx) {
const dev = ctx.query && ctx.query.status === AppStatus.DEV
const all = ctx.query && ctx.query.status === AppStatus.ALL
const apps = (await dbCore.getAllApps({ dev, all })) as App[]
Expand All @@ -185,7 +184,7 @@ export async function fetch(ctx: BBContext) {
ctx.body = await checkAppMetadata(apps)
}

export async function fetchAppDefinition(ctx: BBContext) {
export async function fetchAppDefinition(ctx: UserCtx) {
const layouts = await getLayouts()
const userRoleId = getUserRoleId(ctx)
const accessController = new roles.AccessController()
Expand Down Expand Up @@ -231,7 +230,7 @@ export async function fetchAppPackage(ctx: UserCtx) {
}
}

async function performAppCreate(ctx: BBContext) {
async function performAppCreate(ctx: UserCtx) {
const apps = (await dbCore.getAllApps({ dev: true })) as App[]
const name = ctx.request.body.name,
possibleUrl = ctx.request.body.url
Expand Down Expand Up @@ -360,7 +359,7 @@ async function creationEvents(request: any, app: App) {
}
}

async function appPostCreate(ctx: BBContext, app: App) {
async function appPostCreate(ctx: UserCtx, app: App) {
const tenantId = tenancy.getTenantId()
await migrations.backPopulateMigrations({
type: MigrationType.APP,
Expand Down Expand Up @@ -391,7 +390,7 @@ async function appPostCreate(ctx: BBContext, app: App) {
}
}

export async function create(ctx: BBContext) {
export async function create(ctx: UserCtx) {
const newApplication = await quotas.addApp(() => performAppCreate(ctx))
await appPostCreate(ctx, newApplication)
await cache.bustCache(cache.CacheKey.CHECKLIST)
Expand All @@ -401,7 +400,7 @@ export async function create(ctx: BBContext) {

// This endpoint currently operates as a PATCH rather than a PUT
// Thus name and url fields are handled only if present
export async function update(ctx: BBContext) {
export async function update(ctx: UserCtx) {
const apps = (await dbCore.getAllApps({ dev: true })) as App[]
// validation
const name = ctx.request.body.name,
Expand All @@ -421,7 +420,7 @@ export async function update(ctx: BBContext) {
ctx.body = app
}

export async function updateClient(ctx: BBContext) {
export async function updateClient(ctx: UserCtx) {
// Get current app version
const db = context.getAppDB()
const application = await db.get(DocumentType.APP_METADATA)
Expand All @@ -445,7 +444,7 @@ export async function updateClient(ctx: BBContext) {
ctx.body = app
}

export async function revertClient(ctx: BBContext) {
export async function revertClient(ctx: UserCtx) {
// Check app can be reverted
const db = context.getAppDB()
const application = await db.get(DocumentType.APP_METADATA)
Expand All @@ -471,7 +470,7 @@ export async function revertClient(ctx: BBContext) {
ctx.body = app
}

const unpublishApp = async (ctx: any) => {
async function unpublishApp(ctx: UserCtx) {
let appId = ctx.params.appId
appId = dbCore.getProdAppID(appId)

Expand All @@ -487,7 +486,7 @@ const unpublishApp = async (ctx: any) => {
return result
}

async function destroyApp(ctx: BBContext) {
async function destroyApp(ctx: UserCtx) {
let appId = ctx.params.appId
appId = dbCore.getProdAppID(appId)
const devAppId = dbCore.getDevAppID(appId)
Expand Down Expand Up @@ -515,28 +514,28 @@ async function destroyApp(ctx: BBContext) {
return result
}

async function preDestroyApp(ctx: BBContext) {
async function preDestroyApp(ctx: UserCtx) {
const { rows } = await getUniqueRows([ctx.params.appId])
ctx.rowCount = rows.length
}

async function postDestroyApp(ctx: BBContext) {
async function postDestroyApp(ctx: UserCtx) {
const rowCount = ctx.rowCount
await groups.cleanupApp(ctx.params.appId)
if (rowCount) {
await quotas.removeRows(rowCount)
}
}

export async function destroy(ctx: BBContext) {
export async function destroy(ctx: UserCtx) {
await preDestroyApp(ctx)
const result = await destroyApp(ctx)
await postDestroyApp(ctx)
ctx.status = 200
ctx.body = result
}

export const unpublish = async (ctx: BBContext) => {
export async function unpublish(ctx: UserCtx) {
const prodAppId = dbCore.getProdAppID(ctx.params.appId)
const dbExists = await dbCore.dbExists(prodAppId)

Expand All @@ -551,7 +550,7 @@ export const unpublish = async (ctx: BBContext) => {
ctx.status = 204
}

export async function sync(ctx: BBContext) {
export async function sync(ctx: UserCtx) {
const appId = ctx.params.appId
try {
ctx.body = await sdk.applications.syncApp(appId)
Expand Down
7 changes: 4 additions & 3 deletions packages/server/src/api/controllers/row/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ export async function validate({
}
const errors: any = {}
for (let fieldName of Object.keys(fetchedTable.schema)) {
const constraints = cloneDeep(fetchedTable.schema[fieldName].constraints)
const type = fetchedTable.schema[fieldName].type
const column = fetchedTable.schema[fieldName]
const constraints = cloneDeep(column.constraints)
const type = column.type
// formulas shouldn't validated, data will be deleted anyway
if (type === FieldTypes.FORMULA) {
if (type === FieldTypes.FORMULA || column.autocolumn) {
continue
}
// special case for options, need to always allow unselected (null)
Expand Down