sumba 2.8.0 → 2.9.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.
@@ -1,19 +1,30 @@
1
1
  const useAdmin = ['waibuAdmin']
2
2
 
3
3
  export async function rebuildFilter (modelName, filter, req) {
4
- const { isEmpty, map, find, get } = this.app.lib._
4
+ const { isEmpty, isPlainObject, map, find, get } = this.app.lib._
5
5
  filter.query = filter.query ?? {}
6
+
7
+ const queryByModel = (query) => {
8
+ // by model
9
+ const setting = get(req, `site.setting.dobo.query.${modelName}`)
10
+ if (isPlainObject(setting) && !isEmpty(setting)) query.$and.push(setting)
11
+ return query
12
+ }
13
+
6
14
  const model = this.app.dobo.getModel(modelName)
7
15
  const hasSiteId = model.hasProperty('siteId')
8
16
  const hasUserId = model.hasProperty('userId')
9
17
  const hasTeamId = model.hasProperty('teamId')
10
18
  const isAdmin = find(get(req, 'user.teams', []), { alias: 'administrator' }) && useAdmin.includes(get(req, 'routeOptions.config.ns'))
11
- if (!(hasSiteId || hasUserId || hasTeamId)) return filter
12
19
  const q = { $and: [] }
13
20
  if (!isEmpty(filter.query)) {
14
21
  if (filter.query.$and) q.$and.push(...filter.query.$and)
15
22
  else q.$and.push(filter.query)
16
23
  }
24
+ if (!(hasSiteId || hasUserId || hasTeamId)) {
25
+ filter.query = queryByModel(q)
26
+ return filter
27
+ }
17
28
  if (hasSiteId) q.$and.push({ siteId: req.site.id })
18
29
  if (hasTeamId && !isAdmin) {
19
30
  const teamIds = map(req.user.teams, 'id')
@@ -22,7 +33,7 @@ export async function rebuildFilter (modelName, filter, req) {
22
33
  } else if (!isAdmin) {
23
34
  if (hasUserId) q.$and.push({ userId: req.user.id })
24
35
  }
25
- filter.query = q
36
+ filter.query = queryByModel(q)
26
37
  return filter
27
38
  }
28
39
 
@@ -29,8 +29,16 @@
29
29
  "maxLength": 100,
30
30
  "rules": ["email"]
31
31
  }],
32
- "features": ["sumba:personInCharge", "sumba:address", "sumba:social", {
33
- "name": "sumba:status",
34
- "default": "ACTIVE"
35
- }, "dobo:createdAt", "dobo:updatedAt", "dobo:immutable"]
32
+ "features": [
33
+ "sumba:personInCharge",
34
+ "sumba:address",
35
+ "sumba:social",
36
+ {
37
+ "name": "sumba:status",
38
+ "default": "ACTIVE"
39
+ },
40
+ "dobo:createdAt",
41
+ "dobo:updatedAt",
42
+ "dobo:immutable"
43
+ ]
36
44
  }
@@ -1,4 +1,5 @@
1
1
  {
2
+ "buildLevel": 4,
2
3
  "properties": [{
3
4
  "name": "teamId",
4
5
  "type": "string",
@@ -1,4 +1,5 @@
1
1
  {
2
+ "buildLevel": 3,
2
3
  "properties": [
3
4
  "alias,,20,,true",
4
5
  "name,,50,true,true"
@@ -4,7 +4,7 @@ const auth = {
4
4
  const { camelCase } = this.app.lib._
5
5
  const { req } = socket
6
6
  const { session } = req
7
- const site = await this.getSite(session.siteId)
7
+ const site = await this.getSite(session.siteId, true)
8
8
  socket.join(camelCase(`site ${site.alias}`))
9
9
  let user
10
10
  if (session.userId) {
package/index.js CHANGED
@@ -20,7 +20,10 @@ async function factory (pkgName) {
20
20
  constructor () {
21
21
  super(pkgName, me.app)
22
22
  this.config = {
23
- multiSite: false,
23
+ multiSite: {
24
+ enabled: false,
25
+ catchAll: 'default'
26
+ },
24
27
  waibu: {
25
28
  title: 'site',
26
29
  prefix: 'site'
@@ -445,7 +448,8 @@ async function factory (pkgName) {
445
448
 
446
449
  let site = {}
447
450
 
448
- if (!this.config.multiSite) {
451
+ const multiSite = this.config.multiSite === true ? { enabled: true, catchAll: 'default' } : this.config.multiSite
452
+ if (!multiSite.enabled) {
449
453
  const resp = await this.app.dobo.getModel('SumbaSite').findOneRecord({ query: { alias: 'default' } }, { noHook: true })
450
454
  site = omit(resp, omitted)
451
455
  await mergeSetting(site)
@@ -453,16 +457,15 @@ async function factory (pkgName) {
453
457
  }
454
458
  let query
455
459
  if (useId) query = { id: hostname }
456
- else {
457
- query = {
458
- $or: [
459
- { hostname },
460
- { alias: hostname }
461
- ]
460
+ else query = { hostname }
461
+ let row = await this.app.dobo.getModel('SumbaSite').findOneRecord({ query }, { noHook: true })
462
+ if (!row) {
463
+ if (multiSite.catchAll) {
464
+ query = { alias: multiSite.catchAll === true ? 'default' : multiSite.catchAll }
465
+ row = await this.app.dobo.getModel('SumbaSite').findOneRecord({ query }, { noHook: true })
462
466
  }
467
+ if (!row) throw this.error('unknownSite')
463
468
  }
464
- const row = await this.app.dobo.getModel('SumbaSite').findOneRecord({ query }, { noHook: true })
465
- if (!row) throw this.error('unknownSite')
466
469
  if (row.status !== 'ACTIVE') throw this.error('siteInactiveInfo')
467
470
  site = omit(row, omitted)
468
471
  await mergeSetting(site)
@@ -72,6 +72,10 @@ async function createNewSite (alias, hostname, verbose) {
72
72
  const fixtures = data[m]
73
73
  for (const f of fixtures) {
74
74
  f.siteId = newSite.id + ''
75
+ for (const key in f) {
76
+ const val = f[key]
77
+ if (isString(val) && val.slice(0, 2) === '?:') f[key] = await mdl._simpleLookup(val.slice(2), options)
78
+ }
75
79
  await mdl.createRecord(f, options)
76
80
  }
77
81
  if (verbose) this.print.succeed('writingModel%s%s', mdl.name, fixtures.length)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sumba",
3
- "version": "2.8.0",
3
+ "version": "2.9.0",
4
4
  "description": "Biz Suite for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,10 +1,16 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-03-12
4
+
5
+ - [2.9.0] Add ability to restrict/filter dobo's records through site setting
6
+ - [2.9.0] Multisite config now accept object. If set to ```true``` it defaults to ```catchAll: 'default'```
7
+
3
8
  ## 2026-03-11
4
9
 
5
10
  - [2.8.0] Add ```createNewSite()``` and ```applet.crateNewSite```
6
11
  - [2.8.0] Add ```removeSite()``` and ```applet.removeSite```
7
12
  - [2.8.0] Set ```site.json```, ```user.json```, ```team.json```, ```team-user.json``` first fixture as immutable row
13
+ - [2.8.1] Bug fix in ```createNewSite()```
8
14
 
9
15
  ## 2026-03-08
10
16