@simitgroup/simpleapp-generator 2.0.1-b-alpha → 2.0.1-c-alpha

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/ReleaseNote.md CHANGED
@@ -1,3 +1,7 @@
1
+ [2.0.1c-alpha]
2
+
3
+ 1. Reopen searchWithRelation code
4
+
1
5
  [2.0.1b-alpha]
2
6
 
3
7
  1. Update menu permission
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simitgroup/simpleapp-generator",
3
- "version": "2.0.1b-alpha",
3
+ "version": "2.0.1c-alpha",
4
4
  "description": "frontend nuxtjs and backend nests code generator using jsonschema",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1316,63 +1316,63 @@ export class SimpleAppService<T extends SchemaFields> {
1316
1316
  },
1317
1317
  ];
1318
1318
 
1319
- // // Relation lookups
1320
- // Object.entries(option.relations).forEach(([relationName, relationOption]) => {
1321
- // // Prevent mini api user lookup sensitive data
1322
- // if (!allowedRelations.includes(relationName)) {
1323
- // throw new BadRequestException(`Not allowed to lookup ${relationName}`);
1324
- // }
1325
-
1326
- // const subPipeline: PipelineStage.Lookup['$lookup']['pipeline'] = [];
1327
-
1328
- // subPipeline.push({
1329
- // $match: {
1330
- // $expr: { $eq: [`$${relationOption.foreignField}`, '$$localValue'] },
1331
- // },
1332
- // ...relationOption.filter,
1333
- // });
1334
-
1335
- // // Relation sort
1336
- // if (relationOption.sort) {
1337
- // subPipeline.push({
1338
- // $sort: relationOption.sort,
1339
- // });
1340
- // }
1341
-
1342
- // // Relation projection
1343
- // if (relationOption.projection) {
1344
- // subPipeline.push({
1345
- // $project: {
1346
- // ...(relationOption.projection ?? {}),
1347
- // },
1348
- // });
1349
- // }
1350
-
1351
- // pipeline.push({
1352
- // $lookup: {
1353
- // from: relationName.toLowerCase(),
1354
- // as: `_${relationName}`,
1355
- // let: { localValue: `$${relationOption.localField}` },
1356
- // pipeline: subPipeline,
1357
- // },
1358
- // });
1359
- // });
1360
-
1361
- // // Root sort
1362
- // if (option.root?.sort) {
1363
- // pipeline.push({
1364
- // $sort: option.root.sort,
1365
- // });
1366
- // }
1319
+ // Relation lookups
1320
+ Object.entries(option.relations).forEach(([relationName, relationOption]) => {
1321
+ // Prevent mini api user lookup sensitive data
1322
+ if (!allowedRelations.includes(relationName)) {
1323
+ throw new BadRequestException(`Not allowed to lookup ${relationName}`);
1324
+ }
1367
1325
 
1368
- // // Root Projection
1369
- // if (option.root.projection) {
1370
- // pipeline.push({
1371
- // $project: {
1372
- // ...(option.root?.projection ?? {}),
1373
- // },
1374
- // });
1375
- // }
1326
+ const subPipeline: PipelineStage.Lookup['$lookup']['pipeline'] = [];
1327
+
1328
+ subPipeline.push({
1329
+ $match: {
1330
+ $expr: { $eq: [`$${relationOption.foreignField}`, '$$localValue'] },
1331
+ },
1332
+ ...relationOption.filter,
1333
+ });
1334
+
1335
+ // Relation sort
1336
+ if (relationOption.sort) {
1337
+ subPipeline.push({
1338
+ $sort: relationOption.sort,
1339
+ });
1340
+ }
1341
+
1342
+ // Relation projection
1343
+ if (relationOption.projection) {
1344
+ subPipeline.push({
1345
+ $project: {
1346
+ ...(relationOption.projection ?? {}),
1347
+ },
1348
+ });
1349
+ }
1350
+
1351
+ pipeline.push({
1352
+ $lookup: {
1353
+ from: relationName.toLowerCase(),
1354
+ as: `_${relationName}`,
1355
+ let: { localValue: `$${relationOption.localField}` },
1356
+ pipeline: subPipeline,
1357
+ },
1358
+ });
1359
+ });
1360
+
1361
+ // Root sort
1362
+ if (option.root?.sort) {
1363
+ pipeline.push({
1364
+ $sort: option.root.sort,
1365
+ });
1366
+ }
1367
+
1368
+ // Root Projection
1369
+ if (option.root.projection) {
1370
+ pipeline.push({
1371
+ $project: {
1372
+ ...(option.root?.projection ?? {}),
1373
+ },
1374
+ });
1375
+ }
1376
1376
 
1377
1377
  return await this.aggregate(appUser, pipeline);
1378
1378
  }
@@ -2,17 +2,24 @@ import { RouteLocationNormalizedGeneric } from 'vue-router';
2
2
  import { getUserProfile } from './../composables/getUserStore.generate';
3
3
 
4
4
  export default defineNuxtRouteMiddleware(async (to, from) => {
5
- console.log(to.path)
6
- const userProfile = getUserProfile()
5
+ // console.log("to",to.path)
6
+ const uauth = useAuthState()
7
+
8
+ if(isPublicPath(to.path)) return true
9
+ if(!uauth.data.value) return navigateTo('/login')
10
+
11
+ let userProfile = getUserProfile()
7
12
  const xorg = <string>to.params['xorg'] ?? 'MC0wLTA'
8
13
  useNuxtApp().$userstore.xOrg=xorg
9
14
  if(!userProfile?._id){
10
15
  // console.error("middleware detect no user id, reload under xorg",xorg)
11
16
  await reloadUserStoreFromMiddleware(xorg)
17
+ userProfile = getUserProfile()
12
18
  // console.log("after reload",userProfile)
13
- }else if(userProfile.branchId===0 && xorg !='MC0wLTA'){
19
+ }else if(userProfile?.branchId===0 && xorg !='MC0wLTA'){
14
20
  // console.error("middleware detect wrong xorg reload profile for",xorg)
15
21
  await reloadUserStoreFromMiddleware(xorg)
22
+ userProfile = getUserProfile()
16
23
  // console.log("after reload",userProfile)
17
24
  }else{
18
25
  // console.log("use exists, use back the user store")
@@ -21,9 +28,9 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
21
28
 
22
29
 
23
30
  const currentgroup = useCookie('currentGroup').value
24
- if(currentgroup && userProfile.groups.includes(currentgroup)){
31
+ if(currentgroup && userProfile?.groups?.includes(currentgroup)){
25
32
  //use back ground
26
- }else if(userProfile.groups.length>0){
33
+ }else if(userProfile?.groups?.length>0){
27
34
  goTo('pickgroup')
28
35
  }
29
36
  // if (!currentgroup)goTo('pickgroup')
@@ -43,7 +50,7 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
43
50
  }
44
51
 
45
52
  const license = useLicense().getLicense()
46
- console.log("metas check",metas)
53
+ // console.log("metas check",metas)
47
54
  if(metas.length == 0){
48
55
  throw createError({
49
56
  statusCode: 404,
@@ -83,7 +90,8 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
83
90
  if(to.meta['requiredGroups']){
84
91
 
85
92
  const requiredGroups:string[] = to.meta['requiredGroups']
86
- const userGroups = userProfile.groups
93
+ const userGroups = userProfile?.groups || []
94
+ const userRoles = userProfile?.roles || []
87
95
  let allowAccess = false
88
96
  if(['','/'].includes(to.path)) allowAccess= true
89
97
 
@@ -92,7 +100,7 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
92
100
  if(userGroups.includes(g)){
93
101
  allowAccess = true
94
102
  }
95
- if(userProfile.roles.includes(g)){
103
+ if(userRoles.includes(g)){
96
104
  allowAccess = true
97
105
  }
98
106
 
@@ -106,7 +114,7 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
106
114
  });
107
115
  }
108
116
  }
109
- console.log("middleware check isexpired",useLicense().isExpired())
117
+ // console.log("middleware check isexpired",useLicense().isExpired())
110
118
  if(!useLicense().isExpired()) {
111
119
  return true
112
120
  }else if(allowAccessExpired(to)){
@@ -125,15 +133,22 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
125
133
  const allowAccessExpired = (to:RouteLocationNormalizedGeneric)=>{
126
134
  const userProfile = getUserProfile()
127
135
  let allowPass = false
128
- const isSuperAdmin = userProfile.groups.includes('superadmin')
136
+ const isSuperAdmin = userProfile?.groups?.includes('superadmin') ?? false
129
137
  if(isSuperAdmin){
130
138
  allowPass=true
131
139
  }
132
140
  const allowedPath = ['/billing','/pickgroup']
133
141
  for(const p of allowedPath){
134
- console.log("to.path.includes",to.path,p)
142
+ // console.log("to.path.includes",to.path,p)
135
143
  if(to.path.includes(p))allowPass = true
136
144
  }
137
145
 
138
146
  return allowPass
147
+ }
148
+
149
+ const isPublicPath=(path:string)=>{
150
+ if(path.includes('/login')) return true
151
+ if(path.includes('/relogin')) return true
152
+ if(path.includes('/logout')) return true
153
+ return false
139
154
  }