Merge branch 'develop' of github.com:Budibase/budibase into feature/environment-variables

This commit is contained in:
mike12345567 2023-01-09 12:46:13 +00:00
commit 150ce28141
36 changed files with 1203 additions and 948 deletions

View File

@ -67,16 +67,24 @@ jobs:
uses: azure/setup-helm@v1 uses: azure/setup-helm@v1
id: helm-install id: helm-install
# due to helm repo index issue: https://github.com/helm/helm/issues/7363
# we need to create new package in a different dir, merge the index and move the package back
- name: Build and release helm chart - name: Build and release helm chart
run: | run: |
git config user.name "Budibase Helm Bot" git config user.name "Budibase Helm Bot"
git config user.email "<>" git config user.email "<>"
git reset --hard git reset --hard
git pull git pull
helm package charts/budibase --version "$RELEASE_VERSION" --app-version "$RELEASE_VERSION" mkdir sync
echo "Packaging chart to sync dir"
helm package charts/budibase --version "$RELEASE_VERSION" --app-version "$RELEASE_VERSION" --destination sync
echo "Packaging successful"
git checkout gh-pages git checkout gh-pages
mv *.tgz docs echo "Indexing helm repo"
helm repo index docs helm repo index --merge docs/index.yaml sync
mv -f sync/* docs
rm -rf sync
echo "Pushing new helm release"
git add -A git add -A
git commit -m "Helm Release: ${{ env.RELEASE_VERSION }}" git commit -m "Helm Release: ${{ env.RELEASE_VERSION }}"
git push git push

View File

@ -4,9 +4,6 @@ metadata:
annotations: annotations:
kompose.cmd: kompose convert kompose.cmd: kompose convert
kompose.version: 1.21.0 (992df58d8) kompose.version: 1.21.0 (992df58d8)
{{ if .Values.globals.logAnnotations }}
{{ toYaml .Values.globals.logAnnotations | indent 4 }}
{{ end }}
creationTimestamp: null creationTimestamp: null
labels: labels:
io.kompose.service: app-service io.kompose.service: app-service
@ -23,6 +20,9 @@ spec:
annotations: annotations:
kompose.cmd: kompose convert kompose.cmd: kompose convert
kompose.version: 1.21.0 (992df58d8) kompose.version: 1.21.0 (992df58d8)
{{ if .Values.globals.appServiceAnnotations }}
{{ toYaml .Values.globals.appServiceAnnotations | indent 4 }}
{{ end }}
creationTimestamp: null creationTimestamp: null
labels: labels:
io.kompose.service: app-service io.kompose.service: app-service

View File

@ -4,9 +4,6 @@ metadata:
annotations: annotations:
kompose.cmd: kompose convert kompose.cmd: kompose convert
kompose.version: 1.21.0 (992df58d8) kompose.version: 1.21.0 (992df58d8)
{{ if .Values.globals.logAnnotations }}
{{ toYaml .Values.globals.logAnnotations | indent 4 }}
{{ end }}
creationTimestamp: null creationTimestamp: null
labels: labels:
app.kubernetes.io/name: budibase-proxy app.kubernetes.io/name: budibase-proxy
@ -23,6 +20,9 @@ spec:
annotations: annotations:
kompose.cmd: kompose convert kompose.cmd: kompose convert
kompose.version: 1.21.0 (992df58d8) kompose.version: 1.21.0 (992df58d8)
{{ if .Values.globals.proxyServiceAnnotations }}
{{ toYaml .Values.globals.proxyServiceAnnotations | indent 4 }}
{{ end }}
creationTimestamp: null creationTimestamp: null
labels: labels:
app.kubernetes.io/name: budibase-proxy app.kubernetes.io/name: budibase-proxy

View File

@ -4,9 +4,6 @@ metadata:
annotations: annotations:
kompose.cmd: kompose convert kompose.cmd: kompose convert
kompose.version: 1.21.0 (992df58d8) kompose.version: 1.21.0 (992df58d8)
{{ if .Values.globals.logAnnotations }}
{{ toYaml .Values.globals.logAnnotations | indent 4 }}
{{ end }}
creationTimestamp: null creationTimestamp: null
labels: labels:
io.kompose.service: worker-service io.kompose.service: worker-service
@ -24,6 +21,9 @@ spec:
annotations: annotations:
kompose.cmd: kompose convert kompose.cmd: kompose convert
kompose.version: 1.21.0 (992df58d8) kompose.version: 1.21.0 (992df58d8)
{{ if .Values.globals.workerServiceAnnotations }}
{{ toYaml .Values.globals.workerServiceAnnotations | indent 4 }}
{{ end }}
creationTimestamp: null creationTimestamp: null
labels: labels:
io.kompose.service: worker-service io.kompose.service: worker-service

View File

@ -22,12 +22,23 @@ serviceAccount:
podAnnotations: {} podAnnotations: {}
# logAnnotations: # appServiceAnnotations:
# co.elastic.logs/multiline.type: pattern # co.elastic.logs/multiline.type: pattern
# co.elastic.logs/multiline.pattern: '^[[:space:]]' # co.elastic.logs/multiline.pattern: '^[[:space:]]'
# co.elastic.logs/multiline.negate: false # co.elastic.logs/multiline.negate: false
# co.elastic.logs/multiline.match: after # co.elastic.logs/multiline.match: after
# workerServiceAnnotations:
# co.elastic.logs/multiline.type: pattern
# co.elastic.logs/multiline.pattern: '^[[:space:]]'
# co.elastic.logs/multiline.negate: false
# co.elastic.logs/multiline.match: after
# proxyServiceAnnotations:
# co.elastic.logs/module: nginx
# co.elastic.logs/fileset.stdout: access
# co.elastic.logs/fileset.stderr: error
podSecurityContext: podSecurityContext:
{} {}
# fsGroup: 2000 # fsGroup: 2000

View File

@ -1,5 +1,5 @@
{ {
"version": "2.2.11-alpha.1", "version": "2.2.12-alpha.2",
"npmClient": "yarn", "npmClient": "yarn",
"packages": [ "packages": [
"packages/*" "packages/*"

View File

@ -45,8 +45,8 @@
"dev:server": "yarn run kill-server && lerna run --parallel dev:builder --concurrency 1 --scope @budibase/backend-core --scope @budibase/worker --scope @budibase/server", "dev:server": "yarn run kill-server && lerna run --parallel dev:builder --concurrency 1 --scope @budibase/backend-core --scope @budibase/worker --scope @budibase/server",
"test": "lerna run test && yarn test:pro", "test": "lerna run test && yarn test:pro",
"test:pro": "bash scripts/pro/test.sh", "test:pro": "bash scripts/pro/test.sh",
"lint:eslint": "eslint packages", "lint:eslint": "eslint packages && eslint qa-core",
"lint:prettier": "prettier --check \"packages/**/*.{js,ts,svelte}\"", "lint:prettier": "prettier --check \"packages/**/*.{js,ts,svelte}\" && prettier --write \"examples/**/*.{js,ts,svelte}\" && prettier --check \"qa-core/**/*.{js,ts,svelte}\"",
"lint": "yarn run lint:eslint && yarn run lint:prettier", "lint": "yarn run lint:eslint && yarn run lint:prettier",
"lint:fix:eslint": "eslint --fix packages qa-core", "lint:fix:eslint": "eslint --fix packages qa-core",
"lint:fix:prettier": "prettier --write \"packages/**/*.{js,ts,svelte}\" && prettier --write \"examples/**/*.{js,ts,svelte}\" && prettier --write \"qa-core/**/*.{js,ts,svelte}\"", "lint:fix:prettier": "prettier --write \"packages/**/*.{js,ts,svelte}\" && prettier --write \"examples/**/*.{js,ts,svelte}\" && prettier --write \"qa-core/**/*.{js,ts,svelte}\"",
@ -84,4 +84,4 @@
"install:pro": "bash scripts/pro/install.sh", "install:pro": "bash scripts/pro/install.sh",
"dep:clean": "yarn clean && yarn bootstrap" "dep:clean": "yarn clean && yarn bootstrap"
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/backend-core", "name": "@budibase/backend-core",
"version": "2.2.11-alpha.1", "version": "2.2.12-alpha.2",
"description": "Budibase backend core libraries used in server and worker", "description": "Budibase backend core libraries used in server and worker",
"main": "dist/src/index.js", "main": "dist/src/index.js",
"types": "dist/src/index.d.ts", "types": "dist/src/index.d.ts",
@ -23,7 +23,7 @@
}, },
"dependencies": { "dependencies": {
"@budibase/nano": "10.1.1", "@budibase/nano": "10.1.1",
"@budibase/types": "2.2.11-alpha.1", "@budibase/types": "2.2.12-alpha.2",
"@shopify/jest-koa-mocks": "5.0.1", "@shopify/jest-koa-mocks": "5.0.1",
"@techpass/passport-openidconnect": "0.3.2", "@techpass/passport-openidconnect": "0.3.2",
"aws-cloudfront-sign": "2.2.0", "aws-cloudfront-sign": "2.2.0",

View File

@ -1,7 +1,7 @@
{ {
"name": "@budibase/bbui", "name": "@budibase/bbui",
"description": "A UI solution used in the different Budibase projects.", "description": "A UI solution used in the different Budibase projects.",
"version": "2.2.11-alpha.1", "version": "2.2.12-alpha.2",
"license": "MPL-2.0", "license": "MPL-2.0",
"svelte": "src/index.js", "svelte": "src/index.js",
"module": "dist/bbui.es.js", "module": "dist/bbui.es.js",
@ -38,7 +38,7 @@
], ],
"dependencies": { "dependencies": {
"@adobe/spectrum-css-workflow-icons": "1.2.1", "@adobe/spectrum-css-workflow-icons": "1.2.1",
"@budibase/string-templates": "2.2.11-alpha.1", "@budibase/string-templates": "2.2.12-alpha.2",
"@spectrum-css/actionbutton": "1.0.1", "@spectrum-css/actionbutton": "1.0.1",
"@spectrum-css/actiongroup": "1.0.1", "@spectrum-css/actiongroup": "1.0.1",
"@spectrum-css/avatar": "3.0.2", "@spectrum-css/avatar": "3.0.2",

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/builder", "name": "@budibase/builder",
"version": "2.2.11-alpha.1", "version": "2.2.12-alpha.2",
"license": "GPL-3.0", "license": "GPL-3.0",
"private": true, "private": true,
"scripts": { "scripts": {
@ -71,10 +71,10 @@
} }
}, },
"dependencies": { "dependencies": {
"@budibase/bbui": "2.2.11-alpha.1", "@budibase/bbui": "2.2.12-alpha.2",
"@budibase/client": "2.2.11-alpha.1", "@budibase/client": "2.2.12-alpha.2",
"@budibase/frontend-core": "2.2.11-alpha.1", "@budibase/frontend-core": "2.2.12-alpha.2",
"@budibase/string-templates": "2.2.11-alpha.1", "@budibase/string-templates": "2.2.12-alpha.2",
"@sentry/browser": "5.19.1", "@sentry/browser": "5.19.1",
"@spectrum-css/page": "^3.0.1", "@spectrum-css/page": "^3.0.1",
"@spectrum-css/vars": "^3.0.1", "@spectrum-css/vars": "^3.0.1",

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/cli", "name": "@budibase/cli",
"version": "2.2.11-alpha.1", "version": "2.2.12-alpha.2",
"description": "Budibase CLI, for developers, self hosting and migrations.", "description": "Budibase CLI, for developers, self hosting and migrations.",
"main": "src/index.js", "main": "src/index.js",
"bin": { "bin": {
@ -26,9 +26,9 @@
"outputPath": "build" "outputPath": "build"
}, },
"dependencies": { "dependencies": {
"@budibase/backend-core": "2.2.11-alpha.1", "@budibase/backend-core": "2.2.12-alpha.2",
"@budibase/string-templates": "2.2.11-alpha.1", "@budibase/string-templates": "2.2.12-alpha.2",
"@budibase/types": "2.2.11-alpha.1", "@budibase/types": "2.2.12-alpha.2",
"axios": "0.21.2", "axios": "0.21.2",
"chalk": "4.1.0", "chalk": "4.1.0",
"cli-progress": "3.11.2", "cli-progress": "3.11.2",

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/client", "name": "@budibase/client",
"version": "2.2.11-alpha.1", "version": "2.2.12-alpha.2",
"license": "MPL-2.0", "license": "MPL-2.0",
"module": "dist/budibase-client.js", "module": "dist/budibase-client.js",
"main": "dist/budibase-client.js", "main": "dist/budibase-client.js",
@ -19,9 +19,9 @@
"dev:builder": "rollup -cw" "dev:builder": "rollup -cw"
}, },
"dependencies": { "dependencies": {
"@budibase/bbui": "2.2.11-alpha.1", "@budibase/bbui": "2.2.12-alpha.2",
"@budibase/frontend-core": "2.2.11-alpha.1", "@budibase/frontend-core": "2.2.12-alpha.2",
"@budibase/string-templates": "2.2.11-alpha.1", "@budibase/string-templates": "2.2.12-alpha.2",
"@spectrum-css/button": "^3.0.3", "@spectrum-css/button": "^3.0.3",
"@spectrum-css/card": "^3.0.3", "@spectrum-css/card": "^3.0.3",
"@spectrum-css/divider": "^1.0.3", "@spectrum-css/divider": "^1.0.3",

View File

@ -1,12 +1,12 @@
{ {
"name": "@budibase/frontend-core", "name": "@budibase/frontend-core",
"version": "2.2.11-alpha.1", "version": "2.2.12-alpha.2",
"description": "Budibase frontend core libraries used in builder and client", "description": "Budibase frontend core libraries used in builder and client",
"author": "Budibase", "author": "Budibase",
"license": "MPL-2.0", "license": "MPL-2.0",
"svelte": "src/index.js", "svelte": "src/index.js",
"dependencies": { "dependencies": {
"@budibase/bbui": "2.2.11-alpha.1", "@budibase/bbui": "2.2.12-alpha.2",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"svelte": "^3.46.2" "svelte": "^3.46.2"
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/sdk", "name": "@budibase/sdk",
"version": "2.2.11-alpha.1", "version": "2.2.12-alpha.2",
"description": "Budibase Public API SDK", "description": "Budibase Public API SDK",
"author": "Budibase", "author": "Budibase",
"license": "MPL-2.0", "license": "MPL-2.0",

View File

@ -1,7 +1,7 @@
{ {
"name": "@budibase/server", "name": "@budibase/server",
"email": "hi@budibase.com", "email": "hi@budibase.com",
"version": "2.2.11-alpha.1", "version": "2.2.12-alpha.2",
"description": "Budibase Web Server", "description": "Budibase Web Server",
"main": "src/index.ts", "main": "src/index.ts",
"repository": { "repository": {
@ -43,11 +43,11 @@
"license": "GPL-3.0", "license": "GPL-3.0",
"dependencies": { "dependencies": {
"@apidevtools/swagger-parser": "10.0.3", "@apidevtools/swagger-parser": "10.0.3",
"@budibase/backend-core": "2.2.11-alpha.1", "@budibase/backend-core": "2.2.12-alpha.2",
"@budibase/client": "2.2.11-alpha.1", "@budibase/client": "2.2.12-alpha.2",
"@budibase/pro": "2.2.11-alpha.1", "@budibase/pro": "2.2.12-alpha.2",
"@budibase/string-templates": "2.2.11-alpha.1", "@budibase/string-templates": "2.2.12-alpha.2",
"@budibase/types": "2.2.11-alpha.1", "@budibase/types": "2.2.12-alpha.2",
"@bull-board/api": "3.7.0", "@bull-board/api": "3.7.0",
"@bull-board/koa": "3.9.4", "@bull-board/koa": "3.9.4",
"@elastic/elasticsearch": "7.10.0", "@elastic/elasticsearch": "7.10.0",

View File

@ -1,5 +1,5 @@
const setup = require("./utilities") const setup = require("./utilities")
const { events, constants, db } = require("@budibase/backend-core") const { events, constants } = require("@budibase/backend-core")
describe("/static", () => { describe("/static", () => {
let request = setup.getRequest() let request = setup.getRequest()

View File

@ -1,17 +1,16 @@
import { db as dbCore, objectStore } from "@budibase/backend-core" import { db as dbCore, objectStore } from "@budibase/backend-core"
import { Database } from "@budibase/types" import { Database, Row } from "@budibase/types"
import { getAutomationParams, TABLE_ROW_PREFIX } from "../../../db/utils" import { getAutomationParams, TABLE_ROW_PREFIX } from "../../../db/utils"
import { budibaseTempDir } from "../../../utilities/budibaseDir" import { budibaseTempDir } from "../../../utilities/budibaseDir"
import { DB_EXPORT_FILE, GLOBAL_DB_EXPORT_FILE } from "./constants" import { DB_EXPORT_FILE, GLOBAL_DB_EXPORT_FILE } from "./constants"
import { downloadTemplate } from "../../../utilities/fileSystem" import { downloadTemplate } from "../../../utilities/fileSystem"
import { FieldTypes, ObjectStoreBuckets } from "../../../constants" import { ObjectStoreBuckets } from "../../../constants"
import { join } from "path" import { join } from "path"
import fs from "fs" import fs from "fs"
import sdk from "../../" import sdk from "../../"
import { import {
Automation, Automation,
AutomationTriggerStepId, AutomationTriggerStepId,
CouchFindOptions,
RowAttachment, RowAttachment,
} from "@budibase/types" } from "@budibase/types"
const uuid = require("uuid/v4") const uuid = require("uuid/v4")
@ -25,54 +24,45 @@ type TemplateType = {
key?: string key?: string
} }
async function updateAttachmentColumns(prodAppId: string, db: Database) { function rewriteAttachmentUrl(appId: string, attachment: RowAttachment) {
// URL looks like: /prod-budi-app-assets/appId/attachments/file.csv
const urlParts = attachment.key.split("/")
// remove the app ID
urlParts.shift()
// add new app ID
urlParts.unshift(appId)
const key = urlParts.join("/")
return {
...attachment,
key,
url: "", // calculated on retrieval using key
}
}
export async function updateAttachmentColumns(prodAppId: string, db: Database) {
// iterate through attachment documents and update them // iterate through attachment documents and update them
const tables = await sdk.tables.getAllInternalTables(db) const tables = await sdk.tables.getAllInternalTables(db)
let updatedRows: Row[] = []
for (let table of tables) { for (let table of tables) {
const attachmentCols: string[] = [] const { rows, columns } = await sdk.rows.getRowsWithAttachments(
for (let [key, column] of Object.entries(table.schema)) { db.name,
if (column.type === FieldTypes.ATTACHMENT) { table
attachmentCols.push(key) )
} updatedRows = updatedRows.concat(
} rows.map(row => {
// no attachment columns, nothing to do for (let column of columns) {
if (attachmentCols.length === 0) { if (Array.isArray(row[column])) {
continue row[column] = row[column].map((attachment: RowAttachment) =>
} rewriteAttachmentUrl(prodAppId, attachment)
// use the CouchDB Mango query API to lookup rows that have attachments )
const params: CouchFindOptions = {
selector: {
_id: {
$regex: `^${TABLE_ROW_PREFIX}`,
},
},
}
attachmentCols.forEach(col => (params.selector[col] = { $exists: true }))
const { rows } = await dbCore.directCouchFind(db.name, params)
for (let row of rows) {
for (let column of attachmentCols) {
if (!Array.isArray(row[column])) {
continue
}
row[column] = row[column].map((attachment: RowAttachment) => {
// Key looks like: appId/attachments/file.csv
const urlParts = attachment.key.split("/")
// remove the app ID
urlParts.shift()
// add new app ID
urlParts.unshift(prodAppId)
const key = urlParts.join("/")
return {
...attachment,
key,
url: "", // calculated on retrieval using key
} }
}) }
} return row
} })
// write back the updated attachments )
await db.bulkDocs(rows)
} }
// write back the updated attachments
await db.bulkDocs(updatedRows)
} }
async function updateAutomations(prodAppId: string, db: Database) { async function updateAutomations(prodAppId: string, db: Database) {

View File

@ -0,0 +1,60 @@
import { CouchFindOptions, Table, Row } from "@budibase/types"
import { db as dbCore } from "@budibase/backend-core"
import { DocumentType, SEPARATOR } from "../../../db/utils"
import { FieldTypes } from "../../../constants"
// default limit - seems to work well for performance
export const FIND_LIMIT = 25
function generateAttachmentFindParams(
tableId: string,
attachmentCols: string[],
bookmark: null | string
) {
const params: CouchFindOptions = {
selector: {
_id: {
$regex: `^${DocumentType.ROW}${SEPARATOR}${tableId}`,
},
},
limit: FIND_LIMIT,
}
attachmentCols.forEach(col => (params.selector[col] = { $exists: true }))
if (bookmark) {
params.bookmark = bookmark
}
return params
}
export async function getRowsWithAttachments(appId: string, table: Table) {
// iterate through attachment documents and update them
const db = dbCore.getDB(appId)
const attachmentCols: string[] = []
for (let [key, column] of Object.entries(table.schema)) {
if (column.type === FieldTypes.ATTACHMENT) {
attachmentCols.push(key)
}
}
// no attachment columns, nothing to do
if (attachmentCols.length === 0) {
return { rows: [], columns: [] }
}
let bookmark: null | string = null,
rowsLength = 0,
rowList: Row[] = []
do {
const params = generateAttachmentFindParams(
table._id!,
attachmentCols,
bookmark
)
// use the CouchDB Mango query API to lookup rows that have attachments
const resp = await dbCore.directCouchFind(db.name, params)
bookmark = resp.bookmark
rowsLength = resp.rows.length
const rows = resp.rows
rowList = rowList.concat(rows)
} while (rowsLength === FIND_LIMIT)
// write back the updated attachments
return { rows: rowList, columns: attachmentCols }
}

View File

@ -0,0 +1,7 @@
import * as attachments from "./attachments"
import * as rows from "./rows"
export default {
...attachments,
...rows,
}

View File

@ -0,0 +1,18 @@
import { db as dbCore, context } from "@budibase/backend-core"
import { Database, Row } from "@budibase/types"
import { getRowParams } from "../../../db/utils"
export async function getAllInternalRows(appId?: string) {
let db: Database
if (appId) {
db = dbCore.getDB(appId)
} else {
db = context.getAppDB()
}
const response = await db.allDocs(
getRowParams(null, null, {
include_docs: true,
})
)
return response.rows.map(row => row.doc) as Row[]
}

View File

@ -2,6 +2,7 @@ import { default as backups } from "./app/backups"
import { default as tables } from "./app/tables" import { default as tables } from "./app/tables"
import { default as automations } from "./app/automations" import { default as automations } from "./app/automations"
import { default as applications } from "./app/applications" import { default as applications } from "./app/applications"
import { default as rows } from "./app/rows"
import { default as users } from "./users" import { default as users } from "./users"
const sdk = { const sdk = {
@ -9,6 +10,7 @@ const sdk = {
tables, tables,
automations, automations,
applications, applications,
rows,
users, users,
} }

View File

@ -0,0 +1,76 @@
import newid from "../../db/newid"
const attachment = {
size: 73479,
name: "2022-12-14 11_11_44-.png",
url: "/prod-budi-app-assets/app_bbb/attachments/a.png",
extension: "png",
key: "app_bbb/attachments/a.png",
}
const row = {
_id: "ro_ta_aaa",
photo: [attachment],
otherCol: "string",
}
const table = {
_id: "ta_aaa",
name: "photos",
schema: {
photo: {
type: "attachment",
name: "photo",
},
otherCol: {
type: "string",
name: "otherCol",
},
},
}
jest.mock("@budibase/backend-core", () => {
const core = jest.requireActual("@budibase/backend-core")
return {
...core,
db: {
...core.db,
directCouchFind: jest.fn(),
},
}
})
import { db as dbCore } from "@budibase/backend-core"
import sdk from "../index"
describe("should be able to re-write attachment URLs", () => {
it("it should update URLs on a number of rows over the limit", async () => {
const db = dbCore.getDB("app_aaa")
await db.put(table)
const limit = 30
let rows = []
for (let i = 0; i < limit; i++) {
const rowToWrite = {
...row,
_id: `${row._id}_${newid()}`,
}
const { rev } = await db.put(rowToWrite)
rows.push({
...rowToWrite,
_rev: rev,
})
}
dbCore.directCouchFind
// @ts-ignore
.mockReturnValueOnce({ rows: rows.slice(0, 25), bookmark: "aaa" })
.mockReturnValueOnce({ rows: rows.slice(25, limit), bookmark: "bbb" })
await sdk.backups.updateAttachmentColumns(db.name, db)
const finalRows = await sdk.rows.getAllInternalRows(db.name)
for (let rowToCheck of finalRows) {
expect(rowToCheck.otherCol).toBe(row.otherCol)
expect(rowToCheck.photo[0].url).toBe("")
expect(rowToCheck.photo[0].key).toBe(`${db.name}/attachments/a.png`)
}
})
})

View File

@ -1273,13 +1273,13 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
"@budibase/backend-core@2.2.11-alpha.1": "@budibase/backend-core@2.2.12-alpha.2":
version "2.2.11-alpha.1" version "2.2.12-alpha.2"
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.2.11-alpha.1.tgz#adb8835b0db1f671eacc226f39788d6b696353ee" resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.2.12-alpha.2.tgz#5fd62c585e950f5a5c29f301e3acc4b3757908b8"
integrity sha512-8VWYTRbEuhXUWfb/ic9PblWdu6nRidM5Sqo0UK6WXCl9RN0V41UancnyhcWbUf0k9sdm52Y0ESYRr4nzhqU0Fw== integrity sha512-AiZzLWHgGA5hazbtBDAE2dRjxEPMXn437rSWKN4Vx77VplhHTvV4XPmdr4wiRpBmr4C8NGyQJMRW1CddB1qIJw==
dependencies: dependencies:
"@budibase/nano" "10.1.1" "@budibase/nano" "10.1.1"
"@budibase/types" "2.2.11-alpha.1" "@budibase/types" "2.2.12-alpha.2"
"@shopify/jest-koa-mocks" "5.0.1" "@shopify/jest-koa-mocks" "5.0.1"
"@techpass/passport-openidconnect" "0.3.2" "@techpass/passport-openidconnect" "0.3.2"
aws-cloudfront-sign "2.2.0" aws-cloudfront-sign "2.2.0"
@ -1373,13 +1373,13 @@
qs "^6.11.0" qs "^6.11.0"
tough-cookie "^4.1.2" tough-cookie "^4.1.2"
"@budibase/pro@2.2.11-alpha.1": "@budibase/pro@2.2.12-alpha.2":
version "2.2.11-alpha.1" version "2.2.12-alpha.2"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.2.11-alpha.1.tgz#ed435fa569d090330cacb782129d4af796601f3d" resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.2.12-alpha.2.tgz#dbcb12ea725d2b2a81e62bd3068801f2b289fe1d"
integrity sha512-bOMR4nJo/8BAKTiluIH81sf/boB4Iq2dDSvvCl5b3VR4evPRnGQwzFeOPFfi9jKkYJy7F74b/RWjl38VQe3atQ== integrity sha512-9D0+5L6ElSKT1DEV5W7AE1q9UdtoYStjEBF1ePS2aUXRzqmVTEJSqNLs3WjWE5DcN16Ui3VodjJPftsBzwR6HQ==
dependencies: dependencies:
"@budibase/backend-core" "2.2.11-alpha.1" "@budibase/backend-core" "2.2.12-alpha.2"
"@budibase/types" "2.2.11-alpha.1" "@budibase/types" "2.2.12-alpha.2"
"@koa/router" "8.0.8" "@koa/router" "8.0.8"
bull "4.10.1" bull "4.10.1"
joi "17.6.0" joi "17.6.0"
@ -1404,10 +1404,10 @@
svelte-apexcharts "^1.0.2" svelte-apexcharts "^1.0.2"
svelte-flatpickr "^3.1.0" svelte-flatpickr "^3.1.0"
"@budibase/types@2.2.11-alpha.1": "@budibase/types@2.2.12-alpha.2":
version "2.2.11-alpha.1" version "2.2.12-alpha.2"
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.2.11-alpha.1.tgz#a879f21608389763e20cdcd4ddc60146b0666260" resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.2.12-alpha.2.tgz#390959555517f11dc95147518e89f400c59dd520"
integrity sha512-KKld6dGyEqJzU62/gb1+S58O+3LW3BIdvtaV7oNxGE32snNh3iNSTBjFkVJU1gNlk+iAMvLCvkFNqDd3Kca+5Q== integrity sha512-Dz/3kdSkBRyf+AQyaPbAwq6hxD1kQuHht+4C3pyebbHUL440ZhZhJ1o2AAFc8SF1/9SqAk/NFaktAY2vCyRlOQ==
"@bull-board/api@3.7.0": "@bull-board/api@3.7.0":
version "3.7.0" version "3.7.0"

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/string-templates", "name": "@budibase/string-templates",
"version": "2.2.11-alpha.1", "version": "2.2.12-alpha.2",
"description": "Handlebars wrapper for Budibase templating.", "description": "Handlebars wrapper for Budibase templating.",
"main": "src/index.cjs", "main": "src/index.cjs",
"module": "dist/bundle.mjs", "module": "dist/bundle.mjs",

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/types", "name": "@budibase/types",
"version": "2.2.11-alpha.1", "version": "2.2.12-alpha.2",
"description": "Budibase types", "description": "Budibase types",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",

View File

@ -1,7 +1,7 @@
{ {
"name": "@budibase/worker", "name": "@budibase/worker",
"email": "hi@budibase.com", "email": "hi@budibase.com",
"version": "2.2.11-alpha.1", "version": "2.2.12-alpha.2",
"description": "Budibase background service", "description": "Budibase background service",
"main": "src/index.ts", "main": "src/index.ts",
"repository": { "repository": {
@ -36,10 +36,10 @@
"author": "Budibase", "author": "Budibase",
"license": "GPL-3.0", "license": "GPL-3.0",
"dependencies": { "dependencies": {
"@budibase/backend-core": "2.2.11-alpha.1", "@budibase/backend-core": "2.2.12-alpha.2",
"@budibase/pro": "2.2.11-alpha.1", "@budibase/pro": "2.2.12-alpha.2",
"@budibase/string-templates": "2.2.11-alpha.1", "@budibase/string-templates": "2.2.12-alpha.2",
"@budibase/types": "2.2.11-alpha.1", "@budibase/types": "2.2.12-alpha.2",
"@koa/router": "8.0.8", "@koa/router": "8.0.8",
"@sentry/node": "6.17.7", "@sentry/node": "6.17.7",
"@techpass/passport-openidconnect": "0.3.2", "@techpass/passport-openidconnect": "0.3.2",

View File

@ -470,13 +470,13 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
"@budibase/backend-core@2.2.11-alpha.1": "@budibase/backend-core@2.2.12-alpha.2":
version "2.2.11-alpha.1" version "2.2.12-alpha.2"
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.2.11-alpha.1.tgz#adb8835b0db1f671eacc226f39788d6b696353ee" resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.2.12-alpha.2.tgz#5fd62c585e950f5a5c29f301e3acc4b3757908b8"
integrity sha512-8VWYTRbEuhXUWfb/ic9PblWdu6nRidM5Sqo0UK6WXCl9RN0V41UancnyhcWbUf0k9sdm52Y0ESYRr4nzhqU0Fw== integrity sha512-AiZzLWHgGA5hazbtBDAE2dRjxEPMXn437rSWKN4Vx77VplhHTvV4XPmdr4wiRpBmr4C8NGyQJMRW1CddB1qIJw==
dependencies: dependencies:
"@budibase/nano" "10.1.1" "@budibase/nano" "10.1.1"
"@budibase/types" "2.2.11-alpha.1" "@budibase/types" "2.2.12-alpha.2"
"@shopify/jest-koa-mocks" "5.0.1" "@shopify/jest-koa-mocks" "5.0.1"
"@techpass/passport-openidconnect" "0.3.2" "@techpass/passport-openidconnect" "0.3.2"
aws-cloudfront-sign "2.2.0" aws-cloudfront-sign "2.2.0"
@ -520,23 +520,23 @@
qs "^6.11.0" qs "^6.11.0"
tough-cookie "^4.1.2" tough-cookie "^4.1.2"
"@budibase/pro@2.2.11-alpha.1": "@budibase/pro@2.2.12-alpha.2":
version "2.2.11-alpha.1" version "2.2.12-alpha.2"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.2.11-alpha.1.tgz#ed435fa569d090330cacb782129d4af796601f3d" resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.2.12-alpha.2.tgz#dbcb12ea725d2b2a81e62bd3068801f2b289fe1d"
integrity sha512-bOMR4nJo/8BAKTiluIH81sf/boB4Iq2dDSvvCl5b3VR4evPRnGQwzFeOPFfi9jKkYJy7F74b/RWjl38VQe3atQ== integrity sha512-9D0+5L6ElSKT1DEV5W7AE1q9UdtoYStjEBF1ePS2aUXRzqmVTEJSqNLs3WjWE5DcN16Ui3VodjJPftsBzwR6HQ==
dependencies: dependencies:
"@budibase/backend-core" "2.2.11-alpha.1" "@budibase/backend-core" "2.2.12-alpha.2"
"@budibase/types" "2.2.11-alpha.1" "@budibase/types" "2.2.12-alpha.2"
"@koa/router" "8.0.8" "@koa/router" "8.0.8"
bull "4.10.1" bull "4.10.1"
joi "17.6.0" joi "17.6.0"
jsonwebtoken "8.5.1" jsonwebtoken "8.5.1"
node-fetch "^2.6.1" node-fetch "^2.6.1"
"@budibase/types@2.2.11-alpha.1": "@budibase/types@2.2.12-alpha.2":
version "2.2.11-alpha.1" version "2.2.12-alpha.2"
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.2.11-alpha.1.tgz#a879f21608389763e20cdcd4ddc60146b0666260" resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.2.12-alpha.2.tgz#390959555517f11dc95147518e89f400c59dd520"
integrity sha512-KKld6dGyEqJzU62/gb1+S58O+3LW3BIdvtaV7oNxGE32snNh3iNSTBjFkVJU1gNlk+iAMvLCvkFNqDd3Kca+5Q== integrity sha512-Dz/3kdSkBRyf+AQyaPbAwq6hxD1kQuHht+4C3pyebbHUL440ZhZhJ1o2AAFc8SF1/9SqAk/NFaktAY2vCyRlOQ==
"@cspotcode/source-map-support@^0.8.0": "@cspotcode/source-map-support@^0.8.0":
version "0.8.1" version "0.8.1"

View File

@ -26,7 +26,10 @@ export default class TestConfiguration<T> {
} }
async loginAsAdmin() { async loginAsAdmin() {
await this.auth.login(<string>process.env.BB_ADMIN_USER_EMAIL, <string>process.env.BB_ADMIN_USER_PASSWORD) await this.auth.login(
<string>process.env.BB_ADMIN_USER_EMAIL,
<string>process.env.BB_ADMIN_USER_PASSWORD
)
} }
async login(email: string, password: string) { async login(email: string, password: string) {

View File

@ -4,130 +4,128 @@ import InternalAPIClient from "./InternalAPIClient"
import { responseMessage } from "../fixtures/types/responseMessage" import { responseMessage } from "../fixtures/types/responseMessage"
export default class UserManagementApi { export default class UserManagementApi {
api: InternalAPIClient api: InternalAPIClient
constructor(apiClient: InternalAPIClient) { constructor(apiClient: InternalAPIClient) {
this.api = apiClient this.api = apiClient
} }
async search(): Promise<[Response, Partial<User>[]]> { async search(): Promise<[Response, Partial<User>[]]> {
const response = await this.api.post(`/global/users/search`, {}) const response = await this.api.post(`/global/users/search`, {})
const json = await response.json() const json = await response.json()
expect(response).toHaveStatusCode(200) expect(response).toHaveStatusCode(200)
expect(json.data.length).toBeGreaterThan(0) expect(json.data.length).toBeGreaterThan(0)
return [response, json] return [response, json]
} }
async getSelf(): Promise<[Response, Partial<User>]> { async getSelf(): Promise<[Response, Partial<User>]> {
const response = await this.api.get(`/global/self`) const response = await this.api.get(`/global/self`)
const json = await response.json() const json = await response.json()
expect(response).toHaveStatusCode(200) expect(response).toHaveStatusCode(200)
return [response, json] return [response, json]
} }
async getAll(): Promise<[Response, Partial<User>[]]> { async getAll(): Promise<[Response, Partial<User>[]]> {
const response = await this.api.get(`/global/users`) const response = await this.api.get(`/global/users`)
const json = await response.json() const json = await response.json()
expect(response).toHaveStatusCode(200) expect(response).toHaveStatusCode(200)
expect(json.length).toBeGreaterThan(0) expect(json.length).toBeGreaterThan(0)
return [response, json] return [response, json]
} }
// This endpoint is used for one or more users when we want add users with passwords set. // This endpoint is used for one or more users when we want add users with passwords set.
async addMultiple(userList: Partial<User>[]): Promise<[Response, any]> { async addMultiple(userList: Partial<User>[]): Promise<[Response, any]> {
const body = { const body = {
create: { create: {
users: userList, users: userList,
groups: [] groups: [],
} },
}
const response = await this.api.post(`/global/users/bulk`, { body })
const json = await response.json()
expect(response).toHaveStatusCode(200)
expect(json.created.unsuccessful.length).toEqual(0)
expect(json.created.successful.length).toEqual(body.create.users.length)
return [response, json]
} }
const response = await this.api.post(`/global/users/bulk`, { body })
const json = await response.json()
expect(response).toHaveStatusCode(200)
expect(json.created.unsuccessful.length).toEqual(0)
expect(json.created.successful.length).toEqual(body.create.users.length)
return [response, json]
}
async deleteMultiple(userId: string[]): Promise<[Response, responseMessage]> { async deleteMultiple(userId: string[]): Promise<[Response, responseMessage]> {
const body = { const body = {
delete: { delete: {
userIds: [ userIds: [userId],
userId },
]
}
}
const response = await this.api.post(`/global/users/bulk`, { body })
const json = await response.json()
expect(response).toHaveStatusCode(200)
expect(json.deleted.successful.length).toEqual(1)
expect(json.deleted.unsuccessful.length).toEqual(0)
expect(json.deleted.successful[0].userId).toEqual(userId)
return [response, json]
}
async delete(userId: string): Promise<[Response, UserDeletedEvent]> {
const response = await this.api.del(`/global/users/${userId}`)
const json = await response.json()
expect(response).toHaveStatusCode(200)
expect(json.message).toEqual(`User ${userId} deleted.`)
return [response, json]
} }
const response = await this.api.post(`/global/users/bulk`, { body })
const json = await response.json()
expect(response).toHaveStatusCode(200)
expect(json.deleted.successful.length).toEqual(1)
expect(json.deleted.unsuccessful.length).toEqual(0)
expect(json.deleted.successful[0].userId).toEqual(userId)
return [response, json]
}
async delete(userId: string): Promise<[Response, UserDeletedEvent]> {
const response = await this.api.del(`/global/users/${userId}`)
const json = await response.json()
expect(response).toHaveStatusCode(200)
expect(json.message).toEqual(`User ${userId} deleted.`)
return [response, json]
}
async invite(body: any): Promise<[Response, responseMessage]> { async invite(body: any): Promise<[Response, responseMessage]> {
const response = await this.api.post(`/global/users/multi/invite`, { body }) const response = await this.api.post(`/global/users/multi/invite`, { body })
const json = await response.json() const json = await response.json()
expect(response).toHaveStatusCode(200) expect(response).toHaveStatusCode(200)
expect(json.unsuccessful.length).toEqual(0) expect(json.unsuccessful.length).toEqual(0)
expect(json.successful.length).toEqual(body.length) expect(json.successful.length).toEqual(body.length)
return [response, json] return [response, json]
} }
async getRoles(): Promise<[Response, Role[]]> { async getRoles(): Promise<[Response, Role[]]> {
const response = await this.api.get(`/roles`) const response = await this.api.get(`/roles`)
const json = await response.json() const json = await response.json()
expect(response).toHaveStatusCode(200) expect(response).toHaveStatusCode(200)
return [response, json] return [response, json]
} }
async updateInfo(body: any): Promise<[Response, User]> { async updateInfo(body: any): Promise<[Response, User]> {
const response = await this.api.post(`/global/users/`, { body }) const response = await this.api.post(`/global/users/`, { body })
const json = await response.json() const json = await response.json()
expect(response).toHaveStatusCode(200) expect(response).toHaveStatusCode(200)
expect(json._id).toEqual(body._id) expect(json._id).toEqual(body._id)
expect(json._rev).not.toEqual(body._rev) expect(json._rev).not.toEqual(body._rev)
return [response, json] return [response, json]
} }
async forcePasswordReset(body: any): Promise<[Response, User]> { async forcePasswordReset(body: any): Promise<[Response, User]> {
const response = await this.api.post(`/global/users/`, { body }) const response = await this.api.post(`/global/users/`, { body })
const json = await response.json() const json = await response.json()
expect(response).toHaveStatusCode(200) expect(response).toHaveStatusCode(200)
expect(json._id).toEqual(body._id) expect(json._id).toEqual(body._id)
expect(json._rev).not.toEqual(body._rev) expect(json._rev).not.toEqual(body._rev)
return [response, json] return [response, json]
} }
async getInfo(userId: string): Promise<[Response, User]> { async getInfo(userId: string): Promise<[Response, User]> {
const response = await this.api.get(`/global/users/${userId}`) const response = await this.api.get(`/global/users/${userId}`)
const json = await response.json() const json = await response.json()
expect(response).toHaveStatusCode(200) expect(response).toHaveStatusCode(200)
return [response, json] return [response, json]
} }
async changeSelfPassword(body: Partial<User>): Promise<[Response, User]> { async changeSelfPassword(body: Partial<User>): Promise<[Response, User]> {
const response = await this.api.post(`/global/self`, { body }) const response = await this.api.post(`/global/self`, { body })
const json = await response.json() const json = await response.json()
expect(response).toHaveStatusCode(200) expect(response).toHaveStatusCode(200)
expect(json._id).toEqual(body._id) expect(json._id).toEqual(body._id)
expect(json._rev).not.toEqual(body._rev) expect(json._rev).not.toEqual(body._rev)
return [response, json] return [response, json]
} }
async createRole(body: Partial<UserRoles>): Promise<[Response, UserRoles]> { async createRole(body: Partial<UserRoles>): Promise<[Response, UserRoles]> {
const response = await this.api.post(`/roles`, { body }) const response = await this.api.post(`/roles`, { body })
const json = await response.json() const json = await response.json()
expect(response).toHaveStatusCode(200) expect(response).toHaveStatusCode(200)
return [response, json] return [response, json]
} }
} }

View File

@ -13,13 +13,12 @@ export const generateApp = (
// Applications type doesn't work here, save to add useTemplate parameter? // Applications type doesn't work here, save to add useTemplate parameter?
export const appFromTemplate = (): any => { export const appFromTemplate = (): any => {
return ({ return {
name: generator.word(), name: generator.word(),
url: `/${generator.word()}`, url: `/${generator.word()}`,
useTemplate: "true", useTemplate: "true",
templateName: "Near Miss Register", templateName: "Near Miss Register",
templateKey: "app/near-miss-register", templateKey: "app/near-miss-register",
templateFile: undefined, templateFile: undefined,
}) }
} }

View File

@ -1,80 +1,82 @@
import generator from "../../generator"; import generator from "../../generator"
import { User } from "@budibase/types"; import { User } from "@budibase/types"
const generateDeveloper = (): Partial<User> => { const generateDeveloper = (): Partial<User> => {
const randomId = generator.guid(); const randomId = generator.guid()
return ({ return {
email: `pedro+${randomId}@budibase.com`, email: `pedro+${randomId}@budibase.com`,
password: randomId, password: randomId,
roles: {}, roles: {},
forceResetPassword: true, forceResetPassword: true,
builder: { builder: {
global: true global: true,
} },
}) }
} }
const generateAdmin = (): Partial<User> => { const generateAdmin = (): Partial<User> => {
const randomId = generator.guid(); const randomId = generator.guid()
return ({ return {
email: `pedro+${randomId}@budibase.com`, email: `pedro+${randomId}@budibase.com`,
password: randomId, password: randomId,
roles: {}, roles: {},
forceResetPassword: true, forceResetPassword: true,
admin: { admin: {
global: true global: true,
}, },
builder: { builder: {
global: true global: true,
} },
}) }
} }
const generateAppUser = (): Partial<User> => { const generateAppUser = (): Partial<User> => {
const randomId = generator.guid(); const randomId = generator.guid()
return ({ return {
email: `pedro+${randomId}@budibase.com`, email: `pedro+${randomId}@budibase.com`,
password: randomId, password: randomId,
roles: {}, roles: {},
forceResetPassword: true, forceResetPassword: true,
admin: { admin: {
global: false global: false,
}, },
builder: { builder: {
global: false global: false,
} },
}) }
} }
export const generateInviteUser = (): Object[] => { export const generateInviteUser = (): Object[] => {
const randomId = generator.guid(); const randomId = generator.guid()
return [{ return [
email: `pedro+${randomId}@budibase.com`, {
userInfo: { email: `pedro+${randomId}@budibase.com`,
userGroups: [] userInfo: {
} userGroups: [],
}] },
},
]
} }
export const generateUser = (amount: number = 1, role?: string): Partial<User>[] => { export const generateUser = (
const userList: Partial<User>[] = []; amount: number = 1,
for (let i = 0; i < amount; i++) { role?: string
switch (role) { ): Partial<User>[] => {
case "admin": const userList: Partial<User>[] = []
userList.push(generateAdmin()); for (let i = 0; i < amount; i++) {
break; switch (role) {
case "developer": case "admin":
userList.push(generateDeveloper()); userList.push(generateAdmin())
break; break
case "appUser": case "developer":
userList.push(generateAppUser()); userList.push(generateDeveloper())
break; break
default: case "appUser":
userList.push(generateAppUser()); userList.push(generateAppUser())
break; break
} default:
userList.push(generateAppUser())
break
} }
return userList }
} return userList
}

View File

@ -2,7 +2,10 @@ import TestConfiguration from "../../../config/internal-api/TestConfiguration"
import { Application } from "@budibase/server/api/controllers/public/mapping/types" import { Application } from "@budibase/server/api/controllers/public/mapping/types"
import { db } from "@budibase/backend-core" import { db } from "@budibase/backend-core"
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
import { generateApp, appFromTemplate } from "../../../config/internal-api/fixtures/applications" import {
generateApp,
appFromTemplate,
} from "../../../config/internal-api/fixtures/applications"
import generator from "../../../config/generator" import generator from "../../../config/generator"
import generateScreen from "../../../config/internal-api/fixtures/screens" import generateScreen from "../../../config/internal-api/fixtures/screens"
@ -18,7 +21,6 @@ describe("Internal API - Application creation, update, publish and delete", () =
await config.afterAll() await config.afterAll()
}) })
it("Get applications without applications", async () => { it("Get applications without applications", async () => {
await config.applications.fetchEmptyAppList() await config.applications.fetchEmptyAppList()
}) })

View File

@ -1,7 +1,10 @@
import TestConfiguration from "../../../config/internal-api/TestConfiguration" import TestConfiguration from "../../../config/internal-api/TestConfiguration"
import { App } from "@budibase/types" import { App } from "@budibase/types"
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
import { generateApp, appFromTemplate } from "../../../config/internal-api/fixtures/applications" import {
generateApp,
appFromTemplate,
} from "../../../config/internal-api/fixtures/applications"
import { Screen } from "@budibase/types" import { Screen } from "@budibase/types"
import generateScreen from "../../../config/internal-api/fixtures/screens" import generateScreen from "../../../config/internal-api/fixtures/screens"

View File

@ -5,86 +5,84 @@ import { generateUser } from "../../../config/internal-api/fixtures/userManageme
import { User } from "@budibase/types" import { User } from "@budibase/types"
describe("Internal API - User Management & Permissions", () => { describe("Internal API - User Management & Permissions", () => {
const api = new InternalAPIClient() const api = new InternalAPIClient()
const config = new TestConfiguration<Application>(api) const config = new TestConfiguration<Application>(api)
// Before each test, login as admin. Some tests will require login as a different user // Before each test, login as admin. Some tests will require login as a different user
beforeEach(async () => { beforeEach(async () => {
await config.loginAsAdmin() await config.loginAsAdmin()
}) })
afterAll(async () => { afterAll(async () => {
await config.afterAll() await config.afterAll()
}) })
it("Add Users with different roles", async () => { it("Add Users with different roles", async () => {
await config.users.search() await config.users.search()
await config.users.getRoles() await config.users.getRoles()
const admin = generateUser(1, "admin") const admin = generateUser(1, "admin")
expect(admin[0].builder?.global).toEqual(true) expect(admin[0].builder?.global).toEqual(true)
expect(admin[0].admin?.global).toEqual(true) expect(admin[0].admin?.global).toEqual(true)
const developer = generateUser(1, "developer") const developer = generateUser(1, "developer")
expect(developer[0].builder?.global).toEqual(true) expect(developer[0].builder?.global).toEqual(true)
const appUser = generateUser(1, "appUser") const appUser = generateUser(1, "appUser")
expect(appUser[0].builder?.global).toEqual(false) expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false) expect(appUser[0].admin?.global).toEqual(false)
const userList = [...admin, ...developer, ...appUser] const userList = [...admin, ...developer, ...appUser]
await config.users.addMultiple(userList) await config.users.addMultiple(userList)
const [allUsersResponse, allUsersJson] = await config.users.getAll() const [allUsersResponse, allUsersJson] = await config.users.getAll()
expect(allUsersJson.length).toBeGreaterThan(0) expect(allUsersJson.length).toBeGreaterThan(0)
})
it("Delete User", async () => {
const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [userResponse, userJson] = await config.users.addMultiple(appUser)
const userId = userJson.created.successful[0]._id
await config.users.delete(<string>userId)
})
it("Reset Password", async () => {
const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [userResponse, userJson] = await config.users.addMultiple(appUser)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
userJson.created.successful[0]._id
)
const body: User = {
...userInfoJson,
password: "newPassword",
}
await config.users.forcePasswordReset(body)
})
}) it("Change User information", async () => {
const appUser = generateUser()
it("Delete User", async () => { expect(appUser[0].builder?.global).toEqual(false)
const appUser = generateUser() expect(appUser[0].admin?.global).toEqual(false)
expect(appUser[0].builder?.global).toEqual(false) const [userResponse, userJson] = await config.users.addMultiple(appUser)
expect(appUser[0].admin?.global).toEqual(false) const [userInfoResponse, userInfoJson] = await config.users.getInfo(
const [userResponse, userJson] = await config.users.addMultiple(appUser) userJson.created.successful[0]._id
const userId = userJson.created.successful[0]._id )
await config.users.delete(<string>userId) const body: User = {
}) ...userInfoJson,
firstName: "newFirstName",
it("Reset Password", async () => { lastName: "newLastName",
const appUser = generateUser() builder: {
expect(appUser[0].builder?.global).toEqual(false) global: true,
expect(appUser[0].admin?.global).toEqual(false) },
const [userResponse, userJson] = await config.users.addMultiple(appUser) }
const [userInfoResponse, userInfoJson] = await config.users.getInfo(userJson.created.successful[0]._id) await config.users.updateInfo(body)
const body: User = {
...userInfoJson,
password: "newPassword"
}
await config.users.forcePasswordReset(body)
})
it("Change User information", async () => {
const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [userResponse, userJson] = await config.users.addMultiple(appUser)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(userJson.created.successful[0]._id)
const body: User = {
...userInfoJson,
firstName: "newFirstName",
lastName: "newLastName",
builder: {
global: true
}
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(userJson.created.successful[0]._id)
expect(changedUserInfoJson.builder?.global).toBeDefined()
expect(changedUserInfoJson.builder?.global).toEqual(true)
})
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(userJson.created.successful[0]._id)
expect(changedUserInfoJson.builder?.global).toBeDefined()
expect(changedUserInfoJson.builder?.global).toEqual(true)
})
}) })

View File

@ -73,15 +73,15 @@ describe("Public API - /applications endpoints", () => {
}) })
it("POST - unpublish an unpublished application", async () => { it("POST - unpublish an unpublished application", async () => {
const [response] = await config.applications.unpublish( const [response] = await config.applications.unpublish(config.context._id)
config.context._id
)
expect(response).toHaveStatusCode(400) expect(response).toHaveStatusCode(400)
}) })
it("DELETE - delete a published application and the dev application", async () => { it("DELETE - delete a published application and the dev application", async () => {
await config.applications.publish(config.context._id) await config.applications.publish(config.context._id)
const [response, deletion] = await config.applications.delete(config.context._id) const [response, deletion] = await config.applications.delete(
config.context._id
)
expect(response).toHaveStatusCode(200) expect(response).toHaveStatusCode(200)
expect(deletion._id).toEqual(config.context._id) expect(deletion._id).toEqual(config.context._id)