sumba 2.23.0 → 2.25.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/bajo.extend@after-read-config.js +13 -0
- package/extend/bajo/hook/dobo.sumba-attrib-guard$dobo.sumba-x-attrib-guard@after-transaction.js +6 -0
- package/extend/bajo/hook/dobo.sumba-model-guard$dobo.sumba-x-model-guard@after-transaction.js +6 -0
- package/extend/bajo/hook/dobo.sumba-route-guard$dobo.sumba-x-route-guard@after-transaction.js +6 -0
- package/extend/bajo/hook/dobo.sumba-team$dobo.sumba-site@after-transaction.js +8 -0
- package/extend/bajo/hook/dobo@before-count-record.js +3 -3
- package/extend/bajo/hook/{dobo@before-create-record.js → dobo@before-driver-create-record.js} +6 -6
- package/extend/bajo/hook/dobo@before-driver-find-all-record.js +13 -0
- package/extend/bajo/hook/dobo@before-driver-find-record.js +114 -0
- package/extend/bajo/hook/dobo@before-driver-get-record.js +22 -0
- package/extend/bajo/hook/dobo@before-driver-remove-record.js +10 -0
- package/extend/bajo/hook/dobo@before-driver-update-record.js +10 -0
- package/extend/bajo/hook/waibu-mpa@pre-parsing.js +5 -4
- package/extend/bajo/hook/waibu-rest-api@pre-parsing.js +5 -4
- package/extend/bajo/hook/waibu-static@pre-parsing.js +5 -4
- package/extend/bajo/hook/waibu@after-app-boot.js +2 -0
- package/extend/bajo/intl/en-US.json +13 -2
- package/extend/bajo/intl/id.json +20 -2
- package/extend/dobo/feature/site-ids.js +19 -0
- package/extend/dobo/feature/team-ids.js +19 -0
- package/extend/dobo/fixture/{route-guard.js → x-route-guard.js} +2 -4
- package/extend/dobo/model/attrib-guard.js +32 -0
- package/extend/dobo/model/model-guard.js +48 -0
- package/extend/dobo/model/route-guard.js +42 -54
- package/extend/dobo/model/x-attrib-guard.js +14 -0
- package/extend/dobo/model/x-model-guard.js +13 -0
- package/extend/dobo/model/x-route-guard.js +13 -0
- package/extend/waibuDb/schema/attrib-guard.js +15 -0
- package/extend/waibuDb/schema/model-guard.js +15 -0
- package/extend/waibuDb/schema/route-guard.js +1 -1
- package/extend/waibuDb/schema/user.js +19 -26
- package/extend/waibuDb/schema/x-attrib-guard.js +15 -0
- package/extend/waibuDb/schema/x-model-guard.js +15 -0
- package/extend/waibuDb/schema/x-route-guard.js +15 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/attrib-guard/@action.js +11 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/model-guard/@action.js +11 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/reset-user-password.js +2 -1
- package/extend/waibuMpa/extend/waibuAdmin/route/x/attrib-guard/@action.js +12 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/{cache → x/cache}/@action.js +1 -1
- package/extend/waibuMpa/extend/waibuAdmin/route/x/model-guard/@action.js +12 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/x/route-guard/@action.js +12 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/{session → x/session}/@action.js +1 -1
- package/extend/waibuMpa/extend/waibuAdmin/route/{all-sites → x/site}/@action.js +1 -1
- package/index.js +114 -35
- package/lib/get-user.js +9 -8
- package/lib/util.js +58 -23
- package/package.json +1 -1
- package/wiki/CHANGES.md +13 -0
- package/extend/bajo/hook/dobo.sumba-team-guard@after-action.js +0 -6
- package/extend/bajo/hook/dobo.sumba-user-guard@after-action.js +0 -6
- package/extend/bajo/hook/dobo@before-find-record.js +0 -63
- package/extend/bajo/hook/dobo@before-get-record.js +0 -23
- package/extend/bajo/hook/dobo@before-remove-record.js +0 -10
- package/extend/bajo/hook/dobo@before-update-record.js +0 -10
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import path from 'path'
|
|
2
|
+
|
|
3
|
+
async function afterReadConfig (file, result, options) {
|
|
4
|
+
const base = path.basename(file, path.extname(file))
|
|
5
|
+
// rewrite fixtures
|
|
6
|
+
if (!(base === 'route-guard' && Array.isArray(result) && file.includes('/fixture/'))) return
|
|
7
|
+
for (const res of result) {
|
|
8
|
+
if (res.path.slice(0, 2) === ':/') res.path = options.sourceNs + res.path
|
|
9
|
+
res.path = res.path.replaceAll('{ns}', options.sourceNs)
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default afterReadConfig
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
async function afterTransaction (action, ...args) {
|
|
2
|
+
if (!['createRecord', 'updateRecord', 'removeRecord'].includes(action)) return
|
|
3
|
+
await this.getRouteGuards(true)
|
|
4
|
+
await this.getModelGuards(true)
|
|
5
|
+
await this.getAttribGuards(true)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default afterTransaction
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { handler } from './dobo@before-find-record.js'
|
|
1
|
+
import { handler } from './dobo@before-driver-find-record.js'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const doboBeforeDriverCountRecord = {
|
|
4
4
|
level: 1000,
|
|
5
5
|
handler
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
export default
|
|
8
|
+
export default doboBeforeDriverCountRecord
|
package/extend/bajo/hook/{dobo@before-create-record.js → dobo@before-driver-create-record.js}
RENAMED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
const
|
|
1
|
+
const doboBeforeDriverCreateRecord = {
|
|
2
2
|
level: 1000,
|
|
3
|
-
handler: async function (
|
|
3
|
+
handler: async function (model, body, options = {}) {
|
|
4
4
|
const { get } = this.app.lib._
|
|
5
|
+
const { isSet } = this.app.lib.aneka
|
|
5
6
|
const { req } = options
|
|
6
|
-
if (options.noAutoFilter || !req || get(req, 'routeOptions.config.
|
|
7
|
+
if (options.noAutoFilter || !req || get(req, 'routeOptions.config.xSite')) return
|
|
7
8
|
const item = { siteId: 'site.id', userId: 'user.id' }
|
|
8
|
-
const model = this.app.dobo.getModel(modelName)
|
|
9
9
|
for (const i in item) {
|
|
10
10
|
const rec = get(req, item[i])
|
|
11
11
|
const field = model.getProperty(i)
|
|
12
|
-
if (rec && field) body[i] = field.type === 'string' ? (rec + '') : rec
|
|
12
|
+
if (rec && field && !isSet(body[i])) body[i] = field.type === 'string' ? (rec + '') : rec
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export default
|
|
17
|
+
export default doboBeforeDriverCreateRecord
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { rebuildFilter } from './dobo@before-driver-find-record.js'
|
|
2
|
+
|
|
3
|
+
const doboBeforeDriverFindAllRecord = {
|
|
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
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default doboBeforeDriverFindAllRecord
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
async function applyModelGuard ({ model, q, teamIds, options }) {
|
|
2
|
+
const { get, set, orderBy, intersection, without } = this.app.lib._
|
|
3
|
+
const { include } = this.app.lib.aneka
|
|
4
|
+
const { req } = options
|
|
5
|
+
const results = []
|
|
6
|
+
|
|
7
|
+
const guards = await this.getModelGuards()
|
|
8
|
+
const columns = model.getNonVirtualProperties().map(prop => prop.name)
|
|
9
|
+
const filterFn = item => {
|
|
10
|
+
const bySiteId = item.siteIds.includes(req.site.id + '')
|
|
11
|
+
const byModel = item.models.includes(model.name)
|
|
12
|
+
const byTeamId = item.teamIds.length === 0 || include(item.teamIds, teamIds)
|
|
13
|
+
const byColumn = columns.includes(item.column)
|
|
14
|
+
return bySiteId && byModel && byTeamId && byColumn
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
guards.global = orderBy(guards.global.filter(filterFn), ['column'])
|
|
18
|
+
guards.local = orderBy(guards.local.filter(filterFn), ['column'])
|
|
19
|
+
for (const col of columns) {
|
|
20
|
+
let values = []
|
|
21
|
+
let items = guards.global.filter(item => item.column === col && !item.negation)
|
|
22
|
+
for (const item of items) {
|
|
23
|
+
values.push(...item.value)
|
|
24
|
+
}
|
|
25
|
+
items = guards.global.filter(item => item.column === col && item.negation)
|
|
26
|
+
for (const item of items) {
|
|
27
|
+
values = without(values, ...item.value)
|
|
28
|
+
}
|
|
29
|
+
items = guards.local.filter(item => item.column === col && !item.negation)
|
|
30
|
+
const newValues = []
|
|
31
|
+
for (const item of items) {
|
|
32
|
+
newValues.push(...item.value)
|
|
33
|
+
}
|
|
34
|
+
if (newValues.length > 0) values = intersection(values, newValues)
|
|
35
|
+
items = guards.local.filter(item => item.column === col && item.negation)
|
|
36
|
+
for (const item of items) {
|
|
37
|
+
values = without(values, ...item.value)
|
|
38
|
+
}
|
|
39
|
+
if (values.length) results.push(set({}, col, { $in: values }))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const allowEmpty = get(this, `config.dobo.model.${model.name}.allowEmptyQuery`, true)
|
|
43
|
+
if (results.length === 0 && !allowEmpty) throw this.error('_emptyColumnQuery') // signal driver to about with no result immediately
|
|
44
|
+
q.$and.push(...results)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function applyAttribGuard ({ model, teamIds, options }) {
|
|
48
|
+
const { uniq } = this.app.lib._
|
|
49
|
+
const { include } = this.app.lib.aneka
|
|
50
|
+
const { req } = options
|
|
51
|
+
const results = []
|
|
52
|
+
|
|
53
|
+
const guards = await this.getAttribGuards()
|
|
54
|
+
const filterFn = item => {
|
|
55
|
+
const bySiteId = item.siteIds.includes(req.site.id + '')
|
|
56
|
+
const byModel = item.models.includes(model.name)
|
|
57
|
+
const byTeamId = item.teamIds.length === 0 || include(item.teamIds, teamIds)
|
|
58
|
+
return bySiteId && byModel && byTeamId
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let item = guards.global.filter(filterFn)[0]
|
|
62
|
+
if (item) results.push(...item.hiddenCols)
|
|
63
|
+
item = guards.local.filter(filterFn)[0]
|
|
64
|
+
if (item) results.push(...item.hiddenCols)
|
|
65
|
+
options.hidden = options.hidden ?? []
|
|
66
|
+
if (results.length > 0) options.hidden.push(...results)
|
|
67
|
+
options.hidden = uniq(options.hidden)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function rebuildFilter (model, filter = {}, options = {}) {
|
|
71
|
+
const { isEmpty, get } = this.app.lib._
|
|
72
|
+
const { req } = options
|
|
73
|
+
const hasSiteId = model.hasProperty('siteId')
|
|
74
|
+
const hasUserId = model.hasProperty('userId')
|
|
75
|
+
const hasTeamId = model.hasProperty('teamId')
|
|
76
|
+
const teams = get(req, 'user.teams', [])
|
|
77
|
+
const teamIds = teams.map(team => team.id + '')
|
|
78
|
+
const aliases = teams.map(team => team.alias)
|
|
79
|
+
const q = { $and: [] }
|
|
80
|
+
|
|
81
|
+
filter.query = filter.query ?? {}
|
|
82
|
+
if (!isEmpty(filter.query)) {
|
|
83
|
+
if (filter.query.$and) q.$and.push(...filter.query.$and)
|
|
84
|
+
else q.$and.push(filter.query)
|
|
85
|
+
}
|
|
86
|
+
if (req.routeOptions.config.xSite) return
|
|
87
|
+
if (hasSiteId) q.$and.push({ siteId: req.site.id + '' })
|
|
88
|
+
if (aliases.includes('administrator')) {
|
|
89
|
+
filter.query = q
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
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 + '' })
|
|
97
|
+
|
|
98
|
+
await applyModelGuard.call(this, { model, q, teamIds, options })
|
|
99
|
+
await applyAttribGuard.call(this, { model, teamIds, options })
|
|
100
|
+
filter.query = q
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export async function handler (model, filter, options = {}) {
|
|
104
|
+
const { isEmpty } = this.app.lib._
|
|
105
|
+
if (options.noAutoFilter || !options.req || isEmpty((options.req ?? {}).site)) return
|
|
106
|
+
await rebuildFilter.call(this, model, filter, options)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const doboBeforeDriverFindRecord = {
|
|
110
|
+
level: 1000,
|
|
111
|
+
handler
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export default doboBeforeDriverFindRecord
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { rebuildFilter } from './dobo@before-driver-find-record.js'
|
|
2
|
+
|
|
3
|
+
export async function checker (model, id, options = {}) {
|
|
4
|
+
const { req } = options
|
|
5
|
+
|
|
6
|
+
if (options.noAutoFilter || !req) return
|
|
7
|
+
const filter = {}
|
|
8
|
+
await rebuildFilter.call(this, model, filter, options)
|
|
9
|
+
if (filter.query.$and) filter.query.$and.push({ id })
|
|
10
|
+
else filter.query.id = id
|
|
11
|
+
const row = await model.findOneRecord(filter, { count: false })
|
|
12
|
+
if (!row) throw this.app.dobo.error('recordNotFound%s%s', id, this.name, { statusCode: 404 })
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const doboBeforeDriverGetRecord = {
|
|
16
|
+
level: 1000,
|
|
17
|
+
handler: async function (model, id, options) {
|
|
18
|
+
await checker.call(this, model, id, options)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default doboBeforeDriverGetRecord
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { checker } from './dobo@before-driver-get-record.js'
|
|
2
|
+
|
|
3
|
+
const doboBeforeDriverRemoveRecord = {
|
|
4
|
+
level: 1000,
|
|
5
|
+
handler: async function (model, id, options = {}) {
|
|
6
|
+
await checker.call(this, model, id, options.req)
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default doboBeforeDriverRemoveRecord
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { checker } from './dobo@before-driver-get-record.js'
|
|
2
|
+
|
|
3
|
+
const doboBeforeDriverUpdateRecord = {
|
|
4
|
+
level: 1000,
|
|
5
|
+
handler: async function (model, id, body, options = {}) {
|
|
6
|
+
await checker.call(this, model, id, options)
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default doboBeforeDriverUpdateRecord
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { checkUserId, checkTeam, checkTheme, checkIconset,
|
|
1
|
+
import { checkUserId, checkTeam, checkTheme, checkIconset, checkXSite } from '../../../lib/util.js'
|
|
2
2
|
|
|
3
3
|
const preParsing = {
|
|
4
4
|
level: 10,
|
|
5
5
|
handler: async function (req, reply) {
|
|
6
6
|
await checkTheme.call(this, req, reply)
|
|
7
7
|
await checkIconset.call(this, req, reply)
|
|
8
|
-
|
|
9
|
-
if (!
|
|
10
|
-
await
|
|
8
|
+
const secure = await checkUserId.call(this, req, reply, 'waibuMpa')
|
|
9
|
+
if (!secure) return
|
|
10
|
+
await checkTeam.call(this, req, reply, secure)
|
|
11
|
+
await checkXSite.call(this, req, reply)
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { checkUserId, checkTeam,
|
|
1
|
+
import { checkUserId, checkTeam, checkXSite } from '../../../lib/util.js'
|
|
2
2
|
|
|
3
3
|
const preParsing = {
|
|
4
4
|
level: 10,
|
|
5
5
|
handler: async function (req, reply) {
|
|
6
|
-
|
|
7
|
-
if (!
|
|
8
|
-
await
|
|
6
|
+
const secure = await checkUserId.call(this, req, reply, 'waibuRestApi')
|
|
7
|
+
if (!secure) return
|
|
8
|
+
await checkTeam.call(this, req, reply, secure)
|
|
9
|
+
await checkXSite.call(this, req, reply)
|
|
9
10
|
}
|
|
10
11
|
}
|
|
11
12
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { checkUserId, checkTeam,
|
|
1
|
+
import { checkUserId, checkTeam, checkXSite } from '../../../lib/util.js'
|
|
2
2
|
|
|
3
3
|
const preParsing = {
|
|
4
4
|
level: 10,
|
|
5
5
|
handler: async function (req, reply) {
|
|
6
|
-
|
|
7
|
-
if (!
|
|
8
|
-
await
|
|
6
|
+
const secure = await checkUserId.call(this, req, reply, 'waibuStatic')
|
|
7
|
+
if (!secure) return
|
|
8
|
+
await checkTeam.call(this, req, reply, secure)
|
|
9
|
+
await checkXSite.call(this, req, reply)
|
|
9
10
|
}
|
|
10
11
|
}
|
|
11
12
|
|
|
@@ -133,6 +133,13 @@
|
|
|
133
133
|
"allSites": "All Sites",
|
|
134
134
|
"permission": "Permission",
|
|
135
135
|
"routeGuard": "Route Guard",
|
|
136
|
+
"modelGuard": "Model Guard",
|
|
137
|
+
"attribGuard": "Attribute Guard",
|
|
138
|
+
"xRouteGuard": "Route Guard",
|
|
139
|
+
"xModelGuard": "Model Guard",
|
|
140
|
+
"xAttribGuard": "Attribute Guard",
|
|
141
|
+
"xSite": "Cross-Site",
|
|
142
|
+
"xSiteAdminArea": "Cross-Site Admin Area",
|
|
136
143
|
"field": {
|
|
137
144
|
"currentPassword": "Current Password",
|
|
138
145
|
"newPassword": "New Password",
|
|
@@ -158,10 +165,14 @@
|
|
|
158
165
|
"value": "Value",
|
|
159
166
|
"notes": "Notes",
|
|
160
167
|
"path": "Path",
|
|
161
|
-
"
|
|
168
|
+
"negation": "Negation?",
|
|
162
169
|
"anonymous": "Anonymous?",
|
|
163
170
|
"methods": "Methods",
|
|
164
|
-
"
|
|
171
|
+
"teamIds": "Teams",
|
|
172
|
+
"column": "Column",
|
|
173
|
+
"hiddenCols": "Hidden Columns",
|
|
174
|
+
"models": "Models",
|
|
175
|
+
"siteIds": "Sites"
|
|
165
176
|
},
|
|
166
177
|
"validation": {
|
|
167
178
|
"password": {
|
package/extend/bajo/intl/id.json
CHANGED
|
@@ -137,6 +137,15 @@
|
|
|
137
137
|
"statusOpen": "Terbuka",
|
|
138
138
|
"statusClosed": "Tertutup",
|
|
139
139
|
"allSites": "Semua Situs",
|
|
140
|
+
"permission": "Permisi",
|
|
141
|
+
"routeGuard": "Pelindung Rute",
|
|
142
|
+
"modelGuard": "Pelindung Model",
|
|
143
|
+
"attribGuard": "Pelindung Atribut",
|
|
144
|
+
"xRouteGuard": "Pelindung Rute",
|
|
145
|
+
"xModelGuard": "Pelindung Model",
|
|
146
|
+
"xAttribGuard": "Pelindung Atribut",
|
|
147
|
+
"xSite": "Antar Situs",
|
|
148
|
+
"xSiteAdminArea": "Area Admin Antar Situs",
|
|
140
149
|
"field": {
|
|
141
150
|
"currentPassword": "Kata Sandi Saat Ini",
|
|
142
151
|
"newPassword": "Kata Sandi Baru",
|
|
@@ -159,8 +168,17 @@
|
|
|
159
168
|
"user": "Pengguna",
|
|
160
169
|
"team": "Tim",
|
|
161
170
|
"ns": "Ruang Nama Modul",
|
|
162
|
-
"value": "
|
|
163
|
-
"notes": "Catatan"
|
|
171
|
+
"value": "Nilai",
|
|
172
|
+
"notes": "Catatan",
|
|
173
|
+
"path": "Jejak",
|
|
174
|
+
"negation": "Negation?",
|
|
175
|
+
"anonymous": "Anonim?",
|
|
176
|
+
"methods": "Metode",
|
|
177
|
+
"teamIds": "Tim",
|
|
178
|
+
"column": "Kolom",
|
|
179
|
+
"hiddenCols": "Kolom Tersembunyi",
|
|
180
|
+
"models": "Model",
|
|
181
|
+
"siteIds": "Situs"
|
|
164
182
|
},
|
|
165
183
|
"validation": {
|
|
166
184
|
"password": {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
async function siteIds (opts = {}) {
|
|
2
|
+
return {
|
|
3
|
+
properties: [{
|
|
4
|
+
name: 'siteIds',
|
|
5
|
+
type: 'array',
|
|
6
|
+
default: [],
|
|
7
|
+
ref: {
|
|
8
|
+
siteIds: {
|
|
9
|
+
model: 'SumbaSite',
|
|
10
|
+
field: 'id',
|
|
11
|
+
searchField: 'hostname',
|
|
12
|
+
fields: ['id', 'hostname']
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}]
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default siteIds
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
async function teamIds (opts = {}) {
|
|
2
|
+
return {
|
|
3
|
+
properties: [{
|
|
4
|
+
name: 'teamIds',
|
|
5
|
+
type: 'array',
|
|
6
|
+
default: [],
|
|
7
|
+
ref: {
|
|
8
|
+
teamIds: {
|
|
9
|
+
model: 'SumbaTeam',
|
|
10
|
+
field: 'id',
|
|
11
|
+
searchField: 'name',
|
|
12
|
+
fields: ['id', 'alias', 'name']
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}]
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default teamIds
|
|
@@ -10,17 +10,15 @@ const routes = [
|
|
|
10
10
|
'~sumba.restapi:/user/access-token/**/*'
|
|
11
11
|
]
|
|
12
12
|
|
|
13
|
-
async function
|
|
13
|
+
async function routeGuard () {
|
|
14
14
|
return routes.map(r => {
|
|
15
15
|
const anonymous = r[0] === '~'
|
|
16
16
|
return {
|
|
17
17
|
path: anonymous ? r.slice(1) : r,
|
|
18
18
|
anonymous,
|
|
19
|
-
_immutable: true,
|
|
20
|
-
siteId: '?:SumbaSite::alias:default',
|
|
21
19
|
status: 'ACTIVE'
|
|
22
20
|
}
|
|
23
21
|
})
|
|
24
22
|
}
|
|
25
23
|
|
|
26
|
-
export default
|
|
24
|
+
export default routeGuard
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { buildEnd, options } from './model-guard.js'
|
|
2
|
+
|
|
3
|
+
export const properties = [
|
|
4
|
+
{
|
|
5
|
+
name: 'models',
|
|
6
|
+
type: 'array',
|
|
7
|
+
required: true
|
|
8
|
+
},
|
|
9
|
+
'hiddenCols,array',
|
|
10
|
+
'siteId,sumba:siteId',
|
|
11
|
+
'teamIds,sumba:teamIds'
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
export const features = [
|
|
15
|
+
{
|
|
16
|
+
name: 'sumba:status',
|
|
17
|
+
values: ['ACTIVE', 'INACTIVE'],
|
|
18
|
+
default: 'ACTIVE'
|
|
19
|
+
},
|
|
20
|
+
'dobo:updatedAt'
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
async function routeGuard () {
|
|
24
|
+
return {
|
|
25
|
+
properties,
|
|
26
|
+
features,
|
|
27
|
+
options,
|
|
28
|
+
buildEnd
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default routeGuard
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export async function buildEnd (model) {
|
|
2
|
+
const prop = model.properties.find(prop => prop.name === 'models')
|
|
3
|
+
if (prop) prop.values = this.app.sumba.getModelNames(true)
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export const properties = [
|
|
7
|
+
{
|
|
8
|
+
name: 'models',
|
|
9
|
+
type: 'array',
|
|
10
|
+
required: true
|
|
11
|
+
},
|
|
12
|
+
'column,,50,true,true',
|
|
13
|
+
{
|
|
14
|
+
name: 'negation',
|
|
15
|
+
type: 'boolean',
|
|
16
|
+
required: true,
|
|
17
|
+
default: false
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: 'status',
|
|
21
|
+
type: 'sumba:status',
|
|
22
|
+
values: ['ACTIVE', 'INACTIVE'],
|
|
23
|
+
default: 'ACTIVE'
|
|
24
|
+
},
|
|
25
|
+
'value,array,,,true',
|
|
26
|
+
'siteId,sumba:siteId',
|
|
27
|
+
'teamIds,sumba:teamIds'
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
export const options = {
|
|
31
|
+
attachment: false,
|
|
32
|
+
cache: { ttlDur: 0 }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const features = [
|
|
36
|
+
'dobo:updatedAt'
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
async function routeGuard () {
|
|
40
|
+
return {
|
|
41
|
+
properties,
|
|
42
|
+
features,
|
|
43
|
+
options,
|
|
44
|
+
buildEnd
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default routeGuard
|
|
@@ -1,59 +1,47 @@
|
|
|
1
|
+
import { options } from './model-guard.js'
|
|
2
|
+
|
|
3
|
+
export const properties = [
|
|
4
|
+
'path,,255,true,true',
|
|
5
|
+
{
|
|
6
|
+
name: 'methods',
|
|
7
|
+
type: 'array',
|
|
8
|
+
required: true,
|
|
9
|
+
default: ['GET', 'POST', 'UPDATE', 'DELETE'],
|
|
10
|
+
values: ['GET', 'POST', 'UPDATE', 'DELETE']
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: 'weight',
|
|
14
|
+
type: 'smallint',
|
|
15
|
+
default: 0
|
|
16
|
+
}, {
|
|
17
|
+
name: 'negation',
|
|
18
|
+
type: 'boolean',
|
|
19
|
+
required: true,
|
|
20
|
+
default: false
|
|
21
|
+
}, {
|
|
22
|
+
name: 'anonymous',
|
|
23
|
+
type: 'boolean',
|
|
24
|
+
required: true,
|
|
25
|
+
default: false
|
|
26
|
+
},
|
|
27
|
+
'siteId,sumba:siteId',
|
|
28
|
+
'teamIds,sumba:teamIds'
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
export const features = [
|
|
32
|
+
{
|
|
33
|
+
name: 'sumba:status',
|
|
34
|
+
values: ['ACTIVE', 'INACTIVE'],
|
|
35
|
+
default: 'ACTIVE'
|
|
36
|
+
},
|
|
37
|
+
'dobo:updatedAt'
|
|
38
|
+
]
|
|
39
|
+
|
|
1
40
|
async function routeGuard () {
|
|
2
41
|
return {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
{
|
|
7
|
-
name: 'inverse',
|
|
8
|
-
type: 'boolean',
|
|
9
|
-
required: true,
|
|
10
|
-
default: false
|
|
11
|
-
}, {
|
|
12
|
-
name: 'anonymous',
|
|
13
|
-
type: 'boolean',
|
|
14
|
-
required: true,
|
|
15
|
-
default: false
|
|
16
|
-
}, {
|
|
17
|
-
name: 'methods',
|
|
18
|
-
type: 'array',
|
|
19
|
-
required: true,
|
|
20
|
-
default: ['GET', 'POST', 'UPDATE', 'DELETE'],
|
|
21
|
-
values: ['GET', 'POST', 'UPDATE', 'DELETE']
|
|
22
|
-
}, {
|
|
23
|
-
name: 'teams',
|
|
24
|
-
type: 'array',
|
|
25
|
-
default: [],
|
|
26
|
-
ref: {
|
|
27
|
-
teams: {
|
|
28
|
-
model: 'SumbaTeam',
|
|
29
|
-
field: 'alias',
|
|
30
|
-
searchField: 'name',
|
|
31
|
-
fields: ['alias', 'name']
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}, {
|
|
35
|
-
name: 'weight',
|
|
36
|
-
type: 'smallint',
|
|
37
|
-
default: 0
|
|
38
|
-
}
|
|
39
|
-
],
|
|
40
|
-
features: [
|
|
41
|
-
{
|
|
42
|
-
name: 'sumba:status',
|
|
43
|
-
values: ['ACTIVE', 'INACTIVE'],
|
|
44
|
-
default: 'ACTIVE'
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
name: 'dobo:unique',
|
|
48
|
-
fields: ['path', 'anonymous', 'methods', 'teams', 'inverse', 'weight', 'status', 'siteId']
|
|
49
|
-
},
|
|
50
|
-
'dobo:immutable',
|
|
51
|
-
'dobo:updatedAt',
|
|
52
|
-
'sumba:siteId'
|
|
53
|
-
],
|
|
54
|
-
options: {
|
|
55
|
-
persistence: false
|
|
56
|
-
}
|
|
42
|
+
properties,
|
|
43
|
+
features,
|
|
44
|
+
options
|
|
57
45
|
}
|
|
58
46
|
}
|
|
59
47
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { properties, features } from './attrib-guard.js'
|
|
2
|
+
import { options, buildEnd } from './model-guard.js'
|
|
3
|
+
|
|
4
|
+
async function routeGuard () {
|
|
5
|
+
const { isString } = this.app.lib._
|
|
6
|
+
return {
|
|
7
|
+
properties: properties.filter(prop => !isString(prop) || (isString(prop) && !prop.startsWith('teamIds'))),
|
|
8
|
+
features: features.filter(feat => !isString(feat) || (isString(feat) && !['sumba:siteId', 'dobo:updatedAt'].includes(feat))).concat('sumba:siteIds', 'dobo:updatedAt'),
|
|
9
|
+
options,
|
|
10
|
+
buildEnd
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default routeGuard
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { buildEnd, properties, features, options } from './model-guard.js'
|
|
2
|
+
|
|
3
|
+
async function xModelGuard () {
|
|
4
|
+
const { isString } = this.app.lib._
|
|
5
|
+
return {
|
|
6
|
+
properties: properties.filter(prop => !isString(prop) || (isString(prop) && !prop.startsWith('teamIds'))),
|
|
7
|
+
features: features.filter(feat => !isString(feat) || (isString(feat) && !['sumba:siteId', 'dobo:updatedAt'].includes(feat))).concat('sumba:siteIds', 'dobo:updatedAt'),
|
|
8
|
+
options,
|
|
9
|
+
buildEnd
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default xModelGuard
|