sumba 2.25.0 → 2.26.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.
Files changed (58) hide show
  1. package/extend/bajo/hook.js +430 -0
  2. package/extend/dobo/fixture/team-user.json +2 -2
  3. package/extend/dobo/model.js +215 -0
  4. package/extend/dobo/model.json +214 -0
  5. package/index.js +11 -7
  6. package/lib/get-user.js +1 -1
  7. package/package.json +1 -1
  8. package/wiki/CHANGES.md +9 -0
  9. package/extend/bajo/hook/bajo.extend@after-read-config.js +0 -13
  10. package/extend/bajo/hook/dobo.sumba-attrib-guard$dobo.sumba-x-attrib-guard@after-transaction.js +0 -6
  11. package/extend/bajo/hook/dobo.sumba-contact-form@after-create-record.js +0 -17
  12. package/extend/bajo/hook/dobo.sumba-contact-form@before-create-record.js +0 -16
  13. package/extend/bajo/hook/dobo.sumba-model-guard$dobo.sumba-x-model-guard@after-transaction.js +0 -6
  14. package/extend/bajo/hook/dobo.sumba-route-guard$dobo.sumba-x-route-guard@after-transaction.js +0 -6
  15. package/extend/bajo/hook/dobo.sumba-site@after-create-record.js +0 -8
  16. package/extend/bajo/hook/dobo.sumba-site@after-remove-record.js +0 -9
  17. package/extend/bajo/hook/dobo.sumba-site@after-update-record.js +0 -14
  18. package/extend/bajo/hook/dobo.sumba-team$dobo.sumba-site@after-transaction.js +0 -8
  19. package/extend/bajo/hook/dobo.sumba-user@after-create-record.js +0 -15
  20. package/extend/bajo/hook/dobo.sumba-user@after-record-validation.js +0 -8
  21. package/extend/bajo/hook/dobo.sumba-user@after-remove-record.js +0 -7
  22. package/extend/bajo/hook/dobo.sumba-user@after-update-record.js +0 -44
  23. package/extend/bajo/hook/dobo.sumba-user@before-create-record.js +0 -7
  24. package/extend/bajo/hook/dobo.sumba-user@before-record-validation.js +0 -8
  25. package/extend/bajo/hook/dobo.sumba-user@before-update-record.js +0 -9
  26. package/extend/bajo/hook/dobo@before-count-record.js +0 -8
  27. package/extend/bajo/hook/dobo@before-driver-create-record.js +0 -17
  28. package/extend/bajo/hook/dobo@before-driver-find-all-record.js +0 -13
  29. package/extend/bajo/hook/dobo@before-driver-find-record.js +0 -114
  30. package/extend/bajo/hook/dobo@before-driver-get-record.js +0 -22
  31. package/extend/bajo/hook/dobo@before-driver-remove-record.js +0 -10
  32. package/extend/bajo/hook/dobo@before-driver-update-record.js +0 -10
  33. package/extend/bajo/hook/waibu-mpa.sumba@after-build-locals.js +0 -19
  34. package/extend/bajo/hook/waibu-mpa@pre-parsing.js +0 -15
  35. package/extend/bajo/hook/waibu-rest-api@pre-parsing.js +0 -13
  36. package/extend/bajo/hook/waibu-static@pre-parsing.js +0 -13
  37. package/extend/bajo/hook/waibu@after-app-boot.js +0 -7
  38. package/extend/bajo/hook/waibu@after-create-context.js +0 -5
  39. package/extend/bajo/hook/waibu@pre-parsing.js +0 -9
  40. package/extend/dobo/model/attrib-guard.js +0 -32
  41. package/extend/dobo/model/contact-form-cat.json +0 -3
  42. package/extend/dobo/model/contact-form.json +0 -16
  43. package/extend/dobo/model/download.json +0 -19
  44. package/extend/dobo/model/model-guard.js +0 -48
  45. package/extend/dobo/model/route-guard.js +0 -48
  46. package/extend/dobo/model/site-setting.json +0 -16
  47. package/extend/dobo/model/site.json +0 -45
  48. package/extend/dobo/model/team-setting.json +0 -17
  49. package/extend/dobo/model/team-user.json +0 -16
  50. package/extend/dobo/model/team.json +0 -23
  51. package/extend/dobo/model/ticket-cat.json +0 -3
  52. package/extend/dobo/model/ticket-detail.json +0 -7
  53. package/extend/dobo/model/ticket.json +0 -31
  54. package/extend/dobo/model/user-setting.json +0 -17
  55. package/extend/dobo/model/user.js +0 -84
  56. package/extend/dobo/model/x-attrib-guard.js +0 -14
  57. package/extend/dobo/model/x-model-guard.js +0 -13
  58. package/extend/dobo/model/x-route-guard.js +0 -13
@@ -1,114 +0,0 @@
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
@@ -1,22 +0,0 @@
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
@@ -1,10 +0,0 @@
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
@@ -1,10 +0,0 @@
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,19 +0,0 @@
1
- async function afterBuildLocals (locals, req) {
2
- const { routePath } = this.app.waibu
3
- const items = []
4
- if (req.user) {
5
- items.push({ icon: 'person', 't:tooltip': 'yourProfile', href: routePath('sumba:/your-stuff/profile') })
6
- items.push({ icon: 'key', 't:tooltip': 'changePassword', href: routePath('sumba:/your-stuff/change-password') })
7
- items.push({ component: 'navItemSignout', 't:tooltip': 'signout', bottom: true })
8
- } else {
9
- items.push({ icon: 'signin', 't:tooltip': 'signin', href: routePath('sumba:/signin') })
10
- items.push({ icon: 'key', 't:tooltip': 'forgotPassword', href: routePath('sumba:/user/forgot-password') })
11
- items.push({ icon: 'personAdd', 't:tooltip': 'newUserSignup', href: routePath('sumba:/user/signup') })
12
- }
13
- items.push({ divider: true })
14
- items.push({ icon: 'envelope', 't:tooltip': 'contactForm', href: routePath('sumba:/help/contact-form') })
15
- items.push({ icon: 'chat', 't:tooltip': 'troubleTickets', href: routePath('sumba:/help/trouble-tickets') })
16
- locals.sidebar = items
17
- }
18
-
19
- export default afterBuildLocals
@@ -1,15 +0,0 @@
1
- import { checkUserId, checkTeam, checkTheme, checkIconset, checkXSite } from '../../../lib/util.js'
2
-
3
- const preParsing = {
4
- level: 10,
5
- handler: async function (req, reply) {
6
- await checkTheme.call(this, req, reply)
7
- await checkIconset.call(this, req, reply)
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)
12
- }
13
- }
14
-
15
- export default preParsing
@@ -1,13 +0,0 @@
1
- import { checkUserId, checkTeam, checkXSite } from '../../../lib/util.js'
2
-
3
- const preParsing = {
4
- level: 10,
5
- handler: async function (req, reply) {
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)
10
- }
11
- }
12
-
13
- export default preParsing
@@ -1,13 +0,0 @@
1
- import { checkUserId, checkTeam, checkXSite } from '../../../lib/util.js'
2
-
3
- const preParsing = {
4
- level: 10,
5
- handler: async function (req, reply) {
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)
10
- }
11
- }
12
-
13
- export default preParsing
@@ -1,7 +0,0 @@
1
- async function afterAppBoot () {
2
- await this.getRouteGuards(true)
3
- await this.getModelGuards(true)
4
- await this.getAttribGuards(true)
5
- }
6
-
7
- export default afterAppBoot
@@ -1,5 +0,0 @@
1
- async function afterCreateContext (ctx) {
2
- ctx.decorateRequest('user', null)
3
- }
4
-
5
- export default afterCreateContext
@@ -1,9 +0,0 @@
1
- const preParsing = {
2
- level: 10,
3
- handler: async function (req, reply) {
4
- const { getHostname } = this.app.waibu
5
- req.site = await this.getSite(getHostname(req))
6
- }
7
- }
8
-
9
- export default preParsing
@@ -1,32 +0,0 @@
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
@@ -1,3 +0,0 @@
1
- {
2
- "features": ["sumba:category", "sumba:siteId"]
3
- }
@@ -1,16 +0,0 @@
1
- {
2
- "properties": [
3
- "firstName,,50,true,true",
4
- "lastName,,50,true,true",
5
- "email,,50,true,true",
6
- "category,,50,true",
7
- "subject,,255,,true",
8
- "message,text"
9
- ],
10
- "features": [{
11
- "name": "sumba:status",
12
- "default": "NEW",
13
- "values": ["NEW", "ACK"]
14
- }, "sumba:userId", "sumba:siteId", "dobo:createdAt", "dobo:updatedAt"
15
- ]
16
- }
@@ -1,19 +0,0 @@
1
- {
2
- "properties": [
3
- "description,,50,true",
4
- "file,text,,,true",
5
- "type,,20,true",
6
- "jobQueue,object",
7
- {
8
- "name": "size",
9
- "type": "integer",
10
- "default": 0,
11
- "index": true
12
- }
13
- ],
14
- "features": ["sumba:siteId", "sumba:userId", "dobo:createdAt", "dobo:updatedAt", {
15
- "name": "sumba:status",
16
- "default": "INQUEUE",
17
- "values": ["INQUEUE", "PROCESSING", "COMPLETE", "FAIL"]
18
- }]
19
- }
@@ -1,48 +0,0 @@
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,48 +0,0 @@
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
-
40
- async function routeGuard () {
41
- return {
42
- properties,
43
- features,
44
- options
45
- }
46
- }
47
-
48
- export default routeGuard
@@ -1,16 +0,0 @@
1
- {
2
- "properties": [
3
- "ns,,50,true,true",
4
- "key,,255,true,true",
5
- "value,text"
6
- ],
7
- "indexes": [{
8
- "fields": ["ns", "key", "siteId"],
9
- "type": "unique"
10
- }],
11
- "features": [
12
- "sumba:siteId",
13
- "dobo:immutable",
14
- "dobo:updatedAt"
15
- ]
16
- }
@@ -1,45 +0,0 @@
1
- {
2
- "buildLevel": 1,
3
- "properties": [{
4
- "name": "hostname",
5
- "type": "string",
6
- "maxLength": 100,
7
- "required": true,
8
- "index": "unique"
9
- }, {
10
- "name": "alias",
11
- "type": "string",
12
- "maxLength": 100,
13
- "index": "unique",
14
- "required": true,
15
- "immutable": true
16
- }, {
17
- "name": "title",
18
- "type": "string",
19
- "maxLength": 50,
20
- "required": true
21
- }, {
22
- "name": "orgName",
23
- "type": "string",
24
- "maxLength": 100,
25
- "index": true
26
- }, {
27
- "name": "email",
28
- "type": "string",
29
- "maxLength": 100,
30
- "rules": ["email"]
31
- }],
32
- "features": [
33
- "sumba:personInCharge",
34
- "sumba:address",
35
- "sumba:social",
36
- {
37
- "name": "sumba:status",
38
- "default": "ACTIVE"
39
- },
40
- "dobo:createdAt",
41
- "dobo:updatedAt",
42
- "dobo:immutable"
43
- ],
44
- "scanables": ["hostname", "alias", "title", "orgName"]
45
- }
@@ -1,17 +0,0 @@
1
- {
2
- "buildLevel": 5,
3
- "properties": [
4
- "ns,,50,true,true",
5
- "key,,255,true,true",
6
- "value,text"
7
- ],
8
- "indexes": [{
9
- "fields": ["ns", "key", "siteId", "teamId"],
10
- "type": "unique"
11
- }],
12
- "features": [
13
- "sumba:siteId",
14
- "dobo:updatedAt",
15
- "sumba:teamId"
16
- ]
17
- }
@@ -1,16 +0,0 @@
1
- {
2
- "buildLevel": 4,
3
- "properties": [],
4
- "indexes": [{
5
- "fields": ["userId", "siteId", "teamId"],
6
- "type": "unique"
7
- }],
8
- "features": [
9
- "dobo:createdAt",
10
- "dobo:updatedAt",
11
- "sumba:teamId",
12
- "sumba:siteId",
13
- "sumba:userId",
14
- "dobo:immutable"
15
- ]
16
- }
@@ -1,23 +0,0 @@
1
- {
2
- "buildLevel": 3,
3
- "properties": [
4
- "alias,,20,,true",
5
- "name,,50,true,true"
6
- ],
7
- "indexes": [{
8
- "fields": ["alias", "siteId"],
9
- "type": "unique"
10
- }],
11
- "features": [
12
- "dobo:createdAt",
13
- "dobo:updatedAt",
14
- "dobo:immutable",
15
- "sumba:siteId",
16
- {
17
- "name": "sumba:status",
18
- "default": "ENABLED",
19
- "values": ["ENABLED", "DISABLED"]
20
- },
21
- "dobo:immutable"
22
- ]
23
- }
@@ -1,3 +0,0 @@
1
- {
2
- "features": ["sumba:category", "sumba:siteId"]
3
- }
@@ -1,7 +0,0 @@
1
- {
2
- "properties": [
3
- "masterId,,255,true,true",
4
- "message,text"
5
- ],
6
- "features": ["dobo:createdAt", "sumba:userId", "sumba:siteId"]
7
- }
@@ -1,31 +0,0 @@
1
- {
2
- "properties": [
3
- "subject,,255,true,true",
4
- {
5
- "name": "cat",
6
- "type": "string",
7
- "maxLength": 50,
8
- "index": true,
9
- "required": true,
10
- "ref": {
11
- "cat": {
12
- "model": "SumbaTicketCat",
13
- "searchField": "name",
14
- "labelField": "name"
15
- }
16
- }
17
- },
18
- "message,text,,,true"
19
- ],
20
- "features": [
21
- "dobo:createdAt",
22
- "dobo:updatedAt",
23
- "sumba:siteId",
24
- "sumba:userId",
25
- {
26
- "name": "sumba:status",
27
- "default": "OPEN",
28
- "values": ["OPEN", "CLOSED"]
29
- }
30
- ]
31
- }
@@ -1,17 +0,0 @@
1
- {
2
- "buildLevel": 5,
3
- "properties": [
4
- "ns,,50,true,true",
5
- "key,,255,true,true",
6
- "value,text"
7
- ],
8
- "indexes": [{
9
- "fields": ["ns", "key", "siteId", "userId"],
10
- "type": "unique"
11
- }],
12
- "features": [
13
- "sumba:siteId",
14
- "dobo:updatedAt",
15
- "sumba:userId"
16
- ]
17
- }