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

This commit is contained in:
Peter Clement 2023-01-09 16:43:37 +00:00
commit 30e90b2d5d
39 changed files with 1207 additions and 948 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,5 +1,5 @@
{
"version": "2.2.11-alpha.1",
"version": "2.2.12-alpha.2",
"npmClient": "yarn",
"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",
"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}\"",

View File

@ -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",

View File

@ -77,6 +77,7 @@ export const StaticDatabases = {
apiKeys: "apikeys",
usageQuota: "usage_quota",
licenseInfo: "license_info",
environmentVariables: "environmentvariables",
},
},
// contains information about tenancy and so on

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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"
}

View File

@ -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",

View File

@ -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",

View File

@ -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,

View File

@ -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()

View File

@ -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) {
// iterate through attachment documents and update them
const tables = await sdk.tables.getAllInternalTables(db)
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
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(prodAppId)
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 { 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)
)
}
}
return row
})
)
}
// write back the updated attachments
await db.bulkDocs(rows)
}
await db.bulkDocs(updatedRows)
}
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 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,
}

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"
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"

View File

@ -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",

View File

@ -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",

View File

@ -1,4 +1,5 @@
export enum Feature {
USER_GROUPS = "userGroups",
APP_BACKUPS = "appBackups",
ENVIRONMENT_VARIABLES = "environmentVariables",
}

View File

@ -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",

View File

@ -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"

View File

@ -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) {

View File

@ -38,8 +38,8 @@ export default class UserManagementApi {
const body = {
create: {
users: userList,
groups: []
}
groups: [],
},
}
const response = await this.api.post(`/global/users/bulk`, { body })
const json = await response.json()
@ -52,10 +52,8 @@ export default class UserManagementApi {
async deleteMultiple(userId: string[]): Promise<[Response, responseMessage]> {
const body = {
delete: {
userIds: [
userId
]
}
userIds: [userId],
},
}
const response = await this.api.post(`/global/users/bulk`, { body })
const json = await response.json()

View File

@ -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,
})
}
}

View File

@ -1,79 +1,81 @@
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 ({
const randomId = generator.guid()
return {
email: `pedro+${randomId}@budibase.com`,
password: randomId,
roles: {},
forceResetPassword: true,
builder: {
global: true
global: true,
},
}
})
}
const generateAdmin = (): Partial<User> => {
const randomId = generator.guid();
return ({
const randomId = generator.guid()
return {
email: `pedro+${randomId}@budibase.com`,
password: randomId,
roles: {},
forceResetPassword: true,
admin: {
global: true
global: true,
},
builder: {
global: true
global: true,
},
}
})
}
const generateAppUser = (): Partial<User> => {
const randomId = generator.guid();
return ({
const randomId = generator.guid()
return {
email: `pedro+${randomId}@budibase.com`,
password: randomId,
roles: {},
forceResetPassword: true,
admin: {
global: false
global: false,
},
builder: {
global: false
global: false,
},
}
})
}
export const generateInviteUser = (): Object[] => {
const randomId = generator.guid();
return [{
const randomId = generator.guid()
return [
{
email: `pedro+${randomId}@budibase.com`,
userInfo: {
userGroups: []
}
}]
userGroups: [],
},
},
]
}
export const generateUser = (amount: number = 1, role?: string): Partial<User>[] => {
const userList: Partial<User>[] = [];
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;
userList.push(generateAdmin())
break
case "developer":
userList.push(generateDeveloper());
break;
userList.push(generateDeveloper())
break
case "appUser":
userList.push(generateAppUser());
break;
userList.push(generateAppUser())
break
default:
userList.push(generateAppUser());
break;
userList.push(generateAppUser())
break
}
}
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 { 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()
})

View File

@ -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"

View File

@ -1,10 +1,16 @@
import TestConfiguration from "../../../config/internal-api/TestConfiguration"
import { Application } from "@budibase/server/api/controllers/public/mapping/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 { generateUser } from "../../../config/internal-api/fixtures/userManagement"
import { User } from "@budibase/types"
import { generateNewColumnForTable, generateTable } from "../../../config/internal-api/fixtures/table"
import {
generateNewColumnForTable,
generateTable,
} from "../../../config/internal-api/fixtures/table"
import generateScreen from "../../../config/internal-api/fixtures/screens"
import { db } from "@budibase/backend-core"
@ -25,31 +31,37 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
const [createUserResponse, createUserJson] = await config.users.addMultiple(
appUser
)
const app = await config.applications.create(appFromTemplate())
config.applications.api.appId = app.appId
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const body: User = {
...userInfoJson,
roles: {
[<string>app.appId]: "BASIC",
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[<string>app.appId]).toBeDefined()
expect(changedUserInfoJson.roles[<string>app.appId]).toEqual("BASIC")
})
it("Add ADMIN user to app", async () => {
const adminUser = generateUser(1, "admin")
expect(adminUser[0].builder?.global).toEqual(true)
expect(adminUser[0].admin?.global).toEqual(true)
const [createUserResponse, createUserJson] = await config.users.addMultiple(adminUser)
const [createUserResponse, createUserJson] = await config.users.addMultiple(
adminUser
)
//const app = await config.applications.create(generateApp())
//config.applications.api.appId = app.appId
@ -57,16 +69,19 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const app = await config.applications.create(appFromTemplate())
config.applications.api.appId = app.appId
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const body: User = {
...userInfoJson,
roles: {
[<string>app.appId]: "ADMIN",
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[<string>app.appId]).toBeDefined()
expect(changedUserInfoJson.roles[<string>app.appId]).toEqual("ADMIN")
@ -75,31 +90,34 @@ describe("Internal API - App Specific Roles & Permissions", () => {
// check published app renders
config.applications.api.appId = db.getProdAppID(app.appId!)
await config.applications.canRender()
})
it("Add POWER user to app", async () => {
const powerUser = generateUser(1, 'developer')
const powerUser = generateUser(1, "developer")
expect(powerUser[0].builder?.global).toEqual(true)
const [createUserResponse, createUserJson] = await config.users.addMultiple(powerUser)
const [createUserResponse, createUserJson] = await config.users.addMultiple(
powerUser
)
const app = await config.applications.create(generateApp())
config.applications.api.appId = app.appId
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const body: User = {
...userInfoJson,
roles: {
[<string>app.appId]: "POWER",
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[<string>app.appId]).toBeDefined()
expect(changedUserInfoJson.roles[<string>app.appId]).toEqual("POWER")
})
describe("Check Access for default roles", () => {
@ -107,21 +125,25 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
const [createUserResponse, createUserJson] =
await config.users.addMultiple(appUser)
const app = await config.applications.create(generateApp())
config.applications.api.appId = app.appId
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const body: User = {
...userInfoJson,
roles: {
[<string>app.appId]: "BASIC",
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[<string>app.appId]).toBeDefined()
expect(changedUserInfoJson.roles[<string>app.appId]).toEqual("BASIC")
@ -130,37 +152,43 @@ describe("Internal API - App Specific Roles & Permissions", () => {
)
await config.login(<string>appUser[0].email, <string>appUser[0].password)
const newColumn = generateNewColumnForTable(createdTableData)
await config.tables.forbiddenSave(
newColumn)
await config.tables.forbiddenSave(newColumn)
await config.tables.forbiddenSave(generateTable())
})
it("Check Table access for developer", async () => {
const developer = generateUser(1, 'developer')
const developer = generateUser(1, "developer")
expect(developer[0].builder?.global).toEqual(true)
const [createUserResponse, createUserJson] = await config.users.addMultiple(developer)
const [createUserResponse, createUserJson] =
await config.users.addMultiple(developer)
const app = await config.applications.create(generateApp())
config.applications.api.appId = app.appId
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const body: User = {
...userInfoJson,
roles: {
[<string>app.appId]: "POWER",
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[<string>app.appId]).toBeDefined()
expect(changedUserInfoJson.roles[<string>app.appId]).toEqual("POWER")
const [createdTableResponse, createdTableData] = await config.tables.save(
generateTable()
)
await config.login(<string>developer[0].email, <string>developer[0].password)
await config.login(
<string>developer[0].email,
<string>developer[0].password
)
const newColumn = generateNewColumnForTable(createdTableData)
const [addColumnResponse, addColumnData] = await config.tables.save(
newColumn,
@ -172,25 +200,32 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const adminUser = generateUser(1, "admin")
expect(adminUser[0].builder?.global).toEqual(true)
expect(adminUser[0].admin?.global).toEqual(true)
const [createUserResponse, createUserJson] = await config.users.addMultiple(adminUser)
const [createUserResponse, createUserJson] =
await config.users.addMultiple(adminUser)
const app = await config.applications.create(generateApp())
config.applications.api.appId = app.appId
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const body: User = {
...userInfoJson,
roles: {
[<string>app.appId]: "ADMIN",
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[<string>app.appId]).toBeDefined()
expect(changedUserInfoJson.roles[<string>app.appId]).toEqual("ADMIN")
await config.login(<string>adminUser[0].email, <string>adminUser[0].password)
await config.login(
<string>adminUser[0].email,
<string>adminUser[0].password
)
const [createdTableResponse, createdTableData] = await config.tables.save(
generateTable()
)
@ -208,14 +243,17 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
const [createUserResponse, createUserJson] =
await config.users.addMultiple(appUser)
// Create App
const app = await config.applications.create(generateApp())
config.applications.api.appId = app.appId
// Update user roles
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const prodAppId = db.getProdAppID(app.appId!)
// Roles must always be set with prod appID
@ -223,11 +261,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
...userInfoJson,
roles: {
[prodAppId]: "BASIC",
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
expect(changedUserInfoJson.roles[prodAppId]).toEqual("BASIC")
@ -236,7 +275,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
await config.screen.create(generateScreen("ADMIN"))
await config.applications.publish(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] =
await config.applications.getAppPackage(<string>app.appId)
expect(firstappPackageJson.screens).toBeDefined()
expect(firstappPackageJson.screens.length).toEqual(3)
@ -245,7 +285,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
// fetch app package
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
const [appPackageResponse, appPackageJson] =
await config.applications.getAppPackage(app.appId!)
expect(appPackageJson.screens).toBeDefined()
expect(appPackageJson.screens.length).toEqual(1)
expect(appPackageJson.screens[0].routing.roleId).toEqual("BASIC")
@ -256,14 +297,17 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
const [createUserResponse, createUserJson] =
await config.users.addMultiple(appUser)
// Create App
const app = await config.applications.create(generateApp())
config.applications.api.appId = app.appId
// Update user roles
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const prodAppId = db.getProdAppID(app.appId!)
// Roles must always be set with prod appID
@ -271,11 +315,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
...userInfoJson,
roles: {
[prodAppId]: "POWER",
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
expect(changedUserInfoJson.roles[prodAppId]).toEqual("POWER")
@ -284,7 +329,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
await config.screen.create(generateScreen("ADMIN"))
await config.applications.publish(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] =
await config.applications.getAppPackage(<string>app.appId)
expect(firstappPackageJson.screens).toBeDefined()
expect(firstappPackageJson.screens.length).toEqual(3)
@ -293,7 +339,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
// fetch app package
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
const [appPackageResponse, appPackageJson] =
await config.applications.getAppPackage(app.appId!)
expect(appPackageJson.screens).toBeDefined()
expect(appPackageJson.screens.length).toEqual(2)
})
@ -303,14 +350,17 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
const [createUserResponse, createUserJson] =
await config.users.addMultiple(appUser)
// Create App
const app = await config.applications.create(generateApp())
config.applications.api.appId = app.appId
// Update user roles
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const prodAppId = db.getProdAppID(app.appId!)
// Roles must always be set with prod appID
@ -318,11 +368,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
...userInfoJson,
roles: {
[prodAppId]: "ADMIN",
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
expect(changedUserInfoJson.roles[prodAppId]).toEqual("ADMIN")
@ -331,7 +382,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
await config.screen.create(generateScreen("ADMIN"))
await config.applications.publish(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] =
await config.applications.getAppPackage(<string>app.appId)
expect(firstappPackageJson.screens).toBeDefined()
expect(firstappPackageJson.screens.length).toEqual(3)
@ -340,7 +392,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
// fetch app package
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
const [appPackageResponse, appPackageJson] =
await config.applications.getAppPackage(app.appId!)
expect(appPackageJson.screens).toBeDefined()
expect(appPackageJson.screens.length).toEqual(3)
})
@ -351,7 +404,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
const [createUserResponse, createUserJson] =
await config.users.addMultiple(appUser)
// Create App
const app = await config.applications.create(generateApp())
@ -361,14 +415,15 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const role = {
inherits: "BASIC",
permissionId: "public",
name: "level 1"
name: "level 1",
}
const [createRoleResponse, createRoleJson] = await config.users.createRole(role)
const [createRoleResponse, createRoleJson] =
await config.users.createRole(role)
// Update user roles
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const prodAppId = db.getProdAppID(app.appId!)
// Roles must always be set with prod appID
@ -376,11 +431,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
...userInfoJson,
roles: {
[prodAppId]: createRoleJson._id,
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
expect(changedUserInfoJson.roles[prodAppId]).toEqual(createRoleJson._id)
@ -389,7 +445,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
await config.screen.create(generateScreen("ADMIN"))
await config.applications.publish(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] =
await config.applications.getAppPackage(<string>app.appId)
expect(firstappPackageJson.screens).toBeDefined()
expect(firstappPackageJson.screens.length).toEqual(3)
@ -398,15 +455,18 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
// fetch app package
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
const [appPackageResponse, appPackageJson] =
await config.applications.getAppPackage(app.appId!)
expect(appPackageJson.screens).toBeDefined()
expect(appPackageJson.screens.length).toEqual(1)
})
it("Custom role access for level 2 permissions", async () => {// Set up user
it("Custom role access for level 2 permissions", async () => {
// Set up user
const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
const [createUserResponse, createUserJson] =
await config.users.addMultiple(appUser)
// Create App
const app = await config.applications.create(generateApp())
@ -416,14 +476,15 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const role = {
inherits: "BASIC",
permissionId: "read_only",
name: "level 2"
name: "level 2",
}
const [createRoleResponse, createRoleJson] = await config.users.createRole(role)
const [createRoleResponse, createRoleJson] =
await config.users.createRole(role)
// Update user roles
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const prodAppId = db.getProdAppID(app.appId!)
// Roles must always be set with prod appID
@ -431,11 +492,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
...userInfoJson,
roles: {
[prodAppId]: createRoleJson._id,
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
expect(changedUserInfoJson.roles[prodAppId]).toEqual(createRoleJson._id)
@ -444,7 +506,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
await config.screen.create(generateScreen("ADMIN"))
await config.applications.publish(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] =
await config.applications.getAppPackage(<string>app.appId)
expect(firstappPackageJson.screens).toBeDefined()
expect(firstappPackageJson.screens.length).toEqual(3)
@ -453,7 +516,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
// fetch app package
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
const [appPackageResponse, appPackageJson] =
await config.applications.getAppPackage(app.appId!)
expect(appPackageJson.screens).toBeDefined()
expect(appPackageJson.screens.length).toEqual(1)
})
@ -461,7 +525,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
const [createUserResponse, createUserJson] =
await config.users.addMultiple(appUser)
// Create App
const app = await config.applications.create(generateApp())
@ -471,14 +536,15 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const role = {
inherits: "BASIC",
permissionId: "write",
name: "level 3"
name: "level 3",
}
const [createRoleResponse, createRoleJson] = await config.users.createRole(role)
const [createRoleResponse, createRoleJson] =
await config.users.createRole(role)
// Update user roles
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const prodAppId = db.getProdAppID(app.appId!)
// Roles must always be set with prod appID
@ -486,11 +552,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
...userInfoJson,
roles: {
[prodAppId]: createRoleJson._id,
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
expect(changedUserInfoJson.roles[prodAppId]).toEqual(createRoleJson._id)
@ -499,7 +566,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
await config.screen.create(generateScreen("ADMIN"))
await config.applications.publish(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] =
await config.applications.getAppPackage(<string>app.appId)
expect(firstappPackageJson.screens).toBeDefined()
expect(firstappPackageJson.screens.length).toEqual(3)
@ -508,7 +576,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
// fetch app package
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
const [appPackageResponse, appPackageJson] =
await config.applications.getAppPackage(app.appId!)
expect(appPackageJson.screens).toBeDefined()
expect(appPackageJson.screens.length).toEqual(1)
})
@ -516,7 +585,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
const [createUserResponse, createUserJson] =
await config.users.addMultiple(appUser)
// Create App
const app = await config.applications.create(generateApp())
@ -526,14 +596,15 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const role = {
inherits: "BASIC",
permissionId: "power",
name: "level 4"
name: "level 4",
}
const [createRoleResponse, createRoleJson] = await config.users.createRole(role)
const [createRoleResponse, createRoleJson] =
await config.users.createRole(role)
// Update user roles
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const prodAppId = db.getProdAppID(app.appId!)
// Roles must always be set with prod appID
@ -541,11 +612,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
...userInfoJson,
roles: {
[prodAppId]: createRoleJson._id,
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
expect(changedUserInfoJson.roles[prodAppId]).toEqual(createRoleJson._id)
@ -554,7 +626,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
await config.screen.create(generateScreen("ADMIN"))
await config.applications.publish(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] =
await config.applications.getAppPackage(<string>app.appId)
expect(firstappPackageJson.screens).toBeDefined()
expect(firstappPackageJson.screens.length).toEqual(3)
@ -563,7 +636,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
// fetch app package
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
const [appPackageResponse, appPackageJson] =
await config.applications.getAppPackage(app.appId!)
expect(appPackageJson.screens).toBeDefined()
expect(appPackageJson.screens.length).toEqual(1)
})
@ -571,7 +645,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
const [createUserResponse, createUserJson] =
await config.users.addMultiple(appUser)
// Create App
const app = await config.applications.create(generateApp())
@ -581,14 +656,15 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const role = {
inherits: "BASIC",
permissionId: "admin",
name: "level 5"
name: "level 5",
}
const [createRoleResponse, createRoleJson] = await config.users.createRole(role)
const [createRoleResponse, createRoleJson] =
await config.users.createRole(role)
// Update user roles
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const prodAppId = db.getProdAppID(app.appId!)
// Roles must always be set with prod appID
@ -596,11 +672,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
...userInfoJson,
roles: {
[prodAppId]: createRoleJson._id,
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
expect(changedUserInfoJson.roles[prodAppId]).toEqual(createRoleJson._id)
@ -609,7 +686,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
await config.screen.create(generateScreen("ADMIN"))
await config.applications.publish(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] =
await config.applications.getAppPackage(<string>app.appId)
expect(firstappPackageJson.screens).toBeDefined()
expect(firstappPackageJson.screens.length).toEqual(3)
@ -618,10 +696,10 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
// fetch app package
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
const [appPackageResponse, appPackageJson] =
await config.applications.getAppPackage(app.appId!)
expect(appPackageJson.screens).toBeDefined()
expect(appPackageJson.screens.length).toEqual(1)
})
})
})

View File

@ -36,9 +36,6 @@ describe("Internal API - User Management & Permissions", () => {
const [allUsersResponse, allUsersJson] = await config.users.getAll()
expect(allUsersJson.length).toBeGreaterThan(0)
})
it("Delete User", async () => {
@ -55,11 +52,12 @@ describe("Internal API - User Management & Permissions", () => {
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 [userInfoResponse, userInfoJson] = await config.users.getInfo(
userJson.created.successful[0]._id
)
const body: User = {
...userInfoJson,
password: "newPassword"
password: "newPassword",
}
await config.users.forcePasswordReset(body)
})
@ -69,22 +67,22 @@ describe("Internal API - User Management & Permissions", () => {
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 [userInfoResponse, userInfoJson] = await config.users.getInfo(
userJson.created.successful[0]._id
)
const body: User = {
...userInfoJson,
firstName: "newFirstName",
lastName: "newLastName",
builder: {
global: true
}
global: true,
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(userJson.created.successful[0]._id)
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 () => {
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)