@budibase/server 2.5.6-alpha.1 → 2.5.6-alpha.10
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/builder/assets/{index.1fe52b59.js → index.5c1a6913.js} +361 -361
- package/builder/assets/index.c0265b74.css +6 -0
- package/builder/index.html +2 -2
- package/dist/api/controllers/automation.js +13 -7
- package/dist/api/controllers/plugin/index.js +6 -37
- package/dist/api/controllers/table/utils.js +2 -1
- package/dist/api/controllers/user.js +1 -83
- package/dist/api/routes/user.js +0 -1
- package/dist/app.js +2 -2
- package/dist/automations/actions.js +32 -6
- package/dist/automations/index.js +3 -2
- package/dist/automations/steps/bash.js +6 -6
- package/dist/automations/steps/createRow.js +11 -11
- package/dist/automations/steps/delay.js +3 -3
- package/dist/automations/steps/deleteRow.js +8 -8
- package/dist/automations/steps/discord.js +8 -8
- package/dist/automations/steps/executeQuery.js +9 -9
- package/dist/automations/steps/executeScript.js +6 -6
- package/dist/automations/steps/filter.js +6 -6
- package/dist/automations/steps/integromat.js +10 -10
- package/dist/automations/steps/loop.js +9 -9
- package/dist/automations/steps/outgoingWebhook.js +10 -10
- package/dist/automations/steps/queryRows.js +14 -14
- package/dist/automations/steps/sendSmtpEmail.js +9 -9
- package/dist/automations/steps/serverLog.js +4 -4
- package/dist/automations/steps/slack.js +6 -6
- package/dist/automations/steps/updateRow.js +11 -11
- package/dist/automations/steps/zapier.js +9 -9
- package/dist/automations/triggerInfo/app.js +5 -5
- package/dist/automations/triggerInfo/cron.js +4 -4
- package/dist/automations/triggerInfo/rowDeleted.js +5 -5
- package/dist/automations/triggerInfo/rowSaved.js +7 -7
- package/dist/automations/triggerInfo/rowUpdated.js +7 -7
- package/dist/automations/triggerInfo/webhook.js +6 -6
- package/dist/events/docUpdates/index.js +17 -0
- package/dist/events/docUpdates/processors.js +18 -0
- package/dist/events/docUpdates/syncUsers.js +49 -0
- package/dist/events/index.js +3 -0
- package/dist/integrations/index.js +3 -3
- package/dist/package.json +9 -8
- package/dist/sdk/app/applications/sync.js +117 -23
- package/dist/sdk/index.js +2 -0
- package/dist/sdk/plugins/index.js +27 -0
- package/dist/sdk/plugins/plugins.js +53 -0
- package/dist/sdk/users/utils.js +21 -4
- package/dist/startup.js +2 -1
- package/dist/threads/automation.js +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utilities/fileSystem/plugin.js +33 -23
- package/dist/utilities/global.js +17 -12
- package/dist/watch.js +2 -2
- package/dist/websockets/client.js +14 -0
- package/dist/websockets/grid.js +60 -0
- package/dist/websockets/index.js +17 -0
- package/dist/websockets/websocket.js +78 -0
- package/jest.config.ts +3 -3
- package/nodemon.json +7 -3
- package/package.json +10 -9
- package/src/api/controllers/automation.ts +12 -6
- package/src/api/controllers/plugin/index.ts +8 -45
- package/src/api/controllers/row/internal.ts +9 -10
- package/src/api/controllers/row/utils.ts +2 -2
- package/src/api/controllers/table/utils.ts +2 -1
- package/src/api/controllers/user.ts +10 -96
- package/src/api/routes/tests/automation.spec.js +2 -2
- package/src/api/routes/tests/user.spec.js +0 -37
- package/src/api/routes/user.ts +0 -5
- package/src/app.ts +2 -2
- package/src/automations/actions.ts +56 -24
- package/src/automations/index.ts +1 -1
- package/src/automations/steps/bash.ts +10 -7
- package/src/automations/steps/createRow.ts +15 -12
- package/src/automations/steps/delay.ts +6 -4
- package/src/automations/steps/deleteRow.ts +12 -9
- package/src/automations/steps/discord.ts +10 -8
- package/src/automations/steps/executeQuery.ts +13 -10
- package/src/automations/steps/executeScript.ts +10 -7
- package/src/automations/steps/filter.ts +8 -6
- package/src/automations/steps/integromat.ts +12 -10
- package/src/automations/steps/loop.ts +16 -10
- package/src/automations/steps/outgoingWebhook.ts +14 -11
- package/src/automations/steps/queryRows.ts +18 -15
- package/src/automations/steps/sendSmtpEmail.ts +11 -9
- package/src/automations/steps/serverLog.ts +6 -4
- package/src/automations/steps/slack.ts +8 -6
- package/src/automations/steps/updateRow.ts +15 -12
- package/src/automations/steps/zapier.ts +11 -9
- package/src/automations/tests/utilities/index.ts +2 -2
- package/src/automations/triggerInfo/app.ts +8 -5
- package/src/automations/triggerInfo/cron.ts +7 -4
- package/src/automations/triggerInfo/rowDeleted.ts +8 -5
- package/src/automations/triggerInfo/rowSaved.ts +10 -7
- package/src/automations/triggerInfo/rowUpdated.ts +10 -7
- package/src/automations/triggerInfo/webhook.ts +9 -6
- package/src/events/docUpdates/index.ts +1 -0
- package/src/events/docUpdates/processors.ts +14 -0
- package/src/events/docUpdates/syncUsers.ts +35 -0
- package/src/events/index.ts +1 -0
- package/src/integrations/index.ts +3 -3
- package/src/sdk/app/applications/sync.ts +129 -22
- package/src/sdk/app/applications/tests/sync.spec.ts +137 -0
- package/src/sdk/index.ts +2 -0
- package/src/sdk/plugins/index.ts +5 -0
- package/src/sdk/plugins/plugins.ts +41 -0
- package/src/sdk/users/tests/utils.spec.ts +1 -32
- package/src/sdk/users/utils.ts +23 -5
- package/src/startup.ts +2 -1
- package/src/tests/utilities/TestConfiguration.ts +28 -0
- package/src/tests/utilities/structures.ts +25 -17
- package/src/threads/automation.ts +2 -2
- package/src/utilities/fileSystem/plugin.ts +13 -4
- package/src/utilities/global.ts +21 -16
- package/src/watch.ts +2 -2
- package/src/websockets/client.ts +11 -0
- package/src/websockets/grid.ts +55 -0
- package/src/websockets/index.ts +14 -0
- package/src/websockets/websocket.ts +83 -0
- package/tsconfig.json +1 -7
- package/builder/assets/index.841e62d8.css +0 -6
- package/dist/websocket.js +0 -22
- package/src/websocket.ts +0 -26
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import TestConfiguration from "../../../../tests/utilities/TestConfiguration"
|
|
2
|
+
import { events, context, roles, constants } from "@budibase/backend-core"
|
|
3
|
+
import { init } from "../../../../events"
|
|
4
|
+
import { rawUserMetadata } from "../../../users/utils"
|
|
5
|
+
import EventEmitter from "events"
|
|
6
|
+
import { UserGroup, UserMetadata, UserRoles, User } from "@budibase/types"
|
|
7
|
+
|
|
8
|
+
const config = new TestConfiguration()
|
|
9
|
+
let app, group: UserGroup, groupUser: User
|
|
10
|
+
const ROLE_ID = roles.BUILTIN_ROLE_IDS.BASIC
|
|
11
|
+
|
|
12
|
+
const emitter = new EventEmitter()
|
|
13
|
+
|
|
14
|
+
function updateCb(docId: string) {
|
|
15
|
+
const isGroup = docId.startsWith(constants.DocumentType.GROUP)
|
|
16
|
+
if (isGroup) {
|
|
17
|
+
emitter.emit("update-group")
|
|
18
|
+
} else {
|
|
19
|
+
emitter.emit("update-user")
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
init(updateCb)
|
|
24
|
+
|
|
25
|
+
function waitForUpdate(opts: { group?: boolean }) {
|
|
26
|
+
return new Promise<void>((resolve, reject) => {
|
|
27
|
+
const timeout = setTimeout(() => {
|
|
28
|
+
reject()
|
|
29
|
+
}, 5000)
|
|
30
|
+
const event = opts?.group ? "update-group" : "update-user"
|
|
31
|
+
emitter.on(event, () => {
|
|
32
|
+
clearTimeout(timeout)
|
|
33
|
+
resolve()
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
beforeAll(async () => {
|
|
39
|
+
app = await config.init("syncApp")
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
async function createUser(email: string, roles: UserRoles, builder?: boolean) {
|
|
43
|
+
const user = await config.createUser({
|
|
44
|
+
email,
|
|
45
|
+
roles,
|
|
46
|
+
builder: builder || false,
|
|
47
|
+
admin: false,
|
|
48
|
+
})
|
|
49
|
+
await context.doInContext(config.appId!, async () => {
|
|
50
|
+
await events.user.created(user)
|
|
51
|
+
})
|
|
52
|
+
return user
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function removeUserRole(user: User) {
|
|
56
|
+
const final = await config.globalUser({
|
|
57
|
+
...user,
|
|
58
|
+
id: user._id,
|
|
59
|
+
roles: {},
|
|
60
|
+
builder: false,
|
|
61
|
+
admin: false,
|
|
62
|
+
})
|
|
63
|
+
await context.doInContext(config.appId!, async () => {
|
|
64
|
+
await events.user.updated(final)
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function createGroupAndUser(email: string) {
|
|
69
|
+
groupUser = await config.createUser({
|
|
70
|
+
email,
|
|
71
|
+
roles: {},
|
|
72
|
+
builder: false,
|
|
73
|
+
admin: false,
|
|
74
|
+
})
|
|
75
|
+
group = await config.createGroup()
|
|
76
|
+
await config.addUserToGroup(group._id!, groupUser._id!)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function removeUserFromGroup() {
|
|
80
|
+
await config.removeUserFromGroup(group._id!, groupUser._id!)
|
|
81
|
+
return context.doInContext(config.appId!, async () => {
|
|
82
|
+
await events.user.updated(groupUser)
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function getUserMetadata(): Promise<UserMetadata[]> {
|
|
87
|
+
return context.doInContext(config.appId!, async () => {
|
|
88
|
+
return await rawUserMetadata()
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function buildRoles() {
|
|
93
|
+
return { [config.prodAppId!]: ROLE_ID }
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
describe("app user/group sync", () => {
|
|
97
|
+
const groupEmail = "test2@test.com",
|
|
98
|
+
normalEmail = "test@test.com"
|
|
99
|
+
async function checkEmail(
|
|
100
|
+
email: string,
|
|
101
|
+
opts?: { group?: boolean; notFound?: boolean }
|
|
102
|
+
) {
|
|
103
|
+
await waitForUpdate(opts || {})
|
|
104
|
+
const metadata = await getUserMetadata()
|
|
105
|
+
const found = metadata.find(data => data.email === email)
|
|
106
|
+
if (opts?.notFound) {
|
|
107
|
+
expect(found).toBeUndefined()
|
|
108
|
+
} else {
|
|
109
|
+
expect(found).toBeDefined()
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
it("should be able to sync a new user, add then remove", async () => {
|
|
114
|
+
const user = await createUser(normalEmail, buildRoles())
|
|
115
|
+
await checkEmail(normalEmail)
|
|
116
|
+
await removeUserRole(user)
|
|
117
|
+
await checkEmail(normalEmail, { notFound: true })
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
it("should be able to sync a group", async () => {
|
|
121
|
+
await createGroupAndUser(groupEmail)
|
|
122
|
+
await checkEmail(groupEmail, { group: true })
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
it("should be able to remove user from group", async () => {
|
|
126
|
+
if (!group) {
|
|
127
|
+
await createGroupAndUser(groupEmail)
|
|
128
|
+
}
|
|
129
|
+
await removeUserFromGroup()
|
|
130
|
+
await checkEmail(groupEmail, { notFound: true })
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
it("should be able to handle builder users", async () => {
|
|
134
|
+
await createUser("test3@test.com", {}, true)
|
|
135
|
+
await checkEmail("test3@test.com")
|
|
136
|
+
})
|
|
137
|
+
})
|
package/src/sdk/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { default as datasources } from "./app/datasources"
|
|
|
6
6
|
import { default as queries } from "./app/queries"
|
|
7
7
|
import { default as rows } from "./app/rows"
|
|
8
8
|
import { default as users } from "./users"
|
|
9
|
+
import { default as plugins } from "./plugins"
|
|
9
10
|
|
|
10
11
|
const sdk = {
|
|
11
12
|
backups,
|
|
@@ -16,6 +17,7 @@ const sdk = {
|
|
|
16
17
|
users,
|
|
17
18
|
datasources,
|
|
18
19
|
queries,
|
|
20
|
+
plugins,
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
// default export for TS
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { FileType, Plugin, PluginSource, PluginType } from "@budibase/types"
|
|
2
|
+
import {
|
|
3
|
+
db as dbCore,
|
|
4
|
+
objectStore,
|
|
5
|
+
plugins as pluginCore,
|
|
6
|
+
tenancy,
|
|
7
|
+
} from "@budibase/backend-core"
|
|
8
|
+
import { fileUpload } from "../../api/controllers/plugin/file"
|
|
9
|
+
import env from "../../environment"
|
|
10
|
+
import { clientAppSocket } from "../../websockets"
|
|
11
|
+
import { sdk as pro } from "@budibase/pro"
|
|
12
|
+
|
|
13
|
+
export async function fetch(type?: PluginType) {
|
|
14
|
+
const db = tenancy.getGlobalDB()
|
|
15
|
+
const response = await db.allDocs(
|
|
16
|
+
dbCore.getPluginParams(null, {
|
|
17
|
+
include_docs: true,
|
|
18
|
+
})
|
|
19
|
+
)
|
|
20
|
+
let plugins = response.rows.map((row: any) => row.doc) as Plugin[]
|
|
21
|
+
plugins = objectStore.enrichPluginURLs(plugins)
|
|
22
|
+
if (type) {
|
|
23
|
+
return plugins.filter((plugin: Plugin) => plugin.schema?.type === type)
|
|
24
|
+
} else {
|
|
25
|
+
return plugins
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function processUploaded(plugin: FileType, source?: PluginSource) {
|
|
30
|
+
const { metadata, directory } = await fileUpload(plugin)
|
|
31
|
+
pluginCore.validate(metadata?.schema)
|
|
32
|
+
|
|
33
|
+
// Only allow components in cloud
|
|
34
|
+
if (!env.SELF_HOSTED && metadata?.schema?.type !== PluginType.COMPONENT) {
|
|
35
|
+
throw new Error("Only component plugins are supported outside of self-host")
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const doc = await pro.plugins.storePlugin(metadata, directory, source)
|
|
39
|
+
clientAppSocket.emit("plugin-update", { name: doc.name, hash: doc.hash })
|
|
40
|
+
return doc
|
|
41
|
+
}
|
|
@@ -121,38 +121,7 @@ describe("syncGlobalUsers", () => {
|
|
|
121
121
|
await syncGlobalUsers()
|
|
122
122
|
|
|
123
123
|
const metadata = await rawUserMetadata()
|
|
124
|
-
expect(metadata).toHaveLength(
|
|
125
|
-
})
|
|
126
|
-
})
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
it("app users are removed when app is removed from user group", async () => {
|
|
130
|
-
await config.doInTenant(async () => {
|
|
131
|
-
const group = await proSdk.groups.save(structures.userGroups.userGroup())
|
|
132
|
-
const user1 = await config.createUser({ admin: false, builder: false })
|
|
133
|
-
const user2 = await config.createUser({ admin: false, builder: false })
|
|
134
|
-
await proSdk.groups.updateGroupApps(group.id, {
|
|
135
|
-
appsToAdd: [
|
|
136
|
-
{ appId: config.prodAppId!, roleId: roles.BUILTIN_ROLE_IDS.BASIC },
|
|
137
|
-
],
|
|
138
|
-
})
|
|
139
|
-
await proSdk.groups.addUsers(group.id, [user1._id, user2._id])
|
|
140
|
-
|
|
141
|
-
await config.doInContext(config.appId, async () => {
|
|
142
|
-
await syncGlobalUsers()
|
|
143
|
-
expect(await rawUserMetadata()).toHaveLength(3)
|
|
144
|
-
|
|
145
|
-
await proSdk.groups.removeUsers(group.id, [user1._id])
|
|
146
|
-
await syncGlobalUsers()
|
|
147
|
-
|
|
148
|
-
const metadata = await rawUserMetadata()
|
|
149
|
-
expect(metadata).toHaveLength(2)
|
|
150
|
-
|
|
151
|
-
expect(metadata).not.toContainEqual(
|
|
152
|
-
expect.objectContaining({
|
|
153
|
-
_id: db.generateUserMetadataID(user1._id),
|
|
154
|
-
})
|
|
155
|
-
)
|
|
124
|
+
expect(metadata).toHaveLength(0)
|
|
156
125
|
})
|
|
157
126
|
})
|
|
158
127
|
})
|
package/src/sdk/users/utils.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { getGlobalUsers } from "../../utilities/global"
|
|
2
2
|
import { context, roles as rolesCore } from "@budibase/backend-core"
|
|
3
3
|
import {
|
|
4
|
+
getGlobalIDFromUserMetadataID,
|
|
4
5
|
generateUserMetadataID,
|
|
5
6
|
getUserMetadataParams,
|
|
6
7
|
InternalTables,
|
|
7
8
|
} from "../../db/utils"
|
|
8
9
|
import { isEqual } from "lodash"
|
|
9
|
-
import { ContextUser, UserMetadata } from "@budibase/types"
|
|
10
|
+
import { ContextUser, UserMetadata, User } from "@budibase/types"
|
|
10
11
|
|
|
11
12
|
export function combineMetadataAndUser(
|
|
12
13
|
user: ContextUser,
|
|
@@ -37,6 +38,10 @@ export function combineMetadataAndUser(
|
|
|
37
38
|
if (found) {
|
|
38
39
|
newDoc._rev = found._rev
|
|
39
40
|
}
|
|
41
|
+
// clear fields that shouldn't be in metadata
|
|
42
|
+
delete newDoc.password
|
|
43
|
+
delete newDoc.forceResetPassword
|
|
44
|
+
delete newDoc.roles
|
|
40
45
|
if (found == null || !isEqual(newDoc, found)) {
|
|
41
46
|
return {
|
|
42
47
|
...found,
|
|
@@ -60,10 +65,9 @@ export async function rawUserMetadata() {
|
|
|
60
65
|
export async function syncGlobalUsers() {
|
|
61
66
|
// sync user metadata
|
|
62
67
|
const db = context.getAppDB()
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
])
|
|
68
|
+
const resp = await Promise.all([getGlobalUsers(), rawUserMetadata()])
|
|
69
|
+
const users = resp[0] as User[]
|
|
70
|
+
const metadata = resp[1] as UserMetadata[]
|
|
67
71
|
const toWrite = []
|
|
68
72
|
for (let user of users) {
|
|
69
73
|
const combined = combineMetadataAndUser(user, metadata)
|
|
@@ -71,5 +75,19 @@ export async function syncGlobalUsers() {
|
|
|
71
75
|
toWrite.push(combined)
|
|
72
76
|
}
|
|
73
77
|
}
|
|
78
|
+
let foundEmails: string[] = []
|
|
79
|
+
for (let data of metadata) {
|
|
80
|
+
if (!data._id) {
|
|
81
|
+
continue
|
|
82
|
+
}
|
|
83
|
+
const alreadyExisting = data.email && foundEmails.indexOf(data.email) !== -1
|
|
84
|
+
const globalId = getGlobalIDFromUserMetadataID(data._id)
|
|
85
|
+
if (!users.find(user => user._id === globalId) || alreadyExisting) {
|
|
86
|
+
toWrite.push({ ...data, _deleted: true })
|
|
87
|
+
}
|
|
88
|
+
if (data.email) {
|
|
89
|
+
foundEmails.push(data.email)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
74
92
|
await db.bulkDocs(toWrite)
|
|
75
93
|
}
|
package/src/startup.ts
CHANGED
|
@@ -10,7 +10,7 @@ import fs from "fs"
|
|
|
10
10
|
import { watch } from "./watch"
|
|
11
11
|
import * as automations from "./automations"
|
|
12
12
|
import * as fileSystem from "./utilities/fileSystem"
|
|
13
|
-
import eventEmitter from "./events"
|
|
13
|
+
import { default as eventEmitter, init as eventInit } from "./events"
|
|
14
14
|
import * as migrations from "./migrations"
|
|
15
15
|
import * as bullboard from "./automations/bullboard"
|
|
16
16
|
import * as pro from "@budibase/pro"
|
|
@@ -63,6 +63,7 @@ export async function startup(app?: any, server?: any) {
|
|
|
63
63
|
eventEmitter.emitPort(env.PORT)
|
|
64
64
|
fileSystem.init()
|
|
65
65
|
await redis.init()
|
|
66
|
+
eventInit()
|
|
66
67
|
|
|
67
68
|
// run migrations on startup if not done via http
|
|
68
69
|
// not recommended in a clustered environment
|
|
@@ -49,6 +49,7 @@ import {
|
|
|
49
49
|
SearchFilters,
|
|
50
50
|
UserRoles,
|
|
51
51
|
} from "@budibase/types"
|
|
52
|
+
import { BUILTIN_ROLE_IDS } from "@budibase/backend-core/src/security/roles"
|
|
52
53
|
|
|
53
54
|
type DefaultUserValues = {
|
|
54
55
|
globalUserId: string
|
|
@@ -306,6 +307,33 @@ class TestConfiguration {
|
|
|
306
307
|
}
|
|
307
308
|
}
|
|
308
309
|
|
|
310
|
+
async createGroup(roleId: string = BUILTIN_ROLE_IDS.BASIC) {
|
|
311
|
+
return context.doInTenant(this.tenantId!, async () => {
|
|
312
|
+
const baseGroup = structures.userGroups.userGroup()
|
|
313
|
+
baseGroup.roles = {
|
|
314
|
+
[this.prodAppId]: roleId,
|
|
315
|
+
}
|
|
316
|
+
const { id, rev } = await pro.sdk.groups.save(baseGroup)
|
|
317
|
+
return {
|
|
318
|
+
_id: id,
|
|
319
|
+
_rev: rev,
|
|
320
|
+
...baseGroup,
|
|
321
|
+
}
|
|
322
|
+
})
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
async addUserToGroup(groupId: string, userId: string) {
|
|
326
|
+
return context.doInTenant(this.tenantId!, async () => {
|
|
327
|
+
await pro.sdk.groups.addUsers(groupId, [userId])
|
|
328
|
+
})
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
async removeUserFromGroup(groupId: string, userId: string) {
|
|
332
|
+
return context.doInTenant(this.tenantId!, async () => {
|
|
333
|
+
await pro.sdk.groups.removeUsers(groupId, [userId])
|
|
334
|
+
})
|
|
335
|
+
}
|
|
336
|
+
|
|
309
337
|
async login({ roleId, userId, builder, prodApp = false }: any = {}) {
|
|
310
338
|
const appId = prodApp ? this.prodAppId : this.appId
|
|
311
339
|
return context.doInAppContext(appId, async () => {
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import { permissions, roles } from "@budibase/backend-core"
|
|
1
|
+
import { permissions, roles, utils } from "@budibase/backend-core"
|
|
2
2
|
import { createHomeScreen } from "../../constants/screens"
|
|
3
3
|
import { EMPTY_LAYOUT } from "../../constants/layouts"
|
|
4
4
|
import { cloneDeep } from "lodash/fp"
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
BUILTIN_ACTION_DEFINITIONS,
|
|
7
|
+
TRIGGER_DEFINITIONS,
|
|
8
|
+
} from "../../automations"
|
|
6
9
|
import {
|
|
7
10
|
Automation,
|
|
8
11
|
AutomationActionStepId,
|
|
12
|
+
AutomationStep,
|
|
13
|
+
AutomationStepType,
|
|
14
|
+
AutomationTrigger,
|
|
9
15
|
AutomationTriggerStepId,
|
|
10
16
|
Datasource,
|
|
11
17
|
SourceName,
|
|
12
18
|
} from "@budibase/types"
|
|
13
19
|
|
|
14
|
-
const { v4: uuidv4 } = require("uuid")
|
|
15
|
-
|
|
16
20
|
export function basicTable() {
|
|
17
21
|
return {
|
|
18
22
|
name: "TestTable",
|
|
@@ -71,19 +75,19 @@ export function view(tableId: string) {
|
|
|
71
75
|
}
|
|
72
76
|
|
|
73
77
|
export function automationStep(
|
|
74
|
-
actionDefinition =
|
|
75
|
-
) {
|
|
78
|
+
actionDefinition = BUILTIN_ACTION_DEFINITIONS.CREATE_ROW
|
|
79
|
+
): AutomationStep {
|
|
76
80
|
return {
|
|
77
|
-
id:
|
|
81
|
+
id: utils.newid(),
|
|
78
82
|
...actionDefinition,
|
|
79
83
|
}
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
export function automationTrigger(
|
|
83
87
|
triggerDefinition = TRIGGER_DEFINITIONS.ROW_SAVED
|
|
84
|
-
) {
|
|
88
|
+
): AutomationTrigger {
|
|
85
89
|
return {
|
|
86
|
-
id:
|
|
90
|
+
id: utils.newid(),
|
|
87
91
|
...triggerDefinition,
|
|
88
92
|
}
|
|
89
93
|
}
|
|
@@ -106,7 +110,7 @@ export function newAutomation({ steps, trigger }: any = {}) {
|
|
|
106
110
|
return automation
|
|
107
111
|
}
|
|
108
112
|
|
|
109
|
-
export function basicAutomation(appId?: string) {
|
|
113
|
+
export function basicAutomation(appId?: string): Automation {
|
|
110
114
|
return {
|
|
111
115
|
name: "My Automation",
|
|
112
116
|
screenId: "kasdkfldsafkl",
|
|
@@ -119,18 +123,22 @@ export function basicAutomation(appId?: string) {
|
|
|
119
123
|
tagline: "test",
|
|
120
124
|
icon: "test",
|
|
121
125
|
description: "test",
|
|
122
|
-
type:
|
|
126
|
+
type: AutomationStepType.TRIGGER,
|
|
123
127
|
id: "test",
|
|
124
128
|
inputs: {},
|
|
125
129
|
schema: {
|
|
126
|
-
inputs: {
|
|
127
|
-
|
|
130
|
+
inputs: {
|
|
131
|
+
properties: {},
|
|
132
|
+
},
|
|
133
|
+
outputs: {
|
|
134
|
+
properties: {},
|
|
135
|
+
},
|
|
128
136
|
},
|
|
129
137
|
},
|
|
130
138
|
steps: [],
|
|
131
139
|
},
|
|
132
140
|
type: "automation",
|
|
133
|
-
appId
|
|
141
|
+
appId: appId!,
|
|
134
142
|
}
|
|
135
143
|
}
|
|
136
144
|
|
|
@@ -154,7 +162,7 @@ export function loopAutomation(tableId: string, loopOpts?: any): Automation {
|
|
|
154
162
|
inputs: {
|
|
155
163
|
tableId,
|
|
156
164
|
},
|
|
157
|
-
schema:
|
|
165
|
+
schema: BUILTIN_ACTION_DEFINITIONS.QUERY_ROWS.schema,
|
|
158
166
|
},
|
|
159
167
|
{
|
|
160
168
|
id: "c",
|
|
@@ -163,7 +171,7 @@ export function loopAutomation(tableId: string, loopOpts?: any): Automation {
|
|
|
163
171
|
internal: true,
|
|
164
172
|
inputs: loopOpts,
|
|
165
173
|
blockToLoop: "d",
|
|
166
|
-
schema:
|
|
174
|
+
schema: BUILTIN_ACTION_DEFINITIONS.LOOP.schema,
|
|
167
175
|
},
|
|
168
176
|
{
|
|
169
177
|
id: "d",
|
|
@@ -173,7 +181,7 @@ export function loopAutomation(tableId: string, loopOpts?: any): Automation {
|
|
|
173
181
|
inputs: {
|
|
174
182
|
text: "log statement",
|
|
175
183
|
},
|
|
176
|
-
schema:
|
|
184
|
+
schema: BUILTIN_ACTION_DEFINITIONS.SERVER_LOG.schema,
|
|
177
185
|
},
|
|
178
186
|
],
|
|
179
187
|
trigger: {
|
|
@@ -27,8 +27,8 @@ import { processObject } from "@budibase/string-templates"
|
|
|
27
27
|
import { cloneDeep } from "lodash/fp"
|
|
28
28
|
import * as sdkUtils from "../sdk/utils"
|
|
29
29
|
import env from "../environment"
|
|
30
|
-
const FILTER_STEP_ID = actions.
|
|
31
|
-
const LOOP_STEP_ID = actions.
|
|
30
|
+
const FILTER_STEP_ID = actions.BUILTIN_ACTION_DEFINITIONS.FILTER.stepId
|
|
31
|
+
const LOOP_STEP_ID = actions.BUILTIN_ACTION_DEFINITIONS.LOOP.stepId
|
|
32
32
|
const CRON_STEP_ID = triggerDefs.CRON.stepId
|
|
33
33
|
const STOPPED_STATUS = { success: true, status: AutomationStatus.STOPPED }
|
|
34
34
|
|
|
@@ -5,6 +5,7 @@ import { join } from "path"
|
|
|
5
5
|
import { objectStore } from "@budibase/backend-core"
|
|
6
6
|
|
|
7
7
|
const DATASOURCE_PATH = join(budibaseTempDir(), "datasource")
|
|
8
|
+
const AUTOMATION_PATH = join(budibaseTempDir(), "automation")
|
|
8
9
|
|
|
9
10
|
export const getPluginMetadata = async (path: string) => {
|
|
10
11
|
let metadata: any = {}
|
|
@@ -33,12 +34,12 @@ export const getPluginMetadata = async (path: string) => {
|
|
|
33
34
|
return { metadata, directory: path }
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
async function getPluginImpl(path: string, plugin: Plugin) {
|
|
37
38
|
const hash = plugin.schema?.hash
|
|
38
|
-
if (!fs.existsSync(
|
|
39
|
-
fs.mkdirSync(
|
|
39
|
+
if (!fs.existsSync(path)) {
|
|
40
|
+
fs.mkdirSync(path)
|
|
40
41
|
}
|
|
41
|
-
const filename = join(
|
|
42
|
+
const filename = join(path, plugin.name)
|
|
42
43
|
const metadataName = `${filename}.bbmetadata`
|
|
43
44
|
if (fs.existsSync(filename)) {
|
|
44
45
|
const currentHash = fs.readFileSync(metadataName, "utf8")
|
|
@@ -62,3 +63,11 @@ export const getDatasourcePlugin = async (plugin: Plugin) => {
|
|
|
62
63
|
|
|
63
64
|
return require(filename)
|
|
64
65
|
}
|
|
66
|
+
|
|
67
|
+
export const getDatasourcePlugin = async (plugin: Plugin) => {
|
|
68
|
+
return getPluginImpl(DATASOURCE_PATH, plugin)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export const getAutomationPlugin = async (plugin: Plugin) => {
|
|
72
|
+
return getPluginImpl(AUTOMATION_PATH, plugin)
|
|
73
|
+
}
|
package/src/utilities/global.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
import env from "../environment"
|
|
10
10
|
import { groups } from "@budibase/pro"
|
|
11
11
|
import { UserCtx, ContextUser, User, UserGroup } from "@budibase/types"
|
|
12
|
+
import { global } from "yargs"
|
|
12
13
|
|
|
13
14
|
export function updateAppRole(
|
|
14
15
|
user: ContextUser,
|
|
@@ -16,7 +17,7 @@ export function updateAppRole(
|
|
|
16
17
|
) {
|
|
17
18
|
appId = appId || context.getAppId()
|
|
18
19
|
|
|
19
|
-
if (!user || !user.roles) {
|
|
20
|
+
if (!user || (!user.roles && !user.userGroups)) {
|
|
20
21
|
return user
|
|
21
22
|
}
|
|
22
23
|
// if in an multi-tenancy environment make sure roles are never updated
|
|
@@ -27,7 +28,7 @@ export function updateAppRole(
|
|
|
27
28
|
return user
|
|
28
29
|
}
|
|
29
30
|
// always use the deployed app
|
|
30
|
-
if (appId) {
|
|
31
|
+
if (appId && user.roles) {
|
|
31
32
|
user.roleId = user.roles[dbCore.getProdAppID(appId)]
|
|
32
33
|
}
|
|
33
34
|
// if a role wasn't found then either set as admin (builder) or public (everyone else)
|
|
@@ -60,7 +61,7 @@ async function checkGroupRoles(
|
|
|
60
61
|
return user
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
async function processUser(
|
|
64
|
+
export async function processUser(
|
|
64
65
|
user: ContextUser,
|
|
65
66
|
opts: { appId?: string; groups?: UserGroup[] } = {}
|
|
66
67
|
) {
|
|
@@ -94,16 +95,15 @@ export async function getGlobalUser(userId: string) {
|
|
|
94
95
|
return processUser(user, { appId })
|
|
95
96
|
}
|
|
96
97
|
|
|
97
|
-
export async function getGlobalUsers(
|
|
98
|
+
export async function getGlobalUsers(
|
|
99
|
+
userIds?: string[],
|
|
100
|
+
opts?: { noProcessing?: boolean }
|
|
101
|
+
) {
|
|
98
102
|
const appId = context.getAppId()
|
|
99
103
|
const db = tenancy.getGlobalDB()
|
|
100
|
-
const allGroups = await groups.fetch()
|
|
101
104
|
let globalUsers
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
getGlobalIDFromUserMetadataID(user._id!)
|
|
105
|
-
)
|
|
106
|
-
globalUsers = (await db.allDocs(getMultiIDParams(globalIds))).rows.map(
|
|
105
|
+
if (userIds) {
|
|
106
|
+
globalUsers = (await db.allDocs(getMultiIDParams(userIds))).rows.map(
|
|
107
107
|
row => row.doc
|
|
108
108
|
)
|
|
109
109
|
} else {
|
|
@@ -126,15 +126,20 @@ export async function getGlobalUsers(users?: ContextUser[]) {
|
|
|
126
126
|
return globalUsers
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
129
|
+
if (opts?.noProcessing) {
|
|
130
|
+
return globalUsers
|
|
131
|
+
} else {
|
|
132
|
+
// pass in the groups, meaning we don't actually need to retrieve them for
|
|
133
|
+
// each user individually
|
|
134
|
+
const allGroups = await groups.fetch()
|
|
135
|
+
return Promise.all(
|
|
136
|
+
globalUsers.map(user => processUser(user, { groups: allGroups }))
|
|
137
|
+
)
|
|
138
|
+
}
|
|
134
139
|
}
|
|
135
140
|
|
|
136
141
|
export async function getGlobalUsersFromMetadata(users: ContextUser[]) {
|
|
137
|
-
const globalUsers = await getGlobalUsers(users)
|
|
142
|
+
const globalUsers = await getGlobalUsers(users.map(user => user._id!))
|
|
138
143
|
return users.map(user => {
|
|
139
144
|
const globalUser = globalUsers.find(
|
|
140
145
|
globalUser => globalUser && user._id?.includes(globalUser._id)
|
package/src/watch.ts
CHANGED
|
@@ -3,7 +3,7 @@ import env from "./environment"
|
|
|
3
3
|
import chokidar from "chokidar"
|
|
4
4
|
import fs from "fs"
|
|
5
5
|
import { constants, tenancy } from "@budibase/backend-core"
|
|
6
|
-
import
|
|
6
|
+
import pluginsSdk from "./sdk/plugins"
|
|
7
7
|
|
|
8
8
|
export function watch() {
|
|
9
9
|
const watchPath = path.join(env.PLUGINS_DIR, "./**/*.tar.gz")
|
|
@@ -27,7 +27,7 @@ export function watch() {
|
|
|
27
27
|
const split = path.split("/")
|
|
28
28
|
const name = split[split.length - 1]
|
|
29
29
|
console.log("Importing plugin:", path)
|
|
30
|
-
await
|
|
30
|
+
await pluginsSdk.processUploaded({ name, path })
|
|
31
31
|
} catch (err: any) {
|
|
32
32
|
const message = err?.message ? err?.message : err
|
|
33
33
|
console.error("Failed to import plugin:", message)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Socket from "./websocket"
|
|
2
|
+
import authorized from "../middleware/authorized"
|
|
3
|
+
import http from "http"
|
|
4
|
+
import Koa from "koa"
|
|
5
|
+
import { permissions } from "@budibase/backend-core"
|
|
6
|
+
|
|
7
|
+
export default class ClientAppWebsocket extends Socket {
|
|
8
|
+
constructor(app: Koa, server: http.Server) {
|
|
9
|
+
super(app, server, "/socket/client", [authorized(permissions.BUILDER)])
|
|
10
|
+
}
|
|
11
|
+
}
|