@budibase/server 2.4.42-alpha.3 → 2.4.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__mocks__/node-fetch.ts +1 -6
- package/builder/assets/favicon.e7fc7733.png +0 -0
- package/builder/assets/{index.7fec1a6d.js → index.3d64bc07.js} +384 -384
- package/builder/assets/index.b0e3aca6.css +6 -0
- package/builder/index.html +7 -7
- package/dist/api/controllers/application.js +24 -28
- package/dist/api/controllers/row/external.js +0 -15
- package/dist/api/controllers/row/utils.js +3 -4
- package/dist/api/controllers/static/index.js +24 -84
- package/dist/api/controllers/static/templates/BudibaseApp.svelte +10 -33
- package/dist/api/controllers/table/utils.js +1 -0
- package/dist/api/routes/public/index.js +0 -8
- package/dist/app.js +0 -1
- package/dist/integrations/redis.js +1 -1
- package/dist/package.json +12 -13
- package/dist/sdk/users/utils.js +1 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utilities/global.js +7 -17
- package/jest.config.ts +0 -1
- package/package.json +13 -14
- package/scripts/test.sh +3 -3
- package/specs/openapi.json +0 -39
- package/specs/openapi.yaml +0 -169
- package/specs/resources/application.ts +0 -11
- package/specs/resources/index.ts +0 -2
- package/src/api/controllers/application.ts +21 -20
- package/src/api/controllers/row/external.ts +0 -14
- package/src/api/controllers/row/utils.ts +3 -4
- package/src/api/controllers/static/index.ts +26 -69
- package/src/api/controllers/static/templates/BudibaseApp.svelte +10 -33
- package/src/api/controllers/table/utils.ts +1 -0
- package/src/api/controllers/view/tests/__snapshots__/viewBuilder.spec.js.snap +48 -48
- package/src/api/routes/public/index.ts +1 -10
- package/src/api/routes/tests/__snapshots__/datasource.spec.ts.snap +22 -22
- package/src/api/routes/tests/__snapshots__/view.spec.js.snap +5 -5
- package/src/api/routes/tests/internalSearch.spec.js +7 -8
- package/src/app.ts +1 -2
- package/src/automations/automationUtils.ts +1 -1
- package/src/automations/tests/automation.spec.js +84 -0
- package/src/definitions/openapi.ts +0 -15
- package/src/integration-test/postgres.spec.ts +52 -46
- package/src/integrations/redis.ts +1 -1
- package/src/integrations/tests/googlesheets.spec.ts +13 -13
- package/src/integrations/tests/redis.spec.ts +5 -9
- package/src/middleware/currentapp.ts +2 -2
- package/src/sdk/users/utils.ts +1 -4
- package/src/tests/jestEnv.ts +0 -1
- package/src/tests/jestSetup.ts +1 -5
- package/src/tests/utilities/TestConfiguration.ts +0 -13
- package/src/tests/utilities/structures.ts +1 -13
- package/src/utilities/global.ts +9 -21
- package/builder/assets/index.3cb1022d.css +0 -6
- package/dist/api/controllers/public/metrics.js +0 -113
- package/dist/api/routes/public/metrics.js +0 -30
- package/specs/resources/metrics.ts +0 -81
- package/src/api/controllers/public/metrics.ts +0 -251
- package/src/api/routes/public/metrics.ts +0 -28
- package/src/api/routes/public/tests/metrics.spec.js +0 -34
- package/src/api/routes/tests/appSync.spec.ts +0 -31
- package/src/automations/tests/automation.spec.ts +0 -99
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
jest.mock("../../threads/automation")
|
|
2
|
+
jest.mock("../../utilities/redis", () => ({
|
|
3
|
+
init: jest.fn(),
|
|
4
|
+
checkTestFlag: () => {
|
|
5
|
+
return false
|
|
6
|
+
},
|
|
7
|
+
}))
|
|
8
|
+
|
|
9
|
+
jest.spyOn(global.console, "error")
|
|
10
|
+
|
|
11
|
+
require("../../environment")
|
|
12
|
+
const automation = require("../index")
|
|
13
|
+
const thread = require("../../threads/automation")
|
|
14
|
+
const triggers = require("../triggers")
|
|
15
|
+
const { basicAutomation } = require("../../tests/utilities/structures")
|
|
16
|
+
const { wait } = require("../../utilities")
|
|
17
|
+
const { makePartial } = require("../../tests/utilities")
|
|
18
|
+
const { cleanInputValues } = require("../automationUtils")
|
|
19
|
+
const setup = require("./utilities")
|
|
20
|
+
|
|
21
|
+
describe("Run through some parts of the automations system", () => {
|
|
22
|
+
let config = setup.getConfig()
|
|
23
|
+
|
|
24
|
+
beforeAll(async () => {
|
|
25
|
+
await automation.init()
|
|
26
|
+
await config.init()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
afterAll(setup.afterAll)
|
|
30
|
+
|
|
31
|
+
it("should be able to init in builder", async () => {
|
|
32
|
+
await triggers.externalTrigger(basicAutomation(), { a: 1, appId: config.appId })
|
|
33
|
+
await wait(100)
|
|
34
|
+
expect(thread.execute).toHaveBeenCalled()
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it("should check coercion", async () => {
|
|
38
|
+
const table = await config.createTable()
|
|
39
|
+
const automation = basicAutomation()
|
|
40
|
+
automation.definition.trigger.inputs.tableId = table._id
|
|
41
|
+
automation.definition.trigger.stepId = "APP"
|
|
42
|
+
automation.definition.trigger.inputs.fields = { a: "number" }
|
|
43
|
+
await triggers.externalTrigger(automation, {
|
|
44
|
+
appId: config.getAppId(),
|
|
45
|
+
fields: {
|
|
46
|
+
a: "1"
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
await wait(100)
|
|
50
|
+
expect(thread.execute).toHaveBeenCalledWith(makePartial({
|
|
51
|
+
data: {
|
|
52
|
+
event: {
|
|
53
|
+
fields: {
|
|
54
|
+
a: 1
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}), expect.any(Function))
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it("should be able to clean inputs with the utilities", () => {
|
|
62
|
+
// can't clean without a schema
|
|
63
|
+
let output = cleanInputValues({a: "1"})
|
|
64
|
+
expect(output.a).toBe("1")
|
|
65
|
+
output = cleanInputValues({a: "1", b: "true", c: "false", d: 1, e: "help"}, {
|
|
66
|
+
properties: {
|
|
67
|
+
a: {
|
|
68
|
+
type: "number",
|
|
69
|
+
},
|
|
70
|
+
b: {
|
|
71
|
+
type: "boolean",
|
|
72
|
+
},
|
|
73
|
+
c: {
|
|
74
|
+
type: "boolean",
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
expect(output.a).toBe(1)
|
|
79
|
+
expect(output.b).toBe(true)
|
|
80
|
+
expect(output.c).toBe(false)
|
|
81
|
+
expect(output.d).toBe(1)
|
|
82
|
+
expect(output.e).toBe("help")
|
|
83
|
+
})
|
|
84
|
+
})
|
|
@@ -22,10 +22,6 @@ export interface paths {
|
|
|
22
22
|
/** Based on application properties (currently only name) search for applications. */
|
|
23
23
|
post: operations["appSearch"];
|
|
24
24
|
};
|
|
25
|
-
"/metrics": {
|
|
26
|
-
/** Output metrics in OpenMetrics format compatible with Prometheus */
|
|
27
|
-
get: operations["metricsGet"];
|
|
28
|
-
};
|
|
29
25
|
"/queries/{queryId}": {
|
|
30
26
|
/** Queries which have been created within a Budibase app can be executed using this, */
|
|
31
27
|
post: operations["queryExecute"];
|
|
@@ -848,17 +844,6 @@ export interface operations {
|
|
|
848
844
|
};
|
|
849
845
|
};
|
|
850
846
|
};
|
|
851
|
-
/** Output metrics in OpenMetrics format compatible with Prometheus */
|
|
852
|
-
metricsGet: {
|
|
853
|
-
responses: {
|
|
854
|
-
/** Returns tenant metrics. */
|
|
855
|
-
200: {
|
|
856
|
-
content: {
|
|
857
|
-
"text/plain": string;
|
|
858
|
-
};
|
|
859
|
-
};
|
|
860
|
-
};
|
|
861
|
-
};
|
|
862
847
|
/** Queries which have been created within a Budibase app can be executed using this, */
|
|
863
848
|
queryExecute: {
|
|
864
849
|
parameters: {
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import fetch from "node-fetch"
|
|
2
|
-
// @ts-ignore
|
|
3
|
-
fetch.mockSearch()
|
|
4
1
|
import {
|
|
5
2
|
generateMakeRequest,
|
|
6
3
|
MakeRequestResponse,
|
|
@@ -19,7 +16,6 @@ import _ from "lodash"
|
|
|
19
16
|
import { generator } from "@budibase/backend-core/tests"
|
|
20
17
|
import { utils } from "@budibase/backend-core"
|
|
21
18
|
import { GenericContainer } from "testcontainers"
|
|
22
|
-
import { generateRowIdField } from "../integrations/utils"
|
|
23
19
|
|
|
24
20
|
const config = setup.getConfig()!
|
|
25
21
|
|
|
@@ -84,10 +80,16 @@ describe("row api - postgres", () => {
|
|
|
84
80
|
name: "id",
|
|
85
81
|
type: FieldType.AUTO,
|
|
86
82
|
autocolumn: true,
|
|
83
|
+
constraints: {
|
|
84
|
+
presence: true,
|
|
85
|
+
},
|
|
87
86
|
},
|
|
88
87
|
title: {
|
|
89
88
|
name: "title",
|
|
90
89
|
type: FieldType.STRING,
|
|
90
|
+
constraints: {
|
|
91
|
+
presence: true,
|
|
92
|
+
},
|
|
91
93
|
},
|
|
92
94
|
},
|
|
93
95
|
sourceId: postgresDatasource._id,
|
|
@@ -119,10 +121,16 @@ describe("row api - postgres", () => {
|
|
|
119
121
|
name: "id",
|
|
120
122
|
type: FieldType.AUTO,
|
|
121
123
|
autocolumn: true,
|
|
124
|
+
constraints: {
|
|
125
|
+
presence: true,
|
|
126
|
+
},
|
|
122
127
|
},
|
|
123
128
|
name: {
|
|
124
129
|
name: "name",
|
|
125
130
|
type: FieldType.STRING,
|
|
131
|
+
constraints: {
|
|
132
|
+
presence: true,
|
|
133
|
+
},
|
|
126
134
|
},
|
|
127
135
|
description: {
|
|
128
136
|
name: "description",
|
|
@@ -136,6 +144,7 @@ describe("row api - postgres", () => {
|
|
|
136
144
|
type: FieldType.LINK,
|
|
137
145
|
constraints: {
|
|
138
146
|
type: "array",
|
|
147
|
+
presence: false,
|
|
139
148
|
},
|
|
140
149
|
fieldName: oneToManyRelationshipInfo.fieldName,
|
|
141
150
|
name: "oneToManyRelation",
|
|
@@ -147,6 +156,7 @@ describe("row api - postgres", () => {
|
|
|
147
156
|
type: FieldType.LINK,
|
|
148
157
|
constraints: {
|
|
149
158
|
type: "array",
|
|
159
|
+
presence: false,
|
|
150
160
|
},
|
|
151
161
|
fieldName: manyToOneRelationshipInfo.fieldName,
|
|
152
162
|
name: "manyToOneRelation",
|
|
@@ -158,6 +168,7 @@ describe("row api - postgres", () => {
|
|
|
158
168
|
type: FieldType.LINK,
|
|
159
169
|
constraints: {
|
|
160
170
|
type: "array",
|
|
171
|
+
presence: false,
|
|
161
172
|
},
|
|
162
173
|
fieldName: manyToManyRelationshipInfo.fieldName,
|
|
163
174
|
name: "manyToManyRelation",
|
|
@@ -298,6 +309,9 @@ describe("row api - postgres", () => {
|
|
|
298
309
|
id: {
|
|
299
310
|
name: "id",
|
|
300
311
|
type: FieldType.AUTO,
|
|
312
|
+
constraints: {
|
|
313
|
+
presence: true,
|
|
314
|
+
},
|
|
301
315
|
},
|
|
302
316
|
},
|
|
303
317
|
sourceId: postgresDatasource._id,
|
|
@@ -907,55 +921,47 @@ describe("row api - postgres", () => {
|
|
|
907
921
|
foreignRows,
|
|
908
922
|
x => x.relationshipType
|
|
909
923
|
)
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
)
|
|
916
|
-
const m2mRow2 = res.body[m2mFieldName].find(
|
|
917
|
-
(row: Row) => row.id === 2
|
|
918
|
-
)
|
|
919
|
-
expect(m2mRow1).toEqual({
|
|
920
|
-
...foreignRowsByType[RelationshipTypes.MANY_TO_MANY][0].row,
|
|
921
|
-
[m2mFieldName]: [
|
|
924
|
+
expect(res.body).toEqual({
|
|
925
|
+
...rowData,
|
|
926
|
+
[`fk_${oneToManyRelationshipInfo.table.name}_${oneToManyRelationshipInfo.fieldName}`]:
|
|
927
|
+
foreignRowsByType[RelationshipTypes.ONE_TO_MANY][0].row.id,
|
|
928
|
+
[oneToManyRelationshipInfo.fieldName]: [
|
|
922
929
|
{
|
|
923
|
-
|
|
930
|
+
...foreignRowsByType[RelationshipTypes.ONE_TO_MANY][0].row,
|
|
931
|
+
_id: expect.any(String),
|
|
932
|
+
_rev: expect.any(String),
|
|
924
933
|
},
|
|
925
934
|
],
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
935
|
+
[manyToOneRelationshipInfo.fieldName]: [
|
|
936
|
+
{
|
|
937
|
+
...foreignRowsByType[RelationshipTypes.MANY_TO_ONE][0].row,
|
|
938
|
+
[`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
|
|
939
|
+
row.id,
|
|
940
|
+
},
|
|
930
941
|
{
|
|
931
|
-
|
|
942
|
+
...foreignRowsByType[RelationshipTypes.MANY_TO_ONE][1].row,
|
|
943
|
+
[`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
|
|
944
|
+
row.id,
|
|
945
|
+
},
|
|
946
|
+
{
|
|
947
|
+
...foreignRowsByType[RelationshipTypes.MANY_TO_ONE][2].row,
|
|
948
|
+
[`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
|
|
949
|
+
row.id,
|
|
950
|
+
},
|
|
951
|
+
],
|
|
952
|
+
[manyToManyRelationshipInfo.fieldName]: [
|
|
953
|
+
{
|
|
954
|
+
...foreignRowsByType[RelationshipTypes.MANY_TO_MANY][0].row,
|
|
955
|
+
},
|
|
956
|
+
{
|
|
957
|
+
...foreignRowsByType[RelationshipTypes.MANY_TO_MANY][1].row,
|
|
932
958
|
},
|
|
933
959
|
],
|
|
960
|
+
id: row.id,
|
|
961
|
+
tableId: row.tableId,
|
|
962
|
+
_id: expect.any(String),
|
|
963
|
+
_rev: expect.any(String),
|
|
934
964
|
})
|
|
935
|
-
expect(res.body[m2oFieldName]).toEqual([
|
|
936
|
-
{
|
|
937
|
-
...foreignRowsByType[RelationshipTypes.MANY_TO_ONE][0].row,
|
|
938
|
-
[`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
|
|
939
|
-
row.id,
|
|
940
|
-
},
|
|
941
|
-
{
|
|
942
|
-
...foreignRowsByType[RelationshipTypes.MANY_TO_ONE][1].row,
|
|
943
|
-
[`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
|
|
944
|
-
row.id,
|
|
945
|
-
},
|
|
946
|
-
{
|
|
947
|
-
...foreignRowsByType[RelationshipTypes.MANY_TO_ONE][2].row,
|
|
948
|
-
[`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
|
|
949
|
-
row.id,
|
|
950
|
-
},
|
|
951
|
-
])
|
|
952
|
-
expect(res.body[o2mFieldName]).toEqual([
|
|
953
|
-
{
|
|
954
|
-
...foreignRowsByType[RelationshipTypes.ONE_TO_MANY][0].row,
|
|
955
|
-
_id: expect.any(String),
|
|
956
|
-
_rev: expect.any(String),
|
|
957
|
-
},
|
|
958
|
-
])
|
|
959
965
|
})
|
|
960
966
|
})
|
|
961
967
|
})
|
|
@@ -39,10 +39,6 @@ describe("Google Sheets Integration", () => {
|
|
|
39
39
|
config.setGoogleAuth("test")
|
|
40
40
|
})
|
|
41
41
|
|
|
42
|
-
afterAll(async () => {
|
|
43
|
-
await config.end()
|
|
44
|
-
})
|
|
45
|
-
|
|
46
42
|
beforeEach(async () => {
|
|
47
43
|
integration = new GoogleSheetsIntegration.integration({
|
|
48
44
|
spreadsheetId: "randomId",
|
|
@@ -103,8 +99,8 @@ describe("Google Sheets Integration", () => {
|
|
|
103
99
|
})
|
|
104
100
|
})
|
|
105
101
|
|
|
106
|
-
test("removing an existing field will remove the
|
|
107
|
-
|
|
102
|
+
test("removing an existing field will not remove the data from the spreadsheet", async () => {
|
|
103
|
+
await config.doInContext(structures.uuid(), async () => {
|
|
108
104
|
const tableColumns = ["name"]
|
|
109
105
|
const table = createBasicTable(structures.uuid(), tableColumns)
|
|
110
106
|
|
|
@@ -113,14 +109,18 @@ describe("Google Sheets Integration", () => {
|
|
|
113
109
|
})
|
|
114
110
|
sheetsByTitle[table.name] = sheet
|
|
115
111
|
await integration.updateTable(table)
|
|
116
|
-
return sheet
|
|
117
|
-
})
|
|
118
|
-
expect(sheet.loadHeaderRow).toBeCalledTimes(1)
|
|
119
|
-
expect(sheet.setHeaderRow).toBeCalledTimes(1)
|
|
120
|
-
expect(sheet.setHeaderRow).toBeCalledWith(["name"])
|
|
121
112
|
|
|
122
|
-
|
|
123
|
-
|
|
113
|
+
expect(sheet.loadHeaderRow).toBeCalledTimes(1)
|
|
114
|
+
expect(sheet.setHeaderRow).toBeCalledTimes(1)
|
|
115
|
+
expect(sheet.setHeaderRow).toBeCalledWith([
|
|
116
|
+
"name",
|
|
117
|
+
"description",
|
|
118
|
+
"location",
|
|
119
|
+
])
|
|
120
|
+
|
|
121
|
+
// No undefineds are sent
|
|
122
|
+
expect((sheet.setHeaderRow as any).mock.calls[0][0]).toHaveLength(3)
|
|
123
|
+
})
|
|
124
124
|
})
|
|
125
125
|
})
|
|
126
126
|
})
|
|
@@ -3,17 +3,17 @@ import { default as RedisIntegration } from "../redis"
|
|
|
3
3
|
|
|
4
4
|
class TestConfiguration {
|
|
5
5
|
integration: any
|
|
6
|
+
redis: any
|
|
6
7
|
|
|
7
8
|
constructor(config: any = {}) {
|
|
8
9
|
this.integration = new RedisIntegration.integration(config)
|
|
9
|
-
|
|
10
|
-
this.integration.client.quit()
|
|
11
|
-
this.integration.client = new Redis({
|
|
10
|
+
this.redis = new Redis({
|
|
12
11
|
data: {
|
|
13
12
|
test: "test",
|
|
14
13
|
result: "1",
|
|
15
14
|
},
|
|
16
15
|
})
|
|
16
|
+
this.integration.client = this.redis
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -24,17 +24,13 @@ describe("Redis Integration", () => {
|
|
|
24
24
|
config = new TestConfiguration()
|
|
25
25
|
})
|
|
26
26
|
|
|
27
|
-
afterAll(() => {
|
|
28
|
-
config.integration.disconnect()
|
|
29
|
-
})
|
|
30
|
-
|
|
31
27
|
it("calls the create method with the correct params", async () => {
|
|
32
28
|
const body = {
|
|
33
29
|
key: "key",
|
|
34
30
|
value: "value",
|
|
35
31
|
}
|
|
36
32
|
await config.integration.create(body)
|
|
37
|
-
expect(await config.
|
|
33
|
+
expect(await config.redis.get("key")).toEqual("value")
|
|
38
34
|
})
|
|
39
35
|
|
|
40
36
|
it("calls the read method with the correct params", async () => {
|
|
@@ -50,7 +46,7 @@ describe("Redis Integration", () => {
|
|
|
50
46
|
key: "test",
|
|
51
47
|
}
|
|
52
48
|
await config.integration.delete(body)
|
|
53
|
-
expect(await config.
|
|
49
|
+
expect(await config.redis.get(body.key)).toEqual(null)
|
|
54
50
|
})
|
|
55
51
|
|
|
56
52
|
it("calls the pipeline method with the correct params", async () => {
|
|
@@ -10,9 +10,9 @@ import { generateUserMetadataID, isDevAppID } from "../db/utils"
|
|
|
10
10
|
import { getCachedSelf } from "../utilities/global"
|
|
11
11
|
import env from "../environment"
|
|
12
12
|
import { isWebhookEndpoint } from "./utils"
|
|
13
|
-
import {
|
|
13
|
+
import { BBContext } from "@budibase/types"
|
|
14
14
|
|
|
15
|
-
export default async (ctx:
|
|
15
|
+
export default async (ctx: BBContext, next: any) => {
|
|
16
16
|
// try to get the appID from the request
|
|
17
17
|
let requestAppId = await utils.getAppIdFromCtx(ctx)
|
|
18
18
|
// get app cookie if it exists
|
package/src/sdk/users/utils.ts
CHANGED
|
@@ -9,10 +9,7 @@ import { isEqual } from "lodash"
|
|
|
9
9
|
|
|
10
10
|
export function combineMetadataAndUser(user: any, metadata: any) {
|
|
11
11
|
// skip users with no access
|
|
12
|
-
if (
|
|
13
|
-
user.roleId == null ||
|
|
14
|
-
user.roleId === rolesCore.BUILTIN_ROLE_IDS.PUBLIC
|
|
15
|
-
) {
|
|
12
|
+
if (user.roleId === rolesCore.BUILTIN_ROLE_IDS.PUBLIC) {
|
|
16
13
|
return null
|
|
17
14
|
}
|
|
18
15
|
delete user._rev
|
package/src/tests/jestEnv.ts
CHANGED
package/src/tests/jestSetup.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./logging"
|
|
2
2
|
import env from "../environment"
|
|
3
|
-
import { env as coreEnv
|
|
3
|
+
import { env as coreEnv } from "@budibase/backend-core"
|
|
4
4
|
import { testContainerUtils } from "@budibase/backend-core/tests"
|
|
5
5
|
|
|
6
6
|
if (!process.env.DEBUG) {
|
|
@@ -17,7 +17,3 @@ if (!process.env.CI) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
testContainerUtils.setupEnv(env, coreEnv)
|
|
20
|
-
|
|
21
|
-
afterAll(() => {
|
|
22
|
-
timers.cleanup()
|
|
23
|
-
})
|
|
@@ -46,7 +46,6 @@ import {
|
|
|
46
46
|
Row,
|
|
47
47
|
SourceName,
|
|
48
48
|
Table,
|
|
49
|
-
SearchFilters,
|
|
50
49
|
} from "@budibase/types"
|
|
51
50
|
|
|
52
51
|
type DefaultUserValues = {
|
|
@@ -165,8 +164,6 @@ class TestConfiguration {
|
|
|
165
164
|
}
|
|
166
165
|
if (this.server) {
|
|
167
166
|
this.server.close()
|
|
168
|
-
} else {
|
|
169
|
-
require("../../app").default.close()
|
|
170
167
|
}
|
|
171
168
|
if (this.allApps) {
|
|
172
169
|
cleanup(this.allApps.map(app => app.appId))
|
|
@@ -571,16 +568,6 @@ class TestConfiguration {
|
|
|
571
568
|
return this._req(null, { tableId }, controllers.row.fetch)
|
|
572
569
|
}
|
|
573
570
|
|
|
574
|
-
async searchRows(tableId: string, searchParams: SearchFilters = {}) {
|
|
575
|
-
if (!tableId && this.table) {
|
|
576
|
-
tableId = this.table._id
|
|
577
|
-
}
|
|
578
|
-
const body = {
|
|
579
|
-
query: searchParams,
|
|
580
|
-
}
|
|
581
|
-
return this._req(body, { tableId }, controllers.row.search)
|
|
582
|
-
}
|
|
583
|
-
|
|
584
571
|
// ROLE
|
|
585
572
|
|
|
586
573
|
async createRole(config?: any) {
|
|
@@ -106,7 +106,7 @@ export function newAutomation({ steps, trigger }: any = {}) {
|
|
|
106
106
|
return automation
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
export function basicAutomation(
|
|
109
|
+
export function basicAutomation() {
|
|
110
110
|
return {
|
|
111
111
|
name: "My Automation",
|
|
112
112
|
screenId: "kasdkfldsafkl",
|
|
@@ -114,23 +114,11 @@ export function basicAutomation(appId?: string) {
|
|
|
114
114
|
uiTree: {},
|
|
115
115
|
definition: {
|
|
116
116
|
trigger: {
|
|
117
|
-
stepId: AutomationTriggerStepId.APP,
|
|
118
|
-
name: "test",
|
|
119
|
-
tagline: "test",
|
|
120
|
-
icon: "test",
|
|
121
|
-
description: "test",
|
|
122
|
-
type: "trigger",
|
|
123
|
-
id: "test",
|
|
124
117
|
inputs: {},
|
|
125
|
-
schema: {
|
|
126
|
-
inputs: {},
|
|
127
|
-
outputs: {},
|
|
128
|
-
},
|
|
129
118
|
},
|
|
130
119
|
steps: [],
|
|
131
120
|
},
|
|
132
121
|
type: "automation",
|
|
133
|
-
appId,
|
|
134
122
|
}
|
|
135
123
|
}
|
|
136
124
|
|
package/src/utilities/global.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from "@budibase/backend-core"
|
|
9
9
|
import env from "../environment"
|
|
10
10
|
import { groups } from "@budibase/pro"
|
|
11
|
-
import {
|
|
11
|
+
import { BBContext, ContextUser, User } from "@budibase/types"
|
|
12
12
|
|
|
13
13
|
export function updateAppRole(
|
|
14
14
|
user: ContextUser,
|
|
@@ -43,40 +43,33 @@ export function updateAppRole(
|
|
|
43
43
|
|
|
44
44
|
async function checkGroupRoles(
|
|
45
45
|
user: ContextUser,
|
|
46
|
-
|
|
46
|
+
{ appId }: { appId?: string } = {}
|
|
47
47
|
) {
|
|
48
48
|
if (user.roleId && user.roleId !== roles.BUILTIN_ROLE_IDS.PUBLIC) {
|
|
49
49
|
return user
|
|
50
50
|
}
|
|
51
|
-
if (
|
|
52
|
-
user.roleId = await groups.getGroupRoleId(user as User,
|
|
53
|
-
groups: opts.groups,
|
|
54
|
-
})
|
|
55
|
-
}
|
|
56
|
-
// final fallback, simply couldn't find a role - user must be public
|
|
57
|
-
if (!user.roleId) {
|
|
58
|
-
user.roleId = roles.BUILTIN_ROLE_IDS.PUBLIC
|
|
51
|
+
if (appId) {
|
|
52
|
+
user.roleId = await groups.getGroupRoleId(user as User, appId)
|
|
59
53
|
}
|
|
60
54
|
return user
|
|
61
55
|
}
|
|
62
56
|
|
|
63
57
|
async function processUser(
|
|
64
58
|
user: ContextUser,
|
|
65
|
-
|
|
59
|
+
{ appId }: { appId?: string } = {}
|
|
66
60
|
) {
|
|
67
61
|
if (user) {
|
|
68
62
|
delete user.password
|
|
69
63
|
}
|
|
70
|
-
|
|
71
|
-
user = updateAppRole(user, { appId })
|
|
64
|
+
user = await updateAppRole(user, { appId })
|
|
72
65
|
if (!user.roleId && user?.userGroups?.length) {
|
|
73
|
-
user = await checkGroupRoles(user, { appId
|
|
66
|
+
user = await checkGroupRoles(user, { appId })
|
|
74
67
|
}
|
|
75
68
|
|
|
76
69
|
return user
|
|
77
70
|
}
|
|
78
71
|
|
|
79
|
-
export async function getCachedSelf(ctx:
|
|
72
|
+
export async function getCachedSelf(ctx: BBContext, appId: string) {
|
|
80
73
|
// this has to be tenant aware, can't depend on the context to find it out
|
|
81
74
|
// running some middlewares before the tenancy causes context to break
|
|
82
75
|
const user = await cache.user.getUser(ctx.user?._id!)
|
|
@@ -97,7 +90,6 @@ export async function getGlobalUser(userId: string) {
|
|
|
97
90
|
export async function getGlobalUsers(users?: ContextUser[]) {
|
|
98
91
|
const appId = context.getAppId()
|
|
99
92
|
const db = tenancy.getGlobalDB()
|
|
100
|
-
const allGroups = await groups.fetch()
|
|
101
93
|
let globalUsers
|
|
102
94
|
if (users) {
|
|
103
95
|
const globalIds = users.map(user =>
|
|
@@ -126,11 +118,7 @@ export async function getGlobalUsers(users?: ContextUser[]) {
|
|
|
126
118
|
return globalUsers
|
|
127
119
|
}
|
|
128
120
|
|
|
129
|
-
|
|
130
|
-
// each user individually
|
|
131
|
-
return Promise.all(
|
|
132
|
-
globalUsers.map(user => processUser(user, { groups: allGroups }))
|
|
133
|
-
)
|
|
121
|
+
return globalUsers.map(user => updateAppRole(user))
|
|
134
122
|
}
|
|
135
123
|
|
|
136
124
|
export async function getGlobalUsersFromMetadata(users: ContextUser[]) {
|