@servable/tools 1.2.1 → 1.3.0
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/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"type": "module",
|
|
4
4
|
"source": "src/index.js",
|
|
5
5
|
"main": "src/index.js",
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.3.0",
|
|
7
7
|
"description": "Servable tools is a utility that builds a feature's manifest and documents it.",
|
|
8
8
|
"author": "Servable Community",
|
|
9
9
|
"license": "ISC",
|
|
@@ -133,7 +133,7 @@ export const fetchObject = async ({
|
|
|
133
133
|
export const destroyRowsWithQuery = async ({ query, limitPerBatch } = {}) => {
|
|
134
134
|
query
|
|
135
135
|
.limit(limitPerBatch)
|
|
136
|
-
.find()
|
|
136
|
+
.find({ useMasterKey: true })
|
|
137
137
|
.then(function (results) {
|
|
138
138
|
return Servable.App.Object.destroyAll(results).then(function () {
|
|
139
139
|
return Promise.resolve(results.length);
|
|
@@ -24,10 +24,40 @@ export default async (props) => {
|
|
|
24
24
|
|
|
25
25
|
//#TODO: feature.loader
|
|
26
26
|
const _classLevelPermissions = await feature.loader.schemaClassLevelPermissions()
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
_classSchema.classLevelPermissions
|
|
27
|
+
let __classLevelPermissions
|
|
28
|
+
if (_classLevelPermissions && Object.keys(_classLevelPermissions).length) {
|
|
29
|
+
__classLevelPermissions = preserveMostRestricted([_classSchema.classLevelPermissions, _classLevelPermissions])
|
|
30
|
+
} else {
|
|
31
|
+
__classLevelPermissions = {
|
|
32
|
+
"find": {
|
|
33
|
+
"role:admin": true
|
|
34
|
+
},
|
|
35
|
+
"count": {
|
|
36
|
+
"role:admin": true
|
|
37
|
+
},
|
|
38
|
+
"get": {
|
|
39
|
+
"role:admin": true
|
|
40
|
+
},
|
|
41
|
+
"create": {
|
|
42
|
+
"role:admin": true
|
|
43
|
+
},
|
|
44
|
+
"update": {
|
|
45
|
+
"role:admin": true
|
|
46
|
+
},
|
|
47
|
+
"delete": {
|
|
48
|
+
"role:admin": true
|
|
49
|
+
},
|
|
50
|
+
"addField": {
|
|
51
|
+
"role:admin": true
|
|
52
|
+
},
|
|
53
|
+
"protectedFields": {
|
|
54
|
+
"*": []
|
|
55
|
+
}
|
|
56
|
+
}
|
|
30
57
|
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
_classSchema.classLevelPermissions = __classLevelPermissions
|
|
31
61
|
} catch (e) {
|
|
32
62
|
console.error(e)
|
|
33
63
|
}
|
|
@@ -1,68 +1,96 @@
|
|
|
1
1
|
export default (items) => {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
let permissions = dedupePermissions(items)
|
|
3
|
+
const protectedFields = dedupeProtectedFields(items)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
5
|
+
permissions = {
|
|
6
|
+
"find": {
|
|
7
|
+
"role:admin": true
|
|
8
|
+
},
|
|
9
|
+
"count": {
|
|
10
|
+
"role:admin": true
|
|
11
|
+
},
|
|
12
|
+
"get": {
|
|
13
|
+
"role:admin": true
|
|
14
|
+
},
|
|
15
|
+
"create": {
|
|
16
|
+
"role:admin": true
|
|
17
|
+
},
|
|
18
|
+
"update": {
|
|
19
|
+
"role:admin": true
|
|
20
|
+
},
|
|
21
|
+
"delete": {
|
|
22
|
+
"role:admin": true
|
|
23
|
+
},
|
|
24
|
+
"addField": {
|
|
25
|
+
"role:admin": true
|
|
26
|
+
},
|
|
27
|
+
"protectedFields": {
|
|
28
|
+
"*": []
|
|
29
|
+
},
|
|
30
|
+
...permissions
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
...permissions,
|
|
35
|
+
protectedFields
|
|
36
|
+
}
|
|
9
37
|
}
|
|
10
38
|
|
|
11
39
|
const dedupeProtectedFields = (items) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
40
|
+
const a = items[0].protectedFields ? items[0].protectedFields : {}
|
|
41
|
+
const b = items[1].protectedFields ? items[1].protectedFields : {}
|
|
42
|
+
const aKeys = Object.keys(a)
|
|
43
|
+
const bKeys = Object.keys(b)
|
|
16
44
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
45
|
+
const result = {}
|
|
46
|
+
const keys = [...(new Set([...aKeys, ...bKeys]))]
|
|
47
|
+
keys.forEach(key => {
|
|
48
|
+
result[key] = [
|
|
49
|
+
...(a[key] ? a[key] : []),
|
|
50
|
+
...(b[key] ? b[key] : []),
|
|
51
|
+
]
|
|
52
|
+
result[key] = result[key].filter(a => a)
|
|
53
|
+
})
|
|
26
54
|
|
|
27
|
-
|
|
55
|
+
return result
|
|
28
56
|
}
|
|
29
57
|
|
|
30
58
|
const dedupePermissions = (items) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
59
|
+
const a = items[0] ? items[0] : {}
|
|
60
|
+
const b = items[1] ? items[1] : {}
|
|
61
|
+
const aKeys = Object.keys(a).filter(a => a !== "protectedFields")
|
|
62
|
+
const bKeys = Object.keys(b).filter(a => a !== "protectedFields")
|
|
63
|
+
const result = {}
|
|
64
|
+
const keys = [...(new Set([...aKeys, ...bKeys]))]
|
|
65
|
+
keys.forEach(key => {
|
|
66
|
+
result[key] = dedupePermission(a[key], b[key])
|
|
67
|
+
})
|
|
40
68
|
|
|
41
|
-
|
|
69
|
+
return result
|
|
42
70
|
}
|
|
43
71
|
|
|
44
72
|
const dedupePermission = (a, b) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
73
|
+
if (!a) {
|
|
74
|
+
return b
|
|
75
|
+
}
|
|
48
76
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
77
|
+
if (!b) {
|
|
78
|
+
return a
|
|
79
|
+
}
|
|
52
80
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
81
|
+
const aKeys = Object.keys(a)
|
|
82
|
+
const bKeys = Object.keys(b)
|
|
83
|
+
const result = {}
|
|
84
|
+
const keys = [...(new Set([...aKeys, ...bKeys]))]
|
|
57
85
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
86
|
+
keys.forEach(key => {
|
|
87
|
+
if (key === 'requiresAuthentication') {
|
|
88
|
+
result.requiresAuthentication = (a.requiresAuthentication || b.aRequiresAuthentication)
|
|
89
|
+
delete result["*"]
|
|
90
|
+
}
|
|
63
91
|
|
|
64
|
-
|
|
65
|
-
|
|
92
|
+
result[key] = b.hasOwnProperty(key) ? b[key] : a[key]
|
|
93
|
+
})
|
|
66
94
|
|
|
67
|
-
|
|
68
|
-
}
|
|
95
|
+
return result
|
|
96
|
+
}
|