sumba 2.25.0 → 2.25.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.
@@ -1,13 +1,8 @@
1
- import { rebuildFilter } from './dobo@before-driver-find-record.js'
1
+ import { handler } from './dobo@before-driver-find-record.js'
2
2
 
3
3
  const doboBeforeDriverFindAllRecord = {
4
4
  level: 1000,
5
- handler: async function (model, filter, options) {
6
- const { req } = options
7
- const { isEmpty } = this.app.lib._
8
- if (options.noAutoFilter || !req || isEmpty(req.site)) return
9
- await rebuildFilter.call(this, model, filter, options)
10
- }
5
+ handler
11
6
  }
12
7
 
13
8
  export default doboBeforeDriverFindAllRecord
@@ -89,11 +89,29 @@ export async function rebuildFilter (model, filter = {}, options = {}) {
89
89
  filter.query = q
90
90
  return
91
91
  }
92
+ if (!req.user) {
93
+ filter.query = q
94
+ return
95
+ }
96
+
97
+ const condUserId = {
98
+ $or: [
99
+ { userId: req.user.id + '' },
100
+ { userId: { $eq: null } }
101
+ ]
102
+ }
103
+
104
+ const condTeamId = {
105
+ $or: [
106
+ { teamId: { $in: teamIds } },
107
+ { teamId: { $eq: null } }
108
+ ]
109
+ }
92
110
 
93
111
  if (hasTeamId) {
94
- if (hasUserId) q.$and.push({ $or: [{ teamId: { $in: teamIds } }, { userId: req.user.id + '' }] })
95
- else q.$and.push({ teamId: { $in: teamIds } })
96
- } else if (hasUserId) q.$and.push({ userId: req.user.id + '' })
112
+ if (hasUserId) q.$and.push({ $or: [condTeamId, condUserId] })
113
+ else q.$and.push(condTeamId)
114
+ } else if (hasUserId) q.$and.push(condUserId)
97
115
 
98
116
  await applyModelGuard.call(this, { model, q, teamIds, options })
99
117
  await applyAttribGuard.call(this, { model, teamIds, options })
@@ -102,7 +120,8 @@ export async function rebuildFilter (model, filter = {}, options = {}) {
102
120
 
103
121
  export async function handler (model, filter, options = {}) {
104
122
  const { isEmpty } = this.app.lib._
105
- if (options.noAutoFilter || !options.req || isEmpty((options.req ?? {}).site)) return
123
+ const { req = {} } = options
124
+ if (options.noAutoFilter || isEmpty(req) || isEmpty(req.site)) return
106
125
  await rebuildFilter.call(this, model, filter, options)
107
126
  }
108
127
 
@@ -1,9 +1,10 @@
1
1
  import { rebuildFilter } from './dobo@before-driver-find-record.js'
2
2
 
3
3
  export async function checker (model, id, options = {}) {
4
- const { req } = options
4
+ const { isEmpty } = this.app.lib._
5
+ const { req = {} } = options
6
+ if (options.noAutoFilter || isEmpty(req) || isEmpty(req.site)) return
5
7
 
6
- if (options.noAutoFilter || !req) return
7
8
  const filter = {}
8
9
  await rebuildFilter.call(this, model, filter, options)
9
10
  if (filter.query.$and) filter.query.$and.push({ id })
@@ -1,6 +1,6 @@
1
1
  [{
2
- "userId": "?:SumbaUser::username:admin",
3
- "teamId": "?:SumbaTeam::alias:administrator",
4
2
  "siteId": "?:SumbaSite::alias:default",
3
+ "userId": "?:SumbaUser::username:admin+siteId={siteId}",
4
+ "teamId": "?:SumbaTeam::alias:administrator+siteId={siteId}",
5
5
  "_immutable": true
6
6
  }]
@@ -8,9 +8,9 @@
8
8
  "features": [
9
9
  "dobo:createdAt",
10
10
  "dobo:updatedAt",
11
- "sumba:teamId",
12
11
  "sumba:siteId",
13
12
  "sumba:userId",
13
+ "sumba:teamId",
14
14
  "dobo:immutable"
15
15
  ]
16
16
  }
package/index.js CHANGED
@@ -32,7 +32,7 @@ async function factory (pkgName) {
32
32
  super(pkgName, me.app)
33
33
  this.config = {
34
34
  multiSite: cloneDeep(defMultiSite),
35
- crossSiteAdmins: [], // format: "<siteAlias>:<username>"
35
+ xSiteAdmins: [], // format: "<siteAlias>:<username>"
36
36
  waibu: {
37
37
  title: 'site',
38
38
  prefix: 'site'
@@ -175,10 +175,10 @@ async function factory (pkgName) {
175
175
 
176
176
  start = async () => {
177
177
  const { getModel } = this.app.dobo
178
- if (this.config.crossSiteAdmins.length === 0) {
178
+ if (this.config.xSiteAdmins.length === 0) {
179
179
  const site = await getModel('SumbaSite').findOneRecord({ query: { alias: 'default' } }, { noMagic: true })
180
180
  const user = await getModel('SumbaUser').findOneRecord({ query: { username: 'admin', siteId: site.id } }, { noMagic: true })
181
- this.config.crossSiteAdmins.push(`${site.alias}:${user.username}`)
181
+ this.config.xSiteAdmins.push(`${site.alias}:${user.username}`)
182
182
  }
183
183
  }
184
184
 
@@ -556,7 +556,7 @@ async function factory (pkgName) {
556
556
 
557
557
  getRouteGuards = async (reread) => {
558
558
  const { routePath } = this.app.waibu
559
- const { map, orderBy } = this.app.lib._
559
+ const { orderBy } = this.app.lib._
560
560
  const { isSet } = this.app.lib.aneka
561
561
  if (!reread) return this.routeGuards
562
562
 
@@ -571,9 +571,13 @@ async function factory (pkgName) {
571
571
  delete item.siteId
572
572
  return item
573
573
  })
574
- this.routeGuards[type] = orderBy(map(result[type], item => {
575
- item.path = routePath(item.path)
576
- return item
574
+ this.routeGuards[type] = orderBy(result[type].filter(item => {
575
+ try {
576
+ item.path = routePath(item.path)
577
+ return true
578
+ } catch (err) {
579
+ return false
580
+ }
577
581
  }), ['weight', 'path'], ['desc', 'asc'])
578
582
  }
579
583
  return this.routeGuards
package/lib/get-user.js CHANGED
@@ -30,7 +30,7 @@ export async function mergeTeam (user, req) {
30
30
  user.teams.push(item)
31
31
  }
32
32
  }
33
- user.isXSiteAdmin = this.config.crossSiteAdmins.includes(`${req.site.alias}:${user.username}`)
33
+ user.isXSiteAdmin = this.config.xSiteAdmins.includes(`${req.site.alias}:${user.username}`)
34
34
  user.isAdmin = user.teams.some(t => t.alias === 'administrator')
35
35
  for (const field of this.unsafeUserFields) {
36
36
  delete user[field]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sumba",
3
- "version": "2.25.0",
3
+ "version": "2.25.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,9 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-05-25
4
+
5
+ - [2.25.1] Bug fix in several places because name changing ```crossSiteAdmins``` to ```xSiteAdmins```
6
+
3
7
  ## 2026-05-22
4
8
 
5
9
  - [2.25.0] Reorganize admin menu layout & order