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.
- package/extend/bajo/hook/dobo@before-driver-find-all-record.js +2 -7
- package/extend/bajo/hook/dobo@before-driver-find-record.js +23 -4
- package/extend/bajo/hook/dobo@before-driver-get-record.js +3 -2
- package/extend/dobo/fixture/team-user.json +2 -2
- package/extend/dobo/model/team-user.json +1 -1
- package/index.js +11 -7
- package/lib/get-user.js +1 -1
- package/package.json +1 -1
- package/wiki/CHANGES.md +4 -0
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { handler } from './dobo@before-driver-find-record.js'
|
|
2
2
|
|
|
3
3
|
const doboBeforeDriverFindAllRecord = {
|
|
4
4
|
level: 1000,
|
|
5
|
-
handler
|
|
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: [
|
|
95
|
-
else q.$and.push(
|
|
96
|
-
} else if (hasUserId) q.$and.push(
|
|
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
|
-
|
|
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 {
|
|
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
|
}]
|
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
|
-
|
|
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.
|
|
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.
|
|
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 {
|
|
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(
|
|
575
|
-
|
|
576
|
-
|
|
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.
|
|
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