@webitel/ui-sdk 24.12.95 → 24.12.97

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/ui-sdk.css +1 -1
  3. package/dist/ui-sdk.js +3179 -3219
  4. package/dist/ui-sdk.umd.cjs +16 -16
  5. package/package.json +14 -8
  6. package/src/api/defaults/getDefaultInstance/getDefaultInstance.js +5 -2
  7. package/src/api/defaults/index.js +1 -1
  8. package/src/components/wt-dual-panel/wt-dual-panel.vue +1 -2
  9. package/src/components/wt-icon-action/iconMappings.js +1 -1
  10. package/src/composables/useAccessControl/v2/createUserAccessControl.ts +66 -0
  11. package/src/composables/useAccessControl/v2/types/CreateUserAccessControl.d.ts +21 -0
  12. package/src/enums/CrudAction/CrudAction.js +6 -0
  13. package/src/enums/CrudAction/CrudAction.ts +8 -0
  14. package/src/enums/WtObject/WtObject.js +51 -1
  15. package/src/enums/WtObject/WtObject.ts +51 -1
  16. package/src/enums/index.js +6 -19
  17. package/src/enums/index.ts +33 -0
  18. package/src/locale/en/en.js +1 -1
  19. package/src/locale/ru/ru.js +1 -1
  20. package/src/locale/ua/ua.js +1 -1
  21. package/src/modules/Filters/v2/headers/createTableHeadersStore.ts +127 -78
  22. package/src/modules/Filters/v2/persist/usePersistedStorage.ts +0 -5
  23. package/src/modules/Filters/v2/table/createTableStore.store.ts +3 -2
  24. package/src/modules/Userinfo/api/userinfo.js +21 -34
  25. package/src/modules/Userinfo/store/UserinfoStoreModule.js +1 -1
  26. package/src/modules/Userinfo/v2/api/UserinfoAPI.ts +62 -0
  27. package/src/modules/Userinfo/v2/enums/GlobalActions/GlobalActions.ts +36 -0
  28. package/src/modules/Userinfo/v2/enums/ScopeClass/ScopeClass.ts +47 -0
  29. package/src/modules/Userinfo/v2/enums/index.ts +7 -0
  30. package/src/modules/Userinfo/v2/index.ts +0 -0
  31. package/src/modules/Userinfo/v2/mappings/mappings.ts +161 -0
  32. package/src/modules/Userinfo/v2/scripts/utils.ts +123 -0
  33. package/src/modules/Userinfo/v2/stores/__tests__/accessStore.spec.ts +136 -0
  34. package/src/modules/Userinfo/v2/stores/accessStore.ts +131 -0
  35. package/src/modules/Userinfo/v2/stores/userinfoStore.ts +56 -0
  36. package/src/modules/Userinfo/v2/types/UserAccess.d.ts +118 -0
@@ -0,0 +1,131 @@
1
+ import { defineStore } from 'pinia';
2
+ import { NavigationGuard } from 'vue-router';
3
+
4
+ import {
5
+ CrudAction,
6
+ type WtApplication,
7
+ type WtObject,
8
+ } from '../../../../enums';
9
+ import type { SpecialGlobalAction } from '../enums';
10
+ import {
11
+ getWtAppByUiSection,
12
+ makeAppVisibilityMap,
13
+ makeGlobalAccessMap,
14
+ makeScopeAccessMap,
15
+ makeSectionVisibilityMap,
16
+ } from '../scripts/utils';
17
+ import type {
18
+ AppVisibilityMap,
19
+ CreateUserAccessStoreConfig,
20
+ CreateUserAccessStoreRawAccess,
21
+ GlobalActionAccessMap,
22
+ ScopeAccessMap,
23
+ SectionVisibilityMap,
24
+ UiSection,
25
+ UserAccessStore,
26
+ } from '../types/UserAccess.d.ts';
27
+
28
+ export const createUserAccessStore = ({
29
+ namespace = 'userinfo',
30
+ }: CreateUserAccessStoreConfig = {}) => {
31
+ return defineStore(`${namespace}/access`, (): UserAccessStore => {
32
+ let globalAccess: GlobalActionAccessMap = new Map();
33
+
34
+ let scopeAccess: ScopeAccessMap = new Map();
35
+
36
+ let appVisibilityAccess: AppVisibilityMap = new Map();
37
+
38
+ let sectionVisibilityAccess: SectionVisibilityMap = new Map();
39
+
40
+ const hasAccess = (
41
+ action: CrudAction | SpecialGlobalAction,
42
+ object?: WtObject,
43
+ ) => {
44
+ const allowGlobalAccess = globalAccess.get(action);
45
+ if (allowGlobalAccess) return true;
46
+
47
+ const allowScopeAccess =
48
+ object && scopeAccess.get(object)?.get(action as CrudAction);
49
+ if (allowScopeAccess) return true;
50
+
51
+ return false;
52
+ };
53
+
54
+ const hasReadAccess = (object?: WtObject) => {
55
+ return hasAccess(CrudAction.Read, object);
56
+ };
57
+
58
+ const hasCreateAccess = (object?: WtObject) => {
59
+ return hasAccess(CrudAction.Create, object);
60
+ };
61
+
62
+ const hasUpdateAccess = (object?: WtObject) => {
63
+ return hasAccess(CrudAction.Update, object);
64
+ };
65
+
66
+ const hasDeleteAccess = (object?: WtObject) => {
67
+ return hasAccess(CrudAction.Delete, object);
68
+ };
69
+
70
+ const hasApplicationVisibility = (app: WtApplication) => {
71
+ return hasReadAccess() || appVisibilityAccess.get(app);
72
+ };
73
+
74
+ const hasSectionVisibility = (section: UiSection, object: WtObject) => {
75
+ const appOfSection = getWtAppByUiSection(section);
76
+ const objectOfSection = object; /*castUiSectionToWtObject(section)*/
77
+ const hasSectionVisibilityAccess = (section: UiSection) => {
78
+ return sectionVisibilityAccess.get(section);
79
+ };
80
+
81
+ const allowGlobalAccess = hasReadAccess();
82
+ if (allowGlobalAccess) return true;
83
+
84
+ const allowAppVisibility = hasApplicationVisibility(appOfSection);
85
+ const allowObjectAccess = hasReadAccess(objectOfSection);
86
+ const allowSectionVisibility = hasSectionVisibilityAccess(section);
87
+
88
+ return allowAppVisibility && allowObjectAccess && allowSectionVisibility;
89
+ };
90
+
91
+ const routeAccessGuard: NavigationGuard = (to) => {
92
+ /* find last because "matched" has top=>bottom routes order */
93
+ const uiSection = to.matched
94
+ .toReversed()
95
+ .find(({ meta }) => meta.UiSection)?.meta?.UiSection as UiSection;
96
+ /* find last because "matched" has top=>bottom routes order */
97
+ const wtObject = to.matched
98
+ .toReversed()
99
+ .find(({ meta }) => meta.UiSection)?.meta?.WtObject as WtObject;
100
+
101
+ if (uiSection && !hasSectionVisibility(uiSection, wtObject)) {
102
+ // return false;
103
+ return { path: '/access-denied' };
104
+ }
105
+
106
+ return true;
107
+ };
108
+
109
+ const initialize = ({
110
+ permissions: rawGlobalAccess,
111
+ scope: rawScopeAccess,
112
+ access: rawVisibilityAccess,
113
+ }: CreateUserAccessStoreRawAccess) => {
114
+ globalAccess = makeGlobalAccessMap(rawGlobalAccess);
115
+ scopeAccess = makeScopeAccessMap(rawScopeAccess);
116
+ appVisibilityAccess = makeAppVisibilityMap(rawVisibilityAccess);
117
+ sectionVisibilityAccess = makeSectionVisibilityMap(rawVisibilityAccess);
118
+ };
119
+
120
+ return {
121
+ initialize,
122
+
123
+ hasReadAccess,
124
+ hasCreateAccess,
125
+ hasUpdateAccess,
126
+ hasDeleteAccess,
127
+
128
+ routeAccessGuard,
129
+ };
130
+ });
131
+ };
@@ -0,0 +1,56 @@
1
+ import { defineStore } from 'pinia';
2
+ import { ref } from 'vue';
3
+
4
+ import { getSession, getUiVisibilityAccess } from '../api/UserinfoAPI';
5
+ import { createUserAccessStore } from './accessStore';
6
+
7
+ export const createUserinfoStore = () => {
8
+ const namespace = 'userinfo';
9
+ const useAccessStore = createUserAccessStore({
10
+ namespace,
11
+ });
12
+
13
+ const store = defineStore(namespace, () => {
14
+ const accessStore = useAccessStore();
15
+ const {
16
+ hasReadAccess,
17
+ hasCreateAccess,
18
+ hasUpdateAccess,
19
+ hasDeleteAccess,
20
+ initialize: initializeAccessStore,
21
+ routeAccessGuard,
22
+ } = accessStore;
23
+
24
+ const userId = ref();
25
+
26
+ const initialize = async () => {
27
+ const { scope, permissions, ...userinfo } = await getSession();
28
+ const access = await getUiVisibilityAccess();
29
+
30
+ userId.value = userinfo.userId;
31
+
32
+ initializeAccessStore({
33
+ scope,
34
+ permissions,
35
+ access,
36
+ });
37
+ };
38
+
39
+ return {
40
+ userId,
41
+ initialize,
42
+
43
+ hasReadAccess,
44
+ hasCreateAccess,
45
+ hasUpdateAccess,
46
+ hasDeleteAccess,
47
+
48
+ routeAccessGuard,
49
+ };
50
+ });
51
+
52
+ // @ts-ignore
53
+ window._userinfoStore = store;
54
+
55
+ return store;
56
+ };
@@ -0,0 +1,118 @@
1
+ import { NavigationGuard } from 'vue-router';
2
+
3
+ import type {
4
+ AdminSections,
5
+ AuditorSections,
6
+ CrmSections,
7
+ CrudAction,
8
+ SupervisorSections,
9
+ WtApplication,
10
+ WtObject,
11
+ } from '../../../../enums';
12
+ import type {
13
+ CrudGlobalAction,
14
+ ScopeClass,
15
+ SpecialGlobalAction,
16
+ } from '../enums';
17
+
18
+ /**
19
+ * @description
20
+ * Represents union of all Webitel web client applications/sections
21
+ * */
22
+ export type UiSection =
23
+ | AdminSections
24
+ | AuditorSections
25
+ | SupervisorSections
26
+ | CrmSections;
27
+
28
+ /**
29
+ * @internal
30
+ * @description Received from backend
31
+ * */
32
+ export type GlobalAction = CrudGlobalAction | SpecialGlobalAction;
33
+
34
+ /**
35
+ * @internal
36
+ * */
37
+ export interface GlobalAccessApiResponseItem {
38
+ id: GlobalAction;
39
+ name: string;
40
+ usage: string;
41
+ }
42
+
43
+ /**
44
+ * @internal
45
+ * */
46
+ export interface ScopeAccessApiResponseItem {
47
+ class: ScopeClass;
48
+ access: string;
49
+ }
50
+
51
+ /**
52
+ * @internal
53
+ * @description
54
+ * Represents admin->permissions->roles->access.
55
+ * */
56
+ export type VisibilityAccess = unknown;
57
+
58
+ /**
59
+ * @internal
60
+ * @description
61
+ * Represents raw access data, received from backend.
62
+ * */
63
+ export interface CreateUserAccessStoreRawAccess {
64
+ permissions: GlobalAccessApiResponseItem[];
65
+ scope: ScopeAccessApiResponseItem[];
66
+ access: VisibilityAccess;
67
+ }
68
+
69
+ /**
70
+ * @internal
71
+ */
72
+ export interface CreateUserAccessStoreConfig {
73
+ /**
74
+ * @default 'userinfo'
75
+ * */
76
+ namespace?: string;
77
+ }
78
+
79
+ /**
80
+ * @description
81
+ * Map is used for quick access to user permissions
82
+ * */
83
+ export type GlobalActionAccessMap = Map<
84
+ CrudAction | SpecialGlobalAction,
85
+ boolean
86
+ >;
87
+
88
+ /**
89
+ * @description
90
+ * Map is used for quick access to user permissions
91
+ * */
92
+ export type ScopeAccessMap = Map<WtObject, Map<CrudAction, boolean>>;
93
+
94
+ /**
95
+ * @description
96
+ * Map is used for quick access to user permissions
97
+ * */
98
+ export type AppVisibilityMap = Map<WtApplication, boolean>;
99
+
100
+ /**
101
+ * @description
102
+ * Map is used for quick access to user permissions
103
+ * */
104
+ export type SectionVisibilityMap = Map<UiSection, boolean>;
105
+
106
+ export interface UserAccessStore {
107
+ initialize: (CreateUserAccessStoreRawAccess) => void;
108
+
109
+ hasReadAccess: (object?: WtObject) => boolean;
110
+ hasCreateAccess: (object?: WtObject) => boolean;
111
+ hasUpdateAccess: (object?: WtObject) => boolean;
112
+ hasDeleteAccess: (object?: WtObject) => boolean;
113
+
114
+ routeAccessGuard: NavigationGuard;
115
+
116
+ // hasApplicationVisibility: (app: WtApplication) => boolean;
117
+ // hasSectionVisibility: (section: UiSection) => boolean;
118
+ }