sumba 2.25.1 → 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.
- package/extend/bajo/hook.js +430 -0
- package/extend/dobo/model.js +215 -0
- package/extend/dobo/model.json +214 -0
- package/package.json +1 -1
- package/wiki/CHANGES.md +5 -0
- package/extend/bajo/hook/bajo.extend@after-read-config.js +0 -13
- package/extend/bajo/hook/dobo.sumba-attrib-guard$dobo.sumba-x-attrib-guard@after-transaction.js +0 -6
- package/extend/bajo/hook/dobo.sumba-contact-form@after-create-record.js +0 -17
- package/extend/bajo/hook/dobo.sumba-contact-form@before-create-record.js +0 -16
- package/extend/bajo/hook/dobo.sumba-model-guard$dobo.sumba-x-model-guard@after-transaction.js +0 -6
- package/extend/bajo/hook/dobo.sumba-route-guard$dobo.sumba-x-route-guard@after-transaction.js +0 -6
- package/extend/bajo/hook/dobo.sumba-site@after-create-record.js +0 -8
- package/extend/bajo/hook/dobo.sumba-site@after-remove-record.js +0 -9
- package/extend/bajo/hook/dobo.sumba-site@after-update-record.js +0 -14
- package/extend/bajo/hook/dobo.sumba-team$dobo.sumba-site@after-transaction.js +0 -8
- package/extend/bajo/hook/dobo.sumba-user@after-create-record.js +0 -15
- package/extend/bajo/hook/dobo.sumba-user@after-record-validation.js +0 -8
- package/extend/bajo/hook/dobo.sumba-user@after-remove-record.js +0 -7
- package/extend/bajo/hook/dobo.sumba-user@after-update-record.js +0 -44
- package/extend/bajo/hook/dobo.sumba-user@before-create-record.js +0 -7
- package/extend/bajo/hook/dobo.sumba-user@before-record-validation.js +0 -8
- package/extend/bajo/hook/dobo.sumba-user@before-update-record.js +0 -9
- package/extend/bajo/hook/dobo@before-count-record.js +0 -8
- package/extend/bajo/hook/dobo@before-driver-create-record.js +0 -17
- package/extend/bajo/hook/dobo@before-driver-find-all-record.js +0 -8
- package/extend/bajo/hook/dobo@before-driver-find-record.js +0 -133
- package/extend/bajo/hook/dobo@before-driver-get-record.js +0 -23
- package/extend/bajo/hook/dobo@before-driver-remove-record.js +0 -10
- package/extend/bajo/hook/dobo@before-driver-update-record.js +0 -10
- package/extend/bajo/hook/waibu-mpa.sumba@after-build-locals.js +0 -19
- package/extend/bajo/hook/waibu-mpa@pre-parsing.js +0 -15
- package/extend/bajo/hook/waibu-rest-api@pre-parsing.js +0 -13
- package/extend/bajo/hook/waibu-static@pre-parsing.js +0 -13
- package/extend/bajo/hook/waibu@after-app-boot.js +0 -7
- package/extend/bajo/hook/waibu@after-create-context.js +0 -5
- package/extend/bajo/hook/waibu@pre-parsing.js +0 -9
- package/extend/dobo/model/attrib-guard.js +0 -32
- package/extend/dobo/model/contact-form-cat.json +0 -3
- package/extend/dobo/model/contact-form.json +0 -16
- package/extend/dobo/model/download.json +0 -19
- package/extend/dobo/model/model-guard.js +0 -48
- package/extend/dobo/model/route-guard.js +0 -48
- package/extend/dobo/model/site-setting.json +0 -16
- package/extend/dobo/model/site.json +0 -45
- package/extend/dobo/model/team-setting.json +0 -17
- package/extend/dobo/model/team-user.json +0 -16
- package/extend/dobo/model/team.json +0 -23
- package/extend/dobo/model/ticket-cat.json +0 -3
- package/extend/dobo/model/ticket-detail.json +0 -7
- package/extend/dobo/model/ticket.json +0 -31
- package/extend/dobo/model/user-setting.json +0 -17
- package/extend/dobo/model/user.js +0 -84
- package/extend/dobo/model/x-attrib-guard.js +0 -14
- package/extend/dobo/model/x-model-guard.js +0 -13
- package/extend/dobo/model/x-route-guard.js +0 -13
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
[{
|
|
2
|
+
"baseName": "contact-form-cat",
|
|
3
|
+
"features": ["sumba:category", "sumba:siteId"]
|
|
4
|
+
}, {
|
|
5
|
+
"baseName": "contact-form",
|
|
6
|
+
"properties": [
|
|
7
|
+
"firstName,,50,true,true",
|
|
8
|
+
"lastName,,50,true,true",
|
|
9
|
+
"email,,50,true,true",
|
|
10
|
+
"category,,50,true",
|
|
11
|
+
"subject,,255,,true",
|
|
12
|
+
"message,text"
|
|
13
|
+
],
|
|
14
|
+
"features": [{
|
|
15
|
+
"name": "sumba:status",
|
|
16
|
+
"default": "NEW",
|
|
17
|
+
"values": ["NEW", "ACK"]
|
|
18
|
+
}, "sumba:userId", "sumba:siteId", "dobo:createdAt", "dobo:updatedAt"
|
|
19
|
+
]
|
|
20
|
+
}, {
|
|
21
|
+
"baseName": "download",
|
|
22
|
+
"properties": [
|
|
23
|
+
"description,,50,true",
|
|
24
|
+
"file,text,,,true",
|
|
25
|
+
"type,,20,true",
|
|
26
|
+
"jobQueue,object",
|
|
27
|
+
{
|
|
28
|
+
"name": "size",
|
|
29
|
+
"type": "integer",
|
|
30
|
+
"default": 0,
|
|
31
|
+
"index": true
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"features": ["sumba:siteId", "sumba:userId", "dobo:createdAt", "dobo:updatedAt", {
|
|
35
|
+
"name": "sumba:status",
|
|
36
|
+
"default": "INQUEUE",
|
|
37
|
+
"values": ["INQUEUE", "PROCESSING", "COMPLETE", "FAIL"]
|
|
38
|
+
}]
|
|
39
|
+
}, {
|
|
40
|
+
"baseName": "site-setting",
|
|
41
|
+
"properties": [
|
|
42
|
+
"ns,,50,true,true",
|
|
43
|
+
"key,,255,true,true",
|
|
44
|
+
"value,text"
|
|
45
|
+
],
|
|
46
|
+
"indexes": [{
|
|
47
|
+
"fields": ["ns", "key", "siteId"],
|
|
48
|
+
"type": "unique"
|
|
49
|
+
}],
|
|
50
|
+
"features": [
|
|
51
|
+
"sumba:siteId",
|
|
52
|
+
"dobo:immutable",
|
|
53
|
+
"dobo:updatedAt"
|
|
54
|
+
]
|
|
55
|
+
}, {
|
|
56
|
+
"buildLevel": 1,
|
|
57
|
+
"baseName": "site",
|
|
58
|
+
"properties": [{
|
|
59
|
+
"name": "hostname",
|
|
60
|
+
"type": "string",
|
|
61
|
+
"maxLength": 100,
|
|
62
|
+
"required": true,
|
|
63
|
+
"index": "unique"
|
|
64
|
+
}, {
|
|
65
|
+
"name": "alias",
|
|
66
|
+
"type": "string",
|
|
67
|
+
"maxLength": 100,
|
|
68
|
+
"index": "unique",
|
|
69
|
+
"required": true,
|
|
70
|
+
"immutable": true
|
|
71
|
+
}, {
|
|
72
|
+
"name": "title",
|
|
73
|
+
"type": "string",
|
|
74
|
+
"maxLength": 50,
|
|
75
|
+
"required": true
|
|
76
|
+
}, {
|
|
77
|
+
"name": "orgName",
|
|
78
|
+
"type": "string",
|
|
79
|
+
"maxLength": 100,
|
|
80
|
+
"index": true
|
|
81
|
+
}, {
|
|
82
|
+
"name": "email",
|
|
83
|
+
"type": "string",
|
|
84
|
+
"maxLength": 100,
|
|
85
|
+
"rules": ["email"]
|
|
86
|
+
}],
|
|
87
|
+
"features": [
|
|
88
|
+
"sumba:personInCharge",
|
|
89
|
+
"sumba:address",
|
|
90
|
+
"sumba:social",
|
|
91
|
+
{
|
|
92
|
+
"name": "sumba:status",
|
|
93
|
+
"default": "ACTIVE"
|
|
94
|
+
},
|
|
95
|
+
"dobo:createdAt",
|
|
96
|
+
"dobo:updatedAt",
|
|
97
|
+
"dobo:immutable"
|
|
98
|
+
],
|
|
99
|
+
"scanables": ["hostname", "alias", "title", "orgName"]
|
|
100
|
+
}, {
|
|
101
|
+
"buildLevel": 5,
|
|
102
|
+
"baseName": "team-setting",
|
|
103
|
+
"properties": [
|
|
104
|
+
"ns,,50,true,true",
|
|
105
|
+
"key,,255,true,true",
|
|
106
|
+
"value,text"
|
|
107
|
+
],
|
|
108
|
+
"indexes": [{
|
|
109
|
+
"fields": ["ns", "key", "siteId", "teamId"],
|
|
110
|
+
"type": "unique"
|
|
111
|
+
}],
|
|
112
|
+
"features": [
|
|
113
|
+
"sumba:siteId",
|
|
114
|
+
"dobo:updatedAt",
|
|
115
|
+
"sumba:teamId"
|
|
116
|
+
]
|
|
117
|
+
}, {
|
|
118
|
+
"buildLevel": 4,
|
|
119
|
+
"baseName": "team-user",
|
|
120
|
+
"properties": [],
|
|
121
|
+
"indexes": [{
|
|
122
|
+
"fields": ["userId", "siteId", "teamId"],
|
|
123
|
+
"type": "unique"
|
|
124
|
+
}],
|
|
125
|
+
"features": [
|
|
126
|
+
"dobo:createdAt",
|
|
127
|
+
"dobo:updatedAt",
|
|
128
|
+
"sumba:siteId",
|
|
129
|
+
"sumba:userId",
|
|
130
|
+
"sumba:teamId",
|
|
131
|
+
"dobo:immutable"
|
|
132
|
+
]
|
|
133
|
+
}, {
|
|
134
|
+
"buildLevel": 3,
|
|
135
|
+
"baseName": "team",
|
|
136
|
+
"properties": [
|
|
137
|
+
"alias,,20,,true",
|
|
138
|
+
"name,,50,true,true"
|
|
139
|
+
],
|
|
140
|
+
"indexes": [{
|
|
141
|
+
"fields": ["alias", "siteId"],
|
|
142
|
+
"type": "unique"
|
|
143
|
+
}],
|
|
144
|
+
"features": [
|
|
145
|
+
"dobo:createdAt",
|
|
146
|
+
"dobo:updatedAt",
|
|
147
|
+
"dobo:immutable",
|
|
148
|
+
"sumba:siteId",
|
|
149
|
+
{
|
|
150
|
+
"name": "sumba:status",
|
|
151
|
+
"default": "ENABLED",
|
|
152
|
+
"values": ["ENABLED", "DISABLED"]
|
|
153
|
+
},
|
|
154
|
+
"dobo:immutable"
|
|
155
|
+
]
|
|
156
|
+
}, {
|
|
157
|
+
"baseName": "ticket-cat",
|
|
158
|
+
"features": ["sumba:category", "sumba:siteId"]
|
|
159
|
+
}, {
|
|
160
|
+
"baseName": "ticket-detail",
|
|
161
|
+
"properties": [
|
|
162
|
+
"masterId,,255,true,true",
|
|
163
|
+
"message,text"
|
|
164
|
+
],
|
|
165
|
+
"features": ["dobo:createdAt", "sumba:userId", "sumba:siteId"]
|
|
166
|
+
}, {
|
|
167
|
+
"baseName": "ticket",
|
|
168
|
+
"properties": [
|
|
169
|
+
"subject,,255,true,true",
|
|
170
|
+
{
|
|
171
|
+
"name": "cat",
|
|
172
|
+
"type": "string",
|
|
173
|
+
"maxLength": 50,
|
|
174
|
+
"index": true,
|
|
175
|
+
"required": true,
|
|
176
|
+
"ref": {
|
|
177
|
+
"cat": {
|
|
178
|
+
"model": "SumbaTicketCat",
|
|
179
|
+
"searchField": "name",
|
|
180
|
+
"labelField": "name"
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
"message,text,,,true"
|
|
185
|
+
],
|
|
186
|
+
"features": [
|
|
187
|
+
"dobo:createdAt",
|
|
188
|
+
"dobo:updatedAt",
|
|
189
|
+
"sumba:siteId",
|
|
190
|
+
"sumba:userId",
|
|
191
|
+
{
|
|
192
|
+
"name": "sumba:status",
|
|
193
|
+
"default": "OPEN",
|
|
194
|
+
"values": ["OPEN", "CLOSED"]
|
|
195
|
+
}
|
|
196
|
+
]
|
|
197
|
+
}, {
|
|
198
|
+
"buildLevel": 5,
|
|
199
|
+
"baseName": "user-setting",
|
|
200
|
+
"properties": [
|
|
201
|
+
"ns,,50,true,true",
|
|
202
|
+
"key,,255,true,true",
|
|
203
|
+
"value,text"
|
|
204
|
+
],
|
|
205
|
+
"indexes": [{
|
|
206
|
+
"fields": ["ns", "key", "siteId", "userId"],
|
|
207
|
+
"type": "unique"
|
|
208
|
+
}],
|
|
209
|
+
"features": [
|
|
210
|
+
"sumba:siteId",
|
|
211
|
+
"dobo:updatedAt",
|
|
212
|
+
"sumba:userId"
|
|
213
|
+
]
|
|
214
|
+
}]
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-05-28
|
|
4
|
+
|
|
5
|
+
- [2.26.0] Change hooks to be written in one ```hook.js``` file
|
|
6
|
+
- [2.26.0] Change model schemas to be written in one ```model.js``` file
|
|
7
|
+
|
|
3
8
|
## 2026-05-25
|
|
4
9
|
|
|
5
10
|
- [2.25.1] Bug fix in several places because name changing ```crossSiteAdmins``` to ```xSiteAdmins```
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
async function afterCreateRecord (body, rec, options = {}) {
|
|
2
|
-
const { data } = rec
|
|
3
|
-
const { req } = options
|
|
4
|
-
const { get } = this.app.lib._
|
|
5
|
-
const t = get(req, 't', this.t)
|
|
6
|
-
const to = `${data.firstName} ${data.lastName} <${data.email}>`
|
|
7
|
-
let bcc
|
|
8
|
-
if (req.site) bcc = req.site.email
|
|
9
|
-
const subject = t('contactForm')
|
|
10
|
-
const payload = { to, bcc, subject, data }
|
|
11
|
-
await this.sendMail(
|
|
12
|
-
'sumba.template:/_mail/help-contact-form.html',
|
|
13
|
-
{ payload, options, source: this.ns }
|
|
14
|
-
)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default afterCreateRecord
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
const beforeCreateRecord = {
|
|
2
|
-
level: 1000,
|
|
3
|
-
handler: async function (body, options = {}) {
|
|
4
|
-
const { get, isEmpty } = this.app.lib._
|
|
5
|
-
const user = get(options, 'req.user')
|
|
6
|
-
if (user) {
|
|
7
|
-
if (isEmpty(body.firstName)) body.firstName = user.firstName
|
|
8
|
-
if (isEmpty(body.lastName)) body.lastName = user.firstName
|
|
9
|
-
if (isEmpty(body.email)) body.email = user.email
|
|
10
|
-
}
|
|
11
|
-
if (isEmpty(body.category)) body.category = 'MISC'
|
|
12
|
-
options.checksumId = true
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export default beforeCreateRecord
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { createRefs, getAllFixtures } from '../../../lib/create-new-site.js'
|
|
2
|
-
|
|
3
|
-
async function afterCreateRecord (body, result, options) {
|
|
4
|
-
const fixtures = await getAllFixtures.call(this, result.data.alias)
|
|
5
|
-
await createRefs.call(this, result.data, fixtures, options)
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export default afterCreateRecord
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { removeRefs } from '../../../lib/remove-site.js'
|
|
2
|
-
import { clearCache } from './dobo.sumba-site@after-update-record.js'
|
|
3
|
-
|
|
4
|
-
async function afterRemoveRecord (id, result, options) {
|
|
5
|
-
await removeRefs.call(this, result.oldData, options)
|
|
6
|
-
await clearCache.call(this, id, result)
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export default afterRemoveRecord
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export async function clearCache (id, result) {
|
|
2
|
-
if (!this.app.bajoCache) return
|
|
3
|
-
const { clear } = this.app.bajoCache ?? {}
|
|
4
|
-
const { get } = this.app.lib._
|
|
5
|
-
await clear({ key: 'dobo|SumbaSite|getSite|default' })
|
|
6
|
-
await clear({ key: `dobo|SumbaSite|getSite|multiSite|${id}` })
|
|
7
|
-
await clear({ key: `dobo|SumbaSite|getSite|multiSite|${get(result, 'data.hostname', get(result, 'oldData.hostname'))}` })
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
async function afterUpdateRecord (id, input, result, opts) {
|
|
11
|
-
await clearCache.call(this, id, result)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default afterUpdateRecord
|
|
@@ -1,8 +0,0 @@
|
|
|
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,15 +0,0 @@
|
|
|
1
|
-
async function afterCreateRecord (body, rec, options = {}) {
|
|
2
|
-
const { data } = rec
|
|
3
|
-
const { req } = options
|
|
4
|
-
const { get } = this.app.lib._
|
|
5
|
-
const t = get(req, 't', this.t)
|
|
6
|
-
const to = `${data.firstName} ${data.lastName} <${data.email}>`
|
|
7
|
-
const subject = t('newUserSignup')
|
|
8
|
-
const payload = { to, subject, data }
|
|
9
|
-
await this.sendMail(
|
|
10
|
-
`sumba.template:/_mail/user-signup-success${data.status === 'ACTIVE' ? '-active' : ''}.html`,
|
|
11
|
-
{ payload, options, source: this.ns }
|
|
12
|
-
)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default afterCreateRecord
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
async function afterRecordValidation (body, options) {
|
|
2
|
-
const { isBcrypt, hash } = this.app.bajoExtra
|
|
3
|
-
const { has } = this.app.lib._
|
|
4
|
-
|
|
5
|
-
if (has(body, 'password') && !isBcrypt(body.password)) body.password = await hash(body.password, 'bcrypt')
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export default afterRecordValidation
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
export async function clearCache (id, result) {
|
|
2
|
-
if (!this.app.bajoCache) return
|
|
3
|
-
const { clear } = this.app.bajoCache ?? {}
|
|
4
|
-
const { get } = this.app.lib._
|
|
5
|
-
const token = get(result, 'data.token', get(result, 'oldData.token', ''))
|
|
6
|
-
await clear({ key: `dobo|SumbaUser|getUserById|${id}` })
|
|
7
|
-
await clear({ key: `dobo|SumbaUser|getUserByToken|${token}` })
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
async function afterUpdateRecord (id, body, rec, options = {}) {
|
|
11
|
-
const { data, oldData } = rec
|
|
12
|
-
const { req } = options
|
|
13
|
-
const { get } = this.app.lib._
|
|
14
|
-
const t = get(req, 't', this.t)
|
|
15
|
-
const to = `${data.firstName} ${data.lastName} <${data.email}>`
|
|
16
|
-
const source = this.ns
|
|
17
|
-
|
|
18
|
-
await clearCache.call(this, id, rec)
|
|
19
|
-
|
|
20
|
-
let subject
|
|
21
|
-
const payload = { to, subject, data }
|
|
22
|
-
|
|
23
|
-
if (oldData.status === 'UNVERIFIED' && data.status === 'ACTIVE') {
|
|
24
|
-
payload.subject = t('userActivation')
|
|
25
|
-
await this.sendMail(
|
|
26
|
-
'sumba.template:/_mail/user-activation-success.html',
|
|
27
|
-
{ payload, options, source }
|
|
28
|
-
)
|
|
29
|
-
} else if (oldData.token !== data.token) {
|
|
30
|
-
payload.subject = t('resetApiKey')
|
|
31
|
-
await this.sendMail(
|
|
32
|
-
'sumba.template:/_mail/mystuff-reset-api-key.html',
|
|
33
|
-
{ payload, options, source }
|
|
34
|
-
)
|
|
35
|
-
} else if (body.password) {
|
|
36
|
-
payload.subject = t('changePassword')
|
|
37
|
-
await this.sendMail(
|
|
38
|
-
'sumba.template:/_mail/mystuff-change-password.html',
|
|
39
|
-
{ payload, options, source }
|
|
40
|
-
)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export default afterUpdateRecord
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
async function beforeRecordValidation (body, options = {}) {
|
|
2
|
-
const { set } = this.app.lib._
|
|
3
|
-
const password = await this.passwordRule(options.req)
|
|
4
|
-
const rule = { password }
|
|
5
|
-
set(options, 'validation.params.rule', rule)
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export default beforeRecordValidation
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const doboBeforeDriverCreateRecord = {
|
|
2
|
-
level: 1000,
|
|
3
|
-
handler: async function (model, body, options = {}) {
|
|
4
|
-
const { get } = this.app.lib._
|
|
5
|
-
const { isSet } = this.app.lib.aneka
|
|
6
|
-
const { req } = options
|
|
7
|
-
if (options.noAutoFilter || !req || get(req, 'routeOptions.config.xSite')) return
|
|
8
|
-
const item = { siteId: 'site.id', userId: 'user.id' }
|
|
9
|
-
for (const i in item) {
|
|
10
|
-
const rec = get(req, item[i])
|
|
11
|
-
const field = model.getProperty(i)
|
|
12
|
-
if (rec && field && !isSet(body[i])) body[i] = field.type === 'string' ? (rec + '') : rec
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default doboBeforeDriverCreateRecord
|
|
@@ -1,133 +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
|
-
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
|
-
}
|
|
110
|
-
|
|
111
|
-
if (hasTeamId) {
|
|
112
|
-
if (hasUserId) q.$and.push({ $or: [condTeamId, condUserId] })
|
|
113
|
-
else q.$and.push(condTeamId)
|
|
114
|
-
} else if (hasUserId) q.$and.push(condUserId)
|
|
115
|
-
|
|
116
|
-
await applyModelGuard.call(this, { model, q, teamIds, options })
|
|
117
|
-
await applyAttribGuard.call(this, { model, teamIds, options })
|
|
118
|
-
filter.query = q
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export async function handler (model, filter, options = {}) {
|
|
122
|
-
const { isEmpty } = this.app.lib._
|
|
123
|
-
const { req = {} } = options
|
|
124
|
-
if (options.noAutoFilter || isEmpty(req) || isEmpty(req.site)) return
|
|
125
|
-
await rebuildFilter.call(this, model, filter, options)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const doboBeforeDriverFindRecord = {
|
|
129
|
-
level: 1000,
|
|
130
|
-
handler
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export default doboBeforeDriverFindRecord
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { rebuildFilter } from './dobo@before-driver-find-record.js'
|
|
2
|
-
|
|
3
|
-
export async function checker (model, id, options = {}) {
|
|
4
|
-
const { isEmpty } = this.app.lib._
|
|
5
|
-
const { req = {} } = options
|
|
6
|
-
if (options.noAutoFilter || isEmpty(req) || isEmpty(req.site)) return
|
|
7
|
-
|
|
8
|
-
const filter = {}
|
|
9
|
-
await rebuildFilter.call(this, model, filter, options)
|
|
10
|
-
if (filter.query.$and) filter.query.$and.push({ id })
|
|
11
|
-
else filter.query.id = id
|
|
12
|
-
const row = await model.findOneRecord(filter, { count: false })
|
|
13
|
-
if (!row) throw this.app.dobo.error('recordNotFound%s%s', id, this.name, { statusCode: 404 })
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const doboBeforeDriverGetRecord = {
|
|
17
|
-
level: 1000,
|
|
18
|
-
handler: async function (model, id, options) {
|
|
19
|
-
await checker.call(this, model, id, options)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
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
|