sumba 2.45.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.
@@ -148,6 +148,11 @@
148
148
  "statusComplete": "Complete",
149
149
  "statusFail": "Fail",
150
150
  "fileDownloadNA": "File download is no longer available, has been removed, expired or you don't have permission to access it",
151
+ "modelRequired": "Model is required",
152
+ "modelNotFound%s": "Model '%s' is nowhere to be found",
153
+ "noSiteIdProperty%s": "Model '%s' does not have a 'siteId' property",
154
+ "aboutToRebuildModelWithSite%s%s": "You're about to rebuild model '%s' with alias '%s'. Continue?",
155
+ "modelPopulated%s%s": "Model successfully populated with site '%s' (%s record(s))",
151
156
  "field": {
152
157
  "currentPassword": "Current Password",
153
158
  "newPassword": "New Password",
@@ -154,6 +154,11 @@
154
154
  "statusComplete": "Selesai",
155
155
  "statusFail": "Gagal",
156
156
  "fileDownloadNA": "Unduhan file tidak lagi tersedia, telah dihapus, kedaluwarsa, atau Anda tidak memiliki izin untuk mengaksesnya",
157
+ "modelRequired": "Model harus diisi",
158
+ "modelNotFound%s": "Model '%s' tidak ditemukan",
159
+ "noSiteIdProperty%s": "Model '%s' tidak memiliki properti 'siteId'",
160
+ "aboutToRebuildModelWithSite%s%s": "Anda akan membangun ulang model '%s' dengan alias '%s'. Lanjutkan?",
161
+ "modelPopulated%s%s": "Model berhasil diisi dengan situs '%s' (%s data)",
157
162
  "field": {
158
163
  "currentPassword": "Kata Sandi Saat Ini",
159
164
  "newPassword": "Kata Sandi Baru",
@@ -0,0 +1,54 @@
1
+ async function populateModelWithSite (path, ...args) {
2
+ const { getModel } = this.app.dobo
3
+ const { importPkg } = this.app.bajo
4
+ const { isArray, has } = this.app.lib._
5
+ const confirm = await importPkg('bajoCli:@inquirer/confirm')
6
+ let [modelName, alias, keys] = args
7
+ if (!modelName) this.print.fatal('modelRequired')
8
+ if (!alias) this.print.fatal('aliasRequired')
9
+ const model = getModel(modelName, true)
10
+ if (!model) this.print.fatal('modelNotFound%s', modelName)
11
+ if (!model.hasProperty('siteId')) this.print.fatal('noSiteIdProperty%s', modelName)
12
+ const answer = await confirm({ message: this.print.buildText('aboutToRebuildModelWithSite%s%s', modelName, alias), default: false })
13
+ if (!answer) {
14
+ this.print.fail('aborted')
15
+ this.app.exit()
16
+ }
17
+ if (alias.includes(',')) alias = alias.split(',').map(item => item.trim())
18
+ keys = keys ? keys.split(',').map(item => item.trim()) : []
19
+ await this.app.dobo.start()
20
+ try {
21
+ const fixtures = await model.loadFixtures({ ignoreError: false, collectItems: true })
22
+ const siteModel = getModel('SumbaSite')
23
+ let sites = []
24
+ if (['all', '*'].includes(alias)) {
25
+ sites = await siteModel.findAllRecord({}, { dataOnly: true, fields: ['id', 'hostname'] })
26
+ } else {
27
+ if (!isArray(alias)) alias = [alias]
28
+ sites = await siteModel.findAllRecord({ query: { alias: { $in: alias } } }, { dataOnly: true, fields: ['id', 'hostname'] })
29
+ }
30
+ await model.transaction(async (trx) => {
31
+ for (const site of sites) {
32
+ for (const fixture of fixtures) {
33
+ const siteId = site.id + ''
34
+ fixture.siteId = siteId
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 })
40
+ for (const rec of results) {
41
+ await model.removeRecord(rec.id, { noCache: true, noResult: true, trx, throwNotFound: false })
42
+ }
43
+ await model.createRecord(fixture, { noCache: true, noResult: true, trx })
44
+ }
45
+ this.print.info('modelPopulated%s%s', site.hostname, fixtures.length)
46
+ }
47
+ })
48
+ } catch (err) {
49
+ this.print.fatal(err)
50
+ }
51
+ this.app.exit()
52
+ }
53
+
54
+ export default populateModelWithSite
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
- await this.runQueryGuard({ model, q, teamIds, options, allowEmpty })
1623
- await this.runAttribGuard({ model, teamIds, options })
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sumba",
3
- "version": "2.45.0",
3
+ "version": "2.46.1",
4
4
  "description": "Biz Suite for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-08-14
4
+
5
+ - [2.46.1] Bug fix in `rebuildFilter()`
6
+
7
+ ## 2026-08-13
8
+
9
+ - [2.46.0] Add `populateModelWithSite` applet
10
+
3
11
  ## 2026-08-08
4
12
 
5
13
  - [2.45.0] Add `lat` & `lng` columns to `site` schema