w-web-perm 1.0.3 → 1.0.5
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/README.md +9 -4
- package/dist/css/app.c07ac905.css +1 -0
- package/dist/index.tmp +1 -1
- package/dist/js/app-legacy.08662a52.js +2 -0
- package/dist/js/app-legacy.08662a52.js.map +1 -0
- package/dist/js/app.08662a52.js +2 -0
- package/dist/js/app.08662a52.js.map +1 -0
- package/dist/js/chunk-vendors-legacy.01754e13.js +13 -0
- package/dist/js/chunk-vendors-legacy.01754e13.js.map +1 -0
- package/dist/js/chunk-vendors.01754e13.js +13 -0
- package/dist/js/chunk-vendors.01754e13.js.map +1 -0
- package/dist/w-web-perm.umd.js +2 -2
- package/dist/w-web-perm.umd.js.map +1 -1
- package/docs/WWebPerm.html +41 -5
- package/docs/WWebPerm.mjs.html +346 -23
- package/docs/index.html +1 -1
- package/{g.mDb.mjs → g.backupDb.mjs} +1 -1
- package/g.initialData.mjs +111 -0
- package/{g.mInitialTestData.mjs → g.initialTestData.mjs} +1 -1
- package/g.provideRuleGroups.mjs +56 -0
- package/g.provideTargets.mjs +57 -0
- package/g.provideUsers.mjs +45 -0
- package/package.json +4 -9
- package/public/index.html +1 -1
- package/server/WWebPerm.mjs +345 -22
- package/server/provideRuleGroups.mjs +65 -0
- package/server/provideTargets.mjs +59 -0
- package/server/provideUsers.mjs +68 -0
- package/src/App.vue +2 -10
- package/src/components/Common/CheckYes.vue +2 -2
- package/src/components/Common/CheckYesNo.vue +3 -3
- package/src/components/Common/LoadingWinBar.vue +1 -1
- package/src/components/LayoutContent.vue +35 -62
- package/src/components/LayoutContentGroups.vue +64 -61
- package/src/components/LayoutContentTargets.vue +52 -53
- package/src/components/LayoutContentUsers.vue +62 -60
- package/src/components/VeUser.vue +18 -26
- package/src/components/ruleGroup.vue +11 -11
- package/src/main.js +0 -2
- package/src/schema/tables/ruleGroups.mjs +11 -11
- package/src/schema/tables/targets.mjs +6 -9
- package/src/schema/tables/users.mjs +5 -5
- package/src/store/mutations.mjs +324 -69
- package/srv.mjs +9 -10
- package/tableTags-web-perm.json +1 -1
- package/dist/css/app.79b4b59b.css +0 -1
- package/dist/css/chunk-vendors.1c6c57f9.css +0 -5
- package/dist/js/app-legacy.317c7b7b.js +0 -2
- package/dist/js/app-legacy.317c7b7b.js.map +0 -1
- package/dist/js/app.317c7b7b.js +0 -2
- package/dist/js/app.317c7b7b.js.map +0 -1
- package/dist/js/chunk-vendors-legacy.a074d0c0.js +0 -13
- package/dist/js/chunk-vendors-legacy.a074d0c0.js.map +0 -1
- package/dist/js/chunk-vendors.a074d0c0.js +0 -13
- package/dist/js/chunk-vendors.a074d0c0.js.map +0 -1
- package/g.mInitialData.mjs +0 -147
- package/src/plugins/mVuetify.mjs +0 -12
package/server/WWebPerm.mjs
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
import fs from 'fs'
|
|
3
3
|
import get from 'lodash/get'
|
|
4
|
+
import each from 'lodash/each'
|
|
4
5
|
import keys from 'lodash/keys'
|
|
5
6
|
import iseobj from 'wsemi/src/iseobj.mjs'
|
|
6
7
|
import isestr from 'wsemi/src/isestr.mjs'
|
|
7
8
|
import ispint from 'wsemi/src/ispint.mjs'
|
|
9
|
+
import isearr from 'wsemi/src/isearr.mjs'
|
|
8
10
|
import isfun from 'wsemi/src/isfun.mjs'
|
|
9
11
|
import ispm from 'wsemi/src/ispm.mjs'
|
|
10
12
|
import cint from 'wsemi/src/cint.mjs'
|
|
13
|
+
import j2o from 'wsemi/src/j2o.mjs'
|
|
11
14
|
import strleft from 'wsemi/src/strleft.mjs'
|
|
12
15
|
import strright from 'wsemi/src/strright.mjs'
|
|
13
16
|
import strdelright from 'wsemi/src/strdelright.mjs'
|
|
@@ -21,13 +24,14 @@ import { getUserRules } from '../src/plugins/mShare.mjs'
|
|
|
21
24
|
|
|
22
25
|
|
|
23
26
|
/**
|
|
24
|
-
*
|
|
27
|
+
* 權限伺服器
|
|
25
28
|
*
|
|
26
29
|
* @class
|
|
27
30
|
* @param {Function} WOrm 輸入資料庫ORM函數
|
|
28
31
|
* @param {String} url 輸入資料庫連線字串,例如'mongodb://sername:password@$127.0.0.1:27017'
|
|
29
32
|
* @param {String} db 輸入資料庫名稱字串
|
|
30
33
|
* @param {Function} getUserByToken 輸入處理函數,函數會傳入使用者token,通過此函數處理後並回傳使用者資訊物件,並至少須提供'id'、'email'、'name'、'isAdmin'欄位,且'isAdmin'限輸入'y'或'n',且輸入'y'時會複寫權限系統該使用者之'isAdmin'欄位值
|
|
34
|
+
* @param {Function} verifyUser 輸入處理函數,函數會傳入使用者資訊物件,通過此函數識別後回傳布林值,允許使用者回傳true,反之回傳false
|
|
31
35
|
* @param {Object} [opt={}] 輸入設定物件,預設{}
|
|
32
36
|
* @param {Integer} [opt.serverPort=11006] 輸入伺服器通訊port,預設11006
|
|
33
37
|
* @param {Boolean} [opt.bCheckUser=false] 輸入是否檢查使用者資訊布林值,預設false
|
|
@@ -40,9 +44,73 @@ import { getUserRules } from '../src/plugins/mShare.mjs'
|
|
|
40
44
|
* @param {String} [opt.mappingBy='email'] 輸入外部系統識別使用者token後所提供之資料物件,與權限系統之使用者資料物件,兩者間查找之對應欄位,可選'id'、'email'、'name',預設'email'
|
|
41
45
|
* @returns {Object} 回傳物件,其內server為hapi伺服器實體,wsrv為w-converhp的伺服器事件物件,wsds為w-serv-webdata的伺服器事件物件,可監聽error事件
|
|
42
46
|
* @example
|
|
43
|
-
|
|
47
|
+
* import WOrm from 'w-orm-mongodb/src/WOrmMongodb.mjs' //自行選擇引用ORM, 使用Mongodb測試
|
|
48
|
+
* import WWebPerm from './server/WWebPerm.mjs'
|
|
49
|
+
* import getSettings from './g.getSettings.mjs'
|
|
50
|
+
*
|
|
51
|
+
* //st
|
|
52
|
+
* let st = getSettings()
|
|
53
|
+
*
|
|
54
|
+
* let url = `mongodb://${st.dbUsername}:${st.dbPassword}@${st.dbIP}:${st.dbPort}` //使用Mongodb測試
|
|
55
|
+
* let db = st.dbName
|
|
56
|
+
* let opt = {
|
|
57
|
+
*
|
|
58
|
+
* bCheckUser: false,
|
|
59
|
+
* getUserById: null,
|
|
60
|
+
* bExcludeWhenNotAdmin: false,
|
|
61
|
+
*
|
|
62
|
+
* serverPort: 11006,
|
|
63
|
+
* subfolder: '', //mperm
|
|
64
|
+
*
|
|
65
|
+
* webName: {
|
|
66
|
+
* 'eng': 'Permission Service',
|
|
67
|
+
* 'cht': '權限管理系統',
|
|
68
|
+
* },
|
|
69
|
+
* webDescription: {
|
|
70
|
+
* 'eng': 'A web service package for user permissions and management targets.',
|
|
71
|
+
* 'cht': 'A web service package for user permissions and management targets.',
|
|
72
|
+
* },
|
|
73
|
+
* webLogo: 'data:image/svg+xml;base64,...',
|
|
74
|
+
*
|
|
75
|
+
* }
|
|
76
|
+
*
|
|
77
|
+
* let getUserByToken = async (token) => {
|
|
78
|
+
* // return {} //測試無法登入
|
|
79
|
+
* if (token === '{token-for-application}') { //提供外部應用系統作為存取使用者
|
|
80
|
+
* return {
|
|
81
|
+
* id: 'id-for-application',
|
|
82
|
+
* name: 'application',
|
|
83
|
+
* email: 'admin@example.com',
|
|
84
|
+
* isAdmin: 'y',
|
|
85
|
+
* }
|
|
86
|
+
* }
|
|
87
|
+
* if (token === 'sys') { //開發階段w-ui-loginout自動給予browser使用者(且位於localhost)的token為sys
|
|
88
|
+
* return {
|
|
89
|
+
* id: 'id-for-admin',
|
|
90
|
+
* name: 'tester',
|
|
91
|
+
* email: 'admin@example.com',
|
|
92
|
+
* isAdmin: 'y',
|
|
93
|
+
* }
|
|
94
|
+
* }
|
|
95
|
+
* console.log('invalid token', token)
|
|
96
|
+
* console.log('於生產環境時得加入SSO等驗證token機制')
|
|
97
|
+
* return {}
|
|
98
|
+
* }
|
|
99
|
+
*
|
|
100
|
+
* let verifyUser = (user) => {
|
|
101
|
+
* console.log('於生產環境時得加入驗證user機制')
|
|
102
|
+
* return user.isAdmin === 'y' //測試僅系統管理者使用
|
|
103
|
+
* }
|
|
104
|
+
*
|
|
105
|
+
* //WWebPerm
|
|
106
|
+
* let instWWebPerm = WWebPerm(WOrm, url, db, getUserByToken, verifyUser, opt)
|
|
107
|
+
*
|
|
108
|
+
* instWWebPerm.on('error', (err) => {
|
|
109
|
+
* console.log(err)
|
|
110
|
+
* })
|
|
111
|
+
*
|
|
44
112
|
*/
|
|
45
|
-
function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
113
|
+
function WWebPerm(WOrm, url, db, getUserByToken, verifyUser, opt = {}) {
|
|
46
114
|
let instWServHapiServer = null
|
|
47
115
|
|
|
48
116
|
|
|
@@ -74,6 +142,13 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
74
142
|
}
|
|
75
143
|
|
|
76
144
|
|
|
145
|
+
//check verifyUser
|
|
146
|
+
if (!isfun(verifyUser)) {
|
|
147
|
+
console.log('invalid verifyUser', verifyUser)
|
|
148
|
+
throw new Error('invalid verifyUser')
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
77
152
|
//serverPort
|
|
78
153
|
let serverPort = get(opt, 'serverPort')
|
|
79
154
|
if (!ispint(serverPort)) {
|
|
@@ -123,6 +198,7 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
123
198
|
if (mappingBy !== 'id' && mappingBy !== 'email' && mappingBy !== 'name') {
|
|
124
199
|
mappingBy = 'email'
|
|
125
200
|
}
|
|
201
|
+
// console.log('mappingBy', mappingBy)
|
|
126
202
|
|
|
127
203
|
|
|
128
204
|
//WServOrm
|
|
@@ -198,31 +274,32 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
198
274
|
|
|
199
275
|
//check
|
|
200
276
|
if (!iseobj(userSelf)) {
|
|
201
|
-
console.log(
|
|
202
|
-
return
|
|
277
|
+
console.log(`can not find the user from token`, token)
|
|
278
|
+
return Promise.reject(`can not find the user from token`)
|
|
203
279
|
}
|
|
204
280
|
|
|
205
281
|
//check userSelf
|
|
206
282
|
if (true) {
|
|
207
283
|
let id = get(userSelf, 'id', '')
|
|
208
284
|
if (!isestr(id)) {
|
|
209
|
-
console.log('
|
|
210
|
-
return
|
|
285
|
+
console.log('userSelf', userSelf)
|
|
286
|
+
return Promise.reject(`can not get the userId`)
|
|
211
287
|
}
|
|
212
288
|
let email = get(userSelf, 'email', '')
|
|
213
289
|
if (!isestr(email)) {
|
|
214
|
-
console.log('
|
|
215
|
-
return
|
|
290
|
+
console.log('userSelf', userSelf)
|
|
291
|
+
return Promise.reject(`can not get the email of user`)
|
|
216
292
|
}
|
|
217
293
|
let name = get(userSelf, 'name', '')
|
|
218
294
|
if (!isestr(name)) {
|
|
219
|
-
console.log('
|
|
220
|
-
return
|
|
295
|
+
console.log('userSelf', userSelf)
|
|
296
|
+
return Promise.reject(`can not get userName`)
|
|
221
297
|
}
|
|
222
298
|
let isAdmin = get(userSelf, 'isAdmin', '')
|
|
223
299
|
if (isAdmin !== 'y' && isAdmin !== 'n') {
|
|
224
|
-
console.log('userSelf
|
|
225
|
-
|
|
300
|
+
console.log('userSelf', userSelf)
|
|
301
|
+
console.log('userSelf.isAdmin is not y or n', userSelf.isAdmin)
|
|
302
|
+
return Promise.reject(`can not get the role of user`)
|
|
226
303
|
}
|
|
227
304
|
}
|
|
228
305
|
|
|
@@ -232,8 +309,9 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
232
309
|
|
|
233
310
|
//check
|
|
234
311
|
if (!isestr(vSelf)) {
|
|
235
|
-
console.log('
|
|
236
|
-
|
|
312
|
+
console.log('userSelf', userSelf)
|
|
313
|
+
console.log('mappingBy', mappingBy)
|
|
314
|
+
return Promise.reject(`can not get the prop of user by mappingBy`)
|
|
237
315
|
}
|
|
238
316
|
|
|
239
317
|
//userFind
|
|
@@ -241,6 +319,13 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
241
319
|
userFind = get(userFind, 0, null)
|
|
242
320
|
// console.log('userFind', userFind)
|
|
243
321
|
|
|
322
|
+
//check
|
|
323
|
+
if (!iseobj(userFind)) {
|
|
324
|
+
console.log('userSelf', userSelf)
|
|
325
|
+
console.log('mappingBy', mappingBy)
|
|
326
|
+
return Promise.reject(`can not get the user from perm`)
|
|
327
|
+
}
|
|
328
|
+
|
|
244
329
|
//複寫isAdmin
|
|
245
330
|
let isAdminSrc = get(userSelf, 'isAdmin', '')
|
|
246
331
|
let isAdminSelf = get(userFind, 'isAdmin', '')
|
|
@@ -249,10 +334,112 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
249
334
|
}
|
|
250
335
|
// console.log('userFind(isAdmin)', userFind)
|
|
251
336
|
|
|
337
|
+
//verifyUser
|
|
338
|
+
let b = verifyUser(userFind)
|
|
339
|
+
if (ispm(b)) {
|
|
340
|
+
b = await b
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
//check
|
|
344
|
+
if (!b) {
|
|
345
|
+
console.log('userSelf', userSelf)
|
|
346
|
+
console.log('verifyUser/userFind', userFind)
|
|
347
|
+
return Promise.reject(`user does not have permission`)
|
|
348
|
+
}
|
|
349
|
+
|
|
252
350
|
return userFind
|
|
253
351
|
}
|
|
254
352
|
|
|
255
353
|
|
|
354
|
+
//parsePayload
|
|
355
|
+
let parsePayload = async (req, key) => {
|
|
356
|
+
let inp = get(req, 'payload')
|
|
357
|
+
|
|
358
|
+
//to obj
|
|
359
|
+
if (isestr(inp)) {
|
|
360
|
+
inp = j2o(inp)
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
//check
|
|
364
|
+
if (!iseobj(inp)) {
|
|
365
|
+
console.log('inp', inp)
|
|
366
|
+
return Promise.reject(`invalid inp from req`)
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
//from
|
|
370
|
+
let from = get(inp, 'from', '')
|
|
371
|
+
|
|
372
|
+
//check
|
|
373
|
+
if (!isestr(from)) {
|
|
374
|
+
console.log('inp', inp)
|
|
375
|
+
console.log('from', from)
|
|
376
|
+
return Promise.reject(`invalid from from inp`)
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
//vs
|
|
381
|
+
let vs = get(inp, key, [])
|
|
382
|
+
//users
|
|
383
|
+
//targets
|
|
384
|
+
//ruleGroups
|
|
385
|
+
|
|
386
|
+
//check
|
|
387
|
+
if (!isearr(vs)) {
|
|
388
|
+
console.log('inp', inp)
|
|
389
|
+
console.log(key, vs)
|
|
390
|
+
return Promise.reject(`invalid ${key} from inp`)
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
//resave
|
|
394
|
+
inp = {
|
|
395
|
+
from,
|
|
396
|
+
[key]: vs,
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return inp
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
//syncAndReplaceRows
|
|
404
|
+
let syncAndReplaceRows = async (params, key) => {
|
|
405
|
+
|
|
406
|
+
//from
|
|
407
|
+
let from = get(params, 'from', '')
|
|
408
|
+
// console.log('from', from)
|
|
409
|
+
|
|
410
|
+
//check
|
|
411
|
+
if (!isestr(from)) {
|
|
412
|
+
console.log('params', params)
|
|
413
|
+
console.log('from', from)
|
|
414
|
+
return Promise.reject(`invalid from`)
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
//vs
|
|
418
|
+
let vs = get(params, key, [])
|
|
419
|
+
// console.log(key, vs)
|
|
420
|
+
|
|
421
|
+
//check
|
|
422
|
+
if (!isearr(vs)) {
|
|
423
|
+
console.log('params', params)
|
|
424
|
+
console.log(key, vs)
|
|
425
|
+
return Promise.reject(`invalid ${key}`)
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
//save from
|
|
429
|
+
each(vs, (v, k) => {
|
|
430
|
+
vs[k].from = from
|
|
431
|
+
})
|
|
432
|
+
|
|
433
|
+
//delAll from
|
|
434
|
+
await woItems[key].delAll({ from })
|
|
435
|
+
|
|
436
|
+
//insert
|
|
437
|
+
let r = await woItems[key].insert(vs)
|
|
438
|
+
|
|
439
|
+
return r
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
|
|
256
443
|
//getGenUserByKV
|
|
257
444
|
let getGenUserByKV = async(keyUser, valueUser) => {
|
|
258
445
|
|
|
@@ -382,10 +569,17 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
382
569
|
// console.log('userSelf', userSelf)
|
|
383
570
|
|
|
384
571
|
//check
|
|
385
|
-
if (
|
|
386
|
-
|
|
572
|
+
if (!iseobj(userSelf)) {
|
|
573
|
+
console.log('token', token)
|
|
574
|
+
console.log('[API]getUserByToken/check userSelf: invalid userSelf')
|
|
575
|
+
return Promise.reject(`token does not have permission`)
|
|
387
576
|
}
|
|
388
577
|
|
|
578
|
+
// //check
|
|
579
|
+
// if (get(userSelf, 'isAdmin') !== 'y') { //權限系統須系統管理員才能使用
|
|
580
|
+
// return Promise.reject(`user does not have permission`)
|
|
581
|
+
// }
|
|
582
|
+
|
|
389
583
|
return userSelf
|
|
390
584
|
}
|
|
391
585
|
|
|
@@ -415,7 +609,9 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
415
609
|
|
|
416
610
|
//check
|
|
417
611
|
if (!iseobj(userLogin)) {
|
|
418
|
-
|
|
612
|
+
console.log('token', token)
|
|
613
|
+
console.log('[API]getPerm/check userLogin: invalid userLogin')
|
|
614
|
+
return Promise.reject(`token does not have permission`)
|
|
419
615
|
}
|
|
420
616
|
|
|
421
617
|
//parseUserId
|
|
@@ -424,7 +620,9 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
424
620
|
|
|
425
621
|
//check
|
|
426
622
|
if (!isestr(userId)) {
|
|
427
|
-
|
|
623
|
+
console.log('userLogin', userLogin)
|
|
624
|
+
console.log('[API]getPerm/check userId: invalid userId')
|
|
625
|
+
return Promise.reject(`token does not have permission`)
|
|
428
626
|
}
|
|
429
627
|
|
|
430
628
|
//getGenUserAndRulesByUserId
|
|
@@ -433,7 +631,9 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
433
631
|
|
|
434
632
|
//check
|
|
435
633
|
if (!iseobj(r)) {
|
|
436
|
-
|
|
634
|
+
console.log('userLogin', userLogin)
|
|
635
|
+
console.log('[API]getPerm/getGenUserAndRulesByUserId: user does not have permrules')
|
|
636
|
+
return Promise.reject(`token does not have permission`)
|
|
437
637
|
}
|
|
438
638
|
|
|
439
639
|
return r
|
|
@@ -464,10 +664,17 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
464
664
|
// console.log('userSelf', userSelf)
|
|
465
665
|
|
|
466
666
|
//check
|
|
467
|
-
if (
|
|
468
|
-
|
|
667
|
+
if (!iseobj(userSelf)) {
|
|
668
|
+
console.log('token', token)
|
|
669
|
+
console.log('[API]getPermById/check userSelf: invalid userSelf')
|
|
670
|
+
return Promise.reject(`token does not have permission`)
|
|
469
671
|
}
|
|
470
672
|
|
|
673
|
+
// //check
|
|
674
|
+
// if (get(userSelf, 'isAdmin') !== 'y') { //權限系統須系統管理員才能使用
|
|
675
|
+
// return Promise.reject(`user does not have permission`)
|
|
676
|
+
// }
|
|
677
|
+
|
|
471
678
|
//userId
|
|
472
679
|
let userId = get(req, 'query.userId', '')
|
|
473
680
|
// console.log('userId', userId)
|
|
@@ -478,6 +685,8 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
478
685
|
|
|
479
686
|
//check
|
|
480
687
|
if (!iseobj(r)) {
|
|
688
|
+
console.log('userSelf', userSelf)
|
|
689
|
+
console.log('[API]getPermById/getGenUserAndRulesByUserId: user does not have permrules')
|
|
481
690
|
return Promise.reject(`user does not have permrules`)
|
|
482
691
|
}
|
|
483
692
|
|
|
@@ -488,6 +697,120 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
488
697
|
let r = await pm2resolve(core)() //w-ui-loginout接收已預設格式用pm2resolve轉過, 須另提取state進行判斷
|
|
489
698
|
// console.log('getUserByToken', r)
|
|
490
699
|
|
|
700
|
+
return r
|
|
701
|
+
},
|
|
702
|
+
},
|
|
703
|
+
{
|
|
704
|
+
method: 'POST',
|
|
705
|
+
path: '/syncAndReplaceUsers',
|
|
706
|
+
handler: async function (req, res) {
|
|
707
|
+
// console.log('syncAndReplaceUsers', req)
|
|
708
|
+
// console.log('payload', req.payload)
|
|
709
|
+
|
|
710
|
+
async function core() {
|
|
711
|
+
|
|
712
|
+
//token
|
|
713
|
+
let token = get(req, 'query.token', '')
|
|
714
|
+
|
|
715
|
+
//getTokenUserForSelf
|
|
716
|
+
let user = await getTokenUserForSelf(token)
|
|
717
|
+
|
|
718
|
+
//check
|
|
719
|
+
if (!iseobj(user)) {
|
|
720
|
+
console.log('token', token)
|
|
721
|
+
console.log('[API]syncAndReplaceUsers/check user: invalid user')
|
|
722
|
+
return Promise.reject(`token does not have permission`)
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
//parsePayload
|
|
726
|
+
let inp = await parsePayload(req, 'users')
|
|
727
|
+
|
|
728
|
+
//syncAndReplaceRows
|
|
729
|
+
let r = await syncAndReplaceRows(inp, 'users')
|
|
730
|
+
|
|
731
|
+
return r
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
//pm2resolve core
|
|
735
|
+
let r = await pm2resolve(core)()
|
|
736
|
+
// console.log('verifyIdentity', r)
|
|
737
|
+
|
|
738
|
+
return r
|
|
739
|
+
},
|
|
740
|
+
},
|
|
741
|
+
{
|
|
742
|
+
method: 'POST',
|
|
743
|
+
path: '/syncAndReplaceTargets',
|
|
744
|
+
handler: async function (req, res) {
|
|
745
|
+
// console.log('syncAndReplaceTargets', req)
|
|
746
|
+
// console.log('payload', req.payload)
|
|
747
|
+
|
|
748
|
+
async function core() {
|
|
749
|
+
|
|
750
|
+
//token
|
|
751
|
+
let token = get(req, 'query.token', '')
|
|
752
|
+
|
|
753
|
+
//getTokenUserForSelf
|
|
754
|
+
let user = await getTokenUserForSelf(token)
|
|
755
|
+
|
|
756
|
+
//check
|
|
757
|
+
if (!iseobj(user)) {
|
|
758
|
+
console.log('token', token)
|
|
759
|
+
console.log('[API]syncAndReplaceTargets/check user: invalid user')
|
|
760
|
+
return Promise.reject(`token does not have permission`)
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
//parsePayload
|
|
764
|
+
let inp = await parsePayload(req, 'targets')
|
|
765
|
+
|
|
766
|
+
//syncAndReplaceRows
|
|
767
|
+
let r = await syncAndReplaceRows(inp, 'targets')
|
|
768
|
+
|
|
769
|
+
return r
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
//pm2resolve core
|
|
773
|
+
let r = await pm2resolve(core)()
|
|
774
|
+
// console.log('verifyIdentity', r)
|
|
775
|
+
|
|
776
|
+
return r
|
|
777
|
+
},
|
|
778
|
+
},
|
|
779
|
+
{
|
|
780
|
+
method: 'POST',
|
|
781
|
+
path: '/syncAndReplaceRuleGroups',
|
|
782
|
+
handler: async function (req, res) {
|
|
783
|
+
// console.log('syncAndReplaceRuleGroups', req)
|
|
784
|
+
// console.log('payload', req.payload)
|
|
785
|
+
|
|
786
|
+
async function core() {
|
|
787
|
+
|
|
788
|
+
//token
|
|
789
|
+
let token = get(req, 'query.token', '')
|
|
790
|
+
|
|
791
|
+
//getTokenUserForSelf
|
|
792
|
+
let user = await getTokenUserForSelf(token)
|
|
793
|
+
|
|
794
|
+
//check
|
|
795
|
+
if (!iseobj(user)) {
|
|
796
|
+
console.log('token', token)
|
|
797
|
+
console.log('[API]syncAndReplaceRuleGroups/check user: invalid user')
|
|
798
|
+
return Promise.reject(`token does not have permission`)
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
//parsePayload
|
|
802
|
+
let inp = await parsePayload(req, 'ruleGroups')
|
|
803
|
+
|
|
804
|
+
//syncAndReplaceRows
|
|
805
|
+
let r = await syncAndReplaceRows(inp, 'ruleGroups')
|
|
806
|
+
|
|
807
|
+
return r
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
//pm2resolve core
|
|
811
|
+
let r = await pm2resolve(core)()
|
|
812
|
+
// console.log('verifyIdentity', r)
|
|
813
|
+
|
|
491
814
|
return r
|
|
492
815
|
},
|
|
493
816
|
},
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import axios from 'axios'
|
|
2
|
+
import ltdtpick from 'wsemi/src/ltdtpick.mjs'
|
|
3
|
+
import genPm from 'wsemi/src/genPm.mjs'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
async function provideRuleGroups(url, from, ruleGroups) {
|
|
7
|
+
//url: 指權限伺服器提供的調整ruleGroups網址, 例如 http://localhost:11006/syncAndReplaceRuleGroups
|
|
8
|
+
//from: 指ruleGroup來源
|
|
9
|
+
|
|
10
|
+
//pm
|
|
11
|
+
let pm = genPm()
|
|
12
|
+
|
|
13
|
+
//ks
|
|
14
|
+
let ks = [
|
|
15
|
+
'id',
|
|
16
|
+
'order',
|
|
17
|
+
'name',
|
|
18
|
+
'description',
|
|
19
|
+
'from',
|
|
20
|
+
'crules',
|
|
21
|
+
'userId',
|
|
22
|
+
'timeCreate',
|
|
23
|
+
'userIdUpdate',
|
|
24
|
+
'timeUpdate',
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
//ltdtpick
|
|
28
|
+
ruleGroups = ltdtpick(ruleGroups, ks)
|
|
29
|
+
|
|
30
|
+
//rin
|
|
31
|
+
let rin = {
|
|
32
|
+
from,
|
|
33
|
+
ruleGroups,
|
|
34
|
+
}
|
|
35
|
+
// rin = JSON.stringify(rin)
|
|
36
|
+
|
|
37
|
+
//axios
|
|
38
|
+
await axios({
|
|
39
|
+
method: 'post',
|
|
40
|
+
url,
|
|
41
|
+
headers: { 'Content-Type': 'application/json; charset=utf-8' },
|
|
42
|
+
data: rin,
|
|
43
|
+
})
|
|
44
|
+
.then((res) => {
|
|
45
|
+
// console.log(res)
|
|
46
|
+
let r = {
|
|
47
|
+
msg: '成功傳輸RuleGroups清單',
|
|
48
|
+
res,
|
|
49
|
+
}
|
|
50
|
+
pm.resolve(r)
|
|
51
|
+
})
|
|
52
|
+
.catch((err) => {
|
|
53
|
+
// console.log(err)
|
|
54
|
+
let r = {
|
|
55
|
+
msg: '無法傳輸RuleGroups清單',
|
|
56
|
+
res: err,
|
|
57
|
+
}
|
|
58
|
+
pm.reject(r)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
return pm
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
export default provideRuleGroups
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import axios from 'axios'
|
|
2
|
+
import ltdtpick from 'wsemi/src/ltdtpick.mjs'
|
|
3
|
+
import genPm from 'wsemi/src/genPm.mjs'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
async function provideTargets(url, from, targets) {
|
|
7
|
+
//url: 指權限伺服器提供的調整targets網址, 例如 http://localhost:11006/syncAndReplaceTargets
|
|
8
|
+
//from: 指target來源
|
|
9
|
+
|
|
10
|
+
//pm
|
|
11
|
+
let pm = genPm()
|
|
12
|
+
|
|
13
|
+
//ks
|
|
14
|
+
let ks = [
|
|
15
|
+
'id',
|
|
16
|
+
'order',
|
|
17
|
+
'description',
|
|
18
|
+
'from',
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
//ltdtpick
|
|
22
|
+
targets = ltdtpick(targets, ks)
|
|
23
|
+
|
|
24
|
+
//rin
|
|
25
|
+
let rin = {
|
|
26
|
+
from,
|
|
27
|
+
targets,
|
|
28
|
+
}
|
|
29
|
+
// rin = JSON.stringify(rin)
|
|
30
|
+
|
|
31
|
+
//axios
|
|
32
|
+
await axios({
|
|
33
|
+
method: 'post',
|
|
34
|
+
url,
|
|
35
|
+
headers: { 'Content-Type': 'application/json; charset=utf-8' },
|
|
36
|
+
data: rin,
|
|
37
|
+
})
|
|
38
|
+
.then((res) => {
|
|
39
|
+
// console.log(res)
|
|
40
|
+
let r = {
|
|
41
|
+
msg: '成功傳輸Targets清單',
|
|
42
|
+
res,
|
|
43
|
+
}
|
|
44
|
+
pm.resolve(r)
|
|
45
|
+
})
|
|
46
|
+
.catch((err) => {
|
|
47
|
+
// console.log(err)
|
|
48
|
+
let r = {
|
|
49
|
+
msg: '無法傳輸Targets清單',
|
|
50
|
+
res: err,
|
|
51
|
+
}
|
|
52
|
+
pm.reject(r)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
return pm
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
export default provideTargets
|