sumba 2.28.0 → 2.30.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.
- package/extend/bajo/hook.js +40 -42
- package/extend/bajo/intl/en-US.json +6 -5
- package/extend/bajo/intl/id.json +6 -5
- package/extend/dobo/feature/status.js +3 -1
- package/extend/dobo/fixture/site.json +1 -1
- package/extend/dobo/fixture/team-user.json +1 -1
- package/extend/dobo/fixture/team.json +2 -2
- package/extend/dobo/fixture/user.json +1 -1
- package/extend/dobo/model.js +113 -122
- package/extend/dobo/model.json +2 -40
- package/extend/sumba/route/anonymous.json +5 -0
- package/extend/sumba/route/secure.json +8 -0
- package/extend/waibuDb/schema/anonymous-guard.js +15 -0
- package/extend/waibuDb/schema/{route-guard.js → secure-guard.js} +2 -2
- package/extend/waibuDb/schema/team.json +1 -1
- package/extend/waibuDb/schema/ticket.js +32 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/{x/model-guard → anonymous-guard}/@action.js +2 -3
- package/extend/waibuMpa/extend/waibuAdmin/route/{route-guard → secure-guard}/@action.js +2 -2
- package/extend/waibuMpa/route/access-token.js +3 -1
- package/extend/waibuRestApi/route/manage/anonymous-guard/model-builder.json +4 -0
- package/extend/waibuRestApi/route/manage/{route-guard → secure-guard}/model-builder.json +1 -1
- package/index.js +153 -98
- package/lib/get-user.js +1 -1
- package/lib/util.js +28 -67
- package/package.json +1 -1
- package/wiki/CHANGES.md +13 -0
- package/extend/dobo/fixture/x-route-guard.js +0 -24
- package/extend/waibuDb/schema/ticket.json +0 -16
- package/extend/waibuDb/schema/x-attrib-guard.js +0 -15
- package/extend/waibuDb/schema/x-model-guard.js +0 -15
- package/extend/waibuDb/schema/x-route-guard.js +0 -15
- package/extend/waibuMpa/extend/waibuAdmin/route/x/attrib-guard/@action.js +0 -12
- package/extend/waibuMpa/extend/waibuAdmin/route/x/route-guard/@action.js +0 -12
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
async function ticket () {
|
|
2
|
+
const { routePath } = this.app.waibu
|
|
3
|
+
return {
|
|
4
|
+
common: {
|
|
5
|
+
widget: {
|
|
6
|
+
subject: {
|
|
7
|
+
attr: {
|
|
8
|
+
col: '8-md'
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
cat: {
|
|
12
|
+
addons: [{
|
|
13
|
+
attr: {
|
|
14
|
+
'x-data': true,
|
|
15
|
+
'@click': `location.href='${routePath('waibuAdmin:/site/ticket-cat/add')}'`,
|
|
16
|
+
icon: 'add'
|
|
17
|
+
},
|
|
18
|
+
type: 'button',
|
|
19
|
+
position: 'append'
|
|
20
|
+
}]
|
|
21
|
+
},
|
|
22
|
+
userId: {
|
|
23
|
+
attr: {
|
|
24
|
+
url: 'sumba.restapi:/manage/user'
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default ticket
|
package/extend/waibuMpa/extend/waibuAdmin/route/{x/model-guard → anonymous-guard}/@action.js
RENAMED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
const action = {
|
|
2
2
|
method: ['GET', 'POST'],
|
|
3
|
-
title: '
|
|
4
|
-
xSite: true,
|
|
3
|
+
title: 'anonymousGuard',
|
|
5
4
|
handler: async function (req, reply) {
|
|
6
5
|
const { importModule } = this.app.bajo
|
|
7
6
|
const crudSkel = await importModule('waibuAdmin:/lib/crud-skel.js')
|
|
8
|
-
return await crudSkel.call(this, '
|
|
7
|
+
return await crudSkel.call(this, 'SumbaAnonymousGuard', req, reply)
|
|
9
8
|
}
|
|
10
9
|
}
|
|
11
10
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const action = {
|
|
2
2
|
method: ['GET', 'POST'],
|
|
3
|
-
title: '
|
|
3
|
+
title: 'secureGuard',
|
|
4
4
|
handler: async function (req, reply) {
|
|
5
5
|
const { importModule } = this.app.bajo
|
|
6
6
|
const crudSkel = await importModule('waibuAdmin:/lib/crud-skel.js')
|
|
7
|
-
return await crudSkel.call(this, '
|
|
7
|
+
return await crudSkel.call(this, 'SumbaSecureGuard', req, reply)
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
const apiToken = {
|
|
2
2
|
method: 'POST',
|
|
3
3
|
handler: async function (req, reply) {
|
|
4
|
-
|
|
4
|
+
const { get } = this.app.lib._
|
|
5
|
+
const uid = get(req, 'user.id')
|
|
6
|
+
if (!uid) return ''
|
|
5
7
|
const rec = await this.app.dobo.getModel('SumbaUser').getRecord(req.user.id, { forceNoHidden: true, noCache: true })
|
|
6
8
|
return (await this.createJwtFromUserRecord(rec)).token
|
|
7
9
|
}
|
package/index.js
CHANGED
|
@@ -20,7 +20,7 @@ const defMultiSite = {
|
|
|
20
20
|
async function factory (pkgName) {
|
|
21
21
|
const me = this
|
|
22
22
|
const { getModel } = this.app.dobo
|
|
23
|
-
const { cloneDeep,
|
|
23
|
+
const { cloneDeep, isEmpty } = this.app.lib._
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Sumba class
|
|
@@ -52,6 +52,14 @@ async function factory (pkgName) {
|
|
|
52
52
|
'/help': 'sumba:/help/contact-form',
|
|
53
53
|
'/help/trouble-tickets': 'sumba:/help/trouble-tickets/list'
|
|
54
54
|
},
|
|
55
|
+
redirectSubRoute: {
|
|
56
|
+
waibuAdmin: {
|
|
57
|
+
'/': 'waibuAdmin:/site/site',
|
|
58
|
+
'/x': 'waibuAdmin:/site/x/site/list',
|
|
59
|
+
'/x/*': 'waibuAdmin:/site/x/{2}/list',
|
|
60
|
+
'/*': 'waibuAdmin:/site/{1}/list'
|
|
61
|
+
}
|
|
62
|
+
},
|
|
55
63
|
menuHandler: [{
|
|
56
64
|
title: 'account',
|
|
57
65
|
icon: 'person',
|
|
@@ -155,9 +163,11 @@ async function factory (pkgName) {
|
|
|
155
163
|
getUserByTokenDur: '1m'
|
|
156
164
|
}
|
|
157
165
|
}
|
|
158
|
-
this.
|
|
159
|
-
this.modelGuards =
|
|
160
|
-
this.attribGuards =
|
|
166
|
+
this.secureGuards = []
|
|
167
|
+
this.modelGuards = []
|
|
168
|
+
this.attribGuards = []
|
|
169
|
+
this.secureGuards = []
|
|
170
|
+
this.anonymousGuards = []
|
|
161
171
|
|
|
162
172
|
this.unsafeUserFields = ['password']
|
|
163
173
|
this.selfBind(['createNewSite', 'removeSite', 'getSite', 'getUserById', 'getUserByToken', 'getUserByUsernamePassword'])
|
|
@@ -174,7 +184,11 @@ async function factory (pkgName) {
|
|
|
174
184
|
}
|
|
175
185
|
|
|
176
186
|
start = async () => {
|
|
177
|
-
|
|
187
|
+
await this.populateRouteGuards()
|
|
188
|
+
if (!this.config.multiSite.enabled) {
|
|
189
|
+
this.config.xSiteAdmins = []
|
|
190
|
+
return
|
|
191
|
+
}
|
|
178
192
|
if (this.config.xSiteAdmins.length === 0) {
|
|
179
193
|
const site = await getModel('SumbaSite').findOneRecord({ query: { alias: 'default' } }, { noMagic: true })
|
|
180
194
|
const user = await getModel('SumbaUser').findOneRecord({ query: { username: 'admin', siteId: site.id } }, { noMagic: true })
|
|
@@ -182,6 +196,84 @@ async function factory (pkgName) {
|
|
|
182
196
|
}
|
|
183
197
|
}
|
|
184
198
|
|
|
199
|
+
populateRouteGuards = async () => {
|
|
200
|
+
const { isString, get, difference } = this.app.lib._
|
|
201
|
+
const { pascalCase } = this.app.lib.aneka
|
|
202
|
+
const { eachPlugins, readConfig, breakNsPath } = this.app.bajo
|
|
203
|
+
const { getModel } = this.app.dobo
|
|
204
|
+
|
|
205
|
+
const allNs = this.app.getAllNs()
|
|
206
|
+
const sites = await getModel('SumbaSite').findAllRecord({ query: { status: 'ACTIVE' } }, { noMagic: true, dataOnly: true, fields: ['id', 'hostname'] })
|
|
207
|
+
|
|
208
|
+
const sanitize = (item, ns) => {
|
|
209
|
+
if (isString(item)) item = { path: item }
|
|
210
|
+
let [prefix, ...args] = item.path.split(':')
|
|
211
|
+
const neg = prefix[0] === '!'
|
|
212
|
+
if (neg) prefix = prefix.slice(1)
|
|
213
|
+
if (isEmpty(args)) {
|
|
214
|
+
args = prefix
|
|
215
|
+
prefix = null
|
|
216
|
+
} else args = args.join(':')
|
|
217
|
+
if (isEmpty(prefix)) prefix = ns
|
|
218
|
+
else {
|
|
219
|
+
const [_ns, subNs] = prefix.split('.')
|
|
220
|
+
if (subNs) prefix = `${ns}.${subNs}`
|
|
221
|
+
else if (!allNs.includes(_ns)) prefix = `${ns}.${_ns}`
|
|
222
|
+
else prefix = _ns
|
|
223
|
+
}
|
|
224
|
+
item.path = `${neg ? '!' : ''}${prefix}:${args}`
|
|
225
|
+
item._immutable = item._immutable ?? ['path']
|
|
226
|
+
if (neg) {
|
|
227
|
+
item.allTeams = true
|
|
228
|
+
item.teamIds = []
|
|
229
|
+
item._immutable = ['path', 'teamIds', 'allTeams']
|
|
230
|
+
}
|
|
231
|
+
return item
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const filterFn = item => {
|
|
235
|
+
let [ns] = (item.path.split(':')[0] ?? '').split('.')
|
|
236
|
+
if (ns[0] === '!') ns = ns.slice(1)
|
|
237
|
+
return allNs.includes(ns)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
for (const type of ['secure', 'anonymous']) {
|
|
241
|
+
const routes = []
|
|
242
|
+
// get it from <pluginDir>/extend/sumba/route/*
|
|
243
|
+
await eachPlugins(async function ({ file }) {
|
|
244
|
+
const { ns } = this
|
|
245
|
+
const items = (await readConfig(file)).map(item => sanitize(item, ns)).filter(filterFn)
|
|
246
|
+
routes.push(...items)
|
|
247
|
+
}, { glob: `route/${type}.*`, prefix: this.ns })
|
|
248
|
+
// get it from config
|
|
249
|
+
const items = get(this, `config.route.${type}`, []).map(item => {
|
|
250
|
+
if (isString(item)) item = { path: item }
|
|
251
|
+
const neg = item.path[0] === '!'
|
|
252
|
+
if (neg) item.path.slice(1)
|
|
253
|
+
const { fullNs } = breakNsPath(item.path)
|
|
254
|
+
if (neg) item.path = '!' + item.path
|
|
255
|
+
return sanitize(item, fullNs)
|
|
256
|
+
}).filter(filterFn)
|
|
257
|
+
routes.push(...items)
|
|
258
|
+
const paths = routes.map(item => item.path)
|
|
259
|
+
const model = getModel(pascalCase(`Sumba ${type} Guard`))
|
|
260
|
+
for (const site of sites) {
|
|
261
|
+
const query = { path: { $in: paths }, siteId: site.id }
|
|
262
|
+
const recs = await model.findAllRecord({ query }, { noMagic: true, dataOnly: true, fields: ['path', 'status'] })
|
|
263
|
+
const spaths = difference(paths, recs.map(rec => rec.path))
|
|
264
|
+
for (const path of spaths) {
|
|
265
|
+
const body = cloneDeep(routes.find(r => r.path === path))
|
|
266
|
+
body.status = 'ACTIVE'
|
|
267
|
+
body.siteId = site.id
|
|
268
|
+
await model.sanitizeFixture({ body, lookupValue: body })
|
|
269
|
+
try {
|
|
270
|
+
await model.createRecord(body, { noMagic: true, noReturn: true })
|
|
271
|
+
} catch (err) {}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
185
277
|
_getSetting = async (type, source) => {
|
|
186
278
|
const { defaultsDeep } = this.app.lib.aneka
|
|
187
279
|
const { get } = this.app.lib._
|
|
@@ -208,18 +300,10 @@ async function factory (pkgName) {
|
|
|
208
300
|
adminMenu = async (locals, req) => {
|
|
209
301
|
if (!this.app.waibuAdmin) return
|
|
210
302
|
const { getPluginPrefix } = this.app.waibu
|
|
303
|
+
const { findIndex } = this.app.lib._
|
|
211
304
|
const prefix = getPluginPrefix(this.ns)
|
|
212
305
|
const params = { action: 'list' }
|
|
213
306
|
const items = [{
|
|
214
|
-
title: 'xSite',
|
|
215
|
-
children: [
|
|
216
|
-
{ title: 'allSites', href: `waibuAdmin:/${prefix}/x/site/:action`, params },
|
|
217
|
-
{ title: 'xRouteGuard', href: `waibuAdmin:/${prefix}/x/route-guard/:action`, params },
|
|
218
|
-
{ title: 'xModelGuard', href: `waibuAdmin:/${prefix}/x/model-guard/:action`, params },
|
|
219
|
-
{ title: 'xAttribGuard', href: `waibuAdmin:/${prefix}/x/attrib-guard/:action`, params },
|
|
220
|
-
{ title: 'userSession', href: `waibuAdmin:/${prefix}/x/session/:action`, params }
|
|
221
|
-
]
|
|
222
|
-
}, {
|
|
223
307
|
title: 'manageSite',
|
|
224
308
|
children: [
|
|
225
309
|
{ title: 'siteProfile', href: `waibuAdmin:/${prefix}/site` },
|
|
@@ -242,7 +326,8 @@ async function factory (pkgName) {
|
|
|
242
326
|
}, {
|
|
243
327
|
title: 'permission',
|
|
244
328
|
children: [
|
|
245
|
-
{ title: '
|
|
329
|
+
{ title: 'secureGuard', href: `waibuAdmin:/${prefix}/secure-guard/:action`, params },
|
|
330
|
+
{ title: 'anonymousGuard', href: `waibuAdmin:/${prefix}/anonymous-guard/:action`, params },
|
|
246
331
|
{ title: 'modelGuard', href: `waibuAdmin:/${prefix}/model-guard/:action`, params },
|
|
247
332
|
{ title: 'attribGuard', href: `waibuAdmin:/${prefix}/attrib-guard/:action`, params }
|
|
248
333
|
]
|
|
@@ -260,9 +345,23 @@ async function factory (pkgName) {
|
|
|
260
345
|
{ title: 'manageDownload', href: `waibuAdmin:/${prefix}/download/:action`, params }
|
|
261
346
|
]
|
|
262
347
|
}]
|
|
348
|
+
const sessionMenu = { title: 'userSession', href: `waibuAdmin:/${prefix}/x/session/:action`, params }
|
|
349
|
+
const cacheMenu = { title: 'cacheStorage', href: `waibuAdmin:/${prefix}/x/cache/:action`, params }
|
|
350
|
+
if (this.config.multiSite.enabled) {
|
|
351
|
+
items.unshift({
|
|
352
|
+
title: 'xSite',
|
|
353
|
+
children: [
|
|
354
|
+
{ title: 'allSites', href: `waibuAdmin:/${prefix}/x/site/:action`, params },
|
|
355
|
+
sessionMenu
|
|
356
|
+
]
|
|
357
|
+
})
|
|
358
|
+
} else {
|
|
359
|
+
const idx = findIndex(items, i => i.title === 'misc')
|
|
360
|
+
if (idx > -1) items[idx].children.push(sessionMenu)
|
|
361
|
+
}
|
|
263
362
|
if (this.app.bajoCache) {
|
|
264
|
-
const
|
|
265
|
-
|
|
363
|
+
const idx = findIndex(items, i => i.title === this.config.multiSite.enabled ? 'xSite' : 'misc')
|
|
364
|
+
if (idx > -1)items[idx].children.push(cacheMenu)
|
|
266
365
|
}
|
|
267
366
|
return items
|
|
268
367
|
}
|
|
@@ -377,31 +476,11 @@ async function factory (pkgName) {
|
|
|
377
476
|
return true
|
|
378
477
|
}
|
|
379
478
|
|
|
380
|
-
|
|
381
|
-
const { includes } = this.app.lib.aneka
|
|
479
|
+
checkRouteGuard = (guards, paths) => {
|
|
382
480
|
const { outmatch } = this.app.lib
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
for (const path of paths) {
|
|
387
|
-
if (matchPath(path)) {
|
|
388
|
-
if (item.methods.includes(req.method)) {
|
|
389
|
-
if (includes(teamIds, item.teamIds)) return item
|
|
390
|
-
if (teamIds.length === 0) return item
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
checkPathsByGuard = ({ guards, paths }) => {
|
|
398
|
-
const { outmatch } = this.app.lib
|
|
399
|
-
const matcher = outmatch(guards)
|
|
400
|
-
let guarded
|
|
401
|
-
for (const path of paths) {
|
|
402
|
-
if (!guarded) guarded = matcher(path)
|
|
403
|
-
}
|
|
404
|
-
return guarded
|
|
481
|
+
const all = guards.map(item => item.path)
|
|
482
|
+
const isMatch = outmatch(all)
|
|
483
|
+
return paths.find(isMatch)
|
|
405
484
|
}
|
|
406
485
|
|
|
407
486
|
signout = async ({ req, reply, reason }) => {
|
|
@@ -545,81 +624,56 @@ async function factory (pkgName) {
|
|
|
545
624
|
return await hash(item, this.config.auth.common.apiKey.algo)
|
|
546
625
|
}
|
|
547
626
|
|
|
548
|
-
_fetchGuards = async (type
|
|
627
|
+
_fetchGuards = async (type) => {
|
|
549
628
|
const { getModel } = this.app.dobo
|
|
550
629
|
const options = { noMagic: true, noCache: true, noDriverHook: true, dataOnly: true }
|
|
551
630
|
const filter = { query: { status: 'ACTIVE' } }
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
}
|
|
631
|
+
const results = await getModel(`Sumba${type}Guard`).findAllRecord(filter, options)
|
|
632
|
+
return results.map(result => {
|
|
633
|
+
result.teamIds = result.teamIds.map(item => item + '')
|
|
634
|
+
return result
|
|
635
|
+
})
|
|
557
636
|
}
|
|
558
637
|
|
|
559
|
-
|
|
638
|
+
_getGuards = (inputs = []) => {
|
|
560
639
|
const { routePath } = this.app.waibu
|
|
561
640
|
const { orderBy } = this.app.lib._
|
|
562
|
-
const
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
result
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
return this.routeGuards
|
|
641
|
+
const normal = orderBy(inputs.filter(input => input.path[0] !== '!').map(result => {
|
|
642
|
+
result.path = routePath(result.path)
|
|
643
|
+
return result
|
|
644
|
+
}), ['weight', 'path'], ['desc', 'asc'])
|
|
645
|
+
const inverse = orderBy(inputs.filter(input => input.path[0] === '!').map(result => {
|
|
646
|
+
result.path = routePath(result.path)
|
|
647
|
+
return result
|
|
648
|
+
}), ['weight', 'path'], ['desc', 'asc'])
|
|
649
|
+
return [...normal, ...inverse]
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
getAnonymousGuards = async (reread) => {
|
|
653
|
+
if (!reread) return this.anonymousGuards
|
|
654
|
+
const guards = await this._fetchGuards('Anonymous')
|
|
655
|
+
this.anonymousGuards = this._getGuards(guards)
|
|
656
|
+
return this.anonymousGuards
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
getSecureGuards = async (reread) => {
|
|
660
|
+
if (!reread) return this.secureGuards
|
|
661
|
+
const guards = await this._fetchGuards('Secure')
|
|
662
|
+
this.secureGuards = this._getGuards(guards)
|
|
663
|
+
return this.secureGuards
|
|
586
664
|
}
|
|
587
665
|
|
|
588
666
|
getModelGuards = async (reread) => {
|
|
589
|
-
const { isSet } = this.app.lib.aneka
|
|
590
667
|
if (!reread) return this.modelGuards
|
|
591
668
|
|
|
592
|
-
|
|
593
|
-
for (const type of ['global', 'local']) {
|
|
594
|
-
this.modelGuards[type] = result[type].filter(item => (!isEmpty(item.value)) && (!isEmpty(item.models))).map(item => {
|
|
595
|
-
item.siteIds = item.siteIds ?? []
|
|
596
|
-
if (item.siteIds.length === 0) item.siteIds = [...result.siteIds]
|
|
597
|
-
if (item.siteId) item.siteIds = uniq([...item.siteIds, item.siteId].filter(i => isSet(i)).map(i => i + ''))
|
|
598
|
-
item.teamIds = (item.teamIds ?? []).filter(i => isSet(i)).map(i => i + '')
|
|
599
|
-
delete item.siteId
|
|
600
|
-
return item
|
|
601
|
-
})
|
|
602
|
-
}
|
|
669
|
+
this.modelGuards = await this._fetchGuards('Model')
|
|
603
670
|
return this.modelGuards
|
|
604
671
|
}
|
|
605
672
|
|
|
606
673
|
getAttribGuards = async (reread) => {
|
|
607
|
-
const { isSet } = this.app.lib.aneka
|
|
608
674
|
if (!reread) return this.attribGuards
|
|
609
675
|
|
|
610
|
-
|
|
611
|
-
for (const type of ['global', 'local']) {
|
|
612
|
-
this.attribGuards[type] = result[type].map(item => {
|
|
613
|
-
item.siteIds = item.siteIds ?? []
|
|
614
|
-
if (item.siteIds.length === 0) item.siteIds = [...result.siteIds]
|
|
615
|
-
if (item.siteId) item.siteIds = uniq([...item.siteIds, item.siteId].filter(i => isSet(i)).map(i => i + ''))
|
|
616
|
-
item.teamIds = (item.teamIds ?? []).filter(i => isSet(i)).map(i => i + '')
|
|
617
|
-
item.models = item.models ?? []
|
|
618
|
-
item.hiddenCols = item.hiddenCols ?? []
|
|
619
|
-
delete item.siteId
|
|
620
|
-
return item
|
|
621
|
-
})
|
|
622
|
-
}
|
|
676
|
+
this.attribGuards = await this._fetchGuards('Model')
|
|
623
677
|
return this.attribGuards
|
|
624
678
|
}
|
|
625
679
|
|
|
@@ -632,6 +686,7 @@ async function factory (pkgName) {
|
|
|
632
686
|
removeSite = removeSite
|
|
633
687
|
getSite = getSite
|
|
634
688
|
getUserById = getUserById
|
|
689
|
+
|
|
635
690
|
getUserByToken = getUserByToken
|
|
636
691
|
getUserByUsernamePassword = getUserByUsernamePassword
|
|
637
692
|
}
|
package/lib/get-user.js
CHANGED
|
@@ -10,7 +10,7 @@ export async function mergeTeam (user, req) {
|
|
|
10
10
|
if (userTeam.length === 0) return
|
|
11
11
|
delete query.userId
|
|
12
12
|
query.id = { $in: map(userTeam, 'teamId') }
|
|
13
|
-
query.status = '
|
|
13
|
+
query.status = 'ACTIVE'
|
|
14
14
|
mdl = getModel('SumbaTeam')
|
|
15
15
|
const teams = await mdl.findAllRecord({ query })
|
|
16
16
|
if (teams.length > 0) {
|
package/lib/util.js
CHANGED
|
@@ -26,7 +26,7 @@ export function parseNsSettings (ns, setting, items) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export function pathsToCheck (req
|
|
29
|
+
export function pathsToCheck (req) {
|
|
30
30
|
const { uniq, without } = this.app.lib._
|
|
31
31
|
const items = [req.routeOptions.url, req.url].map(url => url.split('?')[0].split('#')[0])
|
|
32
32
|
return uniq(without(items, undefined, null))
|
|
@@ -56,36 +56,25 @@ export async function checkTheme (req, reply) {
|
|
|
56
56
|
req.theme = req.theme ?? 'default'
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
export async function checkTeam (req, reply
|
|
60
|
-
const {
|
|
59
|
+
export async function checkTeam (req, reply) {
|
|
60
|
+
const { includes } = this.app.lib.aneka
|
|
61
61
|
const { outmatch } = this.app.lib
|
|
62
|
-
route.teamIds = route.teamIds ?? []
|
|
63
|
-
if (route.teamIds.length === 0) return
|
|
64
62
|
|
|
65
|
-
const teamIds = map(req.user.teams, 'id')
|
|
66
|
-
const teamAliases = map(req.user.teams, 'alias')
|
|
67
63
|
if (req.user.isAdmin) return
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
if (!match) {
|
|
82
|
-
match = this.checkPathsByRoute({ paths, teamIds, guards: globalGuards.filter(item => !item.negation) })
|
|
83
|
-
if (match) {
|
|
84
|
-
const neg = this.checkPathsByRoute({ paths, teamIds, guards: globalGuards.filter(item => item.negation) })
|
|
85
|
-
if (neg) match = undefined
|
|
86
|
-
}
|
|
64
|
+
if (req.routeOptions.config.xSite && req.user.isXSiteAdmin) return
|
|
65
|
+
|
|
66
|
+
const teamIds = req.user.teams.map(item => item.id + '')
|
|
67
|
+
if (req.user.teams.map(item => item.alias).length === 0) throw this.error('accessDenied', { statusCode: 403 })
|
|
68
|
+
|
|
69
|
+
const paths = pathsToCheck.call(this, req)
|
|
70
|
+
const results = (await this.getSecureGuards()).filter(item => {
|
|
71
|
+
if (item.siteId !== req.site.id + '' || item.path[0] === '!') return false
|
|
72
|
+
return paths.some(outmatch([item.path]))
|
|
73
|
+
})
|
|
74
|
+
for (const result of results) {
|
|
75
|
+
if (result.allTeams) continue
|
|
76
|
+
if (!includes(teamIds, result.teamIds)) throw this.error('accessDenied', { statusCode: 403 })
|
|
87
77
|
}
|
|
88
|
-
if (!match) throw this.error('accessDenied', { statusCode: 403 })
|
|
89
78
|
// passed
|
|
90
79
|
}
|
|
91
80
|
|
|
@@ -116,51 +105,22 @@ export async function checkUserId (req, reply, source) {
|
|
|
116
105
|
}
|
|
117
106
|
|
|
118
107
|
const paths = pathsToCheck.call(this, req)
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const globalGuards = guards.global.filter(item => item.siteIds.includes(req.site.id + ''))
|
|
123
|
-
const localGuards = guards.local.filter(item => item.siteIds.includes(req.site.id + ''))
|
|
124
|
-
// find anonymousPath
|
|
125
|
-
anonymousPath = await this.checkPathsByRoute({ req, paths, guards: localGuards.filter(item => item.anonymous && !item.negation) })
|
|
126
|
-
if (anonymousPath) {
|
|
127
|
-
const neg = await this.checkPathsByRoute({ req, paths, guards: localGuards.filter(item => item.anonymous && item.negation) })
|
|
128
|
-
if (neg) anonymousPath = undefined
|
|
129
|
-
}
|
|
130
|
-
if (!anonymousPath) {
|
|
131
|
-
anonymousPath = await this.checkPathsByRoute({ req, paths, guards: globalGuards.filter(item => item.anonymous && !item.negation) })
|
|
132
|
-
if (anonymousPath) {
|
|
133
|
-
const neg = await this.checkPathsByRoute({ req, paths, guards: globalGuards.filter(item => item.anonymous && item.negation) })
|
|
134
|
-
if (neg) anonymousPath = undefined
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
// find securePath
|
|
138
|
-
securePath = await this.checkPathsByRoute({ req, paths, guards: localGuards.filter(item => !item.anonymous && !item.negation) })
|
|
139
|
-
if (securePath) {
|
|
140
|
-
const neg = await this.checkPathsByRoute({ req, paths, guards: localGuards.filter(item => !item.anonymous && item.negation) })
|
|
141
|
-
if (neg) securePath = undefined
|
|
142
|
-
}
|
|
143
|
-
if (!securePath) {
|
|
144
|
-
securePath = await this.checkPathsByRoute({ req, paths, guards: globalGuards.filter(item => !item.anonymous && !item.negation) })
|
|
145
|
-
if (securePath) {
|
|
146
|
-
const neg = await this.checkPathsByRoute({ req, paths, guards: globalGuards.filter(item => !item.anonymous && item.negation) })
|
|
147
|
-
if (neg) securePath = undefined
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
// checking...
|
|
151
|
-
if (!securePath && !anonymousPath) {
|
|
152
|
-
if (userId) await setUser()
|
|
153
|
-
return false // regular, unguarded path. Not secure & not anonymous path
|
|
154
|
-
}
|
|
155
|
-
if (anonymousPath) {
|
|
108
|
+
let guards = (await this.getAnonymousGuards()).filter(item => item.siteId === req.site.id + '')
|
|
109
|
+
const anonymous = this.checkRouteGuard(guards, paths)
|
|
110
|
+
if (anonymous) {
|
|
156
111
|
if (!userId) return false
|
|
157
112
|
req.session.ref = req.url
|
|
158
113
|
return reply.redirectTo(routePath(this.config.redirect.signout))
|
|
159
114
|
}
|
|
160
|
-
|
|
115
|
+
guards = (await this.getSecureGuards()).filter(item => item.siteId === req.site.id + '')
|
|
116
|
+
const secure = this.checkRouteGuard(guards, paths)
|
|
117
|
+
if (!secure) {
|
|
118
|
+
if (userId) await setUser()
|
|
119
|
+
return false // regular, unguarded path. Not secure & not anonymous path
|
|
120
|
+
}
|
|
161
121
|
if (userId) {
|
|
162
122
|
await setUser()
|
|
163
|
-
return
|
|
123
|
+
return secure
|
|
164
124
|
}
|
|
165
125
|
const silentOnError = this.config.auth[webApp].silentOnError ?? this.config.auth.common.silentOnError
|
|
166
126
|
const payload = silentOnError ? { noContent: true } : undefined
|
|
@@ -177,7 +137,7 @@ export async function checkUserId (req, reply, source) {
|
|
|
177
137
|
}
|
|
178
138
|
}
|
|
179
139
|
if (!success) throw this.error('accessDeniedNoAuth', merge({ statusCode: 403 }, payload))
|
|
180
|
-
return
|
|
140
|
+
return secure
|
|
181
141
|
}
|
|
182
142
|
|
|
183
143
|
export async function latLngHook (body, options) {
|
|
@@ -196,6 +156,7 @@ export async function latLngHook (body, options) {
|
|
|
196
156
|
*/
|
|
197
157
|
export async function checkXSite (req, reply) {
|
|
198
158
|
const { get } = this.app.lib._
|
|
159
|
+
if (!this.config.multiSite.enabled) return
|
|
199
160
|
if (!get(req, 'routeOptions.config.xSite')) return
|
|
200
161
|
if (!get(req, 'user.isXSiteAdmin')) throw this.error('accessDenied', { statusCode: 403 })
|
|
201
162
|
}
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-06-10
|
|
4
|
+
|
|
5
|
+
- [2.30.0] Refactoring all guards
|
|
6
|
+
- [2.30.0] Feature ```sumba:status``` now by default using ```ACTIVE``` and ```INACTIVE``` states
|
|
7
|
+
- [2.30.0] Bug in ```multiSite``` handling
|
|
8
|
+
- [2.30.0] Add ```populateRouteGuards()```
|
|
9
|
+
- [2.30.0] Bug fix in ```hook.js```
|
|
10
|
+
|
|
11
|
+
## 2026-06-03
|
|
12
|
+
|
|
13
|
+
- [2.29.0] Some models with property ```values``` now use the newly introduced function values
|
|
14
|
+
- [2.29.0] Add redirections from empty folder to the right page
|
|
15
|
+
|
|
3
16
|
## 2026-06-01
|
|
4
17
|
|
|
5
18
|
- [2.27.3] Bug fix in ```user.js``` schema
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const routes = [
|
|
2
|
-
'sumba:/your-stuff/**/*',
|
|
3
|
-
'sumba:/signout',
|
|
4
|
-
'sumba:/help/trouble-tickets/**/*',
|
|
5
|
-
'sumba.restapi:/user/api-key',
|
|
6
|
-
'sumba.restapi:/your-stuff/**/*',
|
|
7
|
-
'sumba.restapi:/manage/**/*',
|
|
8
|
-
'~sumba:/user/**/*',
|
|
9
|
-
'~sumba:/signin',
|
|
10
|
-
'~sumba.restapi:/user/access-token/**/*'
|
|
11
|
-
]
|
|
12
|
-
|
|
13
|
-
async function routeGuard () {
|
|
14
|
-
return routes.map(r => {
|
|
15
|
-
const anonymous = r[0] === '~'
|
|
16
|
-
return {
|
|
17
|
-
path: anonymous ? r.slice(1) : r,
|
|
18
|
-
anonymous,
|
|
19
|
-
status: 'ACTIVE'
|
|
20
|
-
}
|
|
21
|
-
})
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export default routeGuard
|