@budibase/server 2.4.42-alpha.5 → 2.4.42-alpha.7
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.0d64dce3.js → index.8b525942.js} +220 -220
- package/builder/index.html +1 -1
- package/dist/package.json +7 -7
- package/dist/sdk/users/utils.js +9 -5
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/src/sdk/users/tests/utils.spec.ts +159 -0
- package/src/sdk/users/utils.ts +14 -6
- package/src/tests/utilities/TestConfiguration.ts +2 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/server",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "2.4.42-alpha.
|
|
4
|
+
"version": "2.4.42-alpha.7",
|
|
5
5
|
"description": "Budibase Web Server",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
"license": "GPL-3.0",
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@apidevtools/swagger-parser": "10.0.3",
|
|
47
|
-
"@budibase/backend-core": "2.4.42-alpha.
|
|
48
|
-
"@budibase/client": "2.4.42-alpha.
|
|
49
|
-
"@budibase/pro": "2.4.42-alpha.
|
|
50
|
-
"@budibase/shared-core": "2.4.42-alpha.
|
|
51
|
-
"@budibase/string-templates": "2.4.42-alpha.
|
|
52
|
-
"@budibase/types": "2.4.42-alpha.
|
|
47
|
+
"@budibase/backend-core": "2.4.42-alpha.7",
|
|
48
|
+
"@budibase/client": "2.4.42-alpha.7",
|
|
49
|
+
"@budibase/pro": "2.4.42-alpha.6",
|
|
50
|
+
"@budibase/shared-core": "2.4.42-alpha.7",
|
|
51
|
+
"@budibase/string-templates": "2.4.42-alpha.7",
|
|
52
|
+
"@budibase/types": "2.4.42-alpha.7",
|
|
53
53
|
"@bull-board/api": "3.7.0",
|
|
54
54
|
"@bull-board/koa": "3.9.4",
|
|
55
55
|
"@elastic/elasticsearch": "7.10.0",
|
|
@@ -176,5 +176,5 @@
|
|
|
176
176
|
"optionalDependencies": {
|
|
177
177
|
"oracledb": "5.3.0"
|
|
178
178
|
},
|
|
179
|
-
"gitHead": "
|
|
179
|
+
"gitHead": "e80e92c263008bec301ce3f594c65491bc80d63d"
|
|
180
180
|
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { db, roles } from "@budibase/backend-core"
|
|
2
|
+
import { structures } from "@budibase/backend-core/tests"
|
|
3
|
+
import { sdk as proSdk } from "@budibase/pro"
|
|
4
|
+
|
|
5
|
+
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
|
6
|
+
import { rawUserMetadata, syncGlobalUsers } from "../utils"
|
|
7
|
+
|
|
8
|
+
describe("syncGlobalUsers", () => {
|
|
9
|
+
const config = new TestConfiguration()
|
|
10
|
+
|
|
11
|
+
beforeEach(async () => {
|
|
12
|
+
await config.init()
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
afterAll(config.end)
|
|
16
|
+
|
|
17
|
+
it("the default user is synced", async () => {
|
|
18
|
+
await config.doInContext(config.appId, async () => {
|
|
19
|
+
await syncGlobalUsers()
|
|
20
|
+
|
|
21
|
+
const metadata = await rawUserMetadata()
|
|
22
|
+
expect(metadata).toHaveLength(1)
|
|
23
|
+
expect(metadata).toEqual([
|
|
24
|
+
expect.objectContaining({
|
|
25
|
+
_id: db.generateUserMetadataID(config.user._id),
|
|
26
|
+
}),
|
|
27
|
+
])
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it("admin and builders users are synced", async () => {
|
|
32
|
+
const user1 = await config.createUser({ admin: true })
|
|
33
|
+
const user2 = await config.createUser({ admin: false, builder: true })
|
|
34
|
+
await config.doInContext(config.appId, async () => {
|
|
35
|
+
expect(await rawUserMetadata()).toHaveLength(1)
|
|
36
|
+
await syncGlobalUsers()
|
|
37
|
+
|
|
38
|
+
const metadata = await rawUserMetadata()
|
|
39
|
+
expect(metadata).toHaveLength(3)
|
|
40
|
+
expect(metadata).toContainEqual(
|
|
41
|
+
expect.objectContaining({
|
|
42
|
+
_id: db.generateUserMetadataID(user1._id),
|
|
43
|
+
})
|
|
44
|
+
)
|
|
45
|
+
expect(metadata).toContainEqual(
|
|
46
|
+
expect.objectContaining({
|
|
47
|
+
_id: db.generateUserMetadataID(user2._id),
|
|
48
|
+
})
|
|
49
|
+
)
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it("app users are not synced if not specified", async () => {
|
|
54
|
+
const user = await config.createUser({ admin: false, builder: false })
|
|
55
|
+
await config.doInContext(config.appId, async () => {
|
|
56
|
+
await syncGlobalUsers()
|
|
57
|
+
|
|
58
|
+
const metadata = await rawUserMetadata()
|
|
59
|
+
expect(metadata).toHaveLength(1)
|
|
60
|
+
expect(metadata).not.toContainEqual(
|
|
61
|
+
expect.objectContaining({
|
|
62
|
+
_id: db.generateUserMetadataID(user._id),
|
|
63
|
+
})
|
|
64
|
+
)
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it("app users are added when group is assigned to app", async () => {
|
|
69
|
+
await config.doInTenant(async () => {
|
|
70
|
+
const group = await proSdk.groups.save(structures.userGroups.userGroup())
|
|
71
|
+
const user1 = await config.createUser({ admin: false, builder: false })
|
|
72
|
+
const user2 = await config.createUser({ admin: false, builder: false })
|
|
73
|
+
await proSdk.groups.addUsers(group.id, [user1._id, user2._id])
|
|
74
|
+
|
|
75
|
+
await config.doInContext(config.appId, async () => {
|
|
76
|
+
await syncGlobalUsers()
|
|
77
|
+
expect(await rawUserMetadata()).toHaveLength(1)
|
|
78
|
+
|
|
79
|
+
await proSdk.groups.updateGroupApps(group.id, {
|
|
80
|
+
appsToAdd: [
|
|
81
|
+
{ appId: config.prodAppId!, roleId: roles.BUILTIN_ROLE_IDS.BASIC },
|
|
82
|
+
],
|
|
83
|
+
})
|
|
84
|
+
await syncGlobalUsers()
|
|
85
|
+
|
|
86
|
+
const metadata = await rawUserMetadata()
|
|
87
|
+
expect(metadata).toHaveLength(3)
|
|
88
|
+
expect(metadata).toContainEqual(
|
|
89
|
+
expect.objectContaining({
|
|
90
|
+
_id: db.generateUserMetadataID(user1._id),
|
|
91
|
+
})
|
|
92
|
+
)
|
|
93
|
+
expect(metadata).toContainEqual(
|
|
94
|
+
expect.objectContaining({
|
|
95
|
+
_id: db.generateUserMetadataID(user2._id),
|
|
96
|
+
})
|
|
97
|
+
)
|
|
98
|
+
})
|
|
99
|
+
})
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it("app users are removed when app is removed from user group", async () => {
|
|
103
|
+
await config.doInTenant(async () => {
|
|
104
|
+
const group = await proSdk.groups.save(structures.userGroups.userGroup())
|
|
105
|
+
const user1 = await config.createUser({ admin: false, builder: false })
|
|
106
|
+
const user2 = await config.createUser({ admin: false, builder: false })
|
|
107
|
+
await proSdk.groups.updateGroupApps(group.id, {
|
|
108
|
+
appsToAdd: [
|
|
109
|
+
{ appId: config.prodAppId!, roleId: roles.BUILTIN_ROLE_IDS.BASIC },
|
|
110
|
+
],
|
|
111
|
+
})
|
|
112
|
+
await proSdk.groups.addUsers(group.id, [user1._id, user2._id])
|
|
113
|
+
|
|
114
|
+
await config.doInContext(config.appId, async () => {
|
|
115
|
+
await syncGlobalUsers()
|
|
116
|
+
expect(await rawUserMetadata()).toHaveLength(3)
|
|
117
|
+
|
|
118
|
+
await proSdk.groups.updateGroupApps(group.id, {
|
|
119
|
+
appsToRemove: [{ appId: config.prodAppId! }],
|
|
120
|
+
})
|
|
121
|
+
await syncGlobalUsers()
|
|
122
|
+
|
|
123
|
+
const metadata = await rawUserMetadata()
|
|
124
|
+
expect(metadata).toHaveLength(1)
|
|
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
|
+
)
|
|
156
|
+
})
|
|
157
|
+
})
|
|
158
|
+
})
|
|
159
|
+
})
|
package/src/sdk/users/utils.ts
CHANGED
|
@@ -6,25 +6,33 @@ import {
|
|
|
6
6
|
InternalTables,
|
|
7
7
|
} from "../../db/utils"
|
|
8
8
|
import { isEqual } from "lodash"
|
|
9
|
+
import { ContextUser, UserMetadata } from "@budibase/types"
|
|
9
10
|
|
|
10
|
-
export function combineMetadataAndUser(
|
|
11
|
+
export function combineMetadataAndUser(
|
|
12
|
+
user: ContextUser,
|
|
13
|
+
metadata: UserMetadata | UserMetadata[]
|
|
14
|
+
) {
|
|
15
|
+
const metadataId = generateUserMetadataID(user._id!)
|
|
16
|
+
const found = Array.isArray(metadata)
|
|
17
|
+
? metadata.find(doc => doc._id === metadataId)
|
|
18
|
+
: metadata
|
|
11
19
|
// skip users with no access
|
|
12
20
|
if (
|
|
13
21
|
user.roleId == null ||
|
|
14
22
|
user.roleId === rolesCore.BUILTIN_ROLE_IDS.PUBLIC
|
|
15
23
|
) {
|
|
24
|
+
// If it exists and it should not, we must remove it
|
|
25
|
+
if (found?._id) {
|
|
26
|
+
return { ...found, _deleted: true }
|
|
27
|
+
}
|
|
16
28
|
return null
|
|
17
29
|
}
|
|
18
30
|
delete user._rev
|
|
19
|
-
const metadataId = generateUserMetadataID(user._id)
|
|
20
31
|
const newDoc = {
|
|
21
32
|
...user,
|
|
22
33
|
_id: metadataId,
|
|
23
34
|
tableId: InternalTables.USER_METADATA,
|
|
24
35
|
}
|
|
25
|
-
const found = Array.isArray(metadata)
|
|
26
|
-
? metadata.find(doc => doc._id === metadataId)
|
|
27
|
-
: metadata
|
|
28
36
|
// copy rev over for the purposes of equality check
|
|
29
37
|
if (found) {
|
|
30
38
|
newDoc._rev = found._rev
|
|
@@ -58,7 +66,7 @@ export async function syncGlobalUsers() {
|
|
|
58
66
|
])
|
|
59
67
|
const toWrite = []
|
|
60
68
|
for (let user of users) {
|
|
61
|
-
const combined =
|
|
69
|
+
const combined = combineMetadataAndUser(user, metadata)
|
|
62
70
|
if (combined) {
|
|
63
71
|
toWrite.push(combined)
|
|
64
72
|
}
|
|
@@ -47,6 +47,7 @@ import {
|
|
|
47
47
|
SourceName,
|
|
48
48
|
Table,
|
|
49
49
|
SearchFilters,
|
|
50
|
+
UserRoles,
|
|
50
51
|
} from "@budibase/types"
|
|
51
52
|
|
|
52
53
|
type DefaultUserValues = {
|
|
@@ -277,7 +278,7 @@ class TestConfiguration {
|
|
|
277
278
|
email?: string
|
|
278
279
|
builder?: boolean
|
|
279
280
|
admin?: boolean
|
|
280
|
-
roles?:
|
|
281
|
+
roles?: UserRoles
|
|
281
282
|
} = {}
|
|
282
283
|
) {
|
|
283
284
|
let { id, firstName, lastName, email, builder, admin, roles } = user
|