w-web-perm 1.0.4 → 1.0.6
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.dad1d596.css +1 -0
- package/dist/index.tmp +1 -1
- package/dist/js/app-legacy.4e39a313.js +2 -0
- package/dist/js/app-legacy.4e39a313.js.map +1 -0
- package/dist/js/app.4e39a313.js +2 -0
- package/dist/js/app.4e39a313.js.map +1 -0
- package/dist/js/chunk-vendors-legacy.827f1c54.js +13 -0
- package/dist/js/chunk-vendors-legacy.827f1c54.js.map +1 -0
- package/dist/js/chunk-vendors.827f1c54.js +13 -0
- package/dist/js/chunk-vendors.827f1c54.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 +341 -25
- 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 +2 -7
- package/public/index.html +1 -1
- package/server/WWebPerm.mjs +340 -24
- 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 +37 -68
- package/src/components/LayoutContentGroups.vue +68 -62
- package/src/components/LayoutContentTargets.vue +56 -54
- package/src/components/LayoutContentUsers.vue +66 -61
- 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 +10 -11
- package/tableTags-web-perm.json +1 -1
- package/vue.config.js +1 -1
- package/dist/css/app.79b4b59b.css +0 -1
- package/dist/css/chunk-vendors.99633b53.css +0 -5
- package/dist/js/app-legacy.48e6e535.js +0 -2
- package/dist/js/app-legacy.48e6e535.js.map +0 -1
- package/dist/js/app.7f6428ac.js +0 -2
- package/dist/js/app.7f6428ac.js.map +0 -1
- package/dist/js/chunk-vendors-legacy.7cb6c366.js +0 -13
- package/dist/js/chunk-vendors-legacy.7cb6c366.js.map +0 -1
- package/dist/js/chunk-vendors.7cb6c366.js +0 -13
- package/dist/js/chunk-vendors.7cb6c366.js.map +0 -1
- package/g.mInitialData.mjs +0 -147
- package/src/plugins/mVuetify.mjs +0 -12
package/docs/WWebPerm.html
CHANGED
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
|
|
65
65
|
|
|
66
66
|
|
|
67
|
-
<h4 class="name" id="WWebPerm"><span class="type-signature"></span>new WWebPerm<span class="signature">(WOrm, url, db, getUserByToken, opt<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {Object}</span></h4>
|
|
67
|
+
<h4 class="name" id="WWebPerm"><span class="type-signature"></span>new WWebPerm<span class="signature">(WOrm, url, db, getUserByToken, verifyUser, opt<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {Object}</span></h4>
|
|
68
68
|
|
|
69
69
|
|
|
70
70
|
|
|
@@ -74,13 +74,13 @@
|
|
|
74
74
|
<dl class="details">
|
|
75
75
|
|
|
76
76
|
<dt class="tag-description">Description:</dt>
|
|
77
|
-
<dd class="tag-description"><ul class="dummy"><li><p
|
|
77
|
+
<dd class="tag-description"><ul class="dummy"><li><p>權限伺服器</p></li></ul></dd>
|
|
78
78
|
|
|
79
79
|
|
|
80
80
|
|
|
81
81
|
<dt class="tag-source">Source:</dt>
|
|
82
82
|
<dd class="tag-source"><ul class="dummy"><li>
|
|
83
|
-
<a href="WWebPerm.mjs.html">WWebPerm.mjs</a>, <a href="WWebPerm.mjs.html#
|
|
83
|
+
<a href="WWebPerm.mjs.html">WWebPerm.mjs</a>, <a href="WWebPerm.mjs.html#line113">line 113</a>
|
|
84
84
|
</li></ul></dd>
|
|
85
85
|
|
|
86
86
|
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
|
|
128
128
|
<h5 class="h5-examples">Example</h5>
|
|
129
129
|
|
|
130
|
-
<pre class="prettyprint"><code
|
|
130
|
+
<pre class="prettyprint"><code>import WOrm from 'w-orm-mongodb/src/WOrmMongodb.mjs' //自行選擇引用ORM, 使用Mongodb測試
|
|
131
131
|
bCheckUser: false,
|
|
132
132
|
getUserById: null,
|
|
133
133
|
bExcludeWhenNotAdmin: false,
|
|
134
134
|
serverPort: 11006,
|
|
135
135
|
subfolder: '', //mperm
|
|
136
136
|
webName: {
|
|
137
137
|
'eng': 'Permission Service',
|
|
138
138
|
'cht': '權限管理系統',
|
|
139
139
|
},
|
|
140
140
|
webDescription: {
|
|
141
141
|
'eng': 'A web service package for user permissions and management targets.',
|
|
142
142
|
'cht': 'A web service package for user permissions and management targets.',
|
|
143
143
|
},
|
|
144
144
|
webLogo: 'data:image/svg+xml;base64,...',
|
|
145
145
|
// return {} //測試無法登入
|
|
146
146
|
if (token === '{token-for-application}') { //提供外部應用系統作為存取使用者
|
|
147
147
|
return {
|
|
148
148
|
id: 'id-for-application',
|
|
149
149
|
name: 'application',
|
|
150
150
|
email: 'admin@example.com',
|
|
151
151
|
isAdmin: 'y',
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
if (token === 'sys') { //開發階段w-ui-loginout自動給予browser使用者(且位於localhost)的token為sys
|
|
155
155
|
return {
|
|
156
156
|
id: 'id-for-admin',
|
|
157
157
|
name: 'tester',
|
|
158
158
|
email: 'admin@example.com',
|
|
159
159
|
isAdmin: 'y',
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
console.log('invalid token', token)
|
|
163
163
|
console.log('於生產環境時得加入SSO等驗證token機制')
|
|
164
164
|
return {}
|
|
165
165
|
console.log('於生產環境時得加入驗證user機制')
|
|
166
166
|
return user.isAdmin === 'y' //測試僅系統管理者使用
|
|
167
167
|
console.log(err)
|
|
168
168
|
|
|
169
169
|
|
|
170
170
|
|
|
@@ -303,6 +303,42 @@
|
|
|
303
303
|
|
|
304
304
|
|
|
305
305
|
|
|
306
|
+
<tr>
|
|
307
|
+
|
|
308
|
+
<td class="name"><code>verifyUser</code></td>
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
<td class="type">
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
<span class="param-type">function</span>
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
</td>
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
<td class="attributes">
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
</td>
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
<td class="default">
|
|
333
|
+
|
|
334
|
+
</td>
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
<td class="description last"><p>輸入處理函數,函數會傳入使用者資訊物件,通過此函數識別後回傳布林值,允許使用者回傳true,反之回傳false</p></td>
|
|
338
|
+
</tr>
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
306
342
|
<tr>
|
|
307
343
|
|
|
308
344
|
<td class="name"><code>opt</code></td>
|
|
@@ -813,7 +849,7 @@
|
|
|
813
849
|
<br class="clear">
|
|
814
850
|
|
|
815
851
|
<footer>
|
|
816
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on
|
|
852
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Thu Nov 02 2023 11:12:12 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
817
853
|
</footer>
|
|
818
854
|
|
|
819
855
|
<script>prettyPrint();</script>
|
package/docs/WWebPerm.mjs.html
CHANGED
|
@@ -48,13 +48,16 @@
|
|
|
48
48
|
<pre class="prettyprint source linenums"><code>import path from 'path'
|
|
49
49
|
import fs from 'fs'
|
|
50
50
|
import get from 'lodash/get'
|
|
51
|
+
import each from 'lodash/each'
|
|
51
52
|
import keys from 'lodash/keys'
|
|
52
53
|
import iseobj from 'wsemi/src/iseobj.mjs'
|
|
53
54
|
import isestr from 'wsemi/src/isestr.mjs'
|
|
54
55
|
import ispint from 'wsemi/src/ispint.mjs'
|
|
56
|
+
import isearr from 'wsemi/src/isearr.mjs'
|
|
55
57
|
import isfun from 'wsemi/src/isfun.mjs'
|
|
56
58
|
import ispm from 'wsemi/src/ispm.mjs'
|
|
57
59
|
import cint from 'wsemi/src/cint.mjs'
|
|
60
|
+
import j2o from 'wsemi/src/j2o.mjs'
|
|
58
61
|
import strleft from 'wsemi/src/strleft.mjs'
|
|
59
62
|
import strright from 'wsemi/src/strright.mjs'
|
|
60
63
|
import strdelright from 'wsemi/src/strdelright.mjs'
|
|
@@ -68,13 +71,14 @@ import { getUserRules } from '../src/plugins/mShare.mjs'
|
|
|
68
71
|
|
|
69
72
|
|
|
70
73
|
/**
|
|
71
|
-
*
|
|
74
|
+
* 權限伺服器
|
|
72
75
|
*
|
|
73
76
|
* @class
|
|
74
77
|
* @param {Function} WOrm 輸入資料庫ORM函數
|
|
75
78
|
* @param {String} url 輸入資料庫連線字串,例如'mongodb://sername:password@$127.0.0.1:27017'
|
|
76
79
|
* @param {String} db 輸入資料庫名稱字串
|
|
77
80
|
* @param {Function} getUserByToken 輸入處理函數,函數會傳入使用者token,通過此函數處理後並回傳使用者資訊物件,並至少須提供'id'、'email'、'name'、'isAdmin'欄位,且'isAdmin'限輸入'y'或'n',且輸入'y'時會複寫權限系統該使用者之'isAdmin'欄位值
|
|
81
|
+
* @param {Function} verifyUser 輸入處理函數,函數會傳入使用者資訊物件,通過此函數識別後回傳布林值,允許使用者回傳true,反之回傳false
|
|
78
82
|
* @param {Object} [opt={}] 輸入設定物件,預設{}
|
|
79
83
|
* @param {Integer} [opt.serverPort=11006] 輸入伺服器通訊port,預設11006
|
|
80
84
|
* @param {Boolean} [opt.bCheckUser=false] 輸入是否檢查使用者資訊布林值,預設false
|
|
@@ -87,9 +91,73 @@ import { getUserRules } from '../src/plugins/mShare.mjs'
|
|
|
87
91
|
* @param {String} [opt.mappingBy='email'] 輸入外部系統識別使用者token後所提供之資料物件,與權限系統之使用者資料物件,兩者間查找之對應欄位,可選'id'、'email'、'name',預設'email'
|
|
88
92
|
* @returns {Object} 回傳物件,其內server為hapi伺服器實體,wsrv為w-converhp的伺服器事件物件,wsds為w-serv-webdata的伺服器事件物件,可監聽error事件
|
|
89
93
|
* @example
|
|
90
|
-
|
|
94
|
+
* import WOrm from 'w-orm-mongodb/src/WOrmMongodb.mjs' //自行選擇引用ORM, 使用Mongodb測試
|
|
95
|
+
* import WWebPerm from './server/WWebPerm.mjs'
|
|
96
|
+
* import getSettings from './g.getSettings.mjs'
|
|
97
|
+
*
|
|
98
|
+
* //st
|
|
99
|
+
* let st = getSettings()
|
|
100
|
+
*
|
|
101
|
+
* let url = `mongodb://${st.dbUsername}:${st.dbPassword}@${st.dbIP}:${st.dbPort}` //使用Mongodb測試
|
|
102
|
+
* let db = st.dbName
|
|
103
|
+
* let opt = {
|
|
104
|
+
*
|
|
105
|
+
* bCheckUser: false,
|
|
106
|
+
* getUserById: null,
|
|
107
|
+
* bExcludeWhenNotAdmin: false,
|
|
108
|
+
*
|
|
109
|
+
* serverPort: 11006,
|
|
110
|
+
* subfolder: '', //mperm
|
|
111
|
+
*
|
|
112
|
+
* webName: {
|
|
113
|
+
* 'eng': 'Permission Service',
|
|
114
|
+
* 'cht': '權限管理系統',
|
|
115
|
+
* },
|
|
116
|
+
* webDescription: {
|
|
117
|
+
* 'eng': 'A web service package for user permissions and management targets.',
|
|
118
|
+
* 'cht': 'A web service package for user permissions and management targets.',
|
|
119
|
+
* },
|
|
120
|
+
* webLogo: 'data:image/svg+xml;base64,...',
|
|
121
|
+
*
|
|
122
|
+
* }
|
|
123
|
+
*
|
|
124
|
+
* let getUserByToken = async (token) => {
|
|
125
|
+
* // return {} //測試無法登入
|
|
126
|
+
* if (token === '{token-for-application}') { //提供外部應用系統作為存取使用者
|
|
127
|
+
* return {
|
|
128
|
+
* id: 'id-for-application',
|
|
129
|
+
* name: 'application',
|
|
130
|
+
* email: 'admin@example.com',
|
|
131
|
+
* isAdmin: 'y',
|
|
132
|
+
* }
|
|
133
|
+
* }
|
|
134
|
+
* if (token === 'sys') { //開發階段w-ui-loginout自動給予browser使用者(且位於localhost)的token為sys
|
|
135
|
+
* return {
|
|
136
|
+
* id: 'id-for-admin',
|
|
137
|
+
* name: 'tester',
|
|
138
|
+
* email: 'admin@example.com',
|
|
139
|
+
* isAdmin: 'y',
|
|
140
|
+
* }
|
|
141
|
+
* }
|
|
142
|
+
* console.log('invalid token', token)
|
|
143
|
+
* console.log('於生產環境時得加入SSO等驗證token機制')
|
|
144
|
+
* return {}
|
|
145
|
+
* }
|
|
146
|
+
*
|
|
147
|
+
* let verifyUser = (user) => {
|
|
148
|
+
* console.log('於生產環境時得加入驗證user機制')
|
|
149
|
+
* return user.isAdmin === 'y' //測試僅系統管理者使用
|
|
150
|
+
* }
|
|
151
|
+
*
|
|
152
|
+
* //WWebPerm
|
|
153
|
+
* let instWWebPerm = WWebPerm(WOrm, url, db, getUserByToken, verifyUser, opt)
|
|
154
|
+
*
|
|
155
|
+
* instWWebPerm.on('error', (err) => {
|
|
156
|
+
* console.log(err)
|
|
157
|
+
* })
|
|
158
|
+
*
|
|
91
159
|
*/
|
|
92
|
-
function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
160
|
+
function WWebPerm(WOrm, url, db, getUserByToken, verifyUser, opt = {}) {
|
|
93
161
|
let instWServHapiServer = null
|
|
94
162
|
|
|
95
163
|
|
|
@@ -121,6 +189,13 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
121
189
|
}
|
|
122
190
|
|
|
123
191
|
|
|
192
|
+
//check verifyUser
|
|
193
|
+
if (!isfun(verifyUser)) {
|
|
194
|
+
console.log('invalid verifyUser', verifyUser)
|
|
195
|
+
throw new Error('invalid verifyUser')
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
|
|
124
199
|
//serverPort
|
|
125
200
|
let serverPort = get(opt, 'serverPort')
|
|
126
201
|
if (!ispint(serverPort)) {
|
|
@@ -246,31 +321,32 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
246
321
|
|
|
247
322
|
//check
|
|
248
323
|
if (!iseobj(userSelf)) {
|
|
249
|
-
console.log(
|
|
250
|
-
return
|
|
324
|
+
console.log(`can not find the user from token`, token)
|
|
325
|
+
return Promise.reject(`can not find the user from token`)
|
|
251
326
|
}
|
|
252
327
|
|
|
253
328
|
//check userSelf
|
|
254
329
|
if (true) {
|
|
255
330
|
let id = get(userSelf, 'id', '')
|
|
256
331
|
if (!isestr(id)) {
|
|
257
|
-
console.log('
|
|
258
|
-
return
|
|
332
|
+
console.log('userSelf', userSelf)
|
|
333
|
+
return Promise.reject(`can not get the userId`)
|
|
259
334
|
}
|
|
260
335
|
let email = get(userSelf, 'email', '')
|
|
261
336
|
if (!isestr(email)) {
|
|
262
|
-
console.log('
|
|
263
|
-
return
|
|
337
|
+
console.log('userSelf', userSelf)
|
|
338
|
+
return Promise.reject(`can not get the email of user`)
|
|
264
339
|
}
|
|
265
340
|
let name = get(userSelf, 'name', '')
|
|
266
341
|
if (!isestr(name)) {
|
|
267
|
-
console.log('
|
|
268
|
-
return
|
|
342
|
+
console.log('userSelf', userSelf)
|
|
343
|
+
return Promise.reject(`can not get userName`)
|
|
269
344
|
}
|
|
270
345
|
let isAdmin = get(userSelf, 'isAdmin', '')
|
|
271
346
|
if (isAdmin !== 'y' && isAdmin !== 'n') {
|
|
272
|
-
console.log('userSelf
|
|
273
|
-
|
|
347
|
+
console.log('userSelf', userSelf)
|
|
348
|
+
console.log('userSelf.isAdmin is not y or n', userSelf.isAdmin)
|
|
349
|
+
return Promise.reject(`can not get the role of user`)
|
|
274
350
|
}
|
|
275
351
|
}
|
|
276
352
|
|
|
@@ -280,8 +356,9 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
280
356
|
|
|
281
357
|
//check
|
|
282
358
|
if (!isestr(vSelf)) {
|
|
283
|
-
console.log('
|
|
284
|
-
|
|
359
|
+
console.log('userSelf', userSelf)
|
|
360
|
+
console.log('mappingBy', mappingBy)
|
|
361
|
+
return Promise.reject(`can not get the prop of user by mappingBy`)
|
|
285
362
|
}
|
|
286
363
|
|
|
287
364
|
//userFind
|
|
@@ -291,8 +368,9 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
291
368
|
|
|
292
369
|
//check
|
|
293
370
|
if (!iseobj(userFind)) {
|
|
294
|
-
console.log('
|
|
295
|
-
|
|
371
|
+
console.log('userSelf', userSelf)
|
|
372
|
+
console.log('mappingBy', mappingBy)
|
|
373
|
+
return Promise.reject(`can not get the user from perm`)
|
|
296
374
|
}
|
|
297
375
|
|
|
298
376
|
//複寫isAdmin
|
|
@@ -303,10 +381,112 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
303
381
|
}
|
|
304
382
|
// console.log('userFind(isAdmin)', userFind)
|
|
305
383
|
|
|
384
|
+
//verifyUser
|
|
385
|
+
let b = verifyUser(userFind)
|
|
386
|
+
if (ispm(b)) {
|
|
387
|
+
b = await b
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
//check
|
|
391
|
+
if (!b) {
|
|
392
|
+
console.log('userSelf', userSelf)
|
|
393
|
+
console.log('verifyUser/userFind', userFind)
|
|
394
|
+
return Promise.reject(`user does not have permission`)
|
|
395
|
+
}
|
|
396
|
+
|
|
306
397
|
return userFind
|
|
307
398
|
}
|
|
308
399
|
|
|
309
400
|
|
|
401
|
+
//parsePayload
|
|
402
|
+
let parsePayload = async (req, key) => {
|
|
403
|
+
let inp = get(req, 'payload')
|
|
404
|
+
|
|
405
|
+
//to obj
|
|
406
|
+
if (isestr(inp)) {
|
|
407
|
+
inp = j2o(inp)
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
//check
|
|
411
|
+
if (!iseobj(inp)) {
|
|
412
|
+
console.log('inp', inp)
|
|
413
|
+
return Promise.reject(`invalid inp from req`)
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
//from
|
|
417
|
+
let from = get(inp, 'from', '')
|
|
418
|
+
|
|
419
|
+
//check
|
|
420
|
+
if (!isestr(from)) {
|
|
421
|
+
console.log('inp', inp)
|
|
422
|
+
console.log('from', from)
|
|
423
|
+
return Promise.reject(`invalid from from inp`)
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
//vs
|
|
428
|
+
let vs = get(inp, key, [])
|
|
429
|
+
//users
|
|
430
|
+
//targets
|
|
431
|
+
//ruleGroups
|
|
432
|
+
|
|
433
|
+
//check
|
|
434
|
+
if (!isearr(vs)) {
|
|
435
|
+
console.log('inp', inp)
|
|
436
|
+
console.log(key, vs)
|
|
437
|
+
return Promise.reject(`invalid ${key} from inp`)
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
//resave
|
|
441
|
+
inp = {
|
|
442
|
+
from,
|
|
443
|
+
[key]: vs,
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
return inp
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
//syncAndReplaceRows
|
|
451
|
+
let syncAndReplaceRows = async (params, key) => {
|
|
452
|
+
|
|
453
|
+
//from
|
|
454
|
+
let from = get(params, 'from', '')
|
|
455
|
+
// console.log('from', from)
|
|
456
|
+
|
|
457
|
+
//check
|
|
458
|
+
if (!isestr(from)) {
|
|
459
|
+
console.log('params', params)
|
|
460
|
+
console.log('from', from)
|
|
461
|
+
return Promise.reject(`invalid from`)
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
//vs
|
|
465
|
+
let vs = get(params, key, [])
|
|
466
|
+
// console.log(key, vs)
|
|
467
|
+
|
|
468
|
+
//check
|
|
469
|
+
if (!isearr(vs)) {
|
|
470
|
+
console.log('params', params)
|
|
471
|
+
console.log(key, vs)
|
|
472
|
+
return Promise.reject(`invalid ${key}`)
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
//save from
|
|
476
|
+
each(vs, (v, k) => {
|
|
477
|
+
vs[k].from = from
|
|
478
|
+
})
|
|
479
|
+
|
|
480
|
+
//delAll from
|
|
481
|
+
await woItems[key].delAll({ from })
|
|
482
|
+
|
|
483
|
+
//insert
|
|
484
|
+
let r = await woItems[key].insert(vs)
|
|
485
|
+
|
|
486
|
+
return r
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
|
|
310
490
|
//getGenUserByKV
|
|
311
491
|
let getGenUserByKV = async(keyUser, valueUser) => {
|
|
312
492
|
|
|
@@ -436,10 +616,17 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
436
616
|
// console.log('userSelf', userSelf)
|
|
437
617
|
|
|
438
618
|
//check
|
|
439
|
-
if (
|
|
440
|
-
|
|
619
|
+
if (!iseobj(userSelf)) {
|
|
620
|
+
console.log('token', token)
|
|
621
|
+
console.log('[API]getUserByToken/check userSelf: invalid userSelf')
|
|
622
|
+
return Promise.reject(`token does not have permission`)
|
|
441
623
|
}
|
|
442
624
|
|
|
625
|
+
// //check
|
|
626
|
+
// if (get(userSelf, 'isAdmin') !== 'y') { //權限系統須系統管理員才能使用
|
|
627
|
+
// return Promise.reject(`user does not have permission`)
|
|
628
|
+
// }
|
|
629
|
+
|
|
443
630
|
return userSelf
|
|
444
631
|
}
|
|
445
632
|
|
|
@@ -469,7 +656,9 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
469
656
|
|
|
470
657
|
//check
|
|
471
658
|
if (!iseobj(userLogin)) {
|
|
472
|
-
|
|
659
|
+
console.log('token', token)
|
|
660
|
+
console.log('[API]getPerm/check userLogin: invalid userLogin')
|
|
661
|
+
return Promise.reject(`token does not have permission`)
|
|
473
662
|
}
|
|
474
663
|
|
|
475
664
|
//parseUserId
|
|
@@ -478,7 +667,9 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
478
667
|
|
|
479
668
|
//check
|
|
480
669
|
if (!isestr(userId)) {
|
|
481
|
-
|
|
670
|
+
console.log('userLogin', userLogin)
|
|
671
|
+
console.log('[API]getPerm/check userId: invalid userId')
|
|
672
|
+
return Promise.reject(`token does not have permission`)
|
|
482
673
|
}
|
|
483
674
|
|
|
484
675
|
//getGenUserAndRulesByUserId
|
|
@@ -487,7 +678,9 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
487
678
|
|
|
488
679
|
//check
|
|
489
680
|
if (!iseobj(r)) {
|
|
490
|
-
|
|
681
|
+
console.log('userLogin', userLogin)
|
|
682
|
+
console.log('[API]getPerm/getGenUserAndRulesByUserId: user does not have permrules')
|
|
683
|
+
return Promise.reject(`token does not have permission`)
|
|
491
684
|
}
|
|
492
685
|
|
|
493
686
|
return r
|
|
@@ -518,10 +711,17 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
518
711
|
// console.log('userSelf', userSelf)
|
|
519
712
|
|
|
520
713
|
//check
|
|
521
|
-
if (
|
|
522
|
-
|
|
714
|
+
if (!iseobj(userSelf)) {
|
|
715
|
+
console.log('token', token)
|
|
716
|
+
console.log('[API]getPermById/check userSelf: invalid userSelf')
|
|
717
|
+
return Promise.reject(`token does not have permission`)
|
|
523
718
|
}
|
|
524
719
|
|
|
720
|
+
// //check
|
|
721
|
+
// if (get(userSelf, 'isAdmin') !== 'y') { //權限系統須系統管理員才能使用
|
|
722
|
+
// return Promise.reject(`user does not have permission`)
|
|
723
|
+
// }
|
|
724
|
+
|
|
525
725
|
//userId
|
|
526
726
|
let userId = get(req, 'query.userId', '')
|
|
527
727
|
// console.log('userId', userId)
|
|
@@ -532,6 +732,8 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
532
732
|
|
|
533
733
|
//check
|
|
534
734
|
if (!iseobj(r)) {
|
|
735
|
+
console.log('userSelf', userSelf)
|
|
736
|
+
console.log('[API]getPermById/getGenUserAndRulesByUserId: user does not have permrules')
|
|
535
737
|
return Promise.reject(`user does not have permrules`)
|
|
536
738
|
}
|
|
537
739
|
|
|
@@ -542,6 +744,120 @@ function WWebPerm(WOrm, url, db, getUserByToken, opt = {}) {
|
|
|
542
744
|
let r = await pm2resolve(core)() //w-ui-loginout接收已預設格式用pm2resolve轉過, 須另提取state進行判斷
|
|
543
745
|
// console.log('getUserByToken', r)
|
|
544
746
|
|
|
747
|
+
return r
|
|
748
|
+
},
|
|
749
|
+
},
|
|
750
|
+
{
|
|
751
|
+
method: 'POST',
|
|
752
|
+
path: '/syncAndReplaceUsers',
|
|
753
|
+
handler: async function (req, res) {
|
|
754
|
+
// console.log('syncAndReplaceUsers', req)
|
|
755
|
+
// console.log('payload', req.payload)
|
|
756
|
+
|
|
757
|
+
async function core() {
|
|
758
|
+
|
|
759
|
+
//token
|
|
760
|
+
let token = get(req, 'query.token', '')
|
|
761
|
+
|
|
762
|
+
//getTokenUserForSelf
|
|
763
|
+
let user = await getTokenUserForSelf(token)
|
|
764
|
+
|
|
765
|
+
//check
|
|
766
|
+
if (!iseobj(user)) {
|
|
767
|
+
console.log('token', token)
|
|
768
|
+
console.log('[API]syncAndReplaceUsers/check user: invalid user')
|
|
769
|
+
return Promise.reject(`token does not have permission`)
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
//parsePayload
|
|
773
|
+
let inp = await parsePayload(req, 'users')
|
|
774
|
+
|
|
775
|
+
//syncAndReplaceRows
|
|
776
|
+
let r = await syncAndReplaceRows(inp, 'users')
|
|
777
|
+
|
|
778
|
+
return r
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
//pm2resolve core
|
|
782
|
+
let r = await pm2resolve(core)()
|
|
783
|
+
// console.log('verifyIdentity', r)
|
|
784
|
+
|
|
785
|
+
return r
|
|
786
|
+
},
|
|
787
|
+
},
|
|
788
|
+
{
|
|
789
|
+
method: 'POST',
|
|
790
|
+
path: '/syncAndReplaceTargets',
|
|
791
|
+
handler: async function (req, res) {
|
|
792
|
+
// console.log('syncAndReplaceTargets', req)
|
|
793
|
+
// console.log('payload', req.payload)
|
|
794
|
+
|
|
795
|
+
async function core() {
|
|
796
|
+
|
|
797
|
+
//token
|
|
798
|
+
let token = get(req, 'query.token', '')
|
|
799
|
+
|
|
800
|
+
//getTokenUserForSelf
|
|
801
|
+
let user = await getTokenUserForSelf(token)
|
|
802
|
+
|
|
803
|
+
//check
|
|
804
|
+
if (!iseobj(user)) {
|
|
805
|
+
console.log('token', token)
|
|
806
|
+
console.log('[API]syncAndReplaceTargets/check user: invalid user')
|
|
807
|
+
return Promise.reject(`token does not have permission`)
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
//parsePayload
|
|
811
|
+
let inp = await parsePayload(req, 'targets')
|
|
812
|
+
|
|
813
|
+
//syncAndReplaceRows
|
|
814
|
+
let r = await syncAndReplaceRows(inp, 'targets')
|
|
815
|
+
|
|
816
|
+
return r
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
//pm2resolve core
|
|
820
|
+
let r = await pm2resolve(core)()
|
|
821
|
+
// console.log('verifyIdentity', r)
|
|
822
|
+
|
|
823
|
+
return r
|
|
824
|
+
},
|
|
825
|
+
},
|
|
826
|
+
{
|
|
827
|
+
method: 'POST',
|
|
828
|
+
path: '/syncAndReplaceRuleGroups',
|
|
829
|
+
handler: async function (req, res) {
|
|
830
|
+
// console.log('syncAndReplaceRuleGroups', req)
|
|
831
|
+
// console.log('payload', req.payload)
|
|
832
|
+
|
|
833
|
+
async function core() {
|
|
834
|
+
|
|
835
|
+
//token
|
|
836
|
+
let token = get(req, 'query.token', '')
|
|
837
|
+
|
|
838
|
+
//getTokenUserForSelf
|
|
839
|
+
let user = await getTokenUserForSelf(token)
|
|
840
|
+
|
|
841
|
+
//check
|
|
842
|
+
if (!iseobj(user)) {
|
|
843
|
+
console.log('token', token)
|
|
844
|
+
console.log('[API]syncAndReplaceRuleGroups/check user: invalid user')
|
|
845
|
+
return Promise.reject(`token does not have permission`)
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
//parsePayload
|
|
849
|
+
let inp = await parsePayload(req, 'ruleGroups')
|
|
850
|
+
|
|
851
|
+
//syncAndReplaceRows
|
|
852
|
+
let r = await syncAndReplaceRows(inp, 'ruleGroups')
|
|
853
|
+
|
|
854
|
+
return r
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
//pm2resolve core
|
|
858
|
+
let r = await pm2resolve(core)()
|
|
859
|
+
// console.log('verifyIdentity', r)
|
|
860
|
+
|
|
545
861
|
return r
|
|
546
862
|
},
|
|
547
863
|
},
|
|
@@ -602,7 +918,7 @@ export default WWebPerm
|
|
|
602
918
|
<br class="clear">
|
|
603
919
|
|
|
604
920
|
<footer>
|
|
605
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on
|
|
921
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Thu Nov 02 2023 11:12:12 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
606
922
|
</footer>
|
|
607
923
|
|
|
608
924
|
<script>prettyPrint();</script>
|
package/docs/index.html
CHANGED
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
<br class="clear">
|
|
72
72
|
|
|
73
73
|
<footer>
|
|
74
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on
|
|
74
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Thu Nov 02 2023 11:12:12 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
75
75
|
</footer>
|
|
76
76
|
|
|
77
77
|
<script>prettyPrint();</script>
|