sumba 2.46.0 → 2.46.1
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/bajoCli/applet/populate-model-with-site.js +8 -3
- package/index.js +14 -15
- package/package.json +1 -1
- package/wiki/CHANGES.md +4 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
async function populateModelWithSite (path, ...args) {
|
|
2
2
|
const { getModel } = this.app.dobo
|
|
3
3
|
const { importPkg } = this.app.bajo
|
|
4
|
-
const { isArray } = this.app.lib._
|
|
4
|
+
const { isArray, has } = this.app.lib._
|
|
5
5
|
const confirm = await importPkg('bajoCli:@inquirer/confirm')
|
|
6
|
-
let [modelName, alias] = args
|
|
6
|
+
let [modelName, alias, keys] = args
|
|
7
7
|
if (!modelName) this.print.fatal('modelRequired')
|
|
8
8
|
if (!alias) this.print.fatal('aliasRequired')
|
|
9
9
|
const model = getModel(modelName, true)
|
|
@@ -15,6 +15,7 @@ async function populateModelWithSite (path, ...args) {
|
|
|
15
15
|
this.app.exit()
|
|
16
16
|
}
|
|
17
17
|
if (alias.includes(',')) alias = alias.split(',').map(item => item.trim())
|
|
18
|
+
keys = keys ? keys.split(',').map(item => item.trim()) : []
|
|
18
19
|
await this.app.dobo.start()
|
|
19
20
|
try {
|
|
20
21
|
const fixtures = await model.loadFixtures({ ignoreError: false, collectItems: true })
|
|
@@ -31,7 +32,11 @@ async function populateModelWithSite (path, ...args) {
|
|
|
31
32
|
for (const fixture of fixtures) {
|
|
32
33
|
const siteId = site.id + ''
|
|
33
34
|
fixture.siteId = siteId
|
|
34
|
-
const
|
|
35
|
+
const query = { siteId }
|
|
36
|
+
for (const key of keys) {
|
|
37
|
+
if (has(fixture, key)) query[key] = fixture[key]
|
|
38
|
+
}
|
|
39
|
+
const results = await model.findAllRecord({ query }, { fields: ['id'], trx })
|
|
35
40
|
for (const rec of results) {
|
|
36
41
|
await model.removeRecord(rec.id, { noCache: true, noResult: true, trx, throwNotFound: false })
|
|
37
42
|
}
|
package/index.js
CHANGED
|
@@ -1482,6 +1482,7 @@ async function factory (pkgName) {
|
|
|
1482
1482
|
}
|
|
1483
1483
|
|
|
1484
1484
|
const rules = orderBy(guards.filter(filterFn), ['field'])
|
|
1485
|
+
|
|
1485
1486
|
for (const field of fields) {
|
|
1486
1487
|
if (!model.getNonVirtualProperties(true).includes(field)) continue // or, should it throws exception instead?
|
|
1487
1488
|
const inSetting = this.filterModelFromSetting({ model, field, options })
|
|
@@ -1578,22 +1579,18 @@ async function factory (pkgName) {
|
|
|
1578
1579
|
return
|
|
1579
1580
|
}
|
|
1580
1581
|
if (hasSiteId) q.$and.push({ siteId: req.site.id + '' })
|
|
1581
|
-
if (aliases.includes('administrator')) {
|
|
1582
|
-
if (get(req, 'site.alias') === 'default') {
|
|
1583
|
-
filter.query = q
|
|
1584
|
-
return
|
|
1585
|
-
}
|
|
1586
|
-
const fields = keys(req.getSetting('sumba:queryGuard', {}))
|
|
1587
|
-
const results = []
|
|
1588
|
-
for (const field of fields) {
|
|
1589
|
-
if (!model.hasProperty(field)) continue
|
|
1590
|
-
const inSetting = this.filterModelFromSetting({ model, field, options })
|
|
1591
|
-
if (inSetting.results.length > 0) results.push(...inSetting.results)
|
|
1592
|
-
}
|
|
1593
|
-
if (results.length > 0) q.$and.push(...results)
|
|
1582
|
+
if (aliases.includes('administrator') && (get(req, 'site.alias') === 'default')) {
|
|
1594
1583
|
filter.query = q
|
|
1595
1584
|
return
|
|
1596
1585
|
}
|
|
1586
|
+
const fields = keys(req.getSetting('sumba:queryGuard', {}))
|
|
1587
|
+
const results = []
|
|
1588
|
+
for (const field of fields) {
|
|
1589
|
+
if (!model.hasProperty(field)) continue
|
|
1590
|
+
const inSetting = this.filterModelFromSetting({ model, field, options })
|
|
1591
|
+
if (inSetting.results.length > 0) results.push(...inSetting.results)
|
|
1592
|
+
}
|
|
1593
|
+
if (results.length > 0) q.$and.push(...results)
|
|
1597
1594
|
if (isEmpty(req.user)) {
|
|
1598
1595
|
if (q.$and.length === 0 && !allowEmpty) throw this.error('_emptyColumnQuery')
|
|
1599
1596
|
filter.query = q
|
|
@@ -1619,8 +1616,10 @@ async function factory (pkgName) {
|
|
|
1619
1616
|
else q.$and.push(condTeamId)
|
|
1620
1617
|
} else if (hasUserId) q.$and.push(condUserId)
|
|
1621
1618
|
|
|
1622
|
-
|
|
1623
|
-
|
|
1619
|
+
if (!aliases.includes('administrator')) {
|
|
1620
|
+
await this.runQueryGuard({ model, q, teamIds, options, allowEmpty })
|
|
1621
|
+
await this.runAttribGuard({ model, teamIds, options })
|
|
1622
|
+
}
|
|
1624
1623
|
if (q.$and.length === 0 && !allowEmpty) throw this.error('_emptyColumnQuery')
|
|
1625
1624
|
filter.query = q
|
|
1626
1625
|
}
|
package/package.json
CHANGED