Merge branch 'feature/environment-variables' of github.com:Budibase/budibase into feature/environment-variables
This commit is contained in:
commit
30e90b2d5d
39 changed files with 1207 additions and 948 deletions
14
.github/workflows/release-selfhost.yml
vendored
14
.github/workflows/release-selfhost.yml
vendored
|
@ -67,16 +67,24 @@ jobs:
|
|||
uses: azure/setup-helm@v1
|
||||
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
|
||||
run: |
|
||||
git config user.name "Budibase Helm Bot"
|
||||
git config user.email "<>"
|
||||
git reset --hard
|
||||
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
|
||||
mv *.tgz docs
|
||||
helm repo index docs
|
||||
echo "Indexing helm repo"
|
||||
helm repo index --merge docs/index.yaml sync
|
||||
mv -f sync/* docs
|
||||
rm -rf sync
|
||||
echo "Pushing new helm release"
|
||||
git add -A
|
||||
git commit -m "Helm Release: ${{ env.RELEASE_VERSION }}"
|
||||
git push
|
||||
|
|
|
@ -4,9 +4,6 @@ metadata:
|
|||
annotations:
|
||||
kompose.cmd: kompose convert
|
||||
kompose.version: 1.21.0 (992df58d8)
|
||||
{{ if .Values.globals.logAnnotations }}
|
||||
{{ toYaml .Values.globals.logAnnotations | indent 4 }}
|
||||
{{ end }}
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: app-service
|
||||
|
@ -23,6 +20,9 @@ spec:
|
|||
annotations:
|
||||
kompose.cmd: kompose convert
|
||||
kompose.version: 1.21.0 (992df58d8)
|
||||
{{ if .Values.globals.appServiceAnnotations }}
|
||||
{{ toYaml .Values.globals.appServiceAnnotations | indent 4 }}
|
||||
{{ end }}
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: app-service
|
||||
|
|
|
@ -4,9 +4,6 @@ metadata:
|
|||
annotations:
|
||||
kompose.cmd: kompose convert
|
||||
kompose.version: 1.21.0 (992df58d8)
|
||||
{{ if .Values.globals.logAnnotations }}
|
||||
{{ toYaml .Values.globals.logAnnotations | indent 4 }}
|
||||
{{ end }}
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
app.kubernetes.io/name: budibase-proxy
|
||||
|
@ -23,6 +20,9 @@ spec:
|
|||
annotations:
|
||||
kompose.cmd: kompose convert
|
||||
kompose.version: 1.21.0 (992df58d8)
|
||||
{{ if .Values.globals.proxyServiceAnnotations }}
|
||||
{{ toYaml .Values.globals.proxyServiceAnnotations | indent 4 }}
|
||||
{{ end }}
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
app.kubernetes.io/name: budibase-proxy
|
||||
|
|
|
@ -4,9 +4,6 @@ metadata:
|
|||
annotations:
|
||||
kompose.cmd: kompose convert
|
||||
kompose.version: 1.21.0 (992df58d8)
|
||||
{{ if .Values.globals.logAnnotations }}
|
||||
{{ toYaml .Values.globals.logAnnotations | indent 4 }}
|
||||
{{ end }}
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: worker-service
|
||||
|
@ -24,6 +21,9 @@ spec:
|
|||
annotations:
|
||||
kompose.cmd: kompose convert
|
||||
kompose.version: 1.21.0 (992df58d8)
|
||||
{{ if .Values.globals.workerServiceAnnotations }}
|
||||
{{ toYaml .Values.globals.workerServiceAnnotations | indent 4 }}
|
||||
{{ end }}
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: worker-service
|
||||
|
|
|
@ -22,12 +22,23 @@ serviceAccount:
|
|||
|
||||
podAnnotations: {}
|
||||
|
||||
# logAnnotations:
|
||||
# appServiceAnnotations:
|
||||
# co.elastic.logs/multiline.type: pattern
|
||||
# co.elastic.logs/multiline.pattern: '^[[:space:]]'
|
||||
# co.elastic.logs/multiline.negate: false
|
||||
# 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:
|
||||
{}
|
||||
# fsGroup: 2000
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"version": "2.2.11-alpha.1",
|
||||
"version": "2.2.12-alpha.2",
|
||||
"npmClient": "yarn",
|
||||
"packages": [
|
||||
"packages/*"
|
||||
|
|
|
@ -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",
|
||||
"test": "lerna run test && yarn test:pro",
|
||||
"test:pro": "bash scripts/pro/test.sh",
|
||||
"lint:eslint": "eslint packages",
|
||||
"lint:prettier": "prettier --check \"packages/**/*.{js,ts,svelte}\"",
|
||||
"lint:eslint": "eslint packages && eslint qa-core",
|
||||
"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: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}\"",
|
||||
|
@ -84,4 +84,4 @@
|
|||
"install:pro": "bash scripts/pro/install.sh",
|
||||
"dep:clean": "yarn clean && yarn bootstrap"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"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",
|
||||
"main": "dist/src/index.js",
|
||||
"types": "dist/src/index.d.ts",
|
||||
|
@ -23,7 +23,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@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",
|
||||
"@techpass/passport-openidconnect": "0.3.2",
|
||||
"aws-cloudfront-sign": "2.2.0",
|
||||
|
|
|
@ -77,6 +77,7 @@ export const StaticDatabases = {
|
|||
apiKeys: "apikeys",
|
||||
usageQuota: "usage_quota",
|
||||
licenseInfo: "license_info",
|
||||
environmentVariables: "environmentvariables",
|
||||
},
|
||||
},
|
||||
// contains information about tenancy and so on
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@budibase/bbui",
|
||||
"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",
|
||||
"svelte": "src/index.js",
|
||||
"module": "dist/bbui.es.js",
|
||||
|
@ -38,7 +38,7 @@
|
|||
],
|
||||
"dependencies": {
|
||||
"@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/actiongroup": "1.0.1",
|
||||
"@spectrum-css/avatar": "3.0.2",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/builder",
|
||||
"version": "2.2.11-alpha.1",
|
||||
"version": "2.2.12-alpha.2",
|
||||
"license": "GPL-3.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
@ -71,10 +71,10 @@
|
|||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@budibase/bbui": "2.2.11-alpha.1",
|
||||
"@budibase/client": "2.2.11-alpha.1",
|
||||
"@budibase/frontend-core": "2.2.11-alpha.1",
|
||||
"@budibase/string-templates": "2.2.11-alpha.1",
|
||||
"@budibase/bbui": "2.2.12-alpha.2",
|
||||
"@budibase/client": "2.2.12-alpha.2",
|
||||
"@budibase/frontend-core": "2.2.12-alpha.2",
|
||||
"@budibase/string-templates": "2.2.12-alpha.2",
|
||||
"@sentry/browser": "5.19.1",
|
||||
"@spectrum-css/page": "^3.0.1",
|
||||
"@spectrum-css/vars": "^3.0.1",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/cli",
|
||||
"version": "2.2.11-alpha.1",
|
||||
"version": "2.2.12-alpha.2",
|
||||
"description": "Budibase CLI, for developers, self hosting and migrations.",
|
||||
"main": "src/index.js",
|
||||
"bin": {
|
||||
|
@ -26,9 +26,9 @@
|
|||
"outputPath": "build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@budibase/backend-core": "2.2.11-alpha.1",
|
||||
"@budibase/string-templates": "2.2.11-alpha.1",
|
||||
"@budibase/types": "2.2.11-alpha.1",
|
||||
"@budibase/backend-core": "2.2.12-alpha.2",
|
||||
"@budibase/string-templates": "2.2.12-alpha.2",
|
||||
"@budibase/types": "2.2.12-alpha.2",
|
||||
"axios": "0.21.2",
|
||||
"chalk": "4.1.0",
|
||||
"cli-progress": "3.11.2",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/client",
|
||||
"version": "2.2.11-alpha.1",
|
||||
"version": "2.2.12-alpha.2",
|
||||
"license": "MPL-2.0",
|
||||
"module": "dist/budibase-client.js",
|
||||
"main": "dist/budibase-client.js",
|
||||
|
@ -19,9 +19,9 @@
|
|||
"dev:builder": "rollup -cw"
|
||||
},
|
||||
"dependencies": {
|
||||
"@budibase/bbui": "2.2.11-alpha.1",
|
||||
"@budibase/frontend-core": "2.2.11-alpha.1",
|
||||
"@budibase/string-templates": "2.2.11-alpha.1",
|
||||
"@budibase/bbui": "2.2.12-alpha.2",
|
||||
"@budibase/frontend-core": "2.2.12-alpha.2",
|
||||
"@budibase/string-templates": "2.2.12-alpha.2",
|
||||
"@spectrum-css/button": "^3.0.3",
|
||||
"@spectrum-css/card": "^3.0.3",
|
||||
"@spectrum-css/divider": "^1.0.3",
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"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",
|
||||
"author": "Budibase",
|
||||
"license": "MPL-2.0",
|
||||
"svelte": "src/index.js",
|
||||
"dependencies": {
|
||||
"@budibase/bbui": "2.2.11-alpha.1",
|
||||
"@budibase/bbui": "2.2.12-alpha.2",
|
||||
"lodash": "^4.17.21",
|
||||
"svelte": "^3.46.2"
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/sdk",
|
||||
"version": "2.2.11-alpha.1",
|
||||
"version": "2.2.12-alpha.2",
|
||||
"description": "Budibase Public API SDK",
|
||||
"author": "Budibase",
|
||||
"license": "MPL-2.0",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@budibase/server",
|
||||
"email": "hi@budibase.com",
|
||||
"version": "2.2.11-alpha.1",
|
||||
"version": "2.2.12-alpha.2",
|
||||
"description": "Budibase Web Server",
|
||||
"main": "src/index.ts",
|
||||
"repository": {
|
||||
|
@ -43,11 +43,11 @@
|
|||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
"@apidevtools/swagger-parser": "10.0.3",
|
||||
"@budibase/backend-core": "2.2.11-alpha.1",
|
||||
"@budibase/client": "2.2.11-alpha.1",
|
||||
"@budibase/pro": "2.2.11-alpha.1",
|
||||
"@budibase/string-templates": "2.2.11-alpha.1",
|
||||
"@budibase/types": "2.2.11-alpha.1",
|
||||
"@budibase/backend-core": "2.2.12-alpha.2",
|
||||
"@budibase/client": "2.2.12-alpha.2",
|
||||
"@budibase/pro": "2.2.12-alpha.2",
|
||||
"@budibase/string-templates": "2.2.12-alpha.2",
|
||||
"@budibase/types": "2.2.12-alpha.2",
|
||||
"@bull-board/api": "3.7.0",
|
||||
"@bull-board/koa": "3.9.4",
|
||||
"@elastic/elasticsearch": "7.10.0",
|
||||
|
|
|
@ -33,6 +33,7 @@ export { default as publicRoutes } from "./public"
|
|||
|
||||
const appBackupRoutes = pro.appBackups
|
||||
const scheduleRoutes = pro.schedules
|
||||
const environmentVariableRoutes = pro.environmentVariables
|
||||
|
||||
export const mainRoutes: Router[] = [
|
||||
appBackupRoutes,
|
||||
|
@ -63,6 +64,7 @@ export const mainRoutes: Router[] = [
|
|||
migrationRoutes,
|
||||
pluginRoutes,
|
||||
scheduleRoutes,
|
||||
environmentVariableRoutes,
|
||||
// these need to be handled last as they still use /api/:tableId
|
||||
// this could be breaking as koa may recognise other routes as this
|
||||
tableRoutes,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const setup = require("./utilities")
|
||||
const { events, constants, db } = require("@budibase/backend-core")
|
||||
const { events, constants } = require("@budibase/backend-core")
|
||||
|
||||
describe("/static", () => {
|
||||
let request = setup.getRequest()
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
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 { budibaseTempDir } from "../../../utilities/budibaseDir"
|
||||
import { DB_EXPORT_FILE, GLOBAL_DB_EXPORT_FILE } from "./constants"
|
||||
import { downloadTemplate } from "../../../utilities/fileSystem"
|
||||
import { FieldTypes, ObjectStoreBuckets } from "../../../constants"
|
||||
import { ObjectStoreBuckets } from "../../../constants"
|
||||
import { join } from "path"
|
||||
import fs from "fs"
|
||||
import sdk from "../../"
|
||||
import {
|
||||
Automation,
|
||||
AutomationTriggerStepId,
|
||||
CouchFindOptions,
|
||||
RowAttachment,
|
||||
} from "@budibase/types"
|
||||
const uuid = require("uuid/v4")
|
||||
|
@ -25,54 +24,45 @@ type TemplateType = {
|
|||
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
|
||||
const tables = await sdk.tables.getAllInternalTables(db)
|
||||
let updatedRows: Row[] = []
|
||||
for (let table of tables) {
|
||||
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) {
|
||||
continue
|
||||
}
|
||||
// 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
|
||||
const { rows, columns } = await sdk.rows.getRowsWithAttachments(
|
||||
db.name,
|
||||
table
|
||||
)
|
||||
updatedRows = updatedRows.concat(
|
||||
rows.map(row => {
|
||||
for (let column of columns) {
|
||||
if (Array.isArray(row[column])) {
|
||||
row[column] = row[column].map((attachment: RowAttachment) =>
|
||||
rewriteAttachmentUrl(prodAppId, attachment)
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
// write back the updated attachments
|
||||
await db.bulkDocs(rows)
|
||||
}
|
||||
return row
|
||||
})
|
||||
)
|
||||
}
|
||||
// write back the updated attachments
|
||||
await db.bulkDocs(updatedRows)
|
||||
}
|
||||
|
||||
async function updateAutomations(prodAppId: string, db: Database) {
|
||||
|
|
60
packages/server/src/sdk/app/rows/attachments.ts
Normal file
60
packages/server/src/sdk/app/rows/attachments.ts
Normal 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 }
|
||||
}
|
7
packages/server/src/sdk/app/rows/index.ts
Normal file
7
packages/server/src/sdk/app/rows/index.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import * as attachments from "./attachments"
|
||||
import * as rows from "./rows"
|
||||
|
||||
export default {
|
||||
...attachments,
|
||||
...rows,
|
||||
}
|
18
packages/server/src/sdk/app/rows/rows.ts
Normal file
18
packages/server/src/sdk/app/rows/rows.ts
Normal 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[]
|
||||
}
|
|
@ -2,6 +2,7 @@ import { default as backups } from "./app/backups"
|
|||
import { default as tables } from "./app/tables"
|
||||
import { default as automations } from "./app/automations"
|
||||
import { default as applications } from "./app/applications"
|
||||
import { default as rows } from "./app/rows"
|
||||
import { default as users } from "./users"
|
||||
|
||||
const sdk = {
|
||||
|
@ -9,6 +10,7 @@ const sdk = {
|
|||
tables,
|
||||
automations,
|
||||
applications,
|
||||
rows,
|
||||
users,
|
||||
}
|
||||
|
||||
|
|
76
packages/server/src/sdk/tests/attachments.spec.ts
Normal file
76
packages/server/src/sdk/tests/attachments.spec.ts
Normal 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`)
|
||||
}
|
||||
})
|
||||
})
|
|
@ -1273,13 +1273,13 @@
|
|||
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
|
||||
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
|
||||
|
||||
"@budibase/backend-core@2.2.11-alpha.1":
|
||||
version "2.2.11-alpha.1"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.2.11-alpha.1.tgz#adb8835b0db1f671eacc226f39788d6b696353ee"
|
||||
integrity sha512-8VWYTRbEuhXUWfb/ic9PblWdu6nRidM5Sqo0UK6WXCl9RN0V41UancnyhcWbUf0k9sdm52Y0ESYRr4nzhqU0Fw==
|
||||
"@budibase/backend-core@2.2.12-alpha.2":
|
||||
version "2.2.12-alpha.2"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.2.12-alpha.2.tgz#5fd62c585e950f5a5c29f301e3acc4b3757908b8"
|
||||
integrity sha512-AiZzLWHgGA5hazbtBDAE2dRjxEPMXn437rSWKN4Vx77VplhHTvV4XPmdr4wiRpBmr4C8NGyQJMRW1CddB1qIJw==
|
||||
dependencies:
|
||||
"@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"
|
||||
"@techpass/passport-openidconnect" "0.3.2"
|
||||
aws-cloudfront-sign "2.2.0"
|
||||
|
@ -1373,13 +1373,13 @@
|
|||
qs "^6.11.0"
|
||||
tough-cookie "^4.1.2"
|
||||
|
||||
"@budibase/pro@2.2.11-alpha.1":
|
||||
version "2.2.11-alpha.1"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.2.11-alpha.1.tgz#ed435fa569d090330cacb782129d4af796601f3d"
|
||||
integrity sha512-bOMR4nJo/8BAKTiluIH81sf/boB4Iq2dDSvvCl5b3VR4evPRnGQwzFeOPFfi9jKkYJy7F74b/RWjl38VQe3atQ==
|
||||
"@budibase/pro@2.2.12-alpha.2":
|
||||
version "2.2.12-alpha.2"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.2.12-alpha.2.tgz#dbcb12ea725d2b2a81e62bd3068801f2b289fe1d"
|
||||
integrity sha512-9D0+5L6ElSKT1DEV5W7AE1q9UdtoYStjEBF1ePS2aUXRzqmVTEJSqNLs3WjWE5DcN16Ui3VodjJPftsBzwR6HQ==
|
||||
dependencies:
|
||||
"@budibase/backend-core" "2.2.11-alpha.1"
|
||||
"@budibase/types" "2.2.11-alpha.1"
|
||||
"@budibase/backend-core" "2.2.12-alpha.2"
|
||||
"@budibase/types" "2.2.12-alpha.2"
|
||||
"@koa/router" "8.0.8"
|
||||
bull "4.10.1"
|
||||
joi "17.6.0"
|
||||
|
@ -1404,10 +1404,10 @@
|
|||
svelte-apexcharts "^1.0.2"
|
||||
svelte-flatpickr "^3.1.0"
|
||||
|
||||
"@budibase/types@2.2.11-alpha.1":
|
||||
version "2.2.11-alpha.1"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.2.11-alpha.1.tgz#a879f21608389763e20cdcd4ddc60146b0666260"
|
||||
integrity sha512-KKld6dGyEqJzU62/gb1+S58O+3LW3BIdvtaV7oNxGE32snNh3iNSTBjFkVJU1gNlk+iAMvLCvkFNqDd3Kca+5Q==
|
||||
"@budibase/types@2.2.12-alpha.2":
|
||||
version "2.2.12-alpha.2"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.2.12-alpha.2.tgz#390959555517f11dc95147518e89f400c59dd520"
|
||||
integrity sha512-Dz/3kdSkBRyf+AQyaPbAwq6hxD1kQuHht+4C3pyebbHUL440ZhZhJ1o2AAFc8SF1/9SqAk/NFaktAY2vCyRlOQ==
|
||||
|
||||
"@bull-board/api@3.7.0":
|
||||
version "3.7.0"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/string-templates",
|
||||
"version": "2.2.11-alpha.1",
|
||||
"version": "2.2.12-alpha.2",
|
||||
"description": "Handlebars wrapper for Budibase templating.",
|
||||
"main": "src/index.cjs",
|
||||
"module": "dist/bundle.mjs",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/types",
|
||||
"version": "2.2.11-alpha.1",
|
||||
"version": "2.2.12-alpha.2",
|
||||
"description": "Budibase types",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
export enum Feature {
|
||||
USER_GROUPS = "userGroups",
|
||||
APP_BACKUPS = "appBackups",
|
||||
ENVIRONMENT_VARIABLES = "environmentVariables",
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@budibase/worker",
|
||||
"email": "hi@budibase.com",
|
||||
"version": "2.2.11-alpha.1",
|
||||
"version": "2.2.12-alpha.2",
|
||||
"description": "Budibase background service",
|
||||
"main": "src/index.ts",
|
||||
"repository": {
|
||||
|
@ -36,10 +36,10 @@
|
|||
"author": "Budibase",
|
||||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
"@budibase/backend-core": "2.2.11-alpha.1",
|
||||
"@budibase/pro": "2.2.11-alpha.1",
|
||||
"@budibase/string-templates": "2.2.11-alpha.1",
|
||||
"@budibase/types": "2.2.11-alpha.1",
|
||||
"@budibase/backend-core": "2.2.12-alpha.2",
|
||||
"@budibase/pro": "2.2.12-alpha.2",
|
||||
"@budibase/string-templates": "2.2.12-alpha.2",
|
||||
"@budibase/types": "2.2.12-alpha.2",
|
||||
"@koa/router": "8.0.8",
|
||||
"@sentry/node": "6.17.7",
|
||||
"@techpass/passport-openidconnect": "0.3.2",
|
||||
|
|
|
@ -470,13 +470,13 @@
|
|||
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
|
||||
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
|
||||
|
||||
"@budibase/backend-core@2.2.11-alpha.1":
|
||||
version "2.2.11-alpha.1"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.2.11-alpha.1.tgz#adb8835b0db1f671eacc226f39788d6b696353ee"
|
||||
integrity sha512-8VWYTRbEuhXUWfb/ic9PblWdu6nRidM5Sqo0UK6WXCl9RN0V41UancnyhcWbUf0k9sdm52Y0ESYRr4nzhqU0Fw==
|
||||
"@budibase/backend-core@2.2.12-alpha.2":
|
||||
version "2.2.12-alpha.2"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.2.12-alpha.2.tgz#5fd62c585e950f5a5c29f301e3acc4b3757908b8"
|
||||
integrity sha512-AiZzLWHgGA5hazbtBDAE2dRjxEPMXn437rSWKN4Vx77VplhHTvV4XPmdr4wiRpBmr4C8NGyQJMRW1CddB1qIJw==
|
||||
dependencies:
|
||||
"@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"
|
||||
"@techpass/passport-openidconnect" "0.3.2"
|
||||
aws-cloudfront-sign "2.2.0"
|
||||
|
@ -520,23 +520,23 @@
|
|||
qs "^6.11.0"
|
||||
tough-cookie "^4.1.2"
|
||||
|
||||
"@budibase/pro@2.2.11-alpha.1":
|
||||
version "2.2.11-alpha.1"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.2.11-alpha.1.tgz#ed435fa569d090330cacb782129d4af796601f3d"
|
||||
integrity sha512-bOMR4nJo/8BAKTiluIH81sf/boB4Iq2dDSvvCl5b3VR4evPRnGQwzFeOPFfi9jKkYJy7F74b/RWjl38VQe3atQ==
|
||||
"@budibase/pro@2.2.12-alpha.2":
|
||||
version "2.2.12-alpha.2"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.2.12-alpha.2.tgz#dbcb12ea725d2b2a81e62bd3068801f2b289fe1d"
|
||||
integrity sha512-9D0+5L6ElSKT1DEV5W7AE1q9UdtoYStjEBF1ePS2aUXRzqmVTEJSqNLs3WjWE5DcN16Ui3VodjJPftsBzwR6HQ==
|
||||
dependencies:
|
||||
"@budibase/backend-core" "2.2.11-alpha.1"
|
||||
"@budibase/types" "2.2.11-alpha.1"
|
||||
"@budibase/backend-core" "2.2.12-alpha.2"
|
||||
"@budibase/types" "2.2.12-alpha.2"
|
||||
"@koa/router" "8.0.8"
|
||||
bull "4.10.1"
|
||||
joi "17.6.0"
|
||||
jsonwebtoken "8.5.1"
|
||||
node-fetch "^2.6.1"
|
||||
|
||||
"@budibase/types@2.2.11-alpha.1":
|
||||
version "2.2.11-alpha.1"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.2.11-alpha.1.tgz#a879f21608389763e20cdcd4ddc60146b0666260"
|
||||
integrity sha512-KKld6dGyEqJzU62/gb1+S58O+3LW3BIdvtaV7oNxGE32snNh3iNSTBjFkVJU1gNlk+iAMvLCvkFNqDd3Kca+5Q==
|
||||
"@budibase/types@2.2.12-alpha.2":
|
||||
version "2.2.12-alpha.2"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.2.12-alpha.2.tgz#390959555517f11dc95147518e89f400c59dd520"
|
||||
integrity sha512-Dz/3kdSkBRyf+AQyaPbAwq6hxD1kQuHht+4C3pyebbHUL440ZhZhJ1o2AAFc8SF1/9SqAk/NFaktAY2vCyRlOQ==
|
||||
|
||||
"@cspotcode/source-map-support@^0.8.0":
|
||||
version "0.8.1"
|
||||
|
|
|
@ -26,7 +26,10 @@ export default class TestConfiguration<T> {
|
|||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -4,130 +4,128 @@ import InternalAPIClient from "./InternalAPIClient"
|
|||
import { responseMessage } from "../fixtures/types/responseMessage"
|
||||
|
||||
export default class UserManagementApi {
|
||||
api: InternalAPIClient
|
||||
api: InternalAPIClient
|
||||
|
||||
constructor(apiClient: InternalAPIClient) {
|
||||
this.api = apiClient
|
||||
}
|
||||
constructor(apiClient: InternalAPIClient) {
|
||||
this.api = apiClient
|
||||
}
|
||||
|
||||
async search(): Promise<[Response, Partial<User>[]]> {
|
||||
const response = await this.api.post(`/global/users/search`, {})
|
||||
const json = await response.json()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(json.data.length).toBeGreaterThan(0)
|
||||
return [response, json]
|
||||
}
|
||||
async search(): Promise<[Response, Partial<User>[]]> {
|
||||
const response = await this.api.post(`/global/users/search`, {})
|
||||
const json = await response.json()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(json.data.length).toBeGreaterThan(0)
|
||||
return [response, json]
|
||||
}
|
||||
|
||||
async getSelf(): Promise<[Response, Partial<User>]> {
|
||||
const response = await this.api.get(`/global/self`)
|
||||
const json = await response.json()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
return [response, json]
|
||||
}
|
||||
async getSelf(): Promise<[Response, Partial<User>]> {
|
||||
const response = await this.api.get(`/global/self`)
|
||||
const json = await response.json()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
return [response, json]
|
||||
}
|
||||
|
||||
async getAll(): Promise<[Response, Partial<User>[]]> {
|
||||
const response = await this.api.get(`/global/users`)
|
||||
const json = await response.json()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(json.length).toBeGreaterThan(0)
|
||||
return [response, json]
|
||||
}
|
||||
async getAll(): Promise<[Response, Partial<User>[]]> {
|
||||
const response = await this.api.get(`/global/users`)
|
||||
const json = await response.json()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(json.length).toBeGreaterThan(0)
|
||||
return [response, json]
|
||||
}
|
||||
|
||||
// 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]> {
|
||||
const body = {
|
||||
create: {
|
||||
users: userList,
|
||||
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]
|
||||
// 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]> {
|
||||
const body = {
|
||||
create: {
|
||||
users: userList,
|
||||
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]
|
||||
}
|
||||
|
||||
async deleteMultiple(userId: string[]): Promise<[Response, responseMessage]> {
|
||||
const body = {
|
||||
delete: {
|
||||
userIds: [
|
||||
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]
|
||||
async deleteMultiple(userId: string[]): Promise<[Response, responseMessage]> {
|
||||
const body = {
|
||||
delete: {
|
||||
userIds: [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]
|
||||
}
|
||||
|
||||
async invite(body: any): Promise<[Response, responseMessage]> {
|
||||
const response = await this.api.post(`/global/users/multi/invite`, { body })
|
||||
const json = await response.json()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(json.unsuccessful.length).toEqual(0)
|
||||
expect(json.successful.length).toEqual(body.length)
|
||||
async invite(body: any): Promise<[Response, responseMessage]> {
|
||||
const response = await this.api.post(`/global/users/multi/invite`, { body })
|
||||
const json = await response.json()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(json.unsuccessful.length).toEqual(0)
|
||||
expect(json.successful.length).toEqual(body.length)
|
||||
|
||||
return [response, json]
|
||||
}
|
||||
return [response, json]
|
||||
}
|
||||
|
||||
async getRoles(): Promise<[Response, Role[]]> {
|
||||
const response = await this.api.get(`/roles`)
|
||||
const json = await response.json()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
return [response, json]
|
||||
}
|
||||
async getRoles(): Promise<[Response, Role[]]> {
|
||||
const response = await this.api.get(`/roles`)
|
||||
const json = await response.json()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
return [response, json]
|
||||
}
|
||||
|
||||
async updateInfo(body: any): Promise<[Response, User]> {
|
||||
const response = await this.api.post(`/global/users/`, { body })
|
||||
const json = await response.json()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(json._id).toEqual(body._id)
|
||||
expect(json._rev).not.toEqual(body._rev)
|
||||
return [response, json]
|
||||
}
|
||||
async updateInfo(body: any): Promise<[Response, User]> {
|
||||
const response = await this.api.post(`/global/users/`, { body })
|
||||
const json = await response.json()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(json._id).toEqual(body._id)
|
||||
expect(json._rev).not.toEqual(body._rev)
|
||||
return [response, json]
|
||||
}
|
||||
|
||||
async forcePasswordReset(body: any): Promise<[Response, User]> {
|
||||
const response = await this.api.post(`/global/users/`, { body })
|
||||
const json = await response.json()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(json._id).toEqual(body._id)
|
||||
expect(json._rev).not.toEqual(body._rev)
|
||||
return [response, json]
|
||||
}
|
||||
async forcePasswordReset(body: any): Promise<[Response, User]> {
|
||||
const response = await this.api.post(`/global/users/`, { body })
|
||||
const json = await response.json()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(json._id).toEqual(body._id)
|
||||
expect(json._rev).not.toEqual(body._rev)
|
||||
return [response, json]
|
||||
}
|
||||
|
||||
async getInfo(userId: string): Promise<[Response, User]> {
|
||||
const response = await this.api.get(`/global/users/${userId}`)
|
||||
const json = await response.json()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
return [response, json]
|
||||
}
|
||||
async getInfo(userId: string): Promise<[Response, User]> {
|
||||
const response = await this.api.get(`/global/users/${userId}`)
|
||||
const json = await response.json()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
return [response, json]
|
||||
}
|
||||
|
||||
async changeSelfPassword(body: Partial<User>): Promise<[Response, User]> {
|
||||
const response = await this.api.post(`/global/self`, { body })
|
||||
const json = await response.json()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(json._id).toEqual(body._id)
|
||||
expect(json._rev).not.toEqual(body._rev)
|
||||
return [response, json]
|
||||
}
|
||||
async changeSelfPassword(body: Partial<User>): Promise<[Response, User]> {
|
||||
const response = await this.api.post(`/global/self`, { body })
|
||||
const json = await response.json()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(json._id).toEqual(body._id)
|
||||
expect(json._rev).not.toEqual(body._rev)
|
||||
return [response, json]
|
||||
}
|
||||
|
||||
async createRole(body: Partial<UserRoles>): Promise<[Response, UserRoles]> {
|
||||
const response = await this.api.post(`/roles`, { body })
|
||||
const json = await response.json()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
return [response, json]
|
||||
}
|
||||
}
|
||||
async createRole(body: Partial<UserRoles>): Promise<[Response, UserRoles]> {
|
||||
const response = await this.api.post(`/roles`, { body })
|
||||
const json = await response.json()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
return [response, json]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,13 +13,12 @@ export const generateApp = (
|
|||
|
||||
// Applications type doesn't work here, save to add useTemplate parameter?
|
||||
export const appFromTemplate = (): any => {
|
||||
return ({
|
||||
return {
|
||||
name: generator.word(),
|
||||
url: `/${generator.word()}`,
|
||||
useTemplate: "true",
|
||||
templateName: "Near Miss Register",
|
||||
templateKey: "app/near-miss-register",
|
||||
templateFile: undefined,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,80 +1,82 @@
|
|||
import generator from "../../generator";
|
||||
import { User } from "@budibase/types";
|
||||
|
||||
import generator from "../../generator"
|
||||
import { User } from "@budibase/types"
|
||||
|
||||
const generateDeveloper = (): Partial<User> => {
|
||||
const randomId = generator.guid();
|
||||
return ({
|
||||
email: `pedro+${randomId}@budibase.com`,
|
||||
password: randomId,
|
||||
roles: {},
|
||||
forceResetPassword: true,
|
||||
builder: {
|
||||
global: true
|
||||
}
|
||||
})
|
||||
const randomId = generator.guid()
|
||||
return {
|
||||
email: `pedro+${randomId}@budibase.com`,
|
||||
password: randomId,
|
||||
roles: {},
|
||||
forceResetPassword: true,
|
||||
builder: {
|
||||
global: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const generateAdmin = (): Partial<User> => {
|
||||
const randomId = generator.guid();
|
||||
return ({
|
||||
email: `pedro+${randomId}@budibase.com`,
|
||||
password: randomId,
|
||||
roles: {},
|
||||
forceResetPassword: true,
|
||||
admin: {
|
||||
global: true
|
||||
},
|
||||
builder: {
|
||||
global: true
|
||||
}
|
||||
})
|
||||
const randomId = generator.guid()
|
||||
return {
|
||||
email: `pedro+${randomId}@budibase.com`,
|
||||
password: randomId,
|
||||
roles: {},
|
||||
forceResetPassword: true,
|
||||
admin: {
|
||||
global: true,
|
||||
},
|
||||
builder: {
|
||||
global: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
const generateAppUser = (): Partial<User> => {
|
||||
const randomId = generator.guid();
|
||||
return ({
|
||||
email: `pedro+${randomId}@budibase.com`,
|
||||
password: randomId,
|
||||
roles: {},
|
||||
forceResetPassword: true,
|
||||
admin: {
|
||||
global: false
|
||||
},
|
||||
builder: {
|
||||
global: false
|
||||
}
|
||||
})
|
||||
|
||||
const randomId = generator.guid()
|
||||
return {
|
||||
email: `pedro+${randomId}@budibase.com`,
|
||||
password: randomId,
|
||||
roles: {},
|
||||
forceResetPassword: true,
|
||||
admin: {
|
||||
global: false,
|
||||
},
|
||||
builder: {
|
||||
global: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export const generateInviteUser = (): Object[] => {
|
||||
const randomId = generator.guid();
|
||||
return [{
|
||||
email: `pedro+${randomId}@budibase.com`,
|
||||
userInfo: {
|
||||
userGroups: []
|
||||
}
|
||||
}]
|
||||
|
||||
const randomId = generator.guid()
|
||||
return [
|
||||
{
|
||||
email: `pedro+${randomId}@budibase.com`,
|
||||
userInfo: {
|
||||
userGroups: [],
|
||||
},
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
export const generateUser = (amount: number = 1, role?: string): Partial<User>[] => {
|
||||
const userList: Partial<User>[] = [];
|
||||
for (let i = 0; i < amount; i++) {
|
||||
switch (role) {
|
||||
case "admin":
|
||||
userList.push(generateAdmin());
|
||||
break;
|
||||
case "developer":
|
||||
userList.push(generateDeveloper());
|
||||
break;
|
||||
case "appUser":
|
||||
userList.push(generateAppUser());
|
||||
break;
|
||||
default:
|
||||
userList.push(generateAppUser());
|
||||
break;
|
||||
}
|
||||
export const generateUser = (
|
||||
amount: number = 1,
|
||||
role?: string
|
||||
): Partial<User>[] => {
|
||||
const userList: Partial<User>[] = []
|
||||
for (let i = 0; i < amount; i++) {
|
||||
switch (role) {
|
||||
case "admin":
|
||||
userList.push(generateAdmin())
|
||||
break
|
||||
case "developer":
|
||||
userList.push(generateDeveloper())
|
||||
break
|
||||
case "appUser":
|
||||
userList.push(generateAppUser())
|
||||
break
|
||||
default:
|
||||
userList.push(generateAppUser())
|
||||
break
|
||||
}
|
||||
return userList
|
||||
}
|
||||
}
|
||||
return userList
|
||||
}
|
||||
|
|
|
@ -2,7 +2,10 @@ import TestConfiguration from "../../../config/internal-api/TestConfiguration"
|
|||
import { Application } from "@budibase/server/api/controllers/public/mapping/types"
|
||||
import { db } from "@budibase/backend-core"
|
||||
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 generateScreen from "../../../config/internal-api/fixtures/screens"
|
||||
|
||||
|
@ -18,7 +21,6 @@ describe("Internal API - Application creation, update, publish and delete", () =
|
|||
await config.afterAll()
|
||||
})
|
||||
|
||||
|
||||
it("Get applications without applications", async () => {
|
||||
await config.applications.fetchEmptyAppList()
|
||||
})
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import TestConfiguration from "../../../config/internal-api/TestConfiguration"
|
||||
import { App } from "@budibase/types"
|
||||
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 generateScreen from "../../../config/internal-api/fixtures/screens"
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -5,86 +5,84 @@ import { generateUser } from "../../../config/internal-api/fixtures/userManageme
|
|||
import { User } from "@budibase/types"
|
||||
|
||||
describe("Internal API - User Management & Permissions", () => {
|
||||
const api = new InternalAPIClient()
|
||||
const config = new TestConfiguration<Application>(api)
|
||||
const api = new InternalAPIClient()
|
||||
const config = new TestConfiguration<Application>(api)
|
||||
|
||||
// Before each test, login as admin. Some tests will require login as a different user
|
||||
beforeEach(async () => {
|
||||
await config.loginAsAdmin()
|
||||
})
|
||||
// Before each test, login as admin. Some tests will require login as a different user
|
||||
beforeEach(async () => {
|
||||
await config.loginAsAdmin()
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await config.afterAll()
|
||||
})
|
||||
afterAll(async () => {
|
||||
await config.afterAll()
|
||||
})
|
||||
|
||||
it("Add Users with different roles", async () => {
|
||||
await config.users.search()
|
||||
await config.users.getRoles()
|
||||
it("Add Users with different roles", async () => {
|
||||
await config.users.search()
|
||||
await config.users.getRoles()
|
||||
|
||||
const admin = generateUser(1, "admin")
|
||||
expect(admin[0].builder?.global).toEqual(true)
|
||||
expect(admin[0].admin?.global).toEqual(true)
|
||||
const developer = generateUser(1, "developer")
|
||||
expect(developer[0].builder?.global).toEqual(true)
|
||||
const appUser = generateUser(1, "appUser")
|
||||
expect(appUser[0].builder?.global).toEqual(false)
|
||||
expect(appUser[0].admin?.global).toEqual(false)
|
||||
const admin = generateUser(1, "admin")
|
||||
expect(admin[0].builder?.global).toEqual(true)
|
||||
expect(admin[0].admin?.global).toEqual(true)
|
||||
const developer = generateUser(1, "developer")
|
||||
expect(developer[0].builder?.global).toEqual(true)
|
||||
const appUser = generateUser(1, "appUser")
|
||||
expect(appUser[0].builder?.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()
|
||||
expect(allUsersJson.length).toBeGreaterThan(0)
|
||||
const [allUsersResponse, allUsersJson] = await config.users.getAll()
|
||||
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("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()
|
||||
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)
|
||||
})
|
||||
|
||||
|
||||
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)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -73,15 +73,15 @@ describe("Public API - /applications endpoints", () => {
|
|||
})
|
||||
|
||||
it("POST - unpublish an unpublished application", async () => {
|
||||
const [response] = await config.applications.unpublish(
|
||||
config.context._id
|
||||
)
|
||||
const [response] = await config.applications.unpublish(config.context._id)
|
||||
expect(response).toHaveStatusCode(400)
|
||||
})
|
||||
|
||||
it("DELETE - delete a published application and the dev application", async () => {
|
||||
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(deletion._id).toEqual(config.context._id)
|
||||
|
||||
|
|
Loading…
Reference in a new issue