@simitgroup/simpleapp-generator 1.6.7-o-alpha → 2.0.0-b-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 +9 -0
- package/dist/buildinschemas/autoincreament.js +1 -1
- package/dist/buildinschemas/branch.d.ts.map +1 -1
- package/dist/buildinschemas/branch.js +2 -0
- package/dist/buildinschemas/branch.js.map +1 -1
- package/dist/buildinschemas/docnoformat.js +1 -1
- package/dist/buildinschemas/docnoformat.js.map +1 -1
- package/dist/buildinschemas/documentevent.js +1 -1
- package/dist/buildinschemas/documentnoformat.d.ts +3 -0
- package/dist/buildinschemas/documentnoformat.d.ts.map +1 -0
- package/dist/buildinschemas/documentnoformat.js +58 -0
- package/dist/buildinschemas/documentnoformat.js.map +1 -0
- package/dist/buildinschemas/index.d.ts +0 -5
- package/dist/buildinschemas/index.d.ts.map +1 -1
- package/dist/buildinschemas/index.js +5 -11
- package/dist/buildinschemas/index.js.map +1 -1
- package/dist/buildinschemas/organization.d.ts.map +1 -1
- package/dist/buildinschemas/organization.js +3 -19
- package/dist/buildinschemas/organization.js.map +1 -1
- package/dist/buildinschemas/user.d.ts.map +1 -1
- package/dist/buildinschemas/user.js +5 -2
- package/dist/buildinschemas/user.js.map +1 -1
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +118 -23
- package/dist/generate.js.map +1 -1
- package/dist/type.d.ts +6 -0
- 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 → autoincreament.ts.backup} +1 -1
- package/src/buildinschemas/branch.ts +2 -0
- package/src/buildinschemas/{documentevent.ts → documentevent.ts.backup} +1 -1
- package/src/buildinschemas/{docnoformat.ts → documentnoformat.ts.backup} +3 -3
- package/src/buildinschemas/index.ts +4 -5
- package/src/buildinschemas/organization.ts +3 -19
- package/src/buildinschemas/user.ts +5 -2
- package/src/generate.ts +128 -28
- package/src/type.ts +6 -1
- package/templates/basic/nest/api.controller.ts.eta +153 -0
- package/templates/basic/nest/api.module.ts.eta +32 -0
- package/templates/basic/nest/api.resolver.ts.eta +94 -0
- package/templates/basic/nest/api.schema.ts.eta +20 -0
- package/templates/basic/nest/api.service.ts.eta +85 -0
- package/templates/basic/nest/controller.ts.eta +31 -119
- package/templates/basic/nest/default.ts.eta +16 -10
- package/templates/basic/nest/enum.ts.eta +16 -0
- package/templates/basic/nest/model.ts.eta +6 -28
- package/templates/basic/nest/module.ts.eta +26 -0
- package/templates/basic/nest/resolver.ts.eta +12 -56
- package/templates/basic/nest/schema.ts.eta +133 -0
- package/templates/basic/nest/service.ts.eta +86 -73
- package/templates/basic/nest/service.ts.eta-backup +50 -0
- package/templates/basic/nuxt/default.ts.eta +10 -8
- package/templates/basic/nuxt/pages.[id].vue.eta +2 -2
- package/templates/basic/nuxt/pages.form.vue.eta +2 -2
- package/templates/basic/nuxt/pages.viewer.vue.eta +2 -2
- package/templates/basic/nuxt/simpleapp.doc.ts.eta +1 -1
- package/templates/basic/nuxt/simpleapp.generate.client.ts.eta +7 -5
- package/templates/nest/src/app.module.ts._eta +53 -69
- package/templates/nest/src/main.ts._eta +1 -1
- package/templates/nest/src/simple-app/.core/features/auth/api-key/api-key.service.ts.eta +29 -0
- package/templates/nest/src/simple-app/.core/features/auth/api-key/api-key.type.ts.eta +5 -0
- package/templates/nest/src/simple-app/.core/features/auth/api-key/validators/interface.ts.eta +7 -0
- package/templates/nest/src/simple-app/.core/features/auth/api-key/validators/mini-api-key.validator.ts.eta +30 -0
- package/templates/nest/src/simple-app/.core/features/auth/api-key/validators/static-api-key.validator.ts.eta +27 -0
- package/templates/nest/src/simple-app/.core/features/auth/auth.module.ts.eta +9 -0
- package/templates/nest/src/{simpleapp/generate/commons/roles → simple-app/.core/features/auth/role-guard}/roles.enum.ts.eta +7 -7
- package/templates/nest/src/{simpleapp/generate/commons/roles → simple-app/.core/features/auth/role-guard}/roles.guard.ts.eta +1 -1
- package/templates/nest/src/simple-app/.core/features/auto-increament/auto-increament.model.ts.eta +10 -0
- package/templates/nest/src/simple-app/.core/features/auto-increament/auto-increament.module.ts.eta +18 -0
- package/templates/nest/src/simple-app/.core/features/auto-increament/auto-increament.schema.ts.eta +119 -0
- package/templates/nest/src/simple-app/.core/features/auto-increament/auto-increament.service.ts.eta +65 -0
- package/templates/nest/src/simple-app/.core/features/cron/base/cron.base.ts.eta +13 -0
- package/templates/nest/src/simple-app/.core/features/cron/cron-system/cron-system.module.ts.eta +17 -0
- package/templates/nest/src/simple-app/.core/features/cron/cron-system/cron-system.service.ts.eta +37 -0
- package/templates/nest/src/simple-app/.core/features/cron/cron-system/schemas/index.ts.eta +2 -0
- package/templates/nest/src/simple-app/.core/features/cron/cron.module.ts.eta +10 -0
- package/templates/nest/src/simple-app/.core/features/document-no-format/document-no-format.controller.ts.eta +31 -0
- package/templates/nest/src/simple-app/.core/features/document-no-format/document-no-format.model.ts.eta +15 -0
- package/templates/nest/src/simple-app/.core/features/document-no-format/document-no-format.module.ts.eta +12 -0
- package/templates/nest/src/simple-app/.core/features/document-no-format/document-no-format.schema.ts.eta +162 -0
- package/templates/nest/src/simple-app/.core/features/document-no-format/document-no-format.service.ts.eta +189 -0
- package/templates/nest/src/simple-app/.core/features/event/event.module.ts.eta +9 -0
- package/templates/nest/src/simple-app/.core/features/event/event.type.ts.eta +23 -0
- package/templates/nest/src/simple-app/.core/features/event/interface/event-after-create.interface.ts.eta +5 -0
- package/templates/nest/src/simple-app/.core/features/event/interface/event-after-delete.interface.ts.eta +5 -0
- package/templates/nest/src/simple-app/.core/features/event/interface/event-after-set-status.interface.ts.eta +5 -0
- package/templates/nest/src/simple-app/.core/features/event/interface/event-after-update.interface.ts.eta +5 -0
- package/templates/nest/src/simple-app/.core/features/event/interface/event-before-create.interface.ts.eta +5 -0
- package/templates/nest/src/simple-app/.core/features/event/interface/event-before-delete.interface.ts.eta +5 -0
- package/templates/nest/src/simple-app/.core/features/event/interface/event-before-set-status.interface.ts.eta +5 -0
- package/templates/nest/src/simple-app/.core/features/event/interface/event-before-update.interface.ts.eta +5 -0
- package/templates/nest/src/simple-app/.core/features/event/interface/index.ts.eta +8 -0
- package/templates/nest/src/simple-app/.core/features/foreign-key/foreign-key.module.ts.eta +16 -0
- package/templates/nest/src/simple-app/.core/features/log/log.module.ts.eta +20 -0
- package/templates/nest/src/simple-app/.core/features/log/log.service.ts.eta +68 -0
- package/templates/nest/src/simple-app/.core/features/log/schemas/api-event.schema.ts.eta +57 -0
- package/templates/nest/src/simple-app/.core/features/log/schemas/document-event.schema.ts.eta +87 -0
- package/templates/nest/src/simple-app/.core/features/log/schemas/index.ts.eta +2 -0
- package/templates/nest/src/simple-app/.core/features/maintenance/maintenance.controller.ts.eta +84 -0
- package/templates/nest/src/simple-app/.core/features/maintenance/maintenance.module.ts.eta +19 -0
- package/templates/nest/src/simple-app/.core/features/maintenance/maintenance.service.ts.eta +86 -0
- package/templates/nest/src/simple-app/.core/features/maintenance/schemas/environment.ts.eta +23 -0
- package/templates/nest/src/{simpleapp/maintenance/apischemas → simple-app/.core/features/maintenance/schemas}/index.ts.eta +1 -1
- package/templates/nest/src/simple-app/.core/features/mini-app/developer-portal/developer-portal-bridge.service.ts.eta.eta +31 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/developer-portal/developer-portal-env-development.service.ts.eta +124 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/developer-portal/developer-portal-env-production.service.ts.eta +50 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/developer-portal/developer-portal.controller.ts.eta +41 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/developer-portal/developer-portal.schema.ts.eta +18 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/developer-portal/developer-portal.service.ts.eta +94 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/developer-portal/dto/developer-portal-create-app.dto.ts.eta +22 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/developer-portal/dto/developer-portal-publish-app.dto.ts.eta +0 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/dto/imports.ts.eta +2 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/dto/index.ts.eta +2 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/dto/mini-app.ts.eta +55 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-manager/mini-app-manager-bridge.service.ts.eta +162 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-manager/mini-app-manager-env-development.service.ts.eta +140 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-manager/mini-app-manager-env-production.service.ts.eta +125 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-manager/mini-app-manager-policy.service.ts.eta +43 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-manager/mini-app-manager.controller.ts.eta +81 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-manager/mini-app-manager.enum.ts.eta +5 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-manager/mini-app-manager.error.ts.eta +24 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-manager/mini-app-manager.processor.ts.eta +309 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-manager/mini-app-manager.service.ts.eta +346 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-scope/mini-app-scope.decorator.ts.eta +5 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-scope/mini-app-scope.guard.ts.eta +43 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-scope/mini-app-scope.service.ts.eta +101 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/mini-app.module.ts.eta +24 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/types/miniApp.ts.eta +23 -0
- package/templates/nest/src/simple-app/.core/features/mini-app/utils/mini-app.util.ts.eta +26 -0
- package/templates/nest/src/simple-app/.core/features/policy/policy.module.ts.eta +12 -0
- package/templates/nest/src/simple-app/.core/features/policy/policy.service.ts.eta +45 -0
- package/templates/nest/src/{simpleapp/profile/profile.controller.ts._eta → simple-app/.core/features/profile/profile.controller.ts.eta} +37 -83
- package/templates/nest/src/simple-app/.core/features/profile/profile.module.ts.eta +22 -0
- package/templates/nest/src/simple-app/.core/features/profile/profile.schema.ts.eta +165 -0
- package/templates/nest/src/{simpleapp/profile/profile.service.ts._eta → simple-app/.core/features/profile/profile.service.ts.eta} +36 -48
- package/templates/nest/src/simple-app/.core/features/queue/queue-base/queue-base.consumer.ts.eta +196 -0
- package/templates/nest/src/simple-app/.core/features/queue/queue-base/queue-base.producer.ts.eta +147 -0
- package/templates/nest/src/simple-app/.core/features/queue/queue-user-context/queue-user-context.service.ts.eta +35 -0
- package/templates/nest/src/simple-app/.core/features/queue/queue.module.ts.eta +24 -0
- package/templates/nest/src/simple-app/.core/features/queue/queue.type.ts.eta +75 -0
- package/templates/nest/src/simple-app/.core/features/simple-app-core-features.module.ts.eta +51 -0
- package/templates/nest/src/{simpleapp/generate/commons/robotuser.service.ts.eta → simple-app/.core/features/user-context/robot-user.service.ts.eta} +27 -16
- package/templates/nest/src/simple-app/.core/features/user-context/user-context.module.ts.eta +24 -0
- package/templates/nest/src/simple-app/.core/features/user-context/user-context.type.ts.eta +15 -0
- package/templates/nest/src/{simpleapp/generate/commons → simple-app/.core/features/user-context}/user.context.ts.eta +469 -449
- package/templates/nest/src/{simpleapp/generate/commons/runwebhook.service.ts.eta → simple-app/.core/features/webhook/run-webhook.service.ts.eta} +20 -17
- package/templates/nest/src/simple-app/.core/features/webhook/schemas/index.ts.eta +2 -0
- package/templates/nest/src/simple-app/.core/features/webhook/schemas/webhook-log.schema.ts.eta +116 -0
- package/templates/nest/src/simple-app/.core/features/webhook/schemas/webhook.schema.ts.eta +177 -0
- package/templates/nest/src/simple-app/.core/features/webhook/webhook.module.ts.eta +21 -0
- package/templates/nest/src/{simpleapp/generate/controllers/simpleapp.controller.ts.eta → simple-app/.core/framework/base/simple-app.controller.ts.eta} +20 -35
- package/templates/nest/src/{simpleapp/generate/processors/simpleapp.processor.ts.eta → simple-app/.core/framework/base/simple-app.service.ts.eta} +228 -140
- package/templates/nest/src/simple-app/.core/framework/custom-exception.ts.eta +26 -0
- package/templates/nest/src/simple-app/.core/framework/framework.module.ts.eta +12 -0
- package/templates/nest/src/simple-app/.core/framework/schemas/index.ts.eta +3 -0
- package/templates/nest/src/simple-app/.core/framework/schemas/others.schema.ts.eta +153 -0
- package/templates/nest/src/simple-app/.core/framework/schemas/simple-app.schema.ts.eta +172 -0
- package/templates/nest/src/{simpleapp/generate/commons/interceptors/response.interceptor.ts.eta → simple-app/.core/framework/simple-app.interceptor.ts.eta} +12 -22
- package/templates/nest/src/{simpleapp/generate/commons/middlewares/tenant.middleware.ts.eta → simple-app/.core/framework/simple-app.middleware.ts.eta} +28 -26
- package/templates/nest/src/simple-app/.core/readme.md.eta +3 -0
- package/templates/nest/src/simple-app/.core/resources/core-resources.module.ts.eta +38 -0
- package/templates/nest/src/simple-app/.core/simple-app-core.module.ts.eta +18 -0
- package/templates/nest/src/simple-app/.core/utils/dayjs.ts.eta +47 -0
- package/templates/nest/src/simple-app/.core/utils/locale-tool.ts.eta +11 -0
- package/templates/nest/src/simple-app/.core/utils/string-utils.ts.eta +1 -0
- package/templates/nest/src/simple-app/.resources/readme.md.eta +3 -0
- package/templates/nest/src/simple-app/.resources/resources.module.ts.eta +36 -0
- package/templates/nest/src/simple-app/apis/readme.md.eta +9 -0
- package/templates/nest/src/simple-app/apis/resource-api.module.ts.eta +37 -0
- package/templates/nest/src/simple-app/events/branch-event/branch-event.module.ts._eta +20 -0
- package/templates/nest/src/simple-app/events/branch-event/branch-event.service.ts._eta +43 -0
- package/templates/nest/src/simple-app/events/branch-event/branch-event.type.ts._eta +7 -0
- package/templates/nest/src/simple-app/events/events.module.ts._eta +17 -0
- package/templates/nest/src/simple-app/events/organization-event/organization-event.module.ts._eta +13 -0
- package/templates/nest/src/simple-app/events/organization-event/organization-event.service.ts._eta +52 -0
- package/templates/nest/src/simple-app/events/organization-event/organization-event.type.ts._eta +1 -0
- package/templates/nest/src/simple-app/events/permission-event/permission-event.module.ts.eta +11 -0
- package/templates/nest/src/simple-app/events/permission-event/permission-event.service.ts.eta +33 -0
- package/templates/nest/src/simple-app/events/permission-event/permission-event.type.ts.eta +1 -0
- package/templates/nest/src/simple-app/events/readme.md.eta +76 -0
- package/templates/nest/src/simple-app/events/tenant-event/tenant-event.module.ts_eta +12 -0
- package/templates/nest/src/simple-app/events/tenant-event/tenant-event.service.ts_eta +30 -0
- package/templates/nest/src/simple-app/events/tenant-event/tenant-event.type.ts_eta +1 -0
- package/templates/nest/src/{simpleapp/additional.module.ts._eta → simple-app/features/features.module.ts._eta} +8 -7
- package/templates/nest/src/{printapi/printapi.module.ts.eta → simple-app/features/print/print.module.ts.eta} +4 -4
- package/templates/nest/src/{printapi/printapi.service.ts.eta → simple-app/features/print/print.service.ts.eta} +7 -7
- package/templates/nest/src/simple-app/features/readme.md._eta +6 -0
- package/templates/nest/src/simple-app/simple-app.module.ts.eta +32 -0
- package/templates/nuxt/.env._eta +2 -0
- package/templates/nuxt/app.vue.eta +15 -7
- package/templates/nuxt/components/header/HeaderSelectBranch.vue.eta +2 -1
- package/templates/nuxt/components/image/ImageAvatar.vue._eta +63 -0
- package/templates/nuxt/components/image/ImageOrganization.vue._eta +77 -0
- package/templates/nuxt/components/simpleApp/SimpleAppForm.vue.eta +1 -1
- package/templates/nuxt/components/simpleApp/SimpleAppFormToolBar.vue._eta +95 -20
- package/templates/nuxt/components/user/UserButtonCreateTenant.vue._eta +20 -21
- package/templates/nuxt/components/user/UserTenantPicker.vue._eta +1 -1
- package/templates/nuxt/composables/docformat.generate.ts.eta +4 -2
- package/templates/nuxt/enums/enums.generate.ts.eta +1 -1
- package/templates/nuxt/middleware/30.acl.global.ts.eta +6 -6
- package/templates/nuxt/nuxt.config.ts._eta +1 -0
- package/templates/nuxt/pages/login.vue._eta +21 -15
- package/templates/nuxt/pages/profile.vue._eta +24 -32
- package/templates/nuxt/plugins/20.simpleapp-userstore.ts.eta +31 -24
- package/templates/nuxt/plugins/50.simpleapp-client.ts.eta +2 -2
- package/templates/nuxt/providers/my-provider.ts.eta +5 -6
- package/templates/nuxt/simpleapp/generate/clients/SimpleAppClient.ts.eta +1 -0
- package/templates/nuxt/simpleapp/generate/defaults/index.ts.eta +1 -1
- package/templates/nuxt/simpleapp/generate/types/index.ts.eta +1 -1
- package/templates/nuxt/types/schema.ts.eta +1 -0
- package/templates/nuxt/types/user.ts.eta +39 -38
- package/templates/project/build.sh.eta +2 -2
- package/templates/basic/nest/apischema.ts.eta +0 -96
- package/templates/basic/nest/processor.ts.eta +0 -86
- package/templates/nest/src/cloudapi/cloudapi.module.ts._eta +0 -15
- package/templates/nest/src/cloudapi/cloudapi.service.ts._eta +0 -15
- package/templates/nest/src/enums/enums.generate.ts.eta +0 -23
- package/templates/nest/src/simpleapp/apischemas/index.ts._eta +0 -85
- package/templates/nest/src/simpleapp/generate/apischemas/index.ts.eta +0 -15
- package/templates/nest/src/simpleapp/generate/apischemas/simpleapp.apischema.ts.eta +0 -62
- package/templates/nest/src/simpleapp/generate/commons/audittrail.service.ts.eta +0 -52
- package/templates/nest/src/simpleapp/generate/commons/customkeycloa.guard.ts.eta +0 -45
- package/templates/nest/src/simpleapp/generate/commons/docnogenerator.service.ts.eta +0 -129
- package/templates/nest/src/simpleapp/generate/commons/providers/workflow.provider.ts.etax +0 -87
- package/templates/nest/src/simpleapp/generate/jsonschemas/index.ts.eta +0 -11
- package/templates/nest/src/simpleapp/generate/models/apievent.model.ts.eta +0 -27
- package/templates/nest/src/simpleapp/generate/processors/autoinc.processor.ts.eta +0 -88
- package/templates/nest/src/simpleapp/generate/processors/branch.processor.ts.eta +0 -110
- package/templates/nest/src/simpleapp/generate/processors/docno.processor.ts.eta +0 -77
- package/templates/nest/src/simpleapp/generate/processors/org.processor.ts.eta +0 -110
- package/templates/nest/src/simpleapp/generate/processors/perm.processor.ts.eta +0 -71
- package/templates/nest/src/simpleapp/generate/processors/sysmsg.processor.ts.eta +0 -49
- package/templates/nest/src/simpleapp/generate/processors/tenant.processor.ts.eta +0 -52
- package/templates/nest/src/simpleapp/generate/processors/webhooklog.processor.ts.eta +0 -45
- package/templates/nest/src/simpleapp/generate/types/index.ts.eta +0 -7
- package/templates/nest/src/simpleapp/generate/types/schema.type.ts.eta +0 -193
- package/templates/nest/src/simpleapp/generate/types/simpleapp.type.ts.eta +0 -299
- package/templates/nest/src/simpleapp/generate/types/workflow.type.ts.eta +0 -15
- package/templates/nest/src/simpleapp/generate/workflow/formschema/SimpleApproveReject.ts.eta +0 -8
- package/templates/nest/src/simpleapp/generate/workflow/formschema/index.ts.eta +0 -7
- package/templates/nest/src/simpleapp/generate/workflow/workflow.apischema.ts.eta +0 -136
- package/templates/nest/src/simpleapp/generate/workflow/workflow.config.ts.eta +0 -79
- package/templates/nest/src/simpleapp/generate/workflow/workflow.controller.ts.eta +0 -414
- package/templates/nest/src/simpleapp/generate/workflow/workflow.delegate.ts.eta +0 -201
- package/templates/nest/src/simpleapp/generate/workflow/workflow.service.ts.eta +0 -641
- package/templates/nest/src/simpleapp/generate/workflow/workflow.type.ts.eta +0 -98
- package/templates/nest/src/simpleapp/generate/workflow/workflow.userservice.ts.eta +0 -83
- package/templates/nest/src/simpleapp/maintenance/apischemas/environment.ts.eta +0 -11
- package/templates/nest/src/simpleapp/maintenance/maintenance.controller.ts.eta +0 -72
- package/templates/nest/src/simpleapp/maintenance/maintenance.service.ts.eta +0 -88
- package/templates/nest/src/simpleapp/maintenance/models/environment.model.ts.eta +0 -16
- package/templates/nest/src/simpleapp/profile/profile.apischema.ts._eta +0 -95
- package/templates/nest/src/simpleapp/resolvers/readme.md.eta +0 -1
- package/templates/nest/src/simpleapp/services/autoinc.service.ts.etaxx +0 -59
- package/templates/nest/src/simpleapp/services/branch.service.ts.etaxxx +0 -83
- package/templates/nest/src/simpleapp/services/docno.service.ts.etaxxx +0 -59
- package/templates/nest/src/simpleapp/services/org.service.ts.etaxxx +0 -37
- package/templates/nest/src/simpleapp/services/perm.service.ts.etaxxx +0 -56
- package/templates/nest/src/simpleapp/services/sysmsg.service.ts._etaxxx +0 -43
- package/templates/nest/src/simpleapp/services/tenant.service.ts.etaxxx +0 -38
- package/templates/nest/src/simpleapp/services/user.service.ts.eta.old +0 -118
- package/templates/nest/src/simpleapp/services/userresolver.service.ts._eta +0 -67
- package/templates/nest/src/simpleapp/services/webhook.service.ts._eta +0 -37
- package/templates/nest/src/simpleapp/simpleapp.module.ts.eta +0 -85
- package/templates/nest/src/simpleapp/types/index.ts._eta +0 -45
- package/templates/nest/src/simpleapp/webhooks/branch.ts._eta +0 -44
- package/templates/nest/src/simpleapp/webhooks/index.ts._eta +0 -21
- package/templates/nest/src/simpleapp/workflows/bpmn/readme.md._eta +0 -1
- package/templates/nest/src/simpleapp/workflows/listeners/simpleapp.listener.ts.eta +0 -31
- package/templates/nest/src/simpleapp/workflows/readme.md._eta +0 -1
- package/templates/nuxt/components/image/ImageAvatar.vue.eta +0 -56
- package/templates/nuxt/components/image/ImageOrganization.vue.eta +0 -66
- /package/src/buildinschemas/{webhook.ts → webhook.ts.backup} +0 -0
- /package/src/buildinschemas/{webhooklog.ts → webhooklog.ts.backup} +0 -0
- /package/templates/basic/nest/{type.ts.eta → type.ts.eta-backup} +0 -0
- /package/templates/nest/src/{simpleapp/generate/commons/customkeycloak.guard.ts.eta → simple-app/.core/features/auth/keycloak/keycloak.guard.ts.eta} +0 -0
- /package/templates/nest/src/{simpleapp/generate/commons/roles → simple-app/.core/features/auth/role-guard}/roles.decorator.ts.eta +0 -0
- /package/templates/nest/src/{simpleapp/generate/commons/roles → simple-app/.core/features/auth/role-guard}/roles.group.ts.eta +0 -0
- /package/templates/nest/src/{simpleapp/generate/commons/dicts/documents.ts.eta → simple-app/.core/features/document-no-format/document.dict.ts.eta} +0 -0
- /package/templates/nest/src/{simpleapp/generate/commons/dicts/foreignkeys.ts.eta → simple-app/.core/features/foreign-key/foreignkeys.dict.ts.eta} +0 -0
- /package/templates/nest/src/{simpleapp/maintenance/dbupdate → simple-app/.core/features/maintenance/db-update}/1.00.00/index.ts._eta +0 -0
- /package/templates/nest/src/{simpleapp/maintenance/dbupdate → simple-app/.core/features/maintenance/db-update}/index.ts._eta +0 -0
- /package/templates/nest/src/{simpleapp/maintenance/apischemas/dbupdate.ts.eta → simple-app/.core/features/maintenance/schemas/db-update.ts.eta} +0 -0
- /package/templates/nest/src/{simpleapp/profile/profile.types.ts.eta → simple-app/.core/features/profile/profile.types.ts.eta-backup} +0 -0
- /package/templates/nest/src/{simpleapp/generate/commons/decorators → simple-app/.core/features/user-context}/appuser.decorator.ts.eta +0 -0
- /package/templates/nest/src/{simpleapp/generate/commons/exceptions/SimpleAppExceptionFilter.ts.eta → simple-app/.core/framework/exception-filter.ts.eta} +0 -0
- /package/templates/nest/src/{simpleapp/generate/commons → simple-app/.core/utils}/encryption.static.ts.eta +0 -0
- /package/templates/nest/src/{simpleapp → simple-app}/.gitignore.eta +0 -0
- /package/templates/nest/src/{printapi → simple-app/features/print}/api/.gitignore.eta +0 -0
- /package/templates/nest/src/{printapi → simple-app/features/print}/api/.npmignore.eta +0 -0
- /package/templates/nest/src/{printapi → simple-app/features/print}/api/.openapi-generator/FILES.eta +0 -0
- /package/templates/nest/src/{printapi → simple-app/features/print}/api/.openapi-generator/VERSION.eta +0 -0
- /package/templates/nest/src/{printapi → simple-app/features/print}/api/.openapi-generator-ignore.eta +0 -0
- /package/templates/nest/src/{printapi → simple-app/features/print}/api/api.ts.eta +0 -0
- /package/templates/nest/src/{printapi → simple-app/features/print}/api/base.ts.eta +0 -0
- /package/templates/nest/src/{printapi → simple-app/features/print}/api/common.ts.eta +0 -0
- /package/templates/nest/src/{printapi → simple-app/features/print}/api/configuration.ts.eta +0 -0
- /package/templates/nest/src/{printapi → simple-app/features/print}/api/git_push.sh.eta +0 -0
- /package/templates/nest/src/{printapi → simple-app/features/print}/api/index.ts.eta +0 -0
- /package/templates/nest/src/{printapi → simple-app/features/print}/api/openapitools.json.eta +0 -0
- /package/templates/project/{sharelibs → share-libs}/hello.ts._eta +0 -0
- /package/templates/project/{sharelibs → share-libs}/index.ts.eta +0 -0
- /package/templates/project/{sharelibs → share-libs}/money.ts.eta +0 -0
- /package/templates/project/{sharelibs → share-libs}/validate.ts.eta +0 -0
|
@@ -6,55 +6,66 @@
|
|
|
6
6
|
* 2.
|
|
7
7
|
*/
|
|
8
8
|
import Base64URL from '@darkwolf/base64url';
|
|
9
|
+
import { isEmpty } from 'lodash';
|
|
10
|
+
import { Request } from 'express';
|
|
9
11
|
import { InjectModel } from '@nestjs/mongoose';
|
|
10
12
|
import { BadRequestException, ForbiddenException, Injectable, Logger, Scope } from '@nestjs/common';
|
|
11
13
|
import * as jwt from 'jsonwebtoken';
|
|
12
14
|
import { ClientSession, Model, PipelineStage } from 'mongoose';
|
|
13
|
-
import { Branch, Organization, Permission, Tenant, TenantClientSetting, User, Appintegration, Webhook, Miniappinstallation, TUserType, TMiniApiTokenInfo } from 'src/simpleapp/generate/types';
|
|
14
|
-
import { ProfileUserBranch, ProfileUserInvites } from '../../profile/profile.types';
|
|
15
|
-
import { ModifiedRecords } from '../types';
|
|
16
|
-
import { Role } from './roles/roles.enum';
|
|
17
|
-
import systemWebHooks from '../../webhooks';
|
|
18
|
-
import * as rolegroups from './roles/roles.group';
|
|
19
|
-
import { isEmpty } from 'lodash';
|
|
20
|
-
import { Request } from 'express';
|
|
21
15
|
|
|
16
|
+
// import { Branch, Organization, Permission, Tenant, TenantClientSetting, User, Appintegration, Webhook, Miniappinstallation, TUserType, TMiniApiTokenInfo } from 'src/simpleapp/generate/types';
|
|
17
|
+
import { TUserType, TMiniApiTokenInfo } from 'src/simple-app/.core/framework/schemas';
|
|
18
|
+
import { MiniAppInstallation } from 'src/simple-app/.core/resources/mini-app-installation/mini-app-installation.schema';
|
|
19
|
+
|
|
20
|
+
import { Tenant, TenantClientSetting } from 'src/simple-app/.core/resources/tenant/tenant.schema';
|
|
21
|
+
import { Organization } from 'src/simple-app/.core/resources/organization/organization.schema';
|
|
22
|
+
import { Branch } from 'src/simple-app/.core/resources/branch/branch.schema';
|
|
23
|
+
|
|
24
|
+
import { Permission } from 'src/simple-app/.core/resources/permission/permission.schema';
|
|
25
|
+
import { User } from 'src/simple-app/.core/resources/user/user.schema';
|
|
26
|
+
import { Webhook } from 'src/simple-app/.core/features/webhook/schemas';
|
|
27
|
+
import { UserContextInfo, ProfileUserBranch, ProfileUserInvites, TenantPermission } from 'src/simple-app/.core/features/profile/profile.schema';
|
|
28
|
+
import { ModifiedRecords } from '../../framework/schemas';
|
|
29
|
+
import { Role } from '../auth/role-guard/roles.enum';
|
|
30
|
+
import * as rolegroups from '../auth/role-guard/roles.group';
|
|
31
|
+
|
|
32
|
+
// import systemWebHooks from '../../webhooks';
|
|
22
33
|
@Injectable({ scope: Scope.REQUEST })
|
|
23
|
-
export class UserContext {
|
|
24
|
-
|
|
34
|
+
export class UserContext extends UserContextInfo {
|
|
35
|
+
sessionId: string = crypto.randomUUID();
|
|
25
36
|
|
|
26
37
|
protected logger = new Logger(this.constructor.name);
|
|
27
38
|
|
|
28
|
-
protected uid: string = '';
|
|
39
|
+
// protected uid: string = '';
|
|
29
40
|
|
|
30
|
-
protected _id: string = '';
|
|
41
|
+
// protected _id: string = '';
|
|
31
42
|
|
|
32
|
-
protected uname: string = '';
|
|
43
|
+
// protected uname: string = '';
|
|
33
44
|
|
|
34
|
-
protected email: string = '';
|
|
45
|
+
// protected email: string = '';
|
|
35
46
|
|
|
36
|
-
protected fullname: string = '';
|
|
47
|
+
// protected fullname: string = '';
|
|
37
48
|
|
|
38
|
-
protected xOrg: string = '';
|
|
49
|
+
// protected xOrg: string = '';
|
|
39
50
|
|
|
40
|
-
protected tenantId: number = 0;
|
|
51
|
+
// protected tenantId: number = 0;
|
|
41
52
|
|
|
42
|
-
protected orgId: number = 0;
|
|
53
|
+
// protected orgId: number = 0;
|
|
43
54
|
|
|
44
|
-
protected orgRecordId: string = '';
|
|
55
|
+
// protected orgRecordId: string = '';
|
|
45
56
|
|
|
46
|
-
protected branchRecordId: string = '';
|
|
57
|
+
// protected branchRecordId: string = '';
|
|
47
58
|
|
|
48
|
-
protected branchId: number = 0;
|
|
59
|
+
// protected branchId: number = 0;
|
|
49
60
|
|
|
50
|
-
|
|
61
|
+
private ssoACL: Record<string, { roles: string[] }> = {};
|
|
51
62
|
|
|
52
|
-
|
|
63
|
+
private token: string = '';
|
|
53
64
|
|
|
54
|
-
|
|
65
|
+
private refreshtoken: string = '';
|
|
55
66
|
|
|
56
67
|
// Guest access token obtain from header 'x-guest-accesstoken', during use x-apikey / x-apisecret
|
|
57
|
-
|
|
68
|
+
private guestToken?: string = '';
|
|
58
69
|
|
|
59
70
|
protected guestInfo: {
|
|
60
71
|
uid: string;
|
|
@@ -63,41 +74,41 @@ export class UserContext {
|
|
|
63
74
|
email: string;
|
|
64
75
|
} = { uid: '', uname: '', fullname: '', email: '' };
|
|
65
76
|
|
|
66
|
-
|
|
77
|
+
private miniApiToken?: string;
|
|
67
78
|
|
|
68
|
-
|
|
79
|
+
private miniApiTokenInfo?: TMiniApiTokenInfo;
|
|
69
80
|
|
|
70
|
-
protected groups: string[] = [];
|
|
81
|
+
// protected groups: string[] = [];
|
|
71
82
|
|
|
72
|
-
protected branchCode: string = '';
|
|
83
|
+
// protected branchCode: string = '';
|
|
73
84
|
|
|
74
|
-
protected branchName: string = '';
|
|
85
|
+
// protected branchName: string = '';
|
|
75
86
|
|
|
76
|
-
protected orgCode: string = '';
|
|
87
|
+
// protected orgCode: string = '';
|
|
77
88
|
|
|
78
|
-
protected orgName: string = '';
|
|
89
|
+
// protected orgName: string = '';
|
|
79
90
|
|
|
80
|
-
protected timeZone: string = '';
|
|
91
|
+
// protected timeZone: string = '';
|
|
81
92
|
|
|
82
|
-
protected country: string = '';
|
|
93
|
+
// protected country: string = '';
|
|
83
94
|
|
|
84
|
-
protected offsetMinute: number = 0;
|
|
95
|
+
// protected offsetMinute: number = 0;
|
|
85
96
|
|
|
86
|
-
protected currency: string = '';
|
|
97
|
+
// protected currency: string = '';
|
|
87
98
|
|
|
88
|
-
protected branches:
|
|
99
|
+
// protected branches: ProfileUserBranch[] = [];
|
|
89
100
|
|
|
90
|
-
protected lastActivity: string = new Date().toISOString();
|
|
101
|
+
// protected lastActivity: string = new Date().toISOString();
|
|
91
102
|
|
|
92
|
-
protected invites:
|
|
103
|
+
// protected invites: ProfileUserInvites[] = [];
|
|
93
104
|
|
|
94
|
-
protected roles: Role[] = [];
|
|
105
|
+
// protected roles: Role[] = [];
|
|
95
106
|
|
|
96
|
-
protected moreProps: Record<string, any> = {};
|
|
107
|
+
// protected moreProps: Record<string, any> = {};
|
|
97
108
|
|
|
98
109
|
protected package: string = '';
|
|
99
110
|
|
|
100
|
-
protected webhooks: Webhook[] = systemWebHooks;
|
|
111
|
+
protected webhooks: Webhook[] = []; //systemWebHooks;
|
|
101
112
|
protected clientSetting: TenantClientSetting = {
|
|
102
113
|
auditTrail: false,
|
|
103
114
|
support: false,
|
|
@@ -113,19 +124,21 @@ export class UserContext {
|
|
|
113
124
|
deleteds: {},
|
|
114
125
|
};
|
|
115
126
|
|
|
116
|
-
protected appintegration: {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
} = { simbiz6: false, einvoice: false };
|
|
127
|
+
// protected appintegration: {
|
|
128
|
+
// simbiz6: boolean;
|
|
129
|
+
// einvoice: boolean;
|
|
130
|
+
// } = { simbiz6: false, einvoice: false };
|
|
120
131
|
|
|
121
132
|
protected userType: TUserType = 'normal';
|
|
122
133
|
|
|
123
134
|
constructor(
|
|
124
135
|
private readonly userModel: Model<User>,
|
|
125
136
|
private readonly permModel: Model<Permission>,
|
|
126
|
-
private readonly appModel: Model<Appintegration>,
|
|
127
|
-
private readonly miniAppInstallationModel: Model<
|
|
128
|
-
) {
|
|
137
|
+
// private readonly appModel: Model<Appintegration>,
|
|
138
|
+
private readonly miniAppInstallationModel: Model<MiniAppInstallation>,
|
|
139
|
+
) {
|
|
140
|
+
super();
|
|
141
|
+
}
|
|
129
142
|
|
|
130
143
|
setDBSession = (dbsession: ClientSession) => {
|
|
131
144
|
this.dbsession = dbsession;
|
|
@@ -137,9 +150,9 @@ export class UserContext {
|
|
|
137
150
|
|
|
138
151
|
getUid = () => this.uid;
|
|
139
152
|
|
|
140
|
-
getUname = () => this.
|
|
153
|
+
getUname = () => this.uName;
|
|
141
154
|
|
|
142
|
-
getFullname = () => this.
|
|
155
|
+
getFullname = () => this.fullName;
|
|
143
156
|
|
|
144
157
|
getTenantId = () => this.tenantId;
|
|
145
158
|
|
|
@@ -179,40 +192,9 @@ export class UserContext {
|
|
|
179
192
|
|
|
180
193
|
getModifieds = () => this.modifiedRecords;
|
|
181
194
|
|
|
182
|
-
getBranches = ()
|
|
183
|
-
const data: ProfileUserBranch[] = [];
|
|
184
|
-
|
|
185
|
-
if (Array.isArray(this.branches)) {
|
|
186
|
-
for (let i = 0; i < this.branches.length; i++) {
|
|
187
|
-
const branches = this.branches[i];
|
|
188
|
-
data.push({
|
|
189
|
-
_id: branches._id,
|
|
190
|
-
branch: branches.branch[0],
|
|
191
|
-
groups: branches.groups,
|
|
192
|
-
xOrg: this.generateXOrg(branches.tenantId, branches.orgId, branches.branchId),
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return data;
|
|
197
|
-
};
|
|
195
|
+
getBranches = () => this.branches;
|
|
198
196
|
|
|
199
|
-
getInvites = ()
|
|
200
|
-
const data: ProfileUserInvites[] = [];
|
|
201
|
-
if (this.invites) {
|
|
202
|
-
for (let i = 0; i < this.invites.length; i++) {
|
|
203
|
-
const invite = this.invites[i];
|
|
204
|
-
data.push({
|
|
205
|
-
_id: invite._id,
|
|
206
|
-
email: invite.email,
|
|
207
|
-
tenantId: invite.tenantId,
|
|
208
|
-
fullName: '',
|
|
209
|
-
tenantName: invite.tenant[0].tenantName,
|
|
210
|
-
created: invite.created,
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return data;
|
|
215
|
-
};
|
|
197
|
+
getInvites = () => this.invites;
|
|
216
198
|
|
|
217
199
|
getUserToken = () => this.token;
|
|
218
200
|
|
|
@@ -230,11 +212,12 @@ export class UserContext {
|
|
|
230
212
|
|
|
231
213
|
setCurrentUserInfo = async (tokenstr: string, xOrg: string, webhookModel: Model<Webhook>) => {
|
|
232
214
|
this.setXOrg(xOrg);
|
|
215
|
+
// console.log('xOrg',xOrg)
|
|
233
216
|
await this.setUserToken(tokenstr);
|
|
234
217
|
this.setUserType('normal');
|
|
235
|
-
const wh = await webhookModel.find({ branchId: this.getBranchId(), active: true });
|
|
218
|
+
// const wh = await webhookModel.find({ branchId: this.getBranchId(), active: true });
|
|
236
219
|
|
|
237
|
-
if (Array.isArray(wh) && wh.length > 0) this.webhooks = this.webhooks.concat(wh);
|
|
220
|
+
// if (Array.isArray(wh) && wh.length > 0) this.webhooks = this.webhooks.concat(wh);
|
|
238
221
|
};
|
|
239
222
|
|
|
240
223
|
setPackage = (packageName: string) => {
|
|
@@ -257,116 +240,170 @@ export class UserContext {
|
|
|
257
240
|
this.offsetMinute = offsetMinute;
|
|
258
241
|
};
|
|
259
242
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
243
|
+
// async obtainNoTenantProfile() {
|
|
244
|
+
// const pipelines: PipelineStage[] = [{ $match: { uid: this.uid, tenantId: this.tenantId } }];
|
|
245
|
+
// try {
|
|
246
|
+
// const userdata: User[] = await this.userModel.aggregate(pipelines).exec();
|
|
247
|
+
// const userProfile: UserContextInfo = {
|
|
248
|
+
// _id: '',
|
|
249
|
+
// uid: this.uid,
|
|
250
|
+
// email: this.email,
|
|
251
|
+
// fullName: this.fullName,
|
|
252
|
+
// uName: this.uName,
|
|
253
|
+
// country: '',
|
|
254
|
+
// currency: '',
|
|
255
|
+
// offsetMinute: 0,
|
|
256
|
+
// } as UserContextInfo;
|
|
257
|
+
|
|
258
|
+
// if (Array.isArray(userdata) && userdata.length > 0) {
|
|
259
|
+
// userProfile._id = userdata[0]._id;
|
|
260
|
+
// }
|
|
261
|
+
// return userProfile;
|
|
262
|
+
// } catch (e) {
|
|
263
|
+
// throw e;
|
|
264
|
+
// }
|
|
265
|
+
// }
|
|
266
|
+
async obtainProfileFromDB() {
|
|
267
|
+
// if (this.tenantId == 0) {
|
|
268
|
+
// return this.obtainNoTenantProfile();
|
|
269
|
+
// }
|
|
270
|
+
const pipelines: PipelineStage[] = [
|
|
271
|
+
//get profile
|
|
272
|
+
{ $match: { uid: this.uid, tenantId: this.tenantId } },
|
|
273
|
+
{
|
|
274
|
+
$lookup: {
|
|
275
|
+
from: 'permission',
|
|
276
|
+
as: 'perm',
|
|
277
|
+
localField: '_id',
|
|
278
|
+
foreignField: 'userId',
|
|
279
|
+
pipeline: [{ $match: { tenantId: this.tenantId, orgId: this.orgId, branchId: this.branchId } }],
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
$unwind: {
|
|
284
|
+
path: '$perm',
|
|
285
|
+
preserveNullAndEmptyArrays: true,
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
$project: {
|
|
290
|
+
uid: 1,
|
|
291
|
+
fullName: 1,
|
|
292
|
+
email: 1,
|
|
293
|
+
tenantId: 1,
|
|
294
|
+
orgId: 1,
|
|
295
|
+
branchId: 1,
|
|
296
|
+
groups: '$perm.groups',
|
|
297
|
+
},
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
$lookup: {
|
|
301
|
+
from: 'branch',
|
|
302
|
+
as: 'b',
|
|
303
|
+
localField: 'branchId',
|
|
304
|
+
foreignField: 'branchId',
|
|
305
|
+
pipeline: [
|
|
306
|
+
{
|
|
307
|
+
$lookup: {
|
|
308
|
+
from: 'organization',
|
|
309
|
+
as: 'o',
|
|
310
|
+
localField: 'orgId',
|
|
311
|
+
foreignField: 'orgId',
|
|
312
|
+
pipeline: [{ $project: { orgCode: 1, orgName: 1, offsetMinute: 1, timeZone: 1, currency: 1, country: 1 } }],
|
|
313
|
+
},
|
|
279
314
|
},
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
foreignField: 'branchId',
|
|
286
|
-
as: 'currentbranch',
|
|
315
|
+
{
|
|
316
|
+
$unwind: {
|
|
317
|
+
path: '$o',
|
|
318
|
+
preserveNullAndEmptyArrays: true,
|
|
319
|
+
},
|
|
287
320
|
},
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
321
|
+
],
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
$unwind: {
|
|
326
|
+
path: '$b',
|
|
327
|
+
preserveNullAndEmptyArrays: true,
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
$project: {
|
|
332
|
+
uid: 1,
|
|
333
|
+
fullName: 1,
|
|
334
|
+
email: 1,
|
|
335
|
+
tenantId: 1,
|
|
336
|
+
orgId: 1,
|
|
337
|
+
branchId: 1,
|
|
338
|
+
groups: 1,
|
|
339
|
+
branchRecordId: '$b._id',
|
|
340
|
+
branchCode: '$b.branchCode',
|
|
341
|
+
branchName: '$b.branchName',
|
|
342
|
+
orgRecordId: '$b.organization._id',
|
|
343
|
+
orgCode: '$b.o.orgCode',
|
|
344
|
+
orgName: '$b.o.orgName',
|
|
345
|
+
offsetMinute: '$b.o.offsetMinute',
|
|
346
|
+
timeZone: '$b.o.timeZone',
|
|
347
|
+
currency: '$b.o.currency',
|
|
348
|
+
country: '$b.o.country',
|
|
349
|
+
},
|
|
350
|
+
},
|
|
351
|
+
|
|
352
|
+
//get branches
|
|
353
|
+
{
|
|
354
|
+
$lookup: {
|
|
355
|
+
from: 'permission',
|
|
356
|
+
as: 'branches',
|
|
357
|
+
localField: 'uid',
|
|
358
|
+
foreignField: 'uid',
|
|
359
|
+
pipeline: [
|
|
360
|
+
{ $project: { tenantId: 1, orgId: 1, branchId: 1, groups: 1 } },
|
|
361
|
+
{
|
|
362
|
+
$lookup: {
|
|
363
|
+
from: 'branch',
|
|
364
|
+
as: 'b',
|
|
365
|
+
localField: 'branchId',
|
|
366
|
+
foreignField: 'branchId',
|
|
367
|
+
pipeline: [
|
|
368
|
+
{
|
|
369
|
+
$lookup: {
|
|
370
|
+
from: 'organization',
|
|
371
|
+
as: 'org',
|
|
372
|
+
localField: 'orgId',
|
|
373
|
+
foreignField: 'orgId',
|
|
374
|
+
},
|
|
375
|
+
},
|
|
376
|
+
{ $unwind: '$org' },
|
|
377
|
+
],
|
|
378
|
+
},
|
|
298
379
|
},
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
380
|
+
{ $unwind: '$b' },
|
|
381
|
+
{
|
|
382
|
+
$project: {
|
|
383
|
+
tenantId: 1,
|
|
384
|
+
orgId: 1,
|
|
385
|
+
branchId: 1,
|
|
386
|
+
branch: {
|
|
387
|
+
_id: '$b._id',
|
|
388
|
+
branchCode: '$b.branchCode',
|
|
389
|
+
branchName: '$b.branchName',
|
|
390
|
+
branchId: '$b.branchId',
|
|
391
|
+
},
|
|
392
|
+
|
|
393
|
+
groups: 1,
|
|
394
|
+
orgCode: '$b.org.orgCode',
|
|
395
|
+
orgName: '$b.org.orgName',
|
|
396
|
+
branchCode: '$b.branchCode',
|
|
397
|
+
branchName: '$b.branchName',
|
|
398
|
+
},
|
|
309
399
|
},
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
{
|
|
313
|
-
$unwind: '$currentTenant',
|
|
314
|
-
},
|
|
315
|
-
],
|
|
400
|
+
],
|
|
401
|
+
},
|
|
316
402
|
},
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
if (this.tenantId > 0) {
|
|
322
|
-
pipeline.push(joinPermission);
|
|
323
|
-
pipeline.push({ $unwind: '$permissions' });
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
const userProfiles: UserProfile[] = await this.userModel.aggregate(pipeline);
|
|
327
|
-
if (!userProfiles || userProfiles.length === 0) {
|
|
328
|
-
return undefined;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
const userProfile = userProfiles[0];
|
|
332
|
-
|
|
333
|
-
if (this.tenantId > 0) {
|
|
334
|
-
const userPermissions = userProfile.permissions;
|
|
335
|
-
|
|
336
|
-
if (userPermissions && userPermissions.groups) {
|
|
337
|
-
userProfile.groups = userPermissions.groups;
|
|
338
|
-
userProfile.roles = [Role.Everyone, Role.User] as Role[];
|
|
339
|
-
for (let g = 0; g < userProfile.groups.length; g++) {
|
|
340
|
-
const roles: Role[] = (<() => Role[]>rolegroups[userProfile.groups[g]])();
|
|
341
|
-
for (let r = 0; r < roles.length; r++) {
|
|
342
|
-
if (!userProfile.roles.includes(roles[r])) {
|
|
343
|
-
userProfile.roles.push(roles[r]);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
if (userPermissions.currentTenant.owner.uid == userProfile.uid) {
|
|
348
|
-
userProfile.roles.push(Role.TenantOwner);
|
|
349
|
-
}
|
|
350
|
-
userProfile.tenantRecordId = userPermissions.currentTenant._id;
|
|
351
|
-
userProfile.package = userPermissions.currentTenant.package;
|
|
352
|
-
userProfile.branchRecordId = userPermissions.currentbranch._id;
|
|
353
|
-
userProfile.branchCode = userPermissions.currentbranch.branchCode;
|
|
354
|
-
userProfile.branchName = userPermissions.currentbranch.branchName;
|
|
355
|
-
userProfile.orgRecordId = userPermissions.currentorg._id;
|
|
356
|
-
userProfile.orgCode = userPermissions.currentorg.orgCode;
|
|
357
|
-
userProfile.orgName = userPermissions.currentorg.orgName;
|
|
358
|
-
userProfile.timeZone = userPermissions.currentorg.timeZone;
|
|
359
|
-
userProfile.currency = userPermissions.currentorg.currency;
|
|
360
|
-
userProfile.country = userPermissions.currentorg.country;
|
|
361
|
-
userProfile.offsetMinute = userPermissions.currentorg.offsetMinute;
|
|
362
|
-
userProfile.clientSetting = userPermissions.currentTenant.clientSetting;
|
|
363
|
-
}
|
|
364
|
-
} else {
|
|
365
|
-
userProfile.groups = [];
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
return userProfile;
|
|
369
|
-
};
|
|
403
|
+
];
|
|
404
|
+
const userProfiles: UserContextInfo[] = await this.userModel.aggregate(pipelines).exec();
|
|
405
|
+
return userProfiles[0];
|
|
406
|
+
}
|
|
370
407
|
|
|
371
408
|
setUserToken = async (tokenStr: string) => {
|
|
372
409
|
this.logger.debug(`===setUserToken===`);
|
|
@@ -375,16 +412,17 @@ export class UserContext {
|
|
|
375
412
|
this.token = tokenStr;
|
|
376
413
|
this.uid = tokeninfo?.sub ?? '';
|
|
377
414
|
this.email = <string>tokeninfo?.email ?? '';
|
|
378
|
-
this.
|
|
379
|
-
this.
|
|
415
|
+
this.uName = <string>tokeninfo?.preferred_username ?? '';
|
|
416
|
+
this.fullName = <string>tokeninfo?.name ?? '';
|
|
380
417
|
this.ssoACL = <Record<string, { roles: string[] }>>tokeninfo?.resource_access ?? {};
|
|
381
418
|
this.logger.debug(`User found ${this.uid}`);
|
|
382
419
|
|
|
383
420
|
const userProfile = await this.obtainProfileFromDB();
|
|
421
|
+
// console.log('userProfile', userProfile);
|
|
384
422
|
if (userProfile) {
|
|
385
423
|
this.logger.debug(`User ${this.uid} exists in tenant (${this.tenantId})`);
|
|
386
424
|
|
|
387
|
-
this._id = userProfile._id
|
|
425
|
+
this._id = userProfile._id;
|
|
388
426
|
this.branchCode = userProfile['branchCode'] ?? '';
|
|
389
427
|
this.branchName = userProfile['branchName'] ?? '';
|
|
390
428
|
this.orgCode = userProfile['orgCode'] ?? '';
|
|
@@ -395,12 +433,21 @@ export class UserContext {
|
|
|
395
433
|
this.offsetMinute = userProfile['offsetMinute'] ?? 0;
|
|
396
434
|
this.orgRecordId = userProfile['orgRecordId'] ?? '';
|
|
397
435
|
this.branchRecordId = userProfile['branchRecordId'] ?? '';
|
|
436
|
+
userProfile['branches'].forEach((b) => {
|
|
437
|
+
b.xOrg = this.generateXOrg(b.tenantId, b.orgId, b.branchId);
|
|
438
|
+
});
|
|
439
|
+
this.branches = userProfile['branches'];
|
|
398
440
|
this.groups = userProfile['groups'] ?? [];
|
|
399
|
-
this.clientSetting = userProfile['clientSetting'] ?? {
|
|
441
|
+
this.clientSetting = userProfile['clientSetting'] ?? {
|
|
442
|
+
auditTrail: false,
|
|
443
|
+
disableClassReminder: true,
|
|
444
|
+
webhook: false,
|
|
445
|
+
support: false,
|
|
446
|
+
};
|
|
400
447
|
this.roles = userProfile['roles'] ?? [Role.Everyone, Role.User];
|
|
401
|
-
this.moreProps = this.setMoreProps(userProfile);
|
|
448
|
+
// this.moreProps = this.setMoreProps(userProfile);
|
|
402
449
|
this.package = userProfile['package'];
|
|
403
|
-
this.appintegration = await this.setAppIntegration();
|
|
450
|
+
// this.appintegration = await this.setAppIntegration();
|
|
404
451
|
} else {
|
|
405
452
|
this.logger.debug(`User ${this.uid} not exists in tenant (${this.tenantId})`);
|
|
406
453
|
this.logger.debug(`Set unknown id of current user`);
|
|
@@ -410,11 +457,11 @@ export class UserContext {
|
|
|
410
457
|
if (this.isRealmAdmin() && !this.roles.includes(Role.SuperAdmin)) {
|
|
411
458
|
this.roles.push(Role.SuperAdmin);
|
|
412
459
|
}
|
|
413
|
-
|
|
414
|
-
this.logger.verbose(`User ${this.uid} have _id (${this.getId()}), groups (${this.groups.join(',')}) and roles (${this.getRoles().join(',')}).`);
|
|
460
|
+
// console.log('this.roles',this.roles)
|
|
461
|
+
// this.logger.verbose(`User ${this.uid} have _id (${this.getId()}), groups (${this.groups.join(',')}) and roles (${this.getRoles().join(',')}).`);
|
|
415
462
|
};
|
|
416
463
|
|
|
417
|
-
generateXOrg = (tenantId:
|
|
464
|
+
generateXOrg = (tenantId: Number, orgId: Number, branchId: Number): string => {
|
|
418
465
|
return Base64URL.encodeText(`${tenantId}-${orgId}-${branchId}`);
|
|
419
466
|
};
|
|
420
467
|
|
|
@@ -528,110 +575,57 @@ export class UserContext {
|
|
|
528
575
|
}
|
|
529
576
|
};
|
|
530
577
|
|
|
531
|
-
async getUserInfo(): Promise<
|
|
532
|
-
this.
|
|
578
|
+
async getUserInfo(): Promise<UserContextInfo> {
|
|
579
|
+
const userInfo = this.exportAsProfile();
|
|
580
|
+
return Promise.resolve(userInfo);
|
|
581
|
+
}
|
|
533
582
|
|
|
534
|
-
|
|
535
|
-
|
|
583
|
+
exportAsProfile(): UserContextInfo {
|
|
584
|
+
const result: UserContextInfo = {
|
|
585
|
+
//mongodb user._id
|
|
586
|
+
_id: this._id,
|
|
587
|
+
//keycloak: user sub id
|
|
588
|
+
uid: this.uid,
|
|
589
|
+
//rand: uuid
|
|
536
590
|
sessionId: this.sessionId,
|
|
537
|
-
|
|
538
|
-
|
|
591
|
+
xOrg: this.xOrg,
|
|
592
|
+
// tenant in number
|
|
593
|
+
tenantId: this.tenantId,
|
|
594
|
+
|
|
595
|
+
//org in number
|
|
596
|
+
orgId: this.orgId,
|
|
597
|
+
//org in string (organization._id)
|
|
539
598
|
orgRecordId: this.orgRecordId,
|
|
599
|
+
//branchid in number
|
|
600
|
+
branchId: this.branchId,
|
|
601
|
+
//branch id in string (branch._id)
|
|
540
602
|
branchRecordId: this.branchRecordId,
|
|
541
|
-
|
|
603
|
+
|
|
542
604
|
branchCode: this.branchCode,
|
|
543
605
|
branchName: this.branchName,
|
|
544
606
|
orgCode: this.orgCode,
|
|
545
607
|
orgName: this.orgName,
|
|
546
|
-
timeZone: this.
|
|
547
|
-
currency: this.
|
|
548
|
-
country: this.
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
fullName: this.
|
|
608
|
+
timeZone: this.timeZone,
|
|
609
|
+
currency: this.currency,
|
|
610
|
+
country: this.country,
|
|
611
|
+
//offset in minute, malaysia -480
|
|
612
|
+
offsetMinute: this.offsetMinute,
|
|
613
|
+
email: this.email,
|
|
614
|
+
fullName: this.fullName,
|
|
615
|
+
uName: this.uName,
|
|
553
616
|
groups: this.groups,
|
|
554
|
-
roles: this.
|
|
617
|
+
roles: this.roles,
|
|
555
618
|
branches: this.getBranches(),
|
|
556
619
|
invites: this.getInvites(),
|
|
557
|
-
moreProps: this.
|
|
558
|
-
appintegration: this.getAppIntegration(),
|
|
559
|
-
userType: this.getUserType(),
|
|
620
|
+
moreProps: this.moreProps,
|
|
560
621
|
};
|
|
561
|
-
|
|
562
|
-
if (this.getId() != '') {
|
|
563
|
-
this.logger.verbose('User Info: ' + JSON.stringify(userinfo));
|
|
564
|
-
const filter: PipelineStage = {
|
|
565
|
-
$match: {
|
|
566
|
-
uid: this.uid,
|
|
567
|
-
tenantId: this.tenantId,
|
|
568
|
-
},
|
|
569
|
-
};
|
|
570
|
-
const permission: PipelineStage = {
|
|
571
|
-
$lookup: {
|
|
572
|
-
from: 'permission',
|
|
573
|
-
localField: '_id',
|
|
574
|
-
foreignField: 'userId',
|
|
575
|
-
as: 'permissions',
|
|
576
|
-
pipeline: [
|
|
577
|
-
{
|
|
578
|
-
$lookup: {
|
|
579
|
-
from: 'branch',
|
|
580
|
-
localField: 'branchId',
|
|
581
|
-
foreignField: 'branchId',
|
|
582
|
-
as: 'branch',
|
|
583
|
-
},
|
|
584
|
-
},
|
|
585
|
-
],
|
|
586
|
-
},
|
|
587
|
-
};
|
|
588
|
-
const lookupInvitation: PipelineStage = {
|
|
589
|
-
$lookup: {
|
|
590
|
-
from: 'user',
|
|
591
|
-
localField: 'email',
|
|
592
|
-
foreignField: 'email',
|
|
593
|
-
as: 'invites',
|
|
594
|
-
pipeline: [
|
|
595
|
-
{ $match: { uid: '' } },
|
|
596
|
-
{
|
|
597
|
-
$lookup: {
|
|
598
|
-
from: 'tenant',
|
|
599
|
-
localField: 'tenantId',
|
|
600
|
-
foreignField: 'tenantId',
|
|
601
|
-
as: 'tenant',
|
|
602
|
-
},
|
|
603
|
-
},
|
|
604
|
-
],
|
|
605
|
-
},
|
|
606
|
-
};
|
|
607
|
-
|
|
608
|
-
const pipeline: PipelineStage[] = [filter, permission, lookupInvitation];
|
|
609
|
-
this.logger.verbose('User Info Pipeline: ' + JSON.stringify(pipeline));
|
|
610
|
-
|
|
611
|
-
const userInvitationsAndPermissions: Array<{
|
|
612
|
-
invites?: (ProfileUserInvites & { tenant: Tenant[] })[];
|
|
613
|
-
permissions?: (Permission & { branch: Branch[] })[];
|
|
614
|
-
}> = await this.userModel.aggregate(pipeline);
|
|
615
|
-
|
|
616
|
-
this.logger.verbose('User invitations & permissions data: ' + JSON.stringify(userInvitationsAndPermissions));
|
|
617
|
-
|
|
618
|
-
this.invites = userInvitationsAndPermissions[0].invites;
|
|
619
|
-
this.branches = userInvitationsAndPermissions[0].permissions;
|
|
620
|
-
|
|
621
|
-
userinfo.branches = this.getBranches();
|
|
622
|
-
userinfo.invites = this.getInvites();
|
|
623
|
-
} else if (this.getTenantId() > 0) {
|
|
624
|
-
throw new ForbiddenException(`userNotExistInTenant`, 'Access Deny');
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
return userinfo;
|
|
622
|
+
return result;
|
|
628
623
|
}
|
|
629
|
-
|
|
630
624
|
async decideInvitation(id: string, decision: string): Promise<boolean> {
|
|
631
625
|
const res = await this.userModel.findById(id);
|
|
632
626
|
if (!res.uid) {
|
|
633
627
|
res.uid = this.getUid();
|
|
634
|
-
res.fullName = this.
|
|
628
|
+
res.fullName = this.fullName;
|
|
635
629
|
res.active = true;
|
|
636
630
|
|
|
637
631
|
if (decision == 'accept') {
|
|
@@ -704,92 +698,151 @@ export class UserContext {
|
|
|
704
698
|
}
|
|
705
699
|
}
|
|
706
700
|
|
|
707
|
-
async getAllTenants(): Promise<
|
|
708
|
-
|
|
701
|
+
async getAllTenants(): Promise<TenantPermission[]> {
|
|
702
|
+
let results: TenantPermission[] = [];
|
|
709
703
|
if (this.getId() != '') {
|
|
710
|
-
const
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
pipeline: [
|
|
717
|
-
{
|
|
718
|
-
$lookup: {
|
|
719
|
-
from: 'organization',
|
|
720
|
-
localField: 'orgId',
|
|
721
|
-
foreignField: 'orgId',
|
|
722
|
-
as: 'org',
|
|
723
|
-
},
|
|
724
|
-
},
|
|
725
|
-
{ $unwind: '$org' },
|
|
726
|
-
{
|
|
727
|
-
$lookup: {
|
|
728
|
-
from: 'branch',
|
|
729
|
-
localField: 'branchId',
|
|
730
|
-
foreignField: 'branchId',
|
|
731
|
-
as: 'branch',
|
|
732
|
-
},
|
|
704
|
+
const pipelines: PipelineStage[] = [
|
|
705
|
+
{
|
|
706
|
+
$match: {
|
|
707
|
+
uid: this.uid,
|
|
708
|
+
tenantId: {
|
|
709
|
+
$gt: 0,
|
|
733
710
|
},
|
|
734
|
-
|
|
735
|
-
],
|
|
711
|
+
},
|
|
736
712
|
},
|
|
737
|
-
};
|
|
738
|
-
const pipelines: PipelineStage[] = [
|
|
739
|
-
{ $match: { uid: this.uid, tenantId: { $gt: 0 } } },
|
|
740
713
|
{
|
|
741
714
|
$lookup: {
|
|
742
715
|
from: 'tenant',
|
|
743
716
|
localField: 'tenantId',
|
|
744
717
|
foreignField: 'tenantId',
|
|
745
718
|
as: 'tenant',
|
|
719
|
+
pipeline: [{ $match: { active: true } }],
|
|
720
|
+
},
|
|
721
|
+
},
|
|
722
|
+
{
|
|
723
|
+
$unwind: '$tenant',
|
|
724
|
+
},
|
|
725
|
+
{
|
|
726
|
+
$lookup: {
|
|
727
|
+
from: 'permission',
|
|
728
|
+
localField: '_id',
|
|
729
|
+
foreignField: 'userId',
|
|
730
|
+
as: 'perms',
|
|
731
|
+
pipeline: [
|
|
732
|
+
{
|
|
733
|
+
$lookup: {
|
|
734
|
+
from: 'branch',
|
|
735
|
+
as: 'b',
|
|
736
|
+
localField: 'branchId',
|
|
737
|
+
foreignField: 'branchId',
|
|
738
|
+
pipeline: [
|
|
739
|
+
{
|
|
740
|
+
$lookup: {
|
|
741
|
+
from: 'organization',
|
|
742
|
+
as: 'org',
|
|
743
|
+
localField: 'organization._id',
|
|
744
|
+
foreignField: '_id',
|
|
745
|
+
},
|
|
746
|
+
},
|
|
747
|
+
{ $unwind: '$org' },
|
|
748
|
+
{
|
|
749
|
+
$project: {
|
|
750
|
+
branch: {
|
|
751
|
+
_id: '$_id',
|
|
752
|
+
code: '$branchCode',
|
|
753
|
+
label: '$branchName',
|
|
754
|
+
},
|
|
755
|
+
organization: {
|
|
756
|
+
_id: '$org._id',
|
|
757
|
+
code: '$org.orgCode',
|
|
758
|
+
label: '$org.orgName',
|
|
759
|
+
},
|
|
760
|
+
},
|
|
761
|
+
},
|
|
762
|
+
],
|
|
763
|
+
},
|
|
764
|
+
},
|
|
765
|
+
{ $unwind: '$b' },
|
|
766
|
+
{
|
|
767
|
+
$project: {
|
|
768
|
+
tenantId: 1,
|
|
769
|
+
orgId: 1,
|
|
770
|
+
branchId: 1,
|
|
771
|
+
branch: '$b.branch',
|
|
772
|
+
groups: 1,
|
|
773
|
+
organization: '$b.organization',
|
|
774
|
+
},
|
|
775
|
+
},
|
|
776
|
+
],
|
|
777
|
+
},
|
|
778
|
+
},
|
|
779
|
+
{
|
|
780
|
+
$project: {
|
|
781
|
+
tenantName: '$tenant.tenantName',
|
|
782
|
+
perms: 1,
|
|
746
783
|
},
|
|
747
784
|
},
|
|
748
|
-
permission,
|
|
749
785
|
];
|
|
750
786
|
|
|
751
|
-
const
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
787
|
+
const datas = await this.userModel.aggregate(pipelines);
|
|
788
|
+
for (const r of datas) {
|
|
789
|
+
const perms: ProfileUserBranch[] = [];
|
|
790
|
+
for (const p of r.perms) {
|
|
791
|
+
perms.push({
|
|
792
|
+
permissionId: p._id,
|
|
793
|
+
tenantId: p.tenantId,
|
|
794
|
+
orgId: p.orgId,
|
|
795
|
+
branchId: p.branchId,
|
|
796
|
+
groups: p.groups,
|
|
797
|
+
branch: p.branch,
|
|
798
|
+
orgRecordId: p.organization._id,
|
|
799
|
+
xOrg: this.generateXOrg(p.tenantId, p.orgId, p.branchId),
|
|
800
|
+
});
|
|
755
801
|
}
|
|
756
|
-
> = await this.userModel.aggregate(pipelines);
|
|
757
802
|
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
});
|
|
762
|
-
|
|
763
|
-
activeUserTenants.forEach((activeUserTenant) => {
|
|
764
|
-
const permissions = activeUserTenant.permissions
|
|
765
|
-
.filter((item) => {
|
|
766
|
-
return item.org.active && item.branch.active;
|
|
767
|
-
})
|
|
768
|
-
.map((item) => {
|
|
769
|
-
return {
|
|
770
|
-
_id: item._id,
|
|
771
|
-
orgId: item.orgId,
|
|
772
|
-
branchId: item.branchId,
|
|
773
|
-
groups: item.groups,
|
|
774
|
-
orgRecordId: item.org._id,
|
|
775
|
-
orgCode: item.org.orgCode,
|
|
776
|
-
orgName: item.org.orgName,
|
|
777
|
-
branchCode: item.branch.branchCode,
|
|
778
|
-
branchName: item.branch.branchName,
|
|
779
|
-
xOrg: this.generateXOrg(activeUserTenant.tenantId, item.orgId, item.branchId),
|
|
780
|
-
};
|
|
781
|
-
});
|
|
782
|
-
|
|
783
|
-
results.push({
|
|
784
|
-
_id: activeUserTenant._id,
|
|
785
|
-
fullName: activeUserTenant.fullName,
|
|
786
|
-
tenantId: activeUserTenant.tenantId,
|
|
787
|
-
tenantName: activeUserTenant.tenant[0].tenantName,
|
|
788
|
-
permissions: permissions,
|
|
789
|
-
});
|
|
803
|
+
results.push({
|
|
804
|
+
tenantName: r.tenantName,
|
|
805
|
+
permissions: perms,
|
|
790
806
|
});
|
|
791
807
|
}
|
|
808
|
+
|
|
809
|
+
// if (userTenants) {
|
|
810
|
+
// const activeUserTenants = userTenants.filter((userTenant) => {
|
|
811
|
+
// return userTenant.active === true && userTenant.tenant[0].active === true;
|
|
812
|
+
// });
|
|
813
|
+
|
|
814
|
+
// activeUserTenants.forEach((activeUserTenant) => {
|
|
815
|
+
// const permissions = activeUserTenant.permissions
|
|
816
|
+
// .filter((item) => {
|
|
817
|
+
// return item.org.active && item.branch.active;
|
|
818
|
+
// })
|
|
819
|
+
// .map((item) => {
|
|
820
|
+
// return {
|
|
821
|
+
// _id: item._id,
|
|
822
|
+
// orgId: item.orgId,
|
|
823
|
+
// branchId: item.branchId,
|
|
824
|
+
// groups: item.groups,
|
|
825
|
+
// orgRecordId: item.org._id,
|
|
826
|
+
// orgCode: item.org.orgCode,
|
|
827
|
+
// orgName: item.org.orgName,
|
|
828
|
+
// branchCode: item.branch.branchCode,
|
|
829
|
+
// branchName: item.branch.branchName,
|
|
830
|
+
// xOrg: this.generateXOrg(activeUserTenant.tenantId, item.orgId, item.branchId),
|
|
831
|
+
// };
|
|
832
|
+
// });
|
|
833
|
+
|
|
834
|
+
// results.push({
|
|
835
|
+
// _id: activeUserTenant._id,
|
|
836
|
+
// fullName: activeUserTenant.fullName,
|
|
837
|
+
// tenantId: activeUserTenant.tenantId,
|
|
838
|
+
// tenantName: activeUserTenant.tenant[0].tenantName.toString(),
|
|
839
|
+
// permissions: permissions,
|
|
840
|
+
// });
|
|
841
|
+
// });
|
|
842
|
+
// }
|
|
792
843
|
}
|
|
844
|
+
|
|
845
|
+
// console.log(JSON.stringify(results,null,2))
|
|
793
846
|
return results;
|
|
794
847
|
}
|
|
795
848
|
|
|
@@ -798,8 +851,8 @@ export class UserContext {
|
|
|
798
851
|
this.token = '';
|
|
799
852
|
this.uid = uid;
|
|
800
853
|
this.email = email;
|
|
801
|
-
this.
|
|
802
|
-
this.
|
|
854
|
+
this.uName = uname;
|
|
855
|
+
this.fullName = name;
|
|
803
856
|
this.ssoACL = {};
|
|
804
857
|
this.roles = [Role.Everyone, Role.User, Role.SuperUser];
|
|
805
858
|
this.setXOrg(xorg);
|
|
@@ -829,6 +882,7 @@ export class UserContext {
|
|
|
829
882
|
|
|
830
883
|
async setMiniApiUser(tokenStr: string, xOrg: string) {
|
|
831
884
|
const tokenInfo: TMiniApiTokenInfo = jwt.decode(tokenStr) as TMiniApiTokenInfo;
|
|
885
|
+
|
|
832
886
|
const appId = tokenInfo?.miniAppId ?? '';
|
|
833
887
|
|
|
834
888
|
this.setXOrg(xOrg);
|
|
@@ -843,7 +897,7 @@ export class UserContext {
|
|
|
843
897
|
}
|
|
844
898
|
|
|
845
899
|
this.token = tokenStr;
|
|
846
|
-
this.uid = miniAppInstallation.miniApiUser.uid;
|
|
900
|
+
this.uid = miniAppInstallation.miniApiUser.uid.toString();
|
|
847
901
|
|
|
848
902
|
await this.setUserProfileFromDB();
|
|
849
903
|
}
|
|
@@ -865,66 +919,63 @@ export class UserContext {
|
|
|
865
919
|
}
|
|
866
920
|
|
|
867
921
|
async setUserProfileFromDB() {
|
|
868
|
-
const userProfile = await this.obtainProfileFromDB();
|
|
869
|
-
if (userProfile) {
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
this.logger.verbose(`User ${this.uid} have _id (${this.getId()}), groups (${this.groups.join(',')}) and roles (${this.getRoles().join(',')}).`);
|
|
922
|
+
// const userProfile = await this.obtainProfileFromDB();
|
|
923
|
+
// if (userProfile) {
|
|
924
|
+
// this.logger.debug(`User ${this.uid} exists in tenant (${this.tenantId})`);
|
|
925
|
+
// this._id = userProfile._id.toString();
|
|
926
|
+
// this.email = userProfile.email ?? '';
|
|
927
|
+
// this.uName = userProfile.uname ?? '';
|
|
928
|
+
// this.fullName = userProfile.fullname ?? '';
|
|
929
|
+
// this.branchCode = userProfile['branchCode'] ?? '';
|
|
930
|
+
// this.branchName = userProfile['branchName'] ?? '';
|
|
931
|
+
// this.orgCode = userProfile['orgCode'] ?? '';
|
|
932
|
+
// this.orgName = userProfile['orgName'] ?? '';
|
|
933
|
+
// this.timeZone = userProfile['timeZone'] ?? '';
|
|
934
|
+
// this.currency = userProfile['currency'] ?? '';
|
|
935
|
+
// this.country = userProfile['country'] ?? '';
|
|
936
|
+
// this.offsetMinute = userProfile['offsetMinute'] ?? 0;
|
|
937
|
+
// this.orgRecordId = userProfile['orgRecordId'] ?? '';
|
|
938
|
+
// this.branchRecordId = userProfile['branchRecordId'] ?? '';
|
|
939
|
+
// this.groups = userProfile['groups'] ?? [];
|
|
940
|
+
// this.roles = userProfile['roles'] ?? [Role.Everyone, Role.User];
|
|
941
|
+
// //more complex
|
|
942
|
+
// this.clientSetting = userProfile['clientSetting'] ?? {};
|
|
943
|
+
// this.moreProps = this.setMoreProps(userProfile);
|
|
944
|
+
// this.package = userProfile['package'];
|
|
945
|
+
// // this.appintegration = await this.setAppIntegration();
|
|
946
|
+
// } else {
|
|
947
|
+
// this.logger.debug(`User ${this.uid} not exists in tenant (${this.tenantId})`);
|
|
948
|
+
// this.logger.debug(`Set unknown id of current user`);
|
|
949
|
+
// this.roles = [Role.Everyone, Role.Unknown];
|
|
950
|
+
// }
|
|
951
|
+
// if (this.isRealmAdmin() && !this.roles.includes(Role.SuperAdmin)) {
|
|
952
|
+
// this.roles.push(Role.SuperAdmin);
|
|
953
|
+
// }
|
|
954
|
+
// this.logger.verbose(`User ${this.uid} have _id (${this.getId()}), groups (${this.groups.join(',')}) and roles (${this.getRoles().join(',')}).`);
|
|
904
955
|
}
|
|
905
956
|
|
|
906
|
-
getAppIntegration = () => this.appintegration;
|
|
907
|
-
|
|
908
|
-
async setAppIntegration() {
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
}
|
|
957
|
+
// getAppIntegration = () => this.appintegration;
|
|
958
|
+
|
|
959
|
+
// async setAppIntegration() {
|
|
960
|
+
// const extension: PipelineStage[] = [
|
|
961
|
+
// {
|
|
962
|
+
// $match: {
|
|
963
|
+
// branchId: this.getBranchId(),
|
|
964
|
+
// tenantId: this.getTenantId(),
|
|
965
|
+
// active: true,
|
|
966
|
+
// },
|
|
967
|
+
// },
|
|
968
|
+
// ];
|
|
969
|
+
|
|
970
|
+
// const appintegration = await this.appModel.aggregate(extension);
|
|
971
|
+
// if (appintegration && appintegration.length > 0) {
|
|
972
|
+
// appintegration.forEach((item) => {
|
|
973
|
+
// if (item.appId === 'simbiz6') this.appintegration.simbiz6 = true;
|
|
974
|
+
// if (item.appId === 'einvoice') this.appintegration.einvoice = true;
|
|
975
|
+
// });
|
|
976
|
+
// }
|
|
977
|
+
// return this.appintegration;
|
|
978
|
+
// }
|
|
928
979
|
|
|
929
980
|
/**
|
|
930
981
|
* Define additional properties from user into moreProps
|
|
@@ -952,7 +1003,7 @@ export class UserContext {
|
|
|
952
1003
|
'country',
|
|
953
1004
|
'offsetMinute',
|
|
954
1005
|
'tenantId',
|
|
955
|
-
'lastActivity',
|
|
1006
|
+
// 'lastActivity',
|
|
956
1007
|
'group',
|
|
957
1008
|
'__v',
|
|
958
1009
|
'uid',
|
|
@@ -1015,7 +1066,7 @@ type UserProfile = {
|
|
|
1015
1066
|
country?: string;
|
|
1016
1067
|
offsetMinute?: number;
|
|
1017
1068
|
clientSetting?: TenantClientSetting;
|
|
1018
|
-
lastActivity?: string;
|
|
1069
|
+
// lastActivity?: string;
|
|
1019
1070
|
permissions: {
|
|
1020
1071
|
_id: string;
|
|
1021
1072
|
tenantId: number;
|
|
@@ -1050,34 +1101,3 @@ type UserProfile = {
|
|
|
1050
1101
|
};
|
|
1051
1102
|
};
|
|
1052
1103
|
};
|
|
1053
|
-
|
|
1054
|
-
type UserInfo = {
|
|
1055
|
-
_id: string;
|
|
1056
|
-
sessionId: string;
|
|
1057
|
-
tenantId: number;
|
|
1058
|
-
orgId: number;
|
|
1059
|
-
orgRecordId: string;
|
|
1060
|
-
branchRecordId: string;
|
|
1061
|
-
branchId: number;
|
|
1062
|
-
branchCode: string;
|
|
1063
|
-
branchName: string;
|
|
1064
|
-
orgCode: string;
|
|
1065
|
-
orgName: string;
|
|
1066
|
-
timeZone: string;
|
|
1067
|
-
currency: string;
|
|
1068
|
-
country: string;
|
|
1069
|
-
offsetMinute: number;
|
|
1070
|
-
email: string;
|
|
1071
|
-
uid: string;
|
|
1072
|
-
fullName: string;
|
|
1073
|
-
groups: string[];
|
|
1074
|
-
roles: Role[];
|
|
1075
|
-
branches: ProfileUserBranch[];
|
|
1076
|
-
invites: ProfileUserInvites[];
|
|
1077
|
-
moreProps: Record<string, any>;
|
|
1078
|
-
};
|
|
1079
|
-
|
|
1080
|
-
type UserTenant = User & {
|
|
1081
|
-
tenantName: string;
|
|
1082
|
-
permissions: Permission[];
|
|
1083
|
-
};
|