w-web-perm 1.0.22 → 1.0.24

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.
@@ -80,7 +80,7 @@
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#line132">line 132</a>
83
+ <a href="WWebPerm.mjs.html">WWebPerm.mjs</a>, <a href="WWebPerm.mjs.html#line135">line 135</a>
84
84
  </li></ul></dd>
85
85
 
86
86
 
@@ -925,7 +925,7 @@
925
925
  <br class="clear">
926
926
 
927
927
  <footer>
928
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Tue Sep 24 2024 21:19:05 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
928
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sun Oct 20 2024 09:46:40 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
929
929
  </footer>
930
930
 
931
931
  <script>prettyPrint();</script>
@@ -48,6 +48,7 @@
48
48
  <pre class="prettyprint source linenums"><code>import path from 'path'
49
49
  import fs from 'fs'
50
50
  import get from 'lodash-es/get.js'
51
+ import each from 'lodash-es/each.js'
51
52
  import map from 'lodash-es/map.js'
52
53
  import keys from 'lodash-es/keys.js'
53
54
  import size from 'lodash-es/size.js'
@@ -67,6 +68,8 @@ import pm2resolve from 'wsemi/src/pm2resolve.mjs'
67
68
  import fsIsFolder from 'wsemi/src/fsIsFolder.mjs'
68
69
  import fsIsFile from 'wsemi/src/fsIsFile.mjs'
69
70
  import replace from 'wsemi/src/replace.mjs'
71
+ import haskey from 'wsemi/src/haskey.mjs'
72
+ import arrHas from 'wsemi/src/arrHas.mjs'
70
73
  import ltdtDiffByKey from 'wsemi/src/ltdtDiffByKey.mjs'
71
74
  import ltdtmapping from 'wsemi/src/ltdtmapping.mjs'
72
75
  import WServHapiServer from 'w-serv-hapi/src/WServHapiServer.mjs'
@@ -268,6 +271,7 @@ function WWebPerm(WOrm, url, db, getUserByToken, verifyBrowserUser, verifyAppUse
268
271
 
269
272
  //urlRedirect
270
273
  let urlRedirect = get(opt, 'urlRedirect', '')
274
+ console.log('urlRedirect', urlRedirect)
271
275
 
272
276
 
273
277
  //mappingBy
@@ -339,6 +343,60 @@ function WWebPerm(WOrm, url, db, getUserByToken, verifyBrowserUser, verifyAppUse
339
343
  return r
340
344
  })
341
345
 
346
+ //ckKey
347
+ let ckKey = (rows, key) => {
348
+ let err = null
349
+
350
+ //check
351
+ let kp = {}
352
+ each(rows, (v, k) => {
353
+
354
+ //value
355
+ let value = get(v, key, '')
356
+
357
+ //check
358
+ if (!isestr(value)) {
359
+ err = `rows[${k}].${key} is not an effective string`
360
+ return false //跳出
361
+ }
362
+
363
+ //check
364
+ if (haskey(kp, value)) {
365
+ err = `rows[${k}].${key}[${value}] is duplicate`
366
+ return false //跳出
367
+ }
368
+
369
+ //kp
370
+ kp[value] = true
371
+
372
+ })
373
+
374
+ return err
375
+ }
376
+
377
+ //偵測id,name,email重複
378
+ let err = null
379
+ if (true) {
380
+ if (arrHas(woName, ['targets'])) {
381
+ err = ckKey(rows, 'id')
382
+ if (err !== null) {
383
+ return Promise.reject(err)
384
+ }
385
+ }
386
+ else if (arrHas(woName, ['targets', 'pemis', 'grups'])) { //users可重複name故不列入
387
+ err = ckKey(rows, 'name')
388
+ if (err !== null) {
389
+ return Promise.reject(err)
390
+ }
391
+ }
392
+ else if (arrHas(woName, ['users'])) { //users不能重複email
393
+ err = ckKey(rows, 'email')
394
+ if (err !== null) {
395
+ return Promise.reject(err)
396
+ }
397
+ }
398
+ }
399
+
342
400
  //ltdtDiffByKey
343
401
  let ltdtOld = await woItems[woName].select()
344
402
  let ltdtNew = rows
@@ -1176,7 +1234,7 @@ export default WWebPerm
1176
1234
  <br class="clear">
1177
1235
 
1178
1236
  <footer>
1179
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Tue Sep 24 2024 21:19:05 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1237
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sun Oct 20 2024 09:46:40 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1180
1238
  </footer>
1181
1239
 
1182
1240
  <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 Tue Sep 24 2024 21:19:05 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
74
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sun Oct 20 2024 09:46:40 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
75
75
  </footer>
76
76
 
77
77
  <script>prettyPrint();</script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "w-web-perm",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "main": "dist/w-web-perm.umd.js",
5
5
  "dependencies": {
6
6
  "@mdi/js": "^7.4.47",
@@ -13,7 +13,7 @@
13
13
  "w-serv-hapi": "^1.0.13",
14
14
  "w-serv-orm": "^1.0.11",
15
15
  "w-ui-loginout": "^1.0.8",
16
- "wsemi": "^1.7.60"
16
+ "wsemi": "^1.7.61"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@vue/cli-plugin-babel": "^5.0.8",
@@ -30,7 +30,7 @@
30
30
  "vue": "^2.6.14",
31
31
  "vuex": "^3.6.2",
32
32
  "w-orm-mongodb": "^1.1.32",
33
- "w-package-tools": "^1.0.76"
33
+ "w-package-tools": "^1.0.80"
34
34
  },
35
35
  "scripts": {
36
36
  "serve": "vue-cli-service serve",
@@ -1,6 +1,7 @@
1
1
  import path from 'path'
2
2
  import fs from 'fs'
3
3
  import get from 'lodash-es/get.js'
4
+ import each from 'lodash-es/each.js'
4
5
  import map from 'lodash-es/map.js'
5
6
  import keys from 'lodash-es/keys.js'
6
7
  import size from 'lodash-es/size.js'
@@ -20,6 +21,8 @@ import pm2resolve from 'wsemi/src/pm2resolve.mjs'
20
21
  import fsIsFolder from 'wsemi/src/fsIsFolder.mjs'
21
22
  import fsIsFile from 'wsemi/src/fsIsFile.mjs'
22
23
  import replace from 'wsemi/src/replace.mjs'
24
+ import haskey from 'wsemi/src/haskey.mjs'
25
+ import arrHas from 'wsemi/src/arrHas.mjs'
23
26
  import ltdtDiffByKey from 'wsemi/src/ltdtDiffByKey.mjs'
24
27
  import ltdtmapping from 'wsemi/src/ltdtmapping.mjs'
25
28
  import WServHapiServer from 'w-serv-hapi/src/WServHapiServer.mjs'
@@ -221,6 +224,7 @@ function WWebPerm(WOrm, url, db, getUserByToken, verifyBrowserUser, verifyAppUse
221
224
 
222
225
  //urlRedirect
223
226
  let urlRedirect = get(opt, 'urlRedirect', '')
227
+ console.log('urlRedirect', urlRedirect)
224
228
 
225
229
 
226
230
  //mappingBy
@@ -292,6 +296,60 @@ function WWebPerm(WOrm, url, db, getUserByToken, verifyBrowserUser, verifyAppUse
292
296
  return r
293
297
  })
294
298
 
299
+ //ckKey
300
+ let ckKey = (rows, key) => {
301
+ let err = null
302
+
303
+ //check
304
+ let kp = {}
305
+ each(rows, (v, k) => {
306
+
307
+ //value
308
+ let value = get(v, key, '')
309
+
310
+ //check
311
+ if (!isestr(value)) {
312
+ err = `rows[${k}].${key} is not an effective string`
313
+ return false //跳出
314
+ }
315
+
316
+ //check
317
+ if (haskey(kp, value)) {
318
+ err = `rows[${k}].${key}[${value}] is duplicate`
319
+ return false //跳出
320
+ }
321
+
322
+ //kp
323
+ kp[value] = true
324
+
325
+ })
326
+
327
+ return err
328
+ }
329
+
330
+ //偵測id,name,email重複
331
+ let err = null
332
+ if (true) {
333
+ if (arrHas(woName, ['targets'])) {
334
+ err = ckKey(rows, 'id')
335
+ if (err !== null) {
336
+ return Promise.reject(err)
337
+ }
338
+ }
339
+ else if (arrHas(woName, ['targets', 'pemis', 'grups'])) { //users可重複name故不列入
340
+ err = ckKey(rows, 'name')
341
+ if (err !== null) {
342
+ return Promise.reject(err)
343
+ }
344
+ }
345
+ else if (arrHas(woName, ['users'])) { //users不能重複email
346
+ err = ckKey(rows, 'email')
347
+ if (err !== null) {
348
+ return Promise.reject(err)
349
+ }
350
+ }
351
+ }
352
+
295
353
  //ltdtDiffByKey
296
354
  let ltdtOld = await woItems[woName].select()
297
355
  let ltdtNew = rows
package/src/App.vue CHANGED
@@ -18,6 +18,9 @@
18
18
  <VeCpemis></VeCpemis>
19
19
  <VeCgrups></VeCgrups>
20
20
 
21
+ <VeGrupBlngUsers></VeGrupBlngUsers>
22
+ <VePemiBlngGrups></VePemiBlngGrups>
23
+
21
24
  </div>
22
25
  </template>
23
26
 
@@ -35,6 +38,8 @@ import Layout from './components/Layout.vue'
35
38
  import VeCrules from './components/VeCrules.vue'
36
39
  import VeCpemis from './components/VeCpemis.vue'
37
40
  import VeCgrups from './components/VeCgrups.vue'
41
+ import VeGrupBlngUsers from './components/VeGrupBlngUsers.vue'
42
+ import VePemiBlngGrups from './components/VePemiBlngGrups.vue'
38
43
 
39
44
 
40
45
  export default {
@@ -47,6 +52,8 @@ export default {
47
52
  VeCrules,
48
53
  VeCpemis,
49
54
  VeCgrups,
55
+ VeGrupBlngUsers,
56
+ VePemiBlngGrups,
50
57
  },
51
58
  data: function() {
52
59
  return {
@@ -76,7 +76,7 @@
76
76
 
77
77
  <WButtonCircle
78
78
  :paddingStyle="{v:6,h:6}"
79
- :tooltip="$t('grupDeleteChecks')"
79
+ :tooltip="$t('grupDeleteCheckGrups')"
80
80
  :icon="mdiTrashCanOutline"
81
81
  :backgroundColor="'#fff'"
82
82
  :backgroundColorHover="'#f2f2f2'"
@@ -141,9 +141,11 @@
141
141
 
142
142
  <script>
143
143
  import { mdiSelectGroup, mdiVectorPolylinePlus, mdiCheckboxMarkedCircle, mdiCloudUploadOutline, mdiTrashCanOutline, mdiPlus, mdiPencilOutline, mdiContentCopy } from '@mdi/js/mdi.js'
144
+ import JSON5 from 'json5'
144
145
  import get from 'lodash-es/get.js'
145
146
  import set from 'lodash-es/set.js'
146
147
  import each from 'lodash-es/each.js'
148
+ import map from 'lodash-es/map.js'
147
149
  import size from 'lodash-es/size.js'
148
150
  import filter from 'lodash-es/filter.js'
149
151
  import sortBy from 'lodash-es/sortBy.js'
@@ -199,6 +201,7 @@ export default {
199
201
  let vo = this
200
202
 
201
203
  //註冊至$dg供使用
204
+ vo.$dg.showVeGrupBlngUsersById = vo.showVeGrupBlngUsersById
202
205
  vo.$dg.showVeCpemisById = vo.showVeCpemisById
203
206
 
204
207
  },
@@ -238,8 +241,12 @@ export default {
238
241
  return ''
239
242
  }
240
243
 
241
- //cloneDeep
242
- let items = cloneDeep(vo.grups)
244
+ //grups, users
245
+ let grups = cloneDeep(vo.grups)
246
+ let users = cloneDeep(vo.users)
247
+
248
+ //addUsers
249
+ let items = vo.addUsers(grups, users)
243
250
 
244
251
  //save
245
252
  vo.items = items
@@ -374,6 +381,7 @@ export default {
374
381
  let ks = [
375
382
  'id',
376
383
  'name',
384
+ 'belongUsers',
377
385
  'description',
378
386
  'from',
379
387
  'cpemis',
@@ -388,6 +396,7 @@ export default {
388
396
  let kpHead = {
389
397
  'id': vo.$t('id'),
390
398
  'name': vo.$t('name'),
399
+ 'belongUsers': vo.$t('belongUsers'),
391
400
  'description': vo.$t('description'),
392
401
  'from': vo.$t('from'),
393
402
  'cpemis': vo.$t('grupCpemis'),
@@ -415,13 +424,15 @@ export default {
415
424
  defHeadMinWidth: 150,
416
425
  kpHeadWidth: {
417
426
  'name': 300,
418
- 'cpemis': 100,
427
+ 'belongUsers': 300,
428
+ 'cpemis': 300,
419
429
  'timeCreate': 220,
420
430
  'timeUpdate': 220,
421
431
  },
422
432
  kpHeadFilterType: {
423
433
  'id': 'text',
424
434
  'name': 'text',
435
+ 'belongUsers': 'text',
425
436
  'description': 'text',
426
437
  'from': 'text',
427
438
  'cpemis': 'text',
@@ -442,12 +453,15 @@ export default {
442
453
  'name': true,
443
454
  },
444
455
  kpHeadFilter: {
456
+ 'belongUsers': false,
445
457
  'cpemis': false,
446
458
  },
447
459
  kpHeadSort: {
460
+ 'belongUsers': false,
448
461
  'cpemis': false,
449
462
  },
450
463
  kpHeadFocusHighlight: { //雖然效果不完全, 但因按鈕與cell有padding可被點擊, 故還是需要開啟
464
+ 'belongUsers': false,
451
465
  'cpemis': false,
452
466
  },
453
467
  kpCellRender: {
@@ -470,6 +484,23 @@ export default {
470
484
 
471
485
  return v
472
486
  },
487
+ 'belongUsers': (v, k, r) => {
488
+ // console.log('kpCellRender belongUsers', v, k, r)
489
+
490
+ //id
491
+ let id = get(r, 'id', '')
492
+ // console.log('id', id, k, r)
493
+
494
+ //因kpHeadFocusHighlight設定false時, 仍會於點擊其他可focus的cell, 再點回時依然出現highlight的focus邊框, 故改使用stopPropagation強制吃掉點擊訊息
495
+ //因stopPropagation只吃掉訊息, 原本focus會處於原本可focus的cell, 再重複點時會於前個focus的cell出現highlight邊框, 故再多使用preventDefault阻止瀏覽器預設行為, 此等同於return false
496
+ let t = `
497
+ <div onclick="event.stopPropagation();event.preventDefault();" onmousedown="event.stopPropagation();event.preventDefault();">
498
+ <button style="width:100%; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;" onclick="$vo.$dg.showVeGrupBlngUsersById('${id}')">${v}</button>
499
+ </div>
500
+ `
501
+
502
+ return t
503
+ },
473
504
  'cpemis': (v, k, r) => {
474
505
  // console.log('kpCellRender cpemis', v, k, r)
475
506
 
@@ -481,7 +512,7 @@ export default {
481
512
  //因stopPropagation只吃掉訊息, 原本focus會處於原本可focus的cell, 再重複點時會於前個focus的cell出現highlight邊框, 故再多使用preventDefault阻止瀏覽器預設行為, 此等同於return false
482
513
  let t = `
483
514
  <div onclick="event.stopPropagation();event.preventDefault();" onmousedown="event.stopPropagation();event.preventDefault();">
484
- <button style="width:100%;" onclick="$vo.$dg.showVeCpemisById('${id}')">${vo.$t('grupEditCpemisSimple')}</button>
515
+ <button style="width:100%; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;" onclick="$vo.$dg.showVeCpemisById('${id}')">${vo.getCpemisText(v)}</button>
485
516
  </div>
486
517
  `
487
518
 
@@ -526,6 +557,74 @@ export default {
526
557
 
527
558
  },
528
559
 
560
+ addUsers: function(grups, users) {
561
+ // console.log('method addUsers', grups, users)
562
+
563
+ let vo = this
564
+
565
+ //parse cgrups
566
+ users = map(users, (u) => {
567
+ let kpGrup = JSON5.parse(u.cgrups)
568
+ u.kpGrup = kpGrup
569
+ return u
570
+ })
571
+ // console.log('users', users)
572
+
573
+ //kp
574
+ let kp = {}
575
+ each(users, (u) => {
576
+ each(u.kpGrup, (v, k) => {
577
+ let isActive = get(v, 'isActive', '')
578
+ if (isActive !== 'y') {
579
+ return true //跳出換下一個
580
+ }
581
+ if (!haskey(kp, k)) {
582
+ kp[k] = []
583
+ }
584
+ kp[k].push({
585
+ user: u,
586
+ grup: v,
587
+ })
588
+ })
589
+ })
590
+ // console.log('kp', kp)
591
+
592
+ //items
593
+ let items = map(grups, (g) => {
594
+
595
+ //us
596
+ let us = []
597
+ if (haskey(kp, g.name)) {
598
+ us = kp[g.name]
599
+ }
600
+ // console.log('us', us)
601
+
602
+ //belongUsers
603
+ let belongUsers = vo.$t('grupBlngRnderNoUser')
604
+ let t = vo.$t('grupBlngRnderUsers')
605
+ let n = size(us)
606
+ if (n > 0) {
607
+ t = t.replace('{n}', n)
608
+ if (n === 1) {
609
+ t = t.replace('{nms}', `(${us[0].user.name})`)
610
+ }
611
+ else {
612
+ t = t.replace('{nms}', '')
613
+ }
614
+ belongUsers = t
615
+ }
616
+
617
+ //save belongUsers, us
618
+ g.belongUsers = belongUsers
619
+ g.us = us
620
+
621
+ return g
622
+ })
623
+ // console.log('items', items)
624
+
625
+ return items
626
+ },
627
+
529
628
  addItem: function() {
530
629
  // console.log('method addItem')
531
630
 
@@ -670,6 +769,86 @@ export default {
670
769
 
671
770
  },
672
771
 
772
+ getCpemisText: function(cpemis) {
773
+ // console.log('method getCpemisText', cpemis)
774
+
775
+ let vo = this
776
+
777
+ //kpPemi
778
+ let kpPemi = JSON5.parse(cpemis)
779
+
780
+ let vs = []
781
+ each(kpPemi, (v, k) => {
782
+ // console.log(k, 'v', v)
783
+
784
+ //isActive
785
+ let isActive = get(v, 'isActive', '')
786
+ if (isActive !== 'y') {
787
+ return true //跳出換下一個
788
+ }
789
+ // console.log(k, '_isActive', _isActive)
790
+
791
+ //push
792
+ vs.push(k)
793
+
794
+ })
795
+
796
+ //cpemisText
797
+ let cpemisText = vo.$t('grupRnderCpemisNoPermission')
798
+ let t = vo.$t('grupRnderCpemisHasNPermissions')
799
+ let n = size(vs)
800
+ if (n > 0) {
801
+ t = t.replace('{n}', n)
802
+ if (n === 1) {
803
+ t = t.replace('{nms}', `(${vs[0]})`)
804
+ }
805
+ else {
806
+ t = t.replace('{nms}', '')
807
+ }
808
+ cpemisText = t
809
+ }
810
+
811
+ return cpemisText
812
+ },
813
+
814
+ showVeGrupBlngUsersById: function(id) {
815
+ // console.log('method showVeGrupBlngUsersById', id)
816
+
817
+ let vo = this
818
+
819
+ //check
820
+ if (!isestr(id)) {
821
+ vo.$alert(`${vo.$t('grupEditBlngNoGrupId')}`, { type: 'error' })
822
+ return
823
+ }
824
+
825
+ //rows
826
+ let rows = get(vo, 'opt.rows', [])
827
+
828
+ //find
829
+ let r = null
830
+ // let kr = null
831
+ each(rows, (v, k) => {
832
+ if (get(v, 'id', '') === id) {
833
+ r = v
834
+ // kr = k
835
+ return false //跳出
836
+ }
837
+ })
838
+
839
+ //check
840
+ if (!iseobj(r)) {
841
+ vo.$alert(`${vo.$t('grupEditBlngNoGrupData')}`, { type: 'error' })
842
+ return
843
+ }
844
+
845
+ //showVeGrupBlngUsers
846
+ vo.$dg.showVeGrupBlngUsers(r)
847
+ .then(() => {})
848
+ .catch(() => {})
849
+
850
+ },
851
+
673
852
  showVeCpemisById: function(id) {
674
853
  // console.log('method showVeCpemisById', id)
675
854
 
@@ -677,7 +856,7 @@ export default {
677
856
 
678
857
  //check
679
858
  if (!isestr(id)) {
680
- vo.$alert(`${vo.$t('grupEditCpemisNoId')}`, { type: 'error' })
859
+ vo.$alert(`${vo.$t('grupEditBlngNoGrupId')}`, { type: 'error' })
681
860
  return
682
861
  }
683
862
 
@@ -697,7 +876,7 @@ export default {
697
876
 
698
877
  //check
699
878
  if (!iseobj(r)) {
700
- vo.$alert(`${vo.$t('grupEditCpemisNoGrup')}`, { type: 'error' })
879
+ vo.$alert(`${vo.$t('grupEditBlngNoGrupData')}`, { type: 'error' })
701
880
  return
702
881
  }
703
882