@simitgroup/simpleapp-generator 1.6.6-s-alpha → 1.6.6-u-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
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@ import { Model } from 'mongoose';
|
|
|
13
13
|
import { Permission } from '../../types/perm.type';
|
|
14
14
|
import { User } from '../../types/user.type';
|
|
15
15
|
import { Appintegration } from '../../types/appintegration.type';
|
|
16
|
-
import { Webhook } from '../../types
|
|
16
|
+
import { Webhook } from '../../types';
|
|
17
17
|
import { UserContext } from '../user.context';
|
|
18
18
|
|
|
19
19
|
@Injectable()
|
|
@@ -5,361 +5,338 @@
|
|
|
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
|
-
|
|
181
|
-
|
|
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
|
+
if(xorg !== undefined) {
|
|
66
|
+
await $appPluginsStore.loadInstalledPlugins();
|
|
67
|
+
await $customFieldStore.fetchList();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return await new PROFILEApi(undefined, apiurl, $axios)
|
|
71
|
+
.getProfile()
|
|
72
|
+
.then((res: AxiosResponse) => {
|
|
73
|
+
if (!res) {
|
|
74
|
+
return;
|
|
254
75
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
76
|
+
this._id = res.data._id;
|
|
77
|
+
this.sessionId = res.data.sessionId;
|
|
78
|
+
this.tenantId = res.data.tenantId;
|
|
79
|
+
this.orgId = res.data.orgId;
|
|
80
|
+
this.orgRecordId = res.data.orgRecordId;
|
|
81
|
+
this.branchId = res.data.branchId;
|
|
82
|
+
this.branchRecordId = res.data.branchRecordId;
|
|
83
|
+
this.branchCode = res.data.branchCode;
|
|
84
|
+
this.branchName = res.data.branchName;
|
|
85
|
+
this.orgCode = res.data.orgCode;
|
|
86
|
+
this.orgName = res.data.orgName;
|
|
87
|
+
this.timeZone = res.data.timeZone;
|
|
88
|
+
this.currency = res.data.currency;
|
|
89
|
+
this.country = res.data.country;
|
|
90
|
+
this.offsetMinute = res.data.offsetMinute;
|
|
91
|
+
this.uid = res.data.uid;
|
|
92
|
+
this.email = res.data.email;
|
|
93
|
+
this.fullName = res.data.fullName;
|
|
94
|
+
this.branches = res.data.branches;
|
|
95
|
+
this.groups = res.data.groups;
|
|
96
|
+
this.roles = res.data.roles;
|
|
97
|
+
this.time = res.data.time;
|
|
98
|
+
this.invites = res.data.invites;
|
|
99
|
+
this.moreProps = res.data.moreProps;
|
|
100
|
+
this.package = res.data.moreProps.package;
|
|
101
|
+
this.appintegration.einvoice = res.data.appintegration.einvoice;
|
|
102
|
+
this.appintegration.simbiz6 = res.data.appintegration.simbiz6;
|
|
103
|
+
let cachegroup = useCookie("currentGroup").value ?? "";
|
|
104
|
+
if (!this.groups || !this.groups.includes(cachegroup)) {
|
|
105
|
+
cachegroup = "";
|
|
260
106
|
}
|
|
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
|
|
107
|
+
this.currentGroup = cachegroup;
|
|
108
|
+
useNuxtApp().$event("pickGroup", cachegroup);
|
|
109
|
+
return Promise.resolve(true);
|
|
110
|
+
// return true
|
|
111
|
+
})
|
|
112
|
+
.catch((err: any) => {
|
|
113
|
+
return Promise.reject(err);
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
getCurrentXorg() {
|
|
117
|
+
return useRoute().params.xorg
|
|
118
|
+
? <String>useRoute().params.xorg
|
|
119
|
+
: undefined;
|
|
120
|
+
},
|
|
121
|
+
async pingSession(): Promise<string> {
|
|
122
|
+
let xorg = this.getCurrentXorg();
|
|
123
|
+
let apiurl = "";
|
|
124
|
+
|
|
125
|
+
if (!xorg) {
|
|
126
|
+
apiurl = `${useRuntimeConfig().public.appUrl}/api`;
|
|
127
|
+
} else {
|
|
128
|
+
try {
|
|
129
|
+
const xorgdecode = atob(<string>xorg);
|
|
130
|
+
if (xorgdecode.includes("-")) {
|
|
131
|
+
apiurl = `${useRuntimeConfig().public.appUrl}/api/${xorg}`;
|
|
132
|
+
} else {
|
|
133
|
+
return Promise.reject("wrongxorg");
|
|
302
134
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
135
|
+
} catch (e) {
|
|
136
|
+
return Promise.reject("wrongxorg");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const { $axios } = useNuxtApp();
|
|
140
|
+
try {
|
|
141
|
+
const pingresult = await new PROFILEApi(
|
|
142
|
+
undefined,
|
|
143
|
+
apiurl,
|
|
144
|
+
).getSession();
|
|
145
|
+
if (pingresult.status < 300) return Promise.resolve("ok");
|
|
146
|
+
else return Promise.reject("relogin");
|
|
147
|
+
} catch (e) {
|
|
148
|
+
return Promise.reject(e);
|
|
317
149
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
150
|
+
},
|
|
151
|
+
async decideInvitation(id: string, decision: string) {
|
|
152
|
+
const apiurl = `${useRuntimeConfig().public.appUrl}/api`;
|
|
153
|
+
const { $axios } = useNuxtApp();
|
|
154
|
+
// console.log("decideInvitation",id,decision)
|
|
155
|
+
const result = await new PROFILEApi(
|
|
156
|
+
undefined,
|
|
157
|
+
apiurl,
|
|
158
|
+
$axios,
|
|
159
|
+
).decideInvitation(id, decision);
|
|
160
|
+
|
|
161
|
+
if (result) {
|
|
162
|
+
// console.log(result)
|
|
163
|
+
} else {
|
|
164
|
+
// console.log(result)
|
|
165
|
+
}
|
|
166
|
+
//().then((res:AxiosResponse)=>{ }
|
|
167
|
+
},
|
|
168
|
+
checkHasHighPrivilege() {
|
|
169
|
+
return HIGH_PRIVILEGE_ROLES.some((permission) =>
|
|
170
|
+
this.roles.includes(permission),
|
|
171
|
+
);
|
|
172
|
+
},
|
|
173
|
+
canPerform(resourcename: string, action: string): boolean {
|
|
174
|
+
if (
|
|
175
|
+
this.roles.includes("superadmin") ||
|
|
176
|
+
this.roles.includes("tenantowner") ||
|
|
177
|
+
this.roles.includes("superuser")
|
|
178
|
+
) {
|
|
179
|
+
return true;
|
|
180
|
+
} else if (resourcename == "Paymentverify") {
|
|
181
|
+
if (this.roles.includes("admin") || this.roles.includes("manager")) {
|
|
182
|
+
return true;
|
|
324
183
|
}
|
|
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
|
-
}
|
|
184
|
+
} else if (resourcename == "Reminder") {
|
|
185
|
+
if (this.roles.includes("admin") || this.roles.includes("manager")) {
|
|
186
|
+
return true;
|
|
345
187
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
188
|
+
} else if (resourcename == "Generateinvoice") {
|
|
189
|
+
if (
|
|
190
|
+
this.roles.includes("admin") ||
|
|
191
|
+
this.roles.includes("manager") ||
|
|
192
|
+
this.roles.includes("executive")
|
|
193
|
+
) {
|
|
194
|
+
return true;
|
|
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
|
+
} else if (resourcename == "Appintegration") {
|
|
205
|
+
if (this.roles.includes("admin") || this.roles.includes("manager")) {
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
} else if (resourcename == "Postingtosimbiz") {
|
|
209
|
+
if (this.roles.includes("admin")) {
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
} else if (resourcename == "Studentdescription") {
|
|
213
|
+
if (
|
|
214
|
+
this.roles.includes("admin") ||
|
|
215
|
+
this.roles.includes("manager") ||
|
|
216
|
+
this.roles.includes("executive")
|
|
217
|
+
) {
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
} else {
|
|
221
|
+
const checkstr = `${resourcename}:${action}`;
|
|
222
|
+
// console.log("verify",checkstr)
|
|
223
|
+
return this.roles.includes(checkstr);
|
|
224
|
+
}
|
|
225
|
+
return false;
|
|
226
|
+
},
|
|
227
|
+
haveAccess(resourcename: string) {
|
|
228
|
+
//super admin always full access right
|
|
229
|
+
resourcename = _.upperFirst(resourcename);
|
|
230
|
+
// console.log("have access",resourcename)
|
|
231
|
+
if (
|
|
232
|
+
this.roles.includes("superadmin") ||
|
|
233
|
+
this.roles.includes("tenantowner") ||
|
|
234
|
+
this.roles.includes("superuser")
|
|
235
|
+
) {
|
|
236
|
+
return true;
|
|
237
|
+
} else if (resourcename == "Paymentverify") {
|
|
238
|
+
if (this.roles.includes("admin") || this.roles.includes("manager")) {
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
for (let i = 0; i < this.roles.length; i++) {
|
|
243
|
+
const role: string = this.roles[i];
|
|
244
|
+
if (role.includes(resourcename)) {
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return false;
|
|
249
|
+
},
|
|
250
|
+
async logout(redirecturl: string) {
|
|
251
|
+
const redirectdata = encodeURIComponent(redirecturl);
|
|
252
|
+
const { signOut } = useAuth();
|
|
253
|
+
const { data } = await (<any>useFetch("/api/auth/logout"));
|
|
254
|
+
// remove session
|
|
255
|
+
await signOut({ redirect: false });
|
|
256
|
+
let addPath = encodeURIComponent(`/login?callbackUrl=${redirectdata}`);
|
|
257
|
+
const tourl = `${data.value.path}${addPath}`;
|
|
258
|
+
navigateTo(tourl, { external: true });
|
|
259
|
+
},
|
|
260
|
+
getUserInfo() {
|
|
261
|
+
const userinfo: UserProfile = {
|
|
262
|
+
_id: this._id,
|
|
263
|
+
sessionId: this.sessionId,
|
|
264
|
+
tenantId: this.tenantId,
|
|
265
|
+
orgId: this.orgId,
|
|
266
|
+
branchId: this.branchId,
|
|
267
|
+
orgRecordId: this.orgRecordId,
|
|
268
|
+
branchRecordId: this.branchRecordId,
|
|
269
|
+
uid: this.uid,
|
|
270
|
+
email: this.email,
|
|
271
|
+
branchCode: this.branchCode,
|
|
272
|
+
branchName: this.branchName,
|
|
273
|
+
orgCode: this.orgCode,
|
|
274
|
+
orgName: this.orgName,
|
|
275
|
+
currency: this.currency,
|
|
276
|
+
timeZone: this.timeZone,
|
|
277
|
+
country: this.country,
|
|
278
|
+
offsetMinute: this.offsetMinute,
|
|
279
|
+
fullName: this.fullName,
|
|
280
|
+
branches: this.branches ?? [],
|
|
281
|
+
invites: this.invites ?? [],
|
|
282
|
+
roles: this.roles,
|
|
283
|
+
groups: this.groups,
|
|
284
|
+
currentGroup: this.currentGroup,
|
|
285
|
+
time: this.time,
|
|
286
|
+
moreProps: this.moreProps,
|
|
287
|
+
package: this.package,
|
|
288
|
+
appintegration: this.appintegration,
|
|
289
|
+
};
|
|
290
|
+
return userinfo;
|
|
291
|
+
},
|
|
292
|
+
isExecutive() {
|
|
293
|
+
return this.currentGroup == "executive";
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
});
|
|
350
297
|
|
|
298
|
+
try {
|
|
299
|
+
const pingsessionres = await useUserStore().pingSession();
|
|
351
300
|
|
|
352
|
-
|
|
301
|
+
if (pingsessionres) {
|
|
302
|
+
await useUserStore().loadRemoteUserInfo();
|
|
303
|
+
}
|
|
304
|
+
} catch (e: any) {
|
|
305
|
+
//server down, stop page
|
|
306
|
+
if (e == "wrongxorg") {
|
|
307
|
+
navigateTo("/picktenant", { external: true });
|
|
308
|
+
} else if (e?.code == "ERR_BAD_RESPONSE") {
|
|
309
|
+
throw createError({
|
|
310
|
+
statusCode: e.code,
|
|
311
|
+
statusMessage: e.message,
|
|
312
|
+
fatal: true,
|
|
313
|
+
});
|
|
314
|
+
} else if (e?.response?.status == 302) {
|
|
315
|
+
//no session
|
|
316
|
+
//need authentication, relogin
|
|
317
|
+
if (useRoute().meta.auth !== false) {
|
|
318
|
+
await useUserStore().logout(useRoute().path);
|
|
319
|
+
} else {
|
|
320
|
+
//pulic page, do nothing`
|
|
321
|
+
return {
|
|
353
322
|
provide: {
|
|
354
|
-
|
|
355
|
-
}
|
|
323
|
+
userstore: useUserStore(),
|
|
324
|
+
},
|
|
325
|
+
};
|
|
356
326
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
//
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
327
|
+
}
|
|
328
|
+
// else
|
|
329
|
+
//
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return {
|
|
333
|
+
provide: {
|
|
334
|
+
userstore: useUserStore(),
|
|
335
|
+
},
|
|
336
|
+
};
|
|
337
|
+
// }else{
|
|
338
|
+
|
|
339
|
+
// console.log("No need auth")
|
|
340
|
+
// return true
|
|
341
|
+
// }
|
|
365
342
|
});
|