sumba 2.8.1 → 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
|
|
|
@@ -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:
|
|
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
|
-
|
|
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
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
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)
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
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```
|