@simitgroup/simpleapp-generator 1.6.6-p-alpha → 1.6.6-q-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/dist/buildinschemas/autoincreament.d.ts.map +1 -1
- package/dist/buildinschemas/autoincreament.js +17 -14
- package/dist/buildinschemas/autoincreament.js.map +1 -1
- package/dist/buildinschemas/branch.d.ts.map +1 -1
- package/dist/buildinschemas/branch.js +25 -24
- package/dist/buildinschemas/branch.js.map +1 -1
- package/dist/buildinschemas/changehistories.d.ts.map +1 -1
- package/dist/buildinschemas/changehistories.js +10 -9
- package/dist/buildinschemas/changehistories.js.map +1 -1
- package/dist/buildinschemas/customfield.d.ts.map +1 -1
- package/dist/buildinschemas/customfield.js +14 -24
- package/dist/buildinschemas/customfield.js.map +1 -1
- package/dist/buildinschemas/docnoformat.d.ts.map +1 -1
- package/dist/buildinschemas/docnoformat.js +34 -23
- package/dist/buildinschemas/docnoformat.js.map +1 -1
- package/dist/buildinschemas/documentevent.d.ts.map +1 -1
- package/dist/buildinschemas/documentevent.js +36 -26
- package/dist/buildinschemas/documentevent.js.map +1 -1
- package/dist/buildinschemas/keyvaluepair.d.ts.map +1 -1
- package/dist/buildinschemas/keyvaluepair.js +7 -6
- package/dist/buildinschemas/keyvaluepair.js.map +1 -1
- package/dist/buildinschemas/organization.d.ts.map +1 -1
- package/dist/buildinschemas/organization.js +34 -30
- package/dist/buildinschemas/organization.js.map +1 -1
- package/dist/buildinschemas/permission.d.ts.map +1 -1
- package/dist/buildinschemas/permission.js +16 -7
- package/dist/buildinschemas/permission.js.map +1 -1
- package/dist/buildinschemas/systemmessage.d.ts.map +1 -1
- package/dist/buildinschemas/systemmessage.js +35 -32
- package/dist/buildinschemas/systemmessage.js.map +1 -1
- package/dist/buildinschemas/tenant.d.ts.map +1 -1
- package/dist/buildinschemas/tenant.js +17 -16
- package/dist/buildinschemas/tenant.js.map +1 -1
- package/dist/buildinschemas/user.d.ts.map +1 -1
- package/dist/buildinschemas/user.js +34 -31
- package/dist/buildinschemas/user.js.map +1 -1
- package/dist/buildinschemas/webhook.d.ts.map +1 -1
- package/dist/buildinschemas/webhook.js +24 -23
- package/dist/buildinschemas/webhook.js.map +1 -1
- package/dist/framework.d.ts.map +1 -1
- package/dist/framework.js +2 -4
- package/dist/framework.js.map +1 -1
- package/dist/generate.js +17 -2
- package/dist/generate.js.map +1 -1
- package/dist/processors/jsonschemabuilder.js +14 -12
- package/dist/processors/jsonschemabuilder.js.map +1 -1
- package/dist/type.d.ts +39 -5
- package/dist/type.d.ts.map +1 -1
- package/dist/type.js.map +1 -1
- package/package.json +1 -1
- package/src/buildinschemas/autoincreament.ts +35 -33
- package/src/buildinschemas/branch.ts +47 -47
- package/src/buildinschemas/changehistories.ts +31 -30
- package/src/buildinschemas/customfield.ts +14 -24
- package/src/buildinschemas/docnoformat.ts +54 -43
- package/src/buildinschemas/documentevent.ts +42 -33
- package/src/buildinschemas/keyvaluepair.ts +25 -25
- package/src/buildinschemas/organization.ts +54 -50
- package/src/buildinschemas/permission.ts +34 -25
- package/src/buildinschemas/systemmessage.ts +39 -38
- package/src/buildinschemas/tenant.ts +46 -45
- package/src/buildinschemas/user.ts +64 -60
- package/src/buildinschemas/webhook.ts +62 -61
- package/src/framework.ts +2 -4
- package/src/generate.ts +17 -1
- package/src/processors/jsonschemabuilder.ts +6 -4
- package/src/type.ts +271 -215
- package/templates/basic/miniAppJsSdk/resource-bridge.service.ts.eta +9 -7
- package/templates/basic/miniAppStreamlitSdk/resource-bridge.service.ts.eta +22 -7
- package/templates/basic/nuxt/jsonschema.ts.eta +7 -0
- package/templates/basic/nuxt/resource-bridge.editable.service.ts.eta +40 -0
- package/templates/basic/nuxt/resource-bridge.service.ts.eta +24 -21
- package/templates/basic/nuxt/simpleapp.generate.client.ts.eta +27 -9
- package/templates/miniAppJsSdk/src/services/bridge-resource-accessor.service.ts.eta +2 -2
- package/templates/miniAppStreamlitSdk/simtrain_eco_mini_app_streamlit_sdk/sdk.py.eta +5 -2
- package/templates/nuxt/components/simpleApp/SimpleAppForm.vue.eta +4 -3
- package/templates/nuxt/components/simpleApp/SimpleAppInputTable.vue.eta +0 -1
- package/templates/nuxt/plugins/18.simpleapp-custom-field-store.ts.eta +9 -3
- package/templates/nuxt/plugins/20.simpleapp-userstore.ts.eta +316 -341
- package/templates/nuxt/simpleapp/generate/clients/SimpleAppClient.ts.eta +32 -22
- package/templates/nuxt/simpleapp/generate/jsonSchemas/index.ts.eta +11 -0
- package/templates/nuxt/simpleapp/generate/miniApp/bridge/constants/common.constant.ts.eta +1 -0
- package/templates/nuxt/simpleapp/generate/miniApp/bridge/constants/resource.constant.ts.eta +2 -2
- package/templates/nuxt/simpleapp/generate/miniApp/bridge/services/bridge-resource-accessor.service.ts.eta +4 -4
- package/templates/nuxt/simpleapp/generate/miniApp/bridge/services/bridge.service.ts.eta +20 -1
- package/templates/nuxt/simpleapp/generate/miniApp/bridge/types/bridge.type.ts.eta +9 -0
- package/templates/nuxt/simpleapp/generate/miniApp/bridge/types/resource-mapper.type.ts.eta +2 -2
- package/templates/project/build.sh.eta +0 -5
- package/templates/nest/src/simpleapp/apischemas/customfield.ts.eta +0 -21
- package/templates/nuxt/simpleapp/generate/clients/SimpleAppCustomFieldClient.ts.eta +0 -188
|
@@ -5,361 +5,336 @@
|
|
|
5
5
|
* Author: Ks Tan
|
|
6
6
|
*/
|
|
7
7
|
import { defineNuxtPlugin } from "#app";
|
|
8
|
-
import {PROFILEApi} from
|
|
9
|
-
import {UserProfile} from
|
|
10
|
-
import axios, { Axios, AxiosError, AxiosResponse } from
|
|
11
|
-
import _ from
|
|
8
|
+
import { PROFILEApi } from "../simpleapp/generate/openapi";
|
|
9
|
+
import { UserProfile } from "~/types";
|
|
10
|
+
import axios, { Axios, AxiosError, AxiosResponse } from "axios";
|
|
11
|
+
import _ from "lodash";
|
|
12
12
|
import { group } from "console";
|
|
13
13
|
import { HIGH_PRIVILEGE_ROLES } from "~/data/constant";
|
|
14
14
|
|
|
15
|
+
export default defineNuxtPlugin(async (nuxtApp) => {
|
|
16
|
+
const useUserStore = defineStore("userstore", {
|
|
17
|
+
state: () => ({
|
|
18
|
+
_id: ref(""),
|
|
19
|
+
sessionId: ref(""),
|
|
20
|
+
tenantId: ref(0),
|
|
21
|
+
orgId: ref(0),
|
|
22
|
+
branchId: ref(0),
|
|
23
|
+
branchRecordId: ref(""),
|
|
24
|
+
branchCode: ref(""),
|
|
25
|
+
branchName: ref(""),
|
|
26
|
+
orgRecordId: ref(""),
|
|
27
|
+
orgCode: ref(""),
|
|
28
|
+
orgName: ref(""),
|
|
29
|
+
timeZone: ref(""),
|
|
30
|
+
currency: ref(""),
|
|
31
|
+
country: ref(""),
|
|
32
|
+
offsetMinute: ref(0),
|
|
33
|
+
uid: ref(""),
|
|
34
|
+
email: ref(""),
|
|
35
|
+
fullName: ref(""),
|
|
36
|
+
roles: ref<string[]>([]),
|
|
37
|
+
groups: ref<string[]>([]),
|
|
38
|
+
currentGroup: ref(""),
|
|
39
|
+
branches: ref([]),
|
|
40
|
+
invites: ref([]),
|
|
41
|
+
time: ref(""),
|
|
42
|
+
moreProps: ref(),
|
|
43
|
+
package: ref(),
|
|
44
|
+
appintegration: ref({
|
|
45
|
+
einvoice: false,
|
|
46
|
+
simbiz6: false,
|
|
47
|
+
}),
|
|
48
|
+
}),
|
|
15
49
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
_id: ref(''),
|
|
20
|
-
sessionId:ref(''),
|
|
21
|
-
tenantId:ref(0),
|
|
22
|
-
orgId:ref(0),
|
|
23
|
-
branchId:ref(0),
|
|
24
|
-
branchRecordId:ref(''),
|
|
25
|
-
branchCode:ref(''),
|
|
26
|
-
branchName:ref(''),
|
|
27
|
-
orgRecordId:ref(''),
|
|
28
|
-
orgCode:ref(''),
|
|
29
|
-
orgName:ref(''),
|
|
30
|
-
timeZone:ref(''),
|
|
31
|
-
currency:ref(''),
|
|
32
|
-
country: ref(''),
|
|
33
|
-
offsetMinute: ref(0),
|
|
34
|
-
uid: ref(''),
|
|
35
|
-
email: ref(''),
|
|
36
|
-
fullName: ref(''),
|
|
37
|
-
roles:ref<string[]>([]),
|
|
38
|
-
groups:ref<string[]>([]),
|
|
39
|
-
currentGroup:ref(''),
|
|
40
|
-
branches:ref([]),
|
|
41
|
-
invites : ref([]),
|
|
42
|
-
time:ref(''),
|
|
43
|
-
moreProps:ref(),
|
|
44
|
-
package: ref(),
|
|
45
|
-
appintegration: ref({
|
|
46
|
-
einvoice: false,
|
|
47
|
-
simbiz6: false
|
|
48
|
-
})
|
|
49
|
-
}),
|
|
50
|
-
|
|
51
|
-
actions:{
|
|
52
|
-
async loadRemoteUserInfo(){
|
|
53
|
-
// console.log('loadRemoteUserInfo')
|
|
54
|
-
|
|
55
|
-
const { $axios, $appPluginsStore, $customFieldStore } = useNuxtApp()
|
|
56
|
-
const route = useRoute();
|
|
57
|
-
let xorg = this.getCurrentXorg()
|
|
58
|
-
|
|
59
|
-
let apiurl=''
|
|
60
|
-
if(xorg===undefined){
|
|
61
|
-
apiurl = `${useRuntimeConfig().public.appUrl}/api`
|
|
62
|
-
}else{
|
|
63
|
-
apiurl = `${useRuntimeConfig().public.appUrl}/api/${xorg}`
|
|
64
|
-
}
|
|
50
|
+
actions: {
|
|
51
|
+
async loadRemoteUserInfo() {
|
|
52
|
+
// console.log('loadRemoteUserInfo')
|
|
65
53
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return await new PROFILEApi(undefined,apiurl,$axios).getProfile().then((res:AxiosResponse)=>{
|
|
70
|
-
if(!res){
|
|
71
|
-
return
|
|
72
|
-
}
|
|
73
|
-
this._id = res.data._id
|
|
74
|
-
this.sessionId = res.data.sessionId
|
|
75
|
-
this.tenantId = res.data.tenantId
|
|
76
|
-
this.orgId = res.data.orgId
|
|
77
|
-
this.orgRecordId = res.data.orgRecordId
|
|
78
|
-
this.branchId = res.data.branchId
|
|
79
|
-
this.branchRecordId = res.data.branchRecordId
|
|
80
|
-
this.branchCode = res.data.branchCode
|
|
81
|
-
this.branchName = res.data.branchName
|
|
82
|
-
this.orgCode = res.data.orgCode
|
|
83
|
-
this.orgName = res.data.orgName
|
|
84
|
-
this.timeZone = res.data.timeZone
|
|
85
|
-
this.currency = res.data.currency
|
|
86
|
-
this.country = res.data.country
|
|
87
|
-
this.offsetMinute = res.data.offsetMinute
|
|
88
|
-
this.uid = res.data.uid
|
|
89
|
-
this.email = res.data.email
|
|
90
|
-
this.fullName = res.data.fullName
|
|
91
|
-
this.branches = res.data.branches
|
|
92
|
-
this.groups = res.data.groups
|
|
93
|
-
this.roles = res.data.roles
|
|
94
|
-
this.time = res.data.time
|
|
95
|
-
this.invites = res.data.invites
|
|
96
|
-
this.moreProps = res.data.moreProps
|
|
97
|
-
this.package = res.data.moreProps.package;
|
|
98
|
-
this.appintegration.einvoice = res.data.appintegration.einvoice;
|
|
99
|
-
this.appintegration.simbiz6 = res.data.appintegration.simbiz6;
|
|
100
|
-
let cachegroup = useCookie('currentGroup').value ?? ''
|
|
101
|
-
if(!this.groups || !this.groups.includes(cachegroup)){
|
|
102
|
-
cachegroup=''
|
|
103
|
-
}
|
|
104
|
-
this.currentGroup = cachegroup
|
|
105
|
-
useNuxtApp().$event('pickGroup',cachegroup)
|
|
106
|
-
return Promise.resolve(true)
|
|
107
|
-
// return true
|
|
108
|
-
}).catch((err:any)=>{
|
|
109
|
-
return Promise.reject(err)
|
|
110
|
-
})
|
|
111
|
-
},
|
|
112
|
-
getCurrentXorg(){
|
|
113
|
-
return (useRoute().params.xorg) ? <String>useRoute().params.xorg : undefined
|
|
114
|
-
},
|
|
115
|
-
async pingSession():Promise<string>{
|
|
116
|
-
let xorg = this.getCurrentXorg()
|
|
117
|
-
let apiurl=''
|
|
118
|
-
|
|
119
|
-
if(!xorg){
|
|
120
|
-
apiurl = `${useRuntimeConfig().public.appUrl}/api`
|
|
121
|
-
}else{
|
|
122
|
-
try{
|
|
123
|
-
const xorgdecode = atob(<string>xorg)
|
|
124
|
-
if(xorgdecode.includes('-')){
|
|
125
|
-
apiurl = `${useRuntimeConfig().public.appUrl}/api/${xorg}`
|
|
126
|
-
}else{
|
|
127
|
-
return Promise.reject('wrongxorg')
|
|
128
|
-
}
|
|
129
|
-
}catch(e){
|
|
130
|
-
return Promise.reject('wrongxorg')
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
const {$axios} = useNuxtApp()
|
|
136
|
-
try{
|
|
137
|
-
const pingresult = await new PROFILEApi(undefined,apiurl).getSession()
|
|
138
|
-
if(pingresult.status<300)
|
|
139
|
-
return Promise.resolve('ok')
|
|
140
|
-
else
|
|
141
|
-
return Promise.reject('relogin')
|
|
142
|
-
}catch(e){
|
|
143
|
-
return Promise.reject(e)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
},
|
|
147
|
-
async decideInvitation(id:string,decision:string){
|
|
148
|
-
const apiurl = `${useRuntimeConfig().public.appUrl}/api`
|
|
149
|
-
const {$axios} = useNuxtApp()
|
|
150
|
-
// console.log("decideInvitation",id,decision)
|
|
151
|
-
const result = await new PROFILEApi(undefined,apiurl,$axios).decideInvitation(id,decision)
|
|
152
|
-
|
|
153
|
-
if(result){
|
|
154
|
-
// console.log(result)
|
|
155
|
-
}else{
|
|
156
|
-
// console.log(result)
|
|
157
|
-
}
|
|
158
|
-
//().then((res:AxiosResponse)=>{ }
|
|
159
|
-
},
|
|
160
|
-
checkHasHighPrivilege(){
|
|
161
|
-
return HIGH_PRIVILEGE_ROLES.some(permission => this.roles.includes(permission))
|
|
162
|
-
},
|
|
163
|
-
canPerform(resourcename:string,action:string):boolean{
|
|
54
|
+
const { $axios, $appPluginsStore, $customFieldStore } = useNuxtApp();
|
|
55
|
+
const route = useRoute();
|
|
56
|
+
let xorg = this.getCurrentXorg();
|
|
164
57
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if (
|
|
181
|
-
this.roles.includes('admin') ||
|
|
182
|
-
this.roles.includes('manager')
|
|
183
|
-
){
|
|
184
|
-
return true;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
else if( resourcename == 'Generateinvoice'){
|
|
188
|
-
if (
|
|
189
|
-
this.roles.includes('admin') ||
|
|
190
|
-
this.roles.includes('manager') ||
|
|
191
|
-
this.roles.includes('executive')
|
|
192
|
-
){
|
|
193
|
-
return true;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
else if( resourcename == 'Upgradelevel'){
|
|
197
|
-
if (
|
|
198
|
-
this.roles.includes('admin') ||
|
|
199
|
-
this.roles.includes('manager') ||
|
|
200
|
-
this.roles.includes('executive')
|
|
201
|
-
){
|
|
202
|
-
return true;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
else if( resourcename == 'Appintegration'){
|
|
206
|
-
if (
|
|
207
|
-
this.roles.includes('admin') ||
|
|
208
|
-
this.roles.includes('manager')
|
|
209
|
-
){
|
|
210
|
-
return true;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
else if( resourcename == 'Postingtosimbiz'){
|
|
214
|
-
if (
|
|
215
|
-
this.roles.includes('admin')
|
|
216
|
-
){
|
|
217
|
-
return true;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
else if( resourcename == 'Studentdescription'){
|
|
221
|
-
if (
|
|
222
|
-
this.roles.includes('admin') ||
|
|
223
|
-
this.roles.includes('manager') ||
|
|
224
|
-
this.roles.includes('executive')
|
|
225
|
-
){
|
|
226
|
-
return true;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
else{
|
|
230
|
-
const checkstr= `${resourcename}:${action}`
|
|
231
|
-
// console.log("verify",checkstr)
|
|
232
|
-
return this.roles.includes(checkstr)
|
|
233
|
-
}
|
|
234
|
-
return false;
|
|
235
|
-
},
|
|
236
|
-
haveAccess(resourcename:string){
|
|
237
|
-
//super admin always full access right
|
|
238
|
-
resourcename = _.upperFirst(resourcename)
|
|
239
|
-
// console.log("have access",resourcename)
|
|
240
|
-
if(
|
|
241
|
-
this.roles.includes('superadmin') ||
|
|
242
|
-
this.roles.includes('tenantowner') ||
|
|
243
|
-
this.roles.includes('superuser')
|
|
244
|
-
){
|
|
245
|
-
return true
|
|
246
|
-
}
|
|
247
|
-
else if( resourcename == 'Paymentverify'){
|
|
248
|
-
if (
|
|
249
|
-
this.roles.includes('admin') ||
|
|
250
|
-
this.roles.includes('manager')
|
|
251
|
-
){
|
|
252
|
-
return true;
|
|
253
|
-
}
|
|
58
|
+
let apiurl = "";
|
|
59
|
+
if (xorg === undefined) {
|
|
60
|
+
apiurl = `${useRuntimeConfig().public.appUrl}/api`;
|
|
61
|
+
} else {
|
|
62
|
+
apiurl = `${useRuntimeConfig().public.appUrl}/api/${xorg}`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
await $appPluginsStore.loadInstalledPlugins();
|
|
66
|
+
await $customFieldStore.fetchList();
|
|
67
|
+
|
|
68
|
+
return await new PROFILEApi(undefined, apiurl, $axios)
|
|
69
|
+
.getProfile()
|
|
70
|
+
.then((res: AxiosResponse) => {
|
|
71
|
+
if (!res) {
|
|
72
|
+
return;
|
|
254
73
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
74
|
+
this._id = res.data._id;
|
|
75
|
+
this.sessionId = res.data.sessionId;
|
|
76
|
+
this.tenantId = res.data.tenantId;
|
|
77
|
+
this.orgId = res.data.orgId;
|
|
78
|
+
this.orgRecordId = res.data.orgRecordId;
|
|
79
|
+
this.branchId = res.data.branchId;
|
|
80
|
+
this.branchRecordId = res.data.branchRecordId;
|
|
81
|
+
this.branchCode = res.data.branchCode;
|
|
82
|
+
this.branchName = res.data.branchName;
|
|
83
|
+
this.orgCode = res.data.orgCode;
|
|
84
|
+
this.orgName = res.data.orgName;
|
|
85
|
+
this.timeZone = res.data.timeZone;
|
|
86
|
+
this.currency = res.data.currency;
|
|
87
|
+
this.country = res.data.country;
|
|
88
|
+
this.offsetMinute = res.data.offsetMinute;
|
|
89
|
+
this.uid = res.data.uid;
|
|
90
|
+
this.email = res.data.email;
|
|
91
|
+
this.fullName = res.data.fullName;
|
|
92
|
+
this.branches = res.data.branches;
|
|
93
|
+
this.groups = res.data.groups;
|
|
94
|
+
this.roles = res.data.roles;
|
|
95
|
+
this.time = res.data.time;
|
|
96
|
+
this.invites = res.data.invites;
|
|
97
|
+
this.moreProps = res.data.moreProps;
|
|
98
|
+
this.package = res.data.moreProps.package;
|
|
99
|
+
this.appintegration.einvoice = res.data.appintegration.einvoice;
|
|
100
|
+
this.appintegration.simbiz6 = res.data.appintegration.simbiz6;
|
|
101
|
+
let cachegroup = useCookie("currentGroup").value ?? "";
|
|
102
|
+
if (!this.groups || !this.groups.includes(cachegroup)) {
|
|
103
|
+
cachegroup = "";
|
|
260
104
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
currency: this.currency,
|
|
289
|
-
timeZone: this.timeZone,
|
|
290
|
-
country: this.country,
|
|
291
|
-
offsetMinute: this.offsetMinute,
|
|
292
|
-
fullName : this.fullName,
|
|
293
|
-
branches:this.branches??[],
|
|
294
|
-
invites: this.invites ?? [],
|
|
295
|
-
roles:this.roles,
|
|
296
|
-
groups:this.groups,
|
|
297
|
-
currentGroup:this.currentGroup,
|
|
298
|
-
time:this.time,
|
|
299
|
-
moreProps: this.moreProps,
|
|
300
|
-
package: this.package,
|
|
301
|
-
appintegration: this.appintegration
|
|
105
|
+
this.currentGroup = cachegroup;
|
|
106
|
+
useNuxtApp().$event("pickGroup", cachegroup);
|
|
107
|
+
return Promise.resolve(true);
|
|
108
|
+
// return true
|
|
109
|
+
})
|
|
110
|
+
.catch((err: any) => {
|
|
111
|
+
return Promise.reject(err);
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
getCurrentXorg() {
|
|
115
|
+
return useRoute().params.xorg
|
|
116
|
+
? <String>useRoute().params.xorg
|
|
117
|
+
: undefined;
|
|
118
|
+
},
|
|
119
|
+
async pingSession(): Promise<string> {
|
|
120
|
+
let xorg = this.getCurrentXorg();
|
|
121
|
+
let apiurl = "";
|
|
122
|
+
|
|
123
|
+
if (!xorg) {
|
|
124
|
+
apiurl = `${useRuntimeConfig().public.appUrl}/api`;
|
|
125
|
+
} else {
|
|
126
|
+
try {
|
|
127
|
+
const xorgdecode = atob(<string>xorg);
|
|
128
|
+
if (xorgdecode.includes("-")) {
|
|
129
|
+
apiurl = `${useRuntimeConfig().public.appUrl}/api/${xorg}`;
|
|
130
|
+
} else {
|
|
131
|
+
return Promise.reject("wrongxorg");
|
|
302
132
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
133
|
+
} catch (e) {
|
|
134
|
+
return Promise.reject("wrongxorg");
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const { $axios } = useNuxtApp();
|
|
138
|
+
try {
|
|
139
|
+
const pingresult = await new PROFILEApi(
|
|
140
|
+
undefined,
|
|
141
|
+
apiurl,
|
|
142
|
+
).getSession();
|
|
143
|
+
if (pingresult.status < 300) return Promise.resolve("ok");
|
|
144
|
+
else return Promise.reject("relogin");
|
|
145
|
+
} catch (e) {
|
|
146
|
+
return Promise.reject(e);
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
async decideInvitation(id: string, decision: string) {
|
|
150
|
+
const apiurl = `${useRuntimeConfig().public.appUrl}/api`;
|
|
151
|
+
const { $axios } = useNuxtApp();
|
|
152
|
+
// console.log("decideInvitation",id,decision)
|
|
153
|
+
const result = await new PROFILEApi(
|
|
154
|
+
undefined,
|
|
155
|
+
apiurl,
|
|
156
|
+
$axios,
|
|
157
|
+
).decideInvitation(id, decision);
|
|
158
|
+
|
|
159
|
+
if (result) {
|
|
160
|
+
// console.log(result)
|
|
161
|
+
} else {
|
|
162
|
+
// console.log(result)
|
|
317
163
|
}
|
|
318
|
-
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
164
|
+
//().then((res:AxiosResponse)=>{ }
|
|
165
|
+
},
|
|
166
|
+
checkHasHighPrivilege() {
|
|
167
|
+
return HIGH_PRIVILEGE_ROLES.some((permission) =>
|
|
168
|
+
this.roles.includes(permission),
|
|
169
|
+
);
|
|
170
|
+
},
|
|
171
|
+
canPerform(resourcename: string, action: string): boolean {
|
|
172
|
+
if (
|
|
173
|
+
this.roles.includes("superadmin") ||
|
|
174
|
+
this.roles.includes("tenantowner") ||
|
|
175
|
+
this.roles.includes("superuser")
|
|
176
|
+
) {
|
|
177
|
+
return true;
|
|
178
|
+
} else if (resourcename == "Paymentverify") {
|
|
179
|
+
if (this.roles.includes("admin") || this.roles.includes("manager")) {
|
|
180
|
+
return true;
|
|
324
181
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
statusMessage:e.message,
|
|
329
|
-
fatal:true
|
|
330
|
-
})
|
|
331
|
-
}else if(e?.response?.status==302){ //no session
|
|
332
|
-
//need authentication, relogin
|
|
333
|
-
if( useRoute().meta.auth !==false){
|
|
334
|
-
await useUserStore().logout(useRoute().path)
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
//pulic page, do nothing`
|
|
338
|
-
return {
|
|
339
|
-
provide: {
|
|
340
|
-
userstore:useUserStore()
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
}
|
|
182
|
+
} else if (resourcename == "Reminder") {
|
|
183
|
+
if (this.roles.includes("admin") || this.roles.includes("manager")) {
|
|
184
|
+
return true;
|
|
345
185
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
186
|
+
} else if (resourcename == "Generateinvoice") {
|
|
187
|
+
if (
|
|
188
|
+
this.roles.includes("admin") ||
|
|
189
|
+
this.roles.includes("manager") ||
|
|
190
|
+
this.roles.includes("executive")
|
|
191
|
+
) {
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
} else if (resourcename == "Upgradelevel") {
|
|
195
|
+
if (
|
|
196
|
+
this.roles.includes("admin") ||
|
|
197
|
+
this.roles.includes("manager") ||
|
|
198
|
+
this.roles.includes("executive")
|
|
199
|
+
) {
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
} else if (resourcename == "Appintegration") {
|
|
203
|
+
if (this.roles.includes("admin") || this.roles.includes("manager")) {
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
} else if (resourcename == "Postingtosimbiz") {
|
|
207
|
+
if (this.roles.includes("admin")) {
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
} else if (resourcename == "Studentdescription") {
|
|
211
|
+
if (
|
|
212
|
+
this.roles.includes("admin") ||
|
|
213
|
+
this.roles.includes("manager") ||
|
|
214
|
+
this.roles.includes("executive")
|
|
215
|
+
) {
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
} else {
|
|
219
|
+
const checkstr = `${resourcename}:${action}`;
|
|
220
|
+
// console.log("verify",checkstr)
|
|
221
|
+
return this.roles.includes(checkstr);
|
|
222
|
+
}
|
|
223
|
+
return false;
|
|
224
|
+
},
|
|
225
|
+
haveAccess(resourcename: string) {
|
|
226
|
+
//super admin always full access right
|
|
227
|
+
resourcename = _.upperFirst(resourcename);
|
|
228
|
+
// console.log("have access",resourcename)
|
|
229
|
+
if (
|
|
230
|
+
this.roles.includes("superadmin") ||
|
|
231
|
+
this.roles.includes("tenantowner") ||
|
|
232
|
+
this.roles.includes("superuser")
|
|
233
|
+
) {
|
|
234
|
+
return true;
|
|
235
|
+
} else if (resourcename == "Paymentverify") {
|
|
236
|
+
if (this.roles.includes("admin") || this.roles.includes("manager")) {
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
for (let i = 0; i < this.roles.length; i++) {
|
|
241
|
+
const role: string = this.roles[i];
|
|
242
|
+
if (role.includes(resourcename)) {
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return false;
|
|
247
|
+
},
|
|
248
|
+
async logout(redirecturl: string) {
|
|
249
|
+
const redirectdata = encodeURIComponent(redirecturl);
|
|
250
|
+
const { signOut } = useAuth();
|
|
251
|
+
const { data } = await (<any>useFetch("/api/auth/logout"));
|
|
252
|
+
// remove session
|
|
253
|
+
await signOut({ redirect: false });
|
|
254
|
+
let addPath = encodeURIComponent(`/login?callbackUrl=${redirectdata}`);
|
|
255
|
+
const tourl = `${data.value.path}${addPath}`;
|
|
256
|
+
navigateTo(tourl, { external: true });
|
|
257
|
+
},
|
|
258
|
+
getUserInfo() {
|
|
259
|
+
const userinfo: UserProfile = {
|
|
260
|
+
_id: this._id,
|
|
261
|
+
sessionId: this.sessionId,
|
|
262
|
+
tenantId: this.tenantId,
|
|
263
|
+
orgId: this.orgId,
|
|
264
|
+
branchId: this.branchId,
|
|
265
|
+
orgRecordId: this.orgRecordId,
|
|
266
|
+
branchRecordId: this.branchRecordId,
|
|
267
|
+
uid: this.uid,
|
|
268
|
+
email: this.email,
|
|
269
|
+
branchCode: this.branchCode,
|
|
270
|
+
branchName: this.branchName,
|
|
271
|
+
orgCode: this.orgCode,
|
|
272
|
+
orgName: this.orgName,
|
|
273
|
+
currency: this.currency,
|
|
274
|
+
timeZone: this.timeZone,
|
|
275
|
+
country: this.country,
|
|
276
|
+
offsetMinute: this.offsetMinute,
|
|
277
|
+
fullName: this.fullName,
|
|
278
|
+
branches: this.branches ?? [],
|
|
279
|
+
invites: this.invites ?? [],
|
|
280
|
+
roles: this.roles,
|
|
281
|
+
groups: this.groups,
|
|
282
|
+
currentGroup: this.currentGroup,
|
|
283
|
+
time: this.time,
|
|
284
|
+
moreProps: this.moreProps,
|
|
285
|
+
package: this.package,
|
|
286
|
+
appintegration: this.appintegration,
|
|
287
|
+
};
|
|
288
|
+
return userinfo;
|
|
289
|
+
},
|
|
290
|
+
isExecutive() {
|
|
291
|
+
return this.currentGroup == "executive";
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
});
|
|
350
295
|
|
|
296
|
+
try {
|
|
297
|
+
const pingsessionres = await useUserStore().pingSession();
|
|
351
298
|
|
|
352
|
-
|
|
299
|
+
if (pingsessionres) {
|
|
300
|
+
await useUserStore().loadRemoteUserInfo();
|
|
301
|
+
}
|
|
302
|
+
} catch (e: any) {
|
|
303
|
+
//server down, stop page
|
|
304
|
+
if (e == "wrongxorg") {
|
|
305
|
+
navigateTo("/picktenant", { external: true });
|
|
306
|
+
} else if (e?.code == "ERR_BAD_RESPONSE") {
|
|
307
|
+
throw createError({
|
|
308
|
+
statusCode: e.code,
|
|
309
|
+
statusMessage: e.message,
|
|
310
|
+
fatal: true,
|
|
311
|
+
});
|
|
312
|
+
} else if (e?.response?.status == 302) {
|
|
313
|
+
//no session
|
|
314
|
+
//need authentication, relogin
|
|
315
|
+
if (useRoute().meta.auth !== false) {
|
|
316
|
+
await useUserStore().logout(useRoute().path);
|
|
317
|
+
} else {
|
|
318
|
+
//pulic page, do nothing`
|
|
319
|
+
return {
|
|
353
320
|
provide: {
|
|
354
|
-
|
|
355
|
-
}
|
|
321
|
+
userstore: useUserStore(),
|
|
322
|
+
},
|
|
323
|
+
};
|
|
356
324
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
//
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
325
|
+
}
|
|
326
|
+
// else
|
|
327
|
+
//
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return {
|
|
331
|
+
provide: {
|
|
332
|
+
userstore: useUserStore(),
|
|
333
|
+
},
|
|
334
|
+
};
|
|
335
|
+
// }else{
|
|
336
|
+
|
|
337
|
+
// console.log("No need auth")
|
|
338
|
+
// return true
|
|
339
|
+
// }
|
|
365
340
|
});
|