sumba 2.32.2 → 2.32.4
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/extend/bajo/hook.js
CHANGED
|
@@ -21,7 +21,7 @@ async function clearCacheUser (id, result) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
async function applyModelGuard ({ model, q, teamIds, options }) {
|
|
24
|
-
const { set, orderBy } = this.app.lib._
|
|
24
|
+
const { set, orderBy, isEmpty, isArray } = this.app.lib._
|
|
25
25
|
const { includes } = this.app.lib.aneka
|
|
26
26
|
const { sanitizeByType } = this.app.dobo
|
|
27
27
|
const { req } = options
|
|
@@ -39,13 +39,19 @@ async function applyModelGuard ({ model, q, teamIds, options }) {
|
|
|
39
39
|
const rules = orderBy(guards.filter(filterFn), ['field'])
|
|
40
40
|
for (const field of fields) {
|
|
41
41
|
if (!model.getNonVirtualProperties(true).includes(field)) continue // or, should it throws exception instead?
|
|
42
|
+
const opValue = req.getSetting(`sumba:modelGuard.${field}`, {})
|
|
43
|
+
for (const op of ['in', 'nin']) {
|
|
44
|
+
if (!isEmpty(opValue[op]) && isArray(opValue[op])) results.push(set({}, field, set({}, '$' + op, opValue[op])))
|
|
45
|
+
}
|
|
42
46
|
const prop = model.getProperty(field)
|
|
43
47
|
const items = rules.filter(item => item.field === field)
|
|
44
48
|
for (const item of items) {
|
|
45
|
-
|
|
49
|
+
let values = item.value.map(val => {
|
|
46
50
|
return sanitizeByType(val, prop.type, { strict: true, inputFormat: 'string', model: model.name })
|
|
47
51
|
})
|
|
48
52
|
const op = item.condition.toLowerCase()
|
|
53
|
+
if (['in', 'nin'].includes(op) && !isEmpty(opValue[op]) && isArray(opValue[op])) values = values.filter(val => opValue[op].includes(val))
|
|
54
|
+
if (isEmpty(values)) continue
|
|
49
55
|
let value
|
|
50
56
|
if (['in', 'nin'].includes(op)) value = set({}, '$' + op, values)
|
|
51
57
|
else if (op === 'between') value = { $gte: values[0], $lte: values[1] }
|
|
@@ -86,7 +92,7 @@ async function rebuildFilter (model, filter = {}, options = {}) {
|
|
|
86
92
|
const hasTeamId = model.hasProperty('teamId')
|
|
87
93
|
const teams = get(req, 'user.teams', [])
|
|
88
94
|
const teamIds = teams.map(team => team.id + '')
|
|
89
|
-
const aliases = teams.map(team => team.alias)
|
|
95
|
+
// const aliases = teams.map(team => team.alias)
|
|
90
96
|
const q = { $and: [] }
|
|
91
97
|
|
|
92
98
|
filter.query = filter.query ?? {}
|
|
@@ -99,10 +105,12 @@ async function rebuildFilter (model, filter = {}, options = {}) {
|
|
|
99
105
|
return
|
|
100
106
|
}
|
|
101
107
|
if (hasSiteId) q.$and.push({ siteId: req.site.id + '' })
|
|
108
|
+
/*
|
|
102
109
|
if (aliases.includes('administrator')) {
|
|
103
110
|
filter.query = q
|
|
104
111
|
return
|
|
105
112
|
}
|
|
113
|
+
*/
|
|
106
114
|
if (isEmpty(req.user)) {
|
|
107
115
|
if (q.$and.length === 0 && !allowEmpty) throw this.error('_emptyColumnQuery')
|
|
108
116
|
filter.query = q
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[{
|
|
2
2
|
"siteId": "?:SumbaSite::alias:default",
|
|
3
|
-
"userId": "?:SumbaUser::username:
|
|
4
|
-
"teamId": "?:SumbaTeam::alias:
|
|
3
|
+
"userId": "?:SumbaUser::username:admin+siteId:'{siteId}'",
|
|
4
|
+
"teamId": "?:SumbaTeam::alias:administrator+siteId:'{siteId}'",
|
|
5
5
|
"_immutable": ["*"]
|
|
6
6
|
}]
|
package/lib/create-new-site.js
CHANGED
|
@@ -60,8 +60,8 @@ export async function createRefs (site, data, options, verbose) {
|
|
|
60
60
|
const mdl = getModel(m)
|
|
61
61
|
const fixtures = data[m]
|
|
62
62
|
for (const f of fixtures) {
|
|
63
|
-
f.siteId = site.id
|
|
64
|
-
const lv = {}
|
|
63
|
+
f.siteId = site.id + ''
|
|
64
|
+
const lv = { siteId: f.siteId }
|
|
65
65
|
for (const key in f) {
|
|
66
66
|
const val = f[key]
|
|
67
67
|
if (isString(val) && val.slice(0, 2) === '?:') f[key] = await mdl._simpleLookup(val.slice(2), lv, options)
|
package/package.json
CHANGED