@tsed/react-formio 1.14.1 → 2.0.0

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 (174) hide show
  1. package/coverage.json +4 -4
  2. package/dist/index.d.ts +3 -2
  3. package/dist/index.js +1277 -3684
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.modern.js +956 -2767
  6. package/dist/index.modern.js.map +1 -1
  7. package/package.json +4 -5
  8. package/readme.md +9 -57
  9. package/src/components/input-tags/inputTags.component.tsx +1 -1
  10. package/src/components/select/select.component.tsx +1 -1
  11. package/src/components/table/filters/sliderColumnFilter.component.tsx +2 -2
  12. package/src/index.ts +3 -2
  13. package/dist/stores/action/action.actions.d.ts +0 -9
  14. package/dist/stores/action/action.actions.spec.d.ts +0 -1
  15. package/dist/stores/action/action.constant.d.ts +0 -1
  16. package/dist/stores/action/action.reducers.d.ts +0 -7
  17. package/dist/stores/action/action.reducers.spec.d.ts +0 -1
  18. package/dist/stores/action/action.selectors.d.ts +0 -2
  19. package/dist/stores/action/action.selectors.spec.d.ts +0 -1
  20. package/dist/stores/action/index.d.ts +0 -4
  21. package/dist/stores/action-info/action-info.actions.d.ts +0 -5
  22. package/dist/stores/action-info/action-info.actions.spec.d.ts +0 -1
  23. package/dist/stores/action-info/action-info.constant.d.ts +0 -1
  24. package/dist/stores/action-info/action-info.reducers.d.ts +0 -7
  25. package/dist/stores/action-info/action-info.reducers.spec.d.ts +0 -1
  26. package/dist/stores/action-info/action-info.selectors.d.ts +0 -2
  27. package/dist/stores/action-info/action-info.selectors.spec.d.ts +0 -1
  28. package/dist/stores/action-info/index.d.ts +0 -4
  29. package/dist/stores/actions/actions.actions.d.ts +0 -5
  30. package/dist/stores/actions/actions.actions.spec.d.ts +0 -1
  31. package/dist/stores/actions/actions.constant.d.ts +0 -1
  32. package/dist/stores/actions/actions.reducers.d.ts +0 -8
  33. package/dist/stores/actions/actions.reducers.spec.d.ts +0 -1
  34. package/dist/stores/actions/actions.selectors.d.ts +0 -2
  35. package/dist/stores/actions/actions.selectors.spec.d.ts +0 -1
  36. package/dist/stores/actions/index.d.ts +0 -4
  37. package/dist/stores/auth/auth.actions.d.ts +0 -9
  38. package/dist/stores/auth/auth.constant.d.ts +0 -1
  39. package/dist/stores/auth/auth.reducers.d.ts +0 -16
  40. package/dist/stores/auth/auth.reducers.spec.d.ts +0 -1
  41. package/dist/stores/auth/auth.selectors.d.ts +0 -6
  42. package/dist/stores/auth/auth.selectors.spec.d.ts +0 -1
  43. package/dist/stores/auth/auth.utils.d.ts +0 -6
  44. package/dist/stores/auth/auth.utils.spec.d.ts +0 -1
  45. package/dist/stores/auth/getAccess.action.d.ts +0 -1
  46. package/dist/stores/auth/getAccess.action.spec.d.ts +0 -1
  47. package/dist/stores/auth/getProjectAccess.action.d.ts +0 -1
  48. package/dist/stores/auth/index.d.ts +0 -10
  49. package/dist/stores/auth/initAuth.action.d.ts +0 -1
  50. package/dist/stores/auth/initAuth.action.spec.d.ts +0 -1
  51. package/dist/stores/auth/logout.action.d.ts +0 -1
  52. package/dist/stores/auth/logout.action.spec.d.ts +0 -1
  53. package/dist/stores/auth/setUser.action.d.ts +0 -1
  54. package/dist/stores/auth/setUser.action.spec.d.ts +0 -1
  55. package/dist/stores/form/form.actions.d.ts +0 -10
  56. package/dist/stores/form/form.actions.spec.d.ts +0 -1
  57. package/dist/stores/form/form.reducers.d.ts +0 -9
  58. package/dist/stores/form/form.reducers.spec.d.ts +0 -1
  59. package/dist/stores/form/form.selectors.d.ts +0 -2
  60. package/dist/stores/form/form.selectors.spec.d.ts +0 -1
  61. package/dist/stores/form/index.d.ts +0 -3
  62. package/dist/stores/forms/forms.actions.d.ts +0 -9
  63. package/dist/stores/forms/forms.actions.spec.d.ts +0 -1
  64. package/dist/stores/forms/forms.reducers.d.ts +0 -16
  65. package/dist/stores/forms/forms.reducers.spec.d.ts +0 -1
  66. package/dist/stores/forms/forms.selectors.d.ts +0 -10
  67. package/dist/stores/forms/forms.selectors.spec.d.ts +0 -1
  68. package/dist/stores/forms/index.d.ts +0 -3
  69. package/dist/stores/index.d.ts +0 -10
  70. package/dist/stores/index.spec.d.ts +0 -1
  71. package/dist/stores/root/index.d.ts +0 -1
  72. package/dist/stores/root/root.selectors.d.ts +0 -5
  73. package/dist/stores/root/root.selectors.spec.d.ts +0 -1
  74. package/dist/stores/submission/index.d.ts +0 -3
  75. package/dist/stores/submission/submission.actions.d.ts +0 -10
  76. package/dist/stores/submission/submission.actions.spec.d.ts +0 -1
  77. package/dist/stores/submission/submission.reducers.d.ts +0 -11
  78. package/dist/stores/submission/submission.reducers.spec.d.ts +0 -1
  79. package/dist/stores/submission/submission.selectors.d.ts +0 -2
  80. package/dist/stores/submission/submission.selectors.spec.d.ts +0 -1
  81. package/dist/stores/submissions/index.d.ts +0 -3
  82. package/dist/stores/submissions/submissions.actions.d.ts +0 -6
  83. package/dist/stores/submissions/submissions.actions.spec.d.ts +0 -1
  84. package/dist/stores/submissions/submissions.reducers.d.ts +0 -17
  85. package/dist/stores/submissions/submissions.reducers.spec.d.ts +0 -1
  86. package/dist/stores/submissions/submissions.selectors.d.ts +0 -9
  87. package/dist/stores/submissions/submissions.selectors.spec.d.ts +0 -1
  88. package/dist/utils/clean.d.ts +0 -1
  89. package/dist/utils/clean.test.d.ts +0 -1
  90. package/dist/utils/mapRequestParams.d.ts +0 -9
  91. package/dist/utils/mapRequestParams.test.d.ts +0 -1
  92. package/dist/utils/url.d.ts +0 -3
  93. package/dist/utils/url.test.d.ts +0 -1
  94. package/src/stores/action/action.actions.spec.ts +0 -114
  95. package/src/stores/action/action.actions.ts +0 -82
  96. package/src/stores/action/action.constant.ts +0 -1
  97. package/src/stores/action/action.reducers.spec.ts +0 -91
  98. package/src/stores/action/action.reducers.ts +0 -54
  99. package/src/stores/action/action.selectors.spec.ts +0 -19
  100. package/src/stores/action/action.selectors.ts +0 -6
  101. package/src/stores/action/index.ts +0 -4
  102. package/src/stores/action-info/action-info.actions.spec.ts +0 -46
  103. package/src/stores/action-info/action-info.actions.ts +0 -32
  104. package/src/stores/action-info/action-info.constant.ts +0 -1
  105. package/src/stores/action-info/action-info.reducers.spec.ts +0 -60
  106. package/src/stores/action-info/action-info.reducers.ts +0 -44
  107. package/src/stores/action-info/action-info.selectors.spec.ts +0 -19
  108. package/src/stores/action-info/action-info.selectors.ts +0 -7
  109. package/src/stores/action-info/index.ts +0 -4
  110. package/src/stores/actions/actions.actions.spec.ts +0 -62
  111. package/src/stores/actions/actions.actions.ts +0 -34
  112. package/src/stores/actions/actions.constant.ts +0 -1
  113. package/src/stores/actions/actions.reducers.spec.ts +0 -62
  114. package/src/stores/actions/actions.reducers.ts +0 -48
  115. package/src/stores/actions/actions.selectors.spec.ts +0 -34
  116. package/src/stores/actions/actions.selectors.ts +0 -7
  117. package/src/stores/actions/index.ts +0 -4
  118. package/src/stores/auth/auth.actions.ts +0 -13
  119. package/src/stores/auth/auth.constant.ts +0 -1
  120. package/src/stores/auth/auth.reducers.spec.ts +0 -376
  121. package/src/stores/auth/auth.reducers.ts +0 -151
  122. package/src/stores/auth/auth.selectors.spec.ts +0 -47
  123. package/src/stores/auth/auth.selectors.ts +0 -14
  124. package/src/stores/auth/auth.utils.spec.ts +0 -29
  125. package/src/stores/auth/auth.utils.tsx +0 -37
  126. package/src/stores/auth/getAccess.action.spec.ts +0 -257
  127. package/src/stores/auth/getAccess.action.ts +0 -57
  128. package/src/stores/auth/getProjectAccess.action.ts +0 -25
  129. package/src/stores/auth/index.ts +0 -10
  130. package/src/stores/auth/initAuth.action.spec.ts +0 -56
  131. package/src/stores/auth/initAuth.action.ts +0 -29
  132. package/src/stores/auth/logout.action.spec.ts +0 -25
  133. package/src/stores/auth/logout.action.ts +0 -9
  134. package/src/stores/auth/setUser.action.spec.ts +0 -25
  135. package/src/stores/auth/setUser.action.ts +0 -9
  136. package/src/stores/form/form.actions.spec.ts +0 -203
  137. package/src/stores/form/form.actions.ts +0 -84
  138. package/src/stores/form/form.reducers.spec.ts +0 -78
  139. package/src/stores/form/form.reducers.ts +0 -59
  140. package/src/stores/form/form.selectors.spec.ts +0 -19
  141. package/src/stores/form/form.selectors.ts +0 -5
  142. package/src/stores/form/index.ts +0 -3
  143. package/src/stores/forms/forms.actions.spec.ts +0 -91
  144. package/src/stores/forms/forms.actions.ts +0 -44
  145. package/src/stores/forms/forms.reducers.spec.ts +0 -97
  146. package/src/stores/forms/forms.reducers.ts +0 -77
  147. package/src/stores/forms/forms.selectors.spec.ts +0 -39
  148. package/src/stores/forms/forms.selectors.ts +0 -6
  149. package/src/stores/forms/index.ts +0 -3
  150. package/src/stores/index.spec.ts +0 -125
  151. package/src/stores/index.ts +0 -33
  152. package/src/stores/root/index.ts +0 -1
  153. package/src/stores/root/root.selectors.spec.ts +0 -94
  154. package/src/stores/root/root.selectors.ts +0 -23
  155. package/src/stores/submission/index.ts +0 -3
  156. package/src/stores/submission/submission.actions.spec.ts +0 -214
  157. package/src/stores/submission/submission.actions.ts +0 -81
  158. package/src/stores/submission/submission.reducers.spec.ts +0 -96
  159. package/src/stores/submission/submission.reducers.ts +0 -70
  160. package/src/stores/submission/submission.selectors.spec.ts +0 -19
  161. package/src/stores/submission/submission.selectors.ts +0 -5
  162. package/src/stores/submissions/index.ts +0 -3
  163. package/src/stores/submissions/submissions.actions.spec.ts +0 -99
  164. package/src/stores/submissions/submissions.actions.ts +0 -38
  165. package/src/stores/submissions/submissions.reducers.spec.ts +0 -98
  166. package/src/stores/submissions/submissions.reducers.ts +0 -78
  167. package/src/stores/submissions/submissions.selectors.spec.ts +0 -39
  168. package/src/stores/submissions/submissions.selectors.ts +0 -6
  169. package/src/utils/clean.test.ts +0 -7
  170. package/src/utils/clean.ts +0 -12
  171. package/src/utils/mapRequestParams.test.ts +0 -81
  172. package/src/utils/mapRequestParams.ts +0 -36
  173. package/src/utils/url.test.ts +0 -31
  174. package/src/utils/url.ts +0 -23
@@ -1,151 +0,0 @@
1
- import { createReducer } from "@tsed/redux-utils";
2
-
3
- import { FormSchema, Submission } from "../../interfaces";
4
- import { RoleSchema } from "../../interfaces/RoleSchema";
5
- import {
6
- failUser,
7
- formAccessUser,
8
- logoutUser,
9
- projectAccessUser,
10
- receiveUser,
11
- requestUser,
12
- submissionAccessUser,
13
- userForms,
14
- userRoles
15
- } from "./auth.actions";
16
- import { AUTH } from "./auth.constant";
17
-
18
- export interface AuthState<User = any> {
19
- init: boolean;
20
- isActive: boolean;
21
- user: null | Submission<User>;
22
- authenticated: boolean;
23
- projectAccess: Record<string, string[]>;
24
- formAccess: Record<string, string[]>;
25
- submissionAccess: Record<string, string[]>;
26
- roles: Record<string, RoleSchema>;
27
- forms: Record<string, FormSchema>;
28
- is: Record<string, boolean>;
29
- error: null | Error;
30
- }
31
-
32
- function createInitialState(): AuthState {
33
- return {
34
- init: false,
35
- isActive: false,
36
- user: null,
37
- authenticated: false,
38
- submissionAccess: {},
39
- formAccess: {},
40
- projectAccess: {},
41
- roles: {},
42
- forms: {},
43
- is: {},
44
- error: null
45
- };
46
- }
47
-
48
- function mapProjectRolesToUserRoles(projectRoles: Record<string, any>, userRoles: any[]) {
49
- return Object.entries(projectRoles).reduce(
50
- (result, [name, role]) => ({
51
- ...result,
52
- [name]: userRoles.includes(role._id)
53
- }),
54
- {}
55
- );
56
- }
57
-
58
- function getUserRoles(projectRoles: Record<string, RoleSchema>) {
59
- return Object.keys(projectRoles).reduce(
60
- (result, name) => ({
61
- ...result,
62
- [name]: name === "anonymous"
63
- }),
64
- {}
65
- );
66
- }
67
-
68
- export const authReducer = createReducer<AuthState>(
69
- {
70
- [requestUser.toString()](state) {
71
- return {
72
- ...state,
73
- init: true,
74
- submissionAccess: false,
75
- isActive: true
76
- };
77
- },
78
- [receiveUser.toString()](state, { user }) {
79
- return {
80
- ...state,
81
- isActive: false,
82
- user,
83
- authenticated: true,
84
- is: mapProjectRolesToUserRoles(state.roles, user.roles),
85
- error: null
86
- };
87
- },
88
- [failUser.toString()](state, { error }: any) {
89
- return {
90
- ...state,
91
- isActive: false,
92
- is: getUserRoles(state.roles),
93
- error
94
- };
95
- },
96
- [logoutUser.toString()](state) {
97
- return {
98
- ...state,
99
- user: null,
100
- isActive: false,
101
- authenticated: false,
102
- is: getUserRoles(state.roles),
103
- error: null
104
- };
105
- },
106
- [submissionAccessUser.toString()](state, { submissionAccess }: any) {
107
- return {
108
- ...state,
109
- submissionAccess
110
- };
111
- },
112
- [formAccessUser.toString()](state, { formAccess }: any) {
113
- return {
114
- ...state,
115
- formAccess
116
- };
117
- },
118
- [userForms.toString()](state, { forms }: any) {
119
- return {
120
- ...state,
121
- forms
122
- };
123
- },
124
- [projectAccessUser.toString()](state, { projectAccess }: any) {
125
- return {
126
- ...state,
127
- projectAccess
128
- };
129
- },
130
- [userRoles.toString()](state, { roles }: any) {
131
- return {
132
- ...state,
133
- roles
134
- };
135
- },
136
- default(state: any) {
137
- if (!window.localStorage.getItem("formioUser")) {
138
- return {
139
- ...state,
140
- user: null,
141
- isActive: false,
142
- authenticated: false,
143
- is: getUserRoles(state.roles),
144
- error: null
145
- };
146
- }
147
- return state;
148
- }
149
- },
150
- createInitialState
151
- )(AUTH);
@@ -1,47 +0,0 @@
1
- import { selectIsAuthenticated, selectRoles, selectUser } from "./auth.selectors";
2
-
3
- describe("auth Selectors", () => {
4
- describe("selectIsAuthenticated()", () => {
5
- it("should return isAuthenticated", () => {
6
- expect(
7
- selectIsAuthenticated({
8
- auth: {
9
- authenticated: true
10
- }
11
- })
12
- ).toEqual(true);
13
- });
14
- });
15
-
16
- describe("selectRoles()", () => {
17
- it("should return roles", () => {
18
- expect(
19
- selectRoles({
20
- auth: {
21
- roles: {
22
- administrator: {}
23
- }
24
- }
25
- })
26
- ).toEqual({
27
- administrator: {}
28
- });
29
- });
30
- });
31
-
32
- describe("selectUser()", () => {
33
- it("should return user", () => {
34
- expect(
35
- selectUser({
36
- auth: {
37
- user: {
38
- _id: "id"
39
- }
40
- }
41
- })
42
- ).toEqual({
43
- _id: "id"
44
- });
45
- });
46
- });
47
- });
@@ -1,14 +0,0 @@
1
- import get from "lodash/get";
2
-
3
- import { RoleSchema, Submission } from "../../interfaces";
4
- import { selectRoot } from "../root";
5
- import { AUTH } from "./auth.constant";
6
- import { AuthState } from "./auth.reducers";
7
-
8
- export const selectAuth = (state: any) => selectRoot<AuthState>(AUTH, state);
9
-
10
- export const selectUser = <User = any>(state: any): null | Submission<User> => get(selectAuth(state), "user");
11
-
12
- export const selectRoles = (state: any): Record<string, RoleSchema> => get(selectAuth(state), "roles");
13
-
14
- export const selectIsAuthenticated = (state: any): boolean => get(selectAuth(state), "authenticated");
@@ -1,29 +0,0 @@
1
- import { isAuthorized } from "./auth.utils";
2
-
3
- describe("Auth utils", () => {
4
- describe("isAuthorized()", () => {
5
- it("should return boolean", () => {
6
- expect(isAuthorized(undefined)).toEqual(false);
7
- expect(isAuthorized({ authenticated: true } as any)).toEqual(true);
8
- expect(isAuthorized({ authenticated: true } as any, [])).toEqual(true);
9
- expect(
10
- isAuthorized(
11
- {
12
- authenticated: true,
13
- is: { administrator: true }
14
- } as any,
15
- ["administrator"]
16
- )
17
- ).toEqual(true);
18
- expect(
19
- isAuthorized(
20
- {
21
- authenticated: true,
22
- is: { administrator: true }
23
- } as any,
24
- ["anonymous"]
25
- )
26
- ).toEqual(false);
27
- });
28
- });
29
- });
@@ -1,37 +0,0 @@
1
- import get from "lodash/get";
2
-
3
- import { FormSchema } from "../../interfaces/FormSchema";
4
- import { AuthState } from "./auth.reducers";
5
-
6
- export function hasRole(auth: AuthState, role: string): boolean {
7
- return auth.is[role];
8
- }
9
-
10
- export function hasRoles(auth: AuthState, roles: string[]): boolean {
11
- roles = ([] as string[]).concat(roles);
12
-
13
- return !!roles.find((role) => hasRole(auth, role));
14
- }
15
-
16
- export function isAuthorized(auth: AuthState, roles: string[] = []): boolean {
17
- if (auth && auth.authenticated) {
18
- if (roles.length) {
19
- return !!hasRoles(auth, roles);
20
- }
21
- return true;
22
- }
23
-
24
- return false;
25
- }
26
-
27
- export function checkRoleFormAccess(auth: AuthState, form?: Partial<FormSchema>, roles?: string[]) {
28
- if (roles && roles.length) {
29
- if (isAuthorized(auth, roles)) {
30
- return true;
31
- }
32
-
33
- return roles.includes("owner") && get(form, "owner") === get(auth, "user._id");
34
- }
35
-
36
- return true;
37
- }
@@ -1,257 +0,0 @@
1
- import { Formio } from "formiojs";
2
-
3
- import { formAccessUser, submissionAccessUser, userForms, userRoles } from "./auth.actions";
4
- import { AUTH } from "./auth.constant";
5
- import { getAccess } from "./getAccess.action";
6
-
7
- jest.mock("./auth.actions");
8
-
9
- describe("getAccess()", () => {
10
- beforeEach(() => {
11
- jest.spyOn(Formio, "makeStaticRequest");
12
- jest.spyOn(Formio, "getProjectUrl");
13
- });
14
- afterEach(() => {
15
- jest.resetAllMocks();
16
- });
17
- it("should get access", async () => {
18
- const dispatch = jest.fn();
19
- const access = {
20
- roles: {
21
- administrator: {
22
- _id: "6016dd751c62ca370d59f0b8",
23
- default: false,
24
- admin: true,
25
- title: "Administrator"
26
- },
27
- authenticated: {
28
- _id: "6016dd751c62ca370d59f0b9",
29
- default: false,
30
- admin: false,
31
- title: "Authenticated"
32
- },
33
- anonymous: {
34
- _id: "6016dd751c62ca370d59f0ba",
35
- default: true,
36
- admin: false,
37
- title: "Anonymous"
38
- }
39
- },
40
- forms: {
41
- user: {
42
- _id: "6016e1fb4ce825382505947d",
43
- title: "User",
44
- name: "user",
45
- path: "user",
46
- access: [
47
- {
48
- roles: ["6016dd751c62ca370d59f0ba", "6016dd751c62ca370d59f0b9", "6016dd751c62ca370d59f0b8"],
49
- type: "read_all"
50
- }
51
- ],
52
- submissionAccess: [
53
- { roles: ["6016dd751c62ca370d59f0b8"], type: "create_all" },
54
- { roles: ["6016dd751c62ca370d59f0b8"], type: "read_all" },
55
- { roles: ["6016dd751c62ca370d59f0b8"], type: "update_all" },
56
- { roles: ["6016dd751c62ca370d59f0b8"], type: "delete_all" },
57
- { roles: [], type: "create_own" },
58
- { roles: [], type: "read_own" },
59
- { roles: [], type: "update_own" },
60
- { roles: [], type: "delete_own" }
61
- ]
62
- },
63
- admin: {
64
- _id: "6016e1fb4ce825382505947e",
65
- title: "Admin",
66
- name: "admin",
67
- path: "admin",
68
- access: [
69
- {
70
- roles: ["6016dd751c62ca370d59f0ba", "6016dd751c62ca370d59f0b9", "6016dd751c62ca370d59f0b8"],
71
- type: "read_all"
72
- }
73
- ],
74
- submissionAccess: [
75
- { roles: ["6016dd751c62ca370d59f0b8"], type: "create_all" },
76
- { roles: ["6016dd751c62ca370d59f0b8"], type: "read_all" },
77
- { roles: ["6016dd751c62ca370d59f0b8"], type: "update_all" },
78
- { roles: ["6016dd751c62ca370d59f0b8"], type: "delete_all" },
79
- { roles: [], type: "create_own" },
80
- { roles: [], type: "read_own" },
81
- { roles: [], type: "update_own" },
82
- { roles: [], type: "delete_own" }
83
- ]
84
- },
85
- todo: {
86
- _id: "6016e1fb4ce825382505947f",
87
- title: "ToDo",
88
- name: "todo",
89
- path: "todo",
90
- access: [
91
- {
92
- roles: ["6016dd751c62ca370d59f0b8", "6016dd751c62ca370d59f0b9", "6016dd751c62ca370d59f0ba"],
93
- type: "read_all"
94
- }
95
- ],
96
- submissionAccess: [
97
- { roles: [], type: "create_all" },
98
- { roles: ["6016dd751c62ca370d59f0b8"], type: "read_all" },
99
- { roles: ["6016dd751c62ca370d59f0b8"], type: "update_all" },
100
- { roles: ["6016dd751c62ca370d59f0b8"], type: "delete_all" },
101
- { roles: ["6016dd751c62ca370d59f0b9"], type: "create_own" },
102
- { roles: ["6016dd751c62ca370d59f0b9"], type: "read_own" },
103
- { roles: ["6016dd751c62ca370d59f0b9"], type: "update_own" },
104
- { roles: ["6016dd751c62ca370d59f0b9"], type: "delete_own" }
105
- ]
106
- }
107
- }
108
- };
109
-
110
- (Formio.makeStaticRequest as any).mockResolvedValue(access);
111
-
112
- await getAccess(dispatch);
113
-
114
- expect(Formio.getProjectUrl).toHaveBeenCalledWith();
115
- expect(Formio.makeStaticRequest).toHaveBeenCalledWith("https://api.form.io/access");
116
-
117
- expect(submissionAccessUser).toHaveBeenCalledWith(AUTH, {
118
- submissionAccess: {
119
- admin: {
120
- create_all: ["6016dd751c62ca370d59f0b8"],
121
- create_own: [],
122
- delete_all: ["6016dd751c62ca370d59f0b8"],
123
- delete_own: [],
124
- read_all: ["6016dd751c62ca370d59f0b8"],
125
- read_own: [],
126
- update_all: ["6016dd751c62ca370d59f0b8"],
127
- update_own: []
128
- },
129
- todo: {
130
- create_all: [],
131
- create_own: ["6016dd751c62ca370d59f0b9"],
132
- delete_all: ["6016dd751c62ca370d59f0b8"],
133
- delete_own: ["6016dd751c62ca370d59f0b9"],
134
- read_all: ["6016dd751c62ca370d59f0b8"],
135
- read_own: ["6016dd751c62ca370d59f0b9"],
136
- update_all: ["6016dd751c62ca370d59f0b8"],
137
- update_own: ["6016dd751c62ca370d59f0b9"]
138
- },
139
- user: {
140
- create_all: ["6016dd751c62ca370d59f0b8"],
141
- create_own: [],
142
- delete_all: ["6016dd751c62ca370d59f0b8"],
143
- delete_own: [],
144
- read_all: ["6016dd751c62ca370d59f0b8"],
145
- read_own: [],
146
- update_all: ["6016dd751c62ca370d59f0b8"],
147
- update_own: []
148
- }
149
- }
150
- });
151
- expect(formAccessUser).toHaveBeenCalledWith(AUTH, {
152
- formAccess: {
153
- admin: {
154
- read_all: ["6016dd751c62ca370d59f0ba", "6016dd751c62ca370d59f0b9", "6016dd751c62ca370d59f0b8"]
155
- },
156
- todo: {
157
- read_all: ["6016dd751c62ca370d59f0b8", "6016dd751c62ca370d59f0b9", "6016dd751c62ca370d59f0ba"]
158
- },
159
- user: {
160
- read_all: ["6016dd751c62ca370d59f0ba", "6016dd751c62ca370d59f0b9", "6016dd751c62ca370d59f0b8"]
161
- }
162
- }
163
- });
164
- expect(userRoles).toHaveBeenCalledWith(AUTH, {
165
- roles: {
166
- administrator: {
167
- _id: "6016dd751c62ca370d59f0b8",
168
- admin: true,
169
- default: false,
170
- title: "Administrator"
171
- },
172
- anonymous: {
173
- _id: "6016dd751c62ca370d59f0ba",
174
- admin: false,
175
- default: true,
176
- title: "Anonymous"
177
- },
178
- authenticated: {
179
- _id: "6016dd751c62ca370d59f0b9",
180
- admin: false,
181
- default: false,
182
- title: "Authenticated"
183
- }
184
- }
185
- });
186
- expect(userForms).toHaveBeenCalledWith(AUTH, {
187
- forms: {
188
- admin: {
189
- _id: "6016e1fb4ce825382505947e",
190
- access: [
191
- {
192
- roles: ["6016dd751c62ca370d59f0ba", "6016dd751c62ca370d59f0b9", "6016dd751c62ca370d59f0b8"],
193
- type: "read_all"
194
- }
195
- ],
196
- name: "admin",
197
- path: "admin",
198
- submissionAccess: [
199
- { roles: ["6016dd751c62ca370d59f0b8"], type: "create_all" },
200
- { roles: ["6016dd751c62ca370d59f0b8"], type: "read_all" },
201
- { roles: ["6016dd751c62ca370d59f0b8"], type: "update_all" },
202
- { roles: ["6016dd751c62ca370d59f0b8"], type: "delete_all" },
203
- { roles: [], type: "create_own" },
204
- { roles: [], type: "read_own" },
205
- { roles: [], type: "update_own" },
206
- { roles: [], type: "delete_own" }
207
- ],
208
- title: "Admin"
209
- },
210
- todo: {
211
- _id: "6016e1fb4ce825382505947f",
212
- access: [
213
- {
214
- roles: ["6016dd751c62ca370d59f0b8", "6016dd751c62ca370d59f0b9", "6016dd751c62ca370d59f0ba"],
215
- type: "read_all"
216
- }
217
- ],
218
- name: "todo",
219
- path: "todo",
220
- submissionAccess: [
221
- { roles: [], type: "create_all" },
222
- { roles: ["6016dd751c62ca370d59f0b8"], type: "read_all" },
223
- { roles: ["6016dd751c62ca370d59f0b8"], type: "update_all" },
224
- { roles: ["6016dd751c62ca370d59f0b8"], type: "delete_all" },
225
- { roles: ["6016dd751c62ca370d59f0b9"], type: "create_own" },
226
- { roles: ["6016dd751c62ca370d59f0b9"], type: "read_own" },
227
- { roles: ["6016dd751c62ca370d59f0b9"], type: "update_own" },
228
- { roles: ["6016dd751c62ca370d59f0b9"], type: "delete_own" }
229
- ],
230
- title: "ToDo"
231
- },
232
- user: {
233
- _id: "6016e1fb4ce825382505947d",
234
- access: [
235
- {
236
- roles: ["6016dd751c62ca370d59f0ba", "6016dd751c62ca370d59f0b9", "6016dd751c62ca370d59f0b8"],
237
- type: "read_all"
238
- }
239
- ],
240
- name: "user",
241
- path: "user",
242
- submissionAccess: [
243
- { roles: ["6016dd751c62ca370d59f0b8"], type: "create_all" },
244
- { roles: ["6016dd751c62ca370d59f0b8"], type: "read_all" },
245
- { roles: ["6016dd751c62ca370d59f0b8"], type: "update_all" },
246
- { roles: ["6016dd751c62ca370d59f0b8"], type: "delete_all" },
247
- { roles: [], type: "create_own" },
248
- { roles: [], type: "read_own" },
249
- { roles: [], type: "update_own" },
250
- { roles: [], type: "delete_own" }
251
- ],
252
- title: "User"
253
- }
254
- }
255
- });
256
- });
257
- });
@@ -1,57 +0,0 @@
1
- import { Formio } from "formiojs";
2
-
3
- import { RoleSchema } from "../../interfaces";
4
- import { FormSchema } from "../../interfaces/FormSchema";
5
- import { formAccessUser, submissionAccessUser, userForms, userRoles } from "./auth.actions";
6
- import { AUTH } from "./auth.constant";
7
-
8
- function transformSubmissionAccess(forms: Record<string, FormSchema>) {
9
- return Object.values(forms).reduce(
10
- (result, form) => ({
11
- ...result,
12
- [form.name as string]: form.submissionAccess.reduce(
13
- (formSubmissionAccess: any, access: any) => ({
14
- ...formSubmissionAccess,
15
- [access.type]: access.roles
16
- }),
17
- {}
18
- )
19
- }),
20
- {}
21
- );
22
- }
23
-
24
- function transformFormAccess(forms: Record<string, FormSchema>) {
25
- return Object.values(forms).reduce(
26
- (result, form) => ({
27
- ...result,
28
- [form.name as string]: form.access.reduce(
29
- (formAccess: any, access: any) => ({
30
- ...formAccess,
31
- [access.type]: access.roles
32
- }),
33
- {}
34
- )
35
- }),
36
- {}
37
- );
38
- }
39
-
40
- export async function getAccess(dispatch: any) {
41
- const projectUrl = Formio.getProjectUrl();
42
-
43
- try {
44
- const result: {
45
- roles: Record<string, RoleSchema>;
46
- forms: Record<string, FormSchema>;
47
- } = await Formio.makeStaticRequest(`${projectUrl}/access`);
48
-
49
- const submissionAccess = transformSubmissionAccess(result.forms);
50
- const formAccess = transformFormAccess(result.forms);
51
-
52
- dispatch(submissionAccessUser(AUTH, { submissionAccess }));
53
- dispatch(formAccessUser(AUTH, { formAccess }));
54
- dispatch(userRoles(AUTH, { roles: result.roles }));
55
- dispatch(userForms(AUTH, { forms: result.forms }));
56
- } catch (err) {}
57
- }
@@ -1,25 +0,0 @@
1
- import { Formio } from "formiojs";
2
-
3
- import { projectAccessUser } from "./auth.actions";
4
- import { AUTH } from "./auth.constant";
5
-
6
- function transformProjectAccess(projectAccess: any[]) {
7
- return projectAccess.reduce(
8
- (result: any, access: any) => ({
9
- ...result,
10
- [access.type]: access.roles
11
- }),
12
- {}
13
- );
14
- }
15
-
16
- export async function getProjectAccess(dispatch: any) {
17
- const projectUrl = Formio.getProjectUrl();
18
-
19
- try {
20
- const project = await Formio.makeStaticRequest(projectUrl);
21
- const projectAccess = transformProjectAccess(project.access);
22
-
23
- dispatch(projectAccessUser(AUTH, projectAccess));
24
- } catch (er) {}
25
- }
@@ -1,10 +0,0 @@
1
- export * from "./auth.actions";
2
- export * from "./auth.constant";
3
- export * from "./auth.reducers";
4
- export * from "./auth.selectors";
5
- export * from "./auth.utils";
6
- export * from "./getAccess.action";
7
- export * from "./getProjectAccess.action";
8
- export * from "./initAuth.action";
9
- export * from "./logout.action";
10
- export * from "./setUser.action";
@@ -1,56 +0,0 @@
1
- import { Formio } from "formiojs";
2
-
3
- import { requestUser } from "./auth.actions";
4
- import { AUTH } from "./auth.constant";
5
- import { getAccess } from "./getAccess.action";
6
- import { getProjectAccess } from "./getProjectAccess.action";
7
- import { initAuth } from "./initAuth.action";
8
- import { logout } from "./logout.action";
9
- import { setUser } from "./setUser.action";
10
-
11
- jest.mock("./getAccess.action");
12
- jest.mock("./getProjectAccess.action");
13
- jest.mock("./setUser.action");
14
- jest.mock("./logout.action");
15
- jest.mock("./auth.actions");
16
-
17
- describe("initAuth()", () => {
18
- beforeEach(() => {
19
- jest.spyOn(Formio, "currentUser");
20
- });
21
- afterEach(() => {
22
- jest.resetAllMocks();
23
- });
24
- it("should init auth", async () => {
25
- const dispatch = jest.fn();
26
- const done = jest.fn();
27
- const user = { data: {} };
28
-
29
- (Formio.currentUser as any).mockResolvedValue(user);
30
-
31
- await initAuth(done)(dispatch);
32
-
33
- expect(requestUser).toHaveBeenCalledWith(AUTH);
34
- expect(Formio.currentUser).toHaveBeenCalledWith();
35
- expect(getAccess).toHaveBeenCalledWith(dispatch);
36
- expect(getProjectAccess).toHaveBeenCalledWith(dispatch);
37
- expect(setUser).toHaveBeenCalledWith(user);
38
- expect(logout).not.toHaveBeenCalled();
39
- });
40
- it("should call logout when user is null", async () => {
41
- const dispatch = jest.fn();
42
- const done = jest.fn();
43
- const user: any = null;
44
-
45
- (Formio.currentUser as any).mockResolvedValue(user);
46
-
47
- await initAuth(done)(dispatch);
48
-
49
- expect(requestUser).toHaveBeenCalledWith(AUTH);
50
- expect(Formio.currentUser).toHaveBeenCalledWith();
51
- expect(getAccess).toHaveBeenCalledWith(dispatch);
52
- expect(getProjectAccess).toHaveBeenCalledWith(dispatch);
53
- expect(setUser).not.toHaveBeenCalledWith();
54
- expect(logout).toHaveBeenCalledWith();
55
- });
56
- });