@webiny/cognito 6.5.2-beta.1 → 6.5.2-beta.2

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 (88) hide show
  1. package/admin/Cognito.js +1 -1
  2. package/admin/Cognito.js.map +1 -1
  3. package/admin/Extension.js +6 -0
  4. package/admin/Extension.js.map +1 -1
  5. package/admin/SecurityPermission.js +1 -1
  6. package/admin/SecurityPermission.js.map +1 -1
  7. package/admin/features/users/resetUserMfa/ResetUserMfaGateway.d.ts +11 -0
  8. package/admin/features/users/resetUserMfa/ResetUserMfaGateway.js +42 -0
  9. package/admin/features/users/resetUserMfa/ResetUserMfaGateway.js.map +1 -0
  10. package/admin/features/users/resetUserMfa/ResetUserMfaUseCase.d.ts +10 -0
  11. package/admin/features/users/resetUserMfa/ResetUserMfaUseCase.js +18 -0
  12. package/admin/features/users/resetUserMfa/ResetUserMfaUseCase.js.map +1 -0
  13. package/admin/features/users/resetUserMfa/abstractions/ResetUserMfaGateway.d.ts +11 -0
  14. package/admin/features/users/resetUserMfa/abstractions/ResetUserMfaGateway.js +5 -0
  15. package/admin/features/users/resetUserMfa/abstractions/ResetUserMfaGateway.js.map +1 -0
  16. package/admin/features/users/resetUserMfa/abstractions/ResetUserMfaUseCase.d.ts +12 -0
  17. package/admin/features/users/resetUserMfa/abstractions/ResetUserMfaUseCase.js +5 -0
  18. package/admin/features/users/resetUserMfa/abstractions/ResetUserMfaUseCase.js.map +1 -0
  19. package/admin/features/users/resetUserMfa/abstractions/index.d.ts +2 -0
  20. package/admin/features/users/resetUserMfa/abstractions/index.js +2 -0
  21. package/admin/features/users/resetUserMfa/feature.d.ts +3 -0
  22. package/admin/features/users/resetUserMfa/feature.js +19 -0
  23. package/admin/features/users/resetUserMfa/feature.js.map +1 -0
  24. package/admin/features/users/resetUserMfa/index.d.ts +2 -0
  25. package/admin/features/users/resetUserMfa/index.js +2 -0
  26. package/admin/presentation/Cognito/components/FederatedProviders.js +1 -1
  27. package/admin/presentation/Cognito/components/FederatedProviders.js.map +1 -1
  28. package/admin/presentation/Cognito/components/SetNewPassword.js.map +1 -1
  29. package/admin/presentation/Cognito/components/SetupTotp.js +6 -5
  30. package/admin/presentation/Cognito/components/SetupTotp.js.map +1 -1
  31. package/admin/presentation/Cognito/components/View.js +5 -5
  32. package/admin/presentation/Cognito/components/View.js.map +1 -1
  33. package/admin/presentation/userMenu/AccountDetails.js +1 -1
  34. package/admin/presentation/userMenu/AccountDetails.js.map +1 -1
  35. package/admin/presentation/users/ResetMfa/ResetMfaPresenter.d.ts +25 -0
  36. package/admin/presentation/users/ResetMfa/ResetMfaPresenter.js +61 -0
  37. package/admin/presentation/users/ResetMfa/ResetMfaPresenter.js.map +1 -0
  38. package/admin/presentation/users/ResetMfa/ResetMfaPresenter.test.d.ts +1 -0
  39. package/admin/presentation/users/ResetMfa/ResetMfaPresenter.test.js +135 -0
  40. package/admin/presentation/users/ResetMfa/ResetMfaPresenter.test.js.map +1 -0
  41. package/admin/presentation/users/ResetMfa/abstractions.d.ts +38 -0
  42. package/admin/presentation/users/ResetMfa/abstractions.js +5 -0
  43. package/admin/presentation/users/ResetMfa/abstractions.js.map +1 -0
  44. package/admin/presentation/users/ResetMfa/feature.d.ts +6 -0
  45. package/admin/presentation/users/ResetMfa/feature.js +17 -0
  46. package/admin/presentation/users/ResetMfa/feature.js.map +1 -0
  47. package/admin/presentation/users/UserForm/UserFormPresenter.test.js +2 -2
  48. package/admin/presentation/users/UserForm/UserFormPresenter.test.js.map +1 -1
  49. package/admin/ui/views/Users/UsersForm.js +5 -1
  50. package/admin/ui/views/Users/UsersForm.js.map +1 -1
  51. package/admin/ui/views/Users/components/ResetMfa.d.ts +12 -0
  52. package/admin/ui/views/Users/components/ResetMfa.js +61 -0
  53. package/admin/ui/views/Users/components/ResetMfa.js.map +1 -0
  54. package/api/CognitoApiFeature.js +2 -0
  55. package/api/CognitoApiFeature.js.map +1 -1
  56. package/api/domain/errors.d.ts +19 -0
  57. package/api/domain/errors.js +21 -1
  58. package/api/domain/errors.js.map +1 -1
  59. package/api/features/CognitoIdp/CognitoIdentityProvider.d.ts +2 -0
  60. package/api/features/CognitoIdp/CognitoIdentityProvider.js +20 -0
  61. package/api/features/CognitoIdp/CognitoIdentityProvider.js.map +1 -1
  62. package/api/features/CognitoIdp/abstractions.d.ts +6 -0
  63. package/api/features/CognitoIdp/abstractions.js.map +1 -1
  64. package/api/features/CognitoService/CognitoService.d.ts +1 -0
  65. package/api/features/CognitoService/CognitoService.js +9 -0
  66. package/api/features/CognitoService/CognitoService.js.map +1 -1
  67. package/api/features/CognitoService/abstractions.d.ts +5 -0
  68. package/api/features/CognitoService/abstractions.js.map +1 -1
  69. package/api/features/CognitoService/adminDeleteSoftwareToken.d.ts +16 -0
  70. package/api/features/CognitoService/adminDeleteSoftwareToken.js +69 -0
  71. package/api/features/CognitoService/adminDeleteSoftwareToken.js.map +1 -0
  72. package/api/features/CognitoService/adminDeleteSoftwareToken.test.d.ts +1 -0
  73. package/api/features/CognitoService/adminDeleteSoftwareToken.test.js +91 -0
  74. package/api/features/CognitoService/adminDeleteSoftwareToken.test.js.map +1 -0
  75. package/api/features/ResetUserMfa/ResetUserMfaUseCase.d.ts +14 -0
  76. package/api/features/ResetUserMfa/ResetUserMfaUseCase.js +43 -0
  77. package/api/features/ResetUserMfa/ResetUserMfaUseCase.js.map +1 -0
  78. package/api/features/ResetUserMfa/abstractions.d.ts +24 -0
  79. package/api/features/ResetUserMfa/abstractions.js +5 -0
  80. package/api/features/ResetUserMfa/abstractions.js.map +1 -0
  81. package/api/features/ResetUserMfa/feature.d.ts +4 -0
  82. package/api/features/ResetUserMfa/feature.js +11 -0
  83. package/api/features/ResetUserMfa/feature.js.map +1 -0
  84. package/api/features/ResetUserMfa/index.d.ts +2 -0
  85. package/api/features/ResetUserMfa/index.js +2 -0
  86. package/api/graphql/user.gql.js +19 -0
  87. package/api/graphql/user.gql.js.map +1 -1
  88. package/package.json +23 -20
@@ -0,0 +1,135 @@
1
+ import { beforeEach, describe, expect, it, vi } from "vitest";
2
+ import { Container } from "@webiny/di";
3
+ import { MainGraphQLClient } from "@webiny/app/features/mainGraphQLClient/index.js";
4
+ import { ResetUserMfaFeature } from "../../../features/users/resetUserMfa/index.js";
5
+ import { ResetMfaFeature } from "./feature.js";
6
+ const user = {
7
+ id: "user-1",
8
+ email: "person@example.com",
9
+ external: false
10
+ };
11
+ const resetResponse = (error = null)=>({
12
+ adminUsers: {
13
+ resetUserMfa: {
14
+ data: error ? null : true,
15
+ error
16
+ }
17
+ }
18
+ });
19
+ describe("ResetMfaPresenter: resetting a user's MFA", ()=>{
20
+ let container;
21
+ let execute;
22
+ const presenter = ()=>ResetMfaFeature.resolve(container).presenter;
23
+ beforeEach(()=>{
24
+ container = new Container();
25
+ execute = vi.fn();
26
+ container.registerInstance(MainGraphQLClient, {
27
+ execute
28
+ });
29
+ ResetUserMfaFeature.register(container);
30
+ ResetMfaFeature.register(container);
31
+ });
32
+ it("offers the reset for another user who signs in with Cognito", ()=>{
33
+ const resetMfa = presenter();
34
+ resetMfa.init({
35
+ user,
36
+ currentIdentityId: "admin-1"
37
+ });
38
+ expect(resetMfa.vm).toEqual({
39
+ available: true,
40
+ resetting: false
41
+ });
42
+ });
43
+ it("doesn't offer the reset for a federated user", ()=>{
44
+ const resetMfa = presenter();
45
+ resetMfa.init({
46
+ user: {
47
+ ...user,
48
+ external: true
49
+ },
50
+ currentIdentityId: "admin-1"
51
+ });
52
+ expect(resetMfa.vm.available).toBe(false);
53
+ });
54
+ it("doesn't offer the reset for yourself", ()=>{
55
+ const resetMfa = presenter();
56
+ resetMfa.init({
57
+ user,
58
+ currentIdentityId: user.id
59
+ });
60
+ expect(resetMfa.vm.available).toBe(false);
61
+ });
62
+ it("doesn't offer the reset without a user", ()=>{
63
+ const resetMfa = presenter();
64
+ resetMfa.init({
65
+ user: void 0,
66
+ currentIdentityId: "admin-1"
67
+ });
68
+ expect(resetMfa.vm.available).toBe(false);
69
+ });
70
+ it("resets the user's MFA and says they'll set it up on their next sign-in", async ()=>{
71
+ execute.mockResolvedValue(resetResponse());
72
+ const resetMfa = presenter();
73
+ resetMfa.init({
74
+ user,
75
+ currentIdentityId: "admin-1"
76
+ });
77
+ const result = await resetMfa.reset();
78
+ expect(result).toEqual({
79
+ type: "reset",
80
+ message: "MFA reset for person@example.com. They'll set it up again on their next sign-in."
81
+ });
82
+ expect(execute).toHaveBeenCalledTimes(1);
83
+ expect(execute.mock.calls[0][0].variables).toEqual({
84
+ id: user.id
85
+ });
86
+ expect(resetMfa.vm.resetting).toBe(false);
87
+ });
88
+ it("shows that it's resetting while the request runs", async ()=>{
89
+ let answer = ()=>{};
90
+ execute.mockReturnValue(new Promise((resolve)=>answer = resolve));
91
+ const resetMfa = presenter();
92
+ resetMfa.init({
93
+ user,
94
+ currentIdentityId: "admin-1"
95
+ });
96
+ const result = resetMfa.reset();
97
+ expect(resetMfa.vm.resetting).toBe(true);
98
+ answer(resetResponse());
99
+ await result;
100
+ expect(resetMfa.vm.resetting).toBe(false);
101
+ });
102
+ it("reports the API's error", async ()=>{
103
+ execute.mockResolvedValue(resetResponse({
104
+ code: "Cognito/User/ResetMfa",
105
+ message: "Failed to reset the user's MFA in Cognito: User has no software token.",
106
+ data: null
107
+ }));
108
+ const resetMfa = presenter();
109
+ resetMfa.init({
110
+ user,
111
+ currentIdentityId: "admin-1"
112
+ });
113
+ const result = await resetMfa.reset();
114
+ expect(result).toEqual({
115
+ type: "failed",
116
+ message: "Failed to reset the user's MFA in Cognito: User has no software token."
117
+ });
118
+ expect(resetMfa.vm.resetting).toBe(false);
119
+ });
120
+ it("doesn't send a reset for a user it isn't offered for", async ()=>{
121
+ const resetMfa = presenter();
122
+ resetMfa.init({
123
+ user: {
124
+ ...user,
125
+ external: true
126
+ },
127
+ currentIdentityId: "admin-1"
128
+ });
129
+ const result = await resetMfa.reset();
130
+ expect(result.type).toBe("failed");
131
+ expect(execute).not.toHaveBeenCalled();
132
+ });
133
+ });
134
+
135
+ //# sourceMappingURL=ResetMfaPresenter.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin/presentation/users/ResetMfa/ResetMfaPresenter.test.js","sources":["../../../../../src/admin/presentation/users/ResetMfa/ResetMfaPresenter.test.ts"],"sourcesContent":["import { describe, it, expect, vi, beforeEach } from \"vitest\";\nimport { Container } from \"@webiny/di\";\nimport { MainGraphQLClient } from \"@webiny/app/features/mainGraphQLClient/index.js\";\nimport { ResetUserMfaFeature } from \"~/admin/features/users/resetUserMfa/index.js\";\nimport { ResetMfaFeature } from \"./feature.js\";\n\nconst user = { id: \"user-1\", email: \"person@example.com\", external: false };\n\nconst resetResponse = (error: Record<string, any> | null = null) => {\n return { adminUsers: { resetUserMfa: { data: error ? null : true, error } } };\n};\n\ndescribe(\"ResetMfaPresenter: resetting a user's MFA\", () => {\n let container: Container;\n let execute: ReturnType<typeof vi.fn>;\n\n const presenter = () => ResetMfaFeature.resolve(container).presenter;\n\n beforeEach(() => {\n container = new Container();\n execute = vi.fn();\n container.registerInstance(MainGraphQLClient, {\n execute\n } as unknown as MainGraphQLClient.Interface);\n\n ResetUserMfaFeature.register(container);\n ResetMfaFeature.register(container);\n });\n\n it(\"offers the reset for another user who signs in with Cognito\", () => {\n const resetMfa = presenter();\n\n resetMfa.init({ user, currentIdentityId: \"admin-1\" });\n\n expect(resetMfa.vm).toEqual({ available: true, resetting: false });\n });\n\n it(\"doesn't offer the reset for a federated user\", () => {\n const resetMfa = presenter();\n\n resetMfa.init({ user: { ...user, external: true }, currentIdentityId: \"admin-1\" });\n\n expect(resetMfa.vm.available).toBe(false);\n });\n\n it(\"doesn't offer the reset for yourself\", () => {\n const resetMfa = presenter();\n\n resetMfa.init({ user, currentIdentityId: user.id });\n\n expect(resetMfa.vm.available).toBe(false);\n });\n\n it(\"doesn't offer the reset without a user\", () => {\n const resetMfa = presenter();\n\n resetMfa.init({ user: undefined, currentIdentityId: \"admin-1\" });\n\n expect(resetMfa.vm.available).toBe(false);\n });\n\n it(\"resets the user's MFA and says they'll set it up on their next sign-in\", async () => {\n execute.mockResolvedValue(resetResponse());\n const resetMfa = presenter();\n resetMfa.init({ user, currentIdentityId: \"admin-1\" });\n\n const result = await resetMfa.reset();\n\n expect(result).toEqual({\n type: \"reset\",\n message:\n \"MFA reset for person@example.com. They'll set it up again on their next sign-in.\"\n });\n expect(execute).toHaveBeenCalledTimes(1);\n expect(execute.mock.calls[0][0].variables).toEqual({ id: user.id });\n expect(resetMfa.vm.resetting).toBe(false);\n });\n\n it(\"shows that it's resetting while the request runs\", async () => {\n let answer: (value: unknown) => void = () => {};\n execute.mockReturnValue(new Promise(resolve => (answer = resolve)));\n const resetMfa = presenter();\n resetMfa.init({ user, currentIdentityId: \"admin-1\" });\n\n const result = resetMfa.reset();\n expect(resetMfa.vm.resetting).toBe(true);\n\n answer(resetResponse());\n await result;\n expect(resetMfa.vm.resetting).toBe(false);\n });\n\n it(\"reports the API's error\", async () => {\n execute.mockResolvedValue(\n resetResponse({\n code: \"Cognito/User/ResetMfa\",\n message: \"Failed to reset the user's MFA in Cognito: User has no software token.\",\n data: null\n })\n );\n const resetMfa = presenter();\n resetMfa.init({ user, currentIdentityId: \"admin-1\" });\n\n const result = await resetMfa.reset();\n\n expect(result).toEqual({\n type: \"failed\",\n message: \"Failed to reset the user's MFA in Cognito: User has no software token.\"\n });\n expect(resetMfa.vm.resetting).toBe(false);\n });\n\n it(\"doesn't send a reset for a user it isn't offered for\", async () => {\n const resetMfa = presenter();\n resetMfa.init({ user: { ...user, external: true }, currentIdentityId: \"admin-1\" });\n\n const result = await resetMfa.reset();\n\n expect(result.type).toBe(\"failed\");\n expect(execute).not.toHaveBeenCalled();\n });\n});\n"],"names":["user","resetResponse","error","describe","container","execute","presenter","ResetMfaFeature","beforeEach","Container","vi","MainGraphQLClient","ResetUserMfaFeature","it","resetMfa","expect","undefined","result","answer","Promise","resolve"],"mappings":";;;;;AAMA,MAAMA,OAAO;IAA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,mBAAmB;QAAU;QAEhF,MAAMiB,SAAS,MAAMH,SAAS,KAAK;QAEnCC,OAAOE,OAAO,IAAI,EAAE,IAAI,CAAC;QACzBF,OAAOV,SAAS,GAAG,CAAC,gBAAgB;IACxC;AACJ"}
@@ -0,0 +1,38 @@
1
+ export interface ResetMfaUser {
2
+ id: string;
3
+ email: string;
4
+ external?: boolean;
5
+ }
6
+ export interface ResetMfaVM {
7
+ /** Whether the user's MFA can be reset here: not for a federated user, nor for yourself. */
8
+ available: boolean;
9
+ resetting: boolean;
10
+ }
11
+ export type ResetMfaResult = {
12
+ type: "reset";
13
+ message: string;
14
+ } | {
15
+ type: "failed";
16
+ message: string;
17
+ };
18
+ export interface ResetMfaInitParams {
19
+ /** The user the form shows. */
20
+ user: ResetMfaUser | undefined;
21
+ /** The ID of the person signed in. */
22
+ currentIdentityId: string | undefined;
23
+ }
24
+ export interface IResetMfaPresenter {
25
+ vm: ResetMfaVM;
26
+ /** Starts the presenter's lifecycle. Calling it again replaces the params. */
27
+ init(params: ResetMfaInitParams): void;
28
+ /** Deletes the user's TOTP software token, so they set up MFA again on their next sign-in. */
29
+ reset(): Promise<ResetMfaResult>;
30
+ }
31
+ export declare const ResetMfaPresenter: import("@webiny/di").Abstraction<IResetMfaPresenter>;
32
+ export declare namespace ResetMfaPresenter {
33
+ type Interface = IResetMfaPresenter;
34
+ type VM = ResetMfaVM;
35
+ type User = ResetMfaUser;
36
+ type InitParams = ResetMfaInitParams;
37
+ type Result = ResetMfaResult;
38
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/admin";
2
+ const ResetMfaPresenter = createAbstraction("Cognito/ResetMfaPresenter");
3
+ export { ResetMfaPresenter };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin/presentation/users/ResetMfa/abstractions.js","sources":["../../../../../src/admin/presentation/users/ResetMfa/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\n\nexport interface ResetMfaUser {\n id: string;\n email: string;\n external?: boolean;\n}\n\nexport interface ResetMfaVM {\n /** Whether the user's MFA can be reset here: not for a federated user, nor for yourself. */\n available: boolean;\n resetting: boolean;\n}\n\nexport type ResetMfaResult =\n | { type: \"reset\"; message: string }\n | { type: \"failed\"; message: string };\n\nexport interface ResetMfaInitParams {\n /** The user the form shows. */\n user: ResetMfaUser | undefined;\n /** The ID of the person signed in. */\n currentIdentityId: string | undefined;\n}\n\nexport interface IResetMfaPresenter {\n vm: ResetMfaVM;\n\n /** Starts the presenter's lifecycle. Calling it again replaces the params. */\n init(params: ResetMfaInitParams): void;\n\n /** Deletes the user's TOTP software token, so they set up MFA again on their next sign-in. */\n reset(): Promise<ResetMfaResult>;\n}\n\nexport const ResetMfaPresenter = createAbstraction<IResetMfaPresenter>(\"Cognito/ResetMfaPresenter\");\n\nexport namespace ResetMfaPresenter {\n export type Interface = IResetMfaPresenter;\n export type VM = ResetMfaVM;\n export type User = ResetMfaUser;\n export type InitParams = ResetMfaInitParams;\n export type Result = ResetMfaResult;\n}\n"],"names":["ResetMfaPresenter","createAbstraction"],"mappings":";AAmCO,MAAMA,oBAAoBC,kBAAsC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The Reset MFA action on an existing user. Needs the ResetUserMfa feature.
3
+ */
4
+ export declare const ResetMfaFeature: import("@webiny/feature/admin").FeatureDefinition<{
5
+ presenter: import("./abstractions.js").IResetMfaPresenter;
6
+ }, []>;
@@ -0,0 +1,17 @@
1
+ import { createFeature } from "@webiny/feature/admin";
2
+ import { ResetMfaPresenter } from "./abstractions.js";
3
+ import { ResetMfaPresenter as external_ResetMfaPresenter_js_ResetMfaPresenter } from "./ResetMfaPresenter.js";
4
+ const ResetMfaFeature = createFeature({
5
+ name: "Cognito/Users/ResetMfa",
6
+ register (container) {
7
+ container.register(external_ResetMfaPresenter_js_ResetMfaPresenter);
8
+ },
9
+ resolve (container) {
10
+ return {
11
+ presenter: container.resolve(ResetMfaPresenter)
12
+ };
13
+ }
14
+ });
15
+ export { ResetMfaFeature };
16
+
17
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin/presentation/users/ResetMfa/feature.js","sources":["../../../../../src/admin/presentation/users/ResetMfa/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/admin\";\nimport { ResetMfaPresenter as PresenterAbstraction } from \"./abstractions.js\";\nimport { ResetMfaPresenter } from \"./ResetMfaPresenter.js\";\n\n/**\n * The Reset MFA action on an existing user. Needs the ResetUserMfa feature.\n */\nexport const ResetMfaFeature = createFeature({\n name: \"Cognito/Users/ResetMfa\",\n register(container) {\n container.register(ResetMfaPresenter);\n },\n resolve(container) {\n return {\n presenter: container.resolve(PresenterAbstraction)\n };\n }\n});\n"],"names":["ResetMfaFeature","createFeature","container","ResetMfaPresenter","PresenterAbstraction"],"mappings":";;;AAOO,MAAMA,kBAAkBC,cAAc;IACzC,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;IACA,SAAQD,SAAS;QACb,OAAO;YACH,WAAWA,UAAU,OAAO,CAACE;QACjC;IACJ;AACJ"}
@@ -148,7 +148,7 @@ describe("UserFormPresenter: creating or linking a user", ()=>{
148
148
  });
149
149
  expect(result).toEqual({
150
150
  type: "created",
151
- user: user
151
+ user
152
152
  });
153
153
  expect(operations()).toEqual([
154
154
  "CreateUser"
@@ -172,7 +172,7 @@ describe("UserFormPresenter: creating or linking a user", ()=>{
172
172
  });
173
173
  expect(result).toEqual({
174
174
  type: "linked",
175
- user: user
175
+ user
176
176
  });
177
177
  expect(operations()).toEqual([
178
178
  "CheckEmail",
@@ -1 +1 @@
1
- {"version":3,"file":"admin/presentation/users/UserForm/UserFormPresenter.test.js","sources":["../../../../../src/admin/presentation/users/UserForm/UserFormPresenter.test.ts"],"sourcesContent":["import { describe, it, expect, vi, beforeEach } from \"vitest\";\nimport { Container } from \"@webiny/di\";\nimport { MainGraphQLClient } from \"@webiny/app/features/mainGraphQLClient/index.js\";\nimport { CreateUserFeature } from \"~/admin/features/users/createUser/index.js\";\nimport { LinkUserFeature } from \"~/admin/features/users/linkUser/index.js\";\nimport { CheckEmailFeature } from \"~/admin/features/users/checkEmail/index.js\";\nimport { UserFormFeature } from \"./feature.js\";\nimport { EMAIL_EXISTS_HERE } from \"./UserFormPresenter.js\";\n\nconst user = {\n id: \"user-1\",\n email: \"person@example.com\",\n firstName: \"Some\",\n lastName: \"Person\",\n avatar: null,\n createdOn: \"2026-10-23T00:00:00.000Z\",\n external: false\n};\n\nconst emailStatus = (status: string) => {\n return { adminUsers: { checkEmail: { data: { status }, error: null } } };\n};\n\nconst userResponse = (data: typeof user | null, error: Record<string, any> | null = null) => {\n return { adminUsers: { user: { data, error } } };\n};\n\ndescribe(\"UserFormPresenter: creating or linking a user\", () => {\n let container: Container;\n let execute: ReturnType<typeof vi.fn>;\n\n const presenter = () => UserFormFeature.resolve(container).presenter;\n\n /** The GraphQL operations the presenter sent, by their operation name. */\n const operations = () => {\n return execute.mock.calls.map(([request]) => {\n return /(query|mutation) (\\w+)/.exec(request.query)?.[2];\n });\n };\n\n beforeEach(() => {\n container = new Container();\n execute = vi.fn();\n container.registerInstance(MainGraphQLClient, {\n execute\n } as unknown as MainGraphQLClient.Interface);\n\n CreateUserFeature.register(container);\n LinkUserFeature.register(container);\n CheckEmailFeature.register(container);\n UserFormFeature.register(container);\n });\n\n it(\"starts in create mode\", () => {\n expect(presenter().vm).toEqual({ mode: \"create\", emailError: null, saving: false });\n });\n\n it(\"stays in create mode for a new email\", async () => {\n execute.mockResolvedValue(emailStatus(\"AVAILABLE\"));\n const form = presenter();\n\n await form.checkEmail(\"new@example.com\");\n\n expect(form.vm).toMatchObject({ mode: \"create\", emailError: null });\n });\n\n it(\"switches to link mode for an email with an account in another tenant\", async () => {\n execute.mockResolvedValue(emailStatus(\"EXISTS_ELSEWHERE\"));\n const form = presenter();\n\n await form.checkEmail(\"person@example.com\");\n\n expect(form.vm).toMatchObject({ mode: \"link\", emailError: null });\n });\n\n it(\"shows an email error for a user already in this tenant\", async () => {\n execute.mockResolvedValue(emailStatus(\"EXISTS_HERE\"));\n const form = presenter();\n\n await form.checkEmail(\"person@example.com\");\n\n expect(form.vm).toMatchObject({ mode: \"create\", emailError: EMAIL_EXISTS_HERE });\n });\n\n it(\"goes back to create mode when the email changes to a new one\", async () => {\n execute.mockResolvedValueOnce(emailStatus(\"EXISTS_ELSEWHERE\"));\n execute.mockResolvedValueOnce(emailStatus(\"AVAILABLE\"));\n const form = presenter();\n\n await form.checkEmail(\"person@example.com\");\n await form.checkEmail(\"someone-new@example.com\");\n\n expect(form.vm).toMatchObject({ mode: \"create\", emailError: null });\n });\n\n it(\"doesn't check an incomplete email, or the same email twice\", async () => {\n execute.mockResolvedValue(emailStatus(\"EXISTS_ELSEWHERE\"));\n const form = presenter();\n\n await form.checkEmail(\"person@\");\n await form.checkEmail(\"person@example.com\");\n await form.checkEmail(\" Person@example.com \");\n\n expect(operations()).toEqual([\"CheckEmail\"]);\n expect(form.vm.mode).toBe(\"link\");\n });\n\n it(\"checks the email as typed, so a mixed-case email in this tenant is found\", async () => {\n execute.mockResolvedValue(emailStatus(\"EXISTS_HERE\"));\n const form = presenter();\n\n await form.checkEmail(\" Foo@X.com \");\n\n expect(execute.mock.calls[0][0].variables).toEqual({ email: \"Foo@X.com\" });\n expect(form.vm).toMatchObject({ mode: \"create\", emailError: EMAIL_EXISTS_HERE });\n });\n\n it(\"keeps the latest email's result when an earlier check answers last\", async () => {\n let answerFirst: (value: unknown) => void = () => {};\n execute.mockReturnValueOnce(new Promise(resolve => (answerFirst = resolve)));\n execute.mockResolvedValueOnce(emailStatus(\"AVAILABLE\"));\n const form = presenter();\n\n const first = form.checkEmail(\"person@example.com\");\n await form.checkEmail(\"someone-new@example.com\");\n answerFirst(emailStatus(\"EXISTS_ELSEWHERE\"));\n await first;\n\n expect(form.vm.mode).toBe(\"create\");\n });\n\n it(\"stays in create mode when the check fails\", async () => {\n execute.mockRejectedValue(new Error(\"Network error\"));\n const form = presenter();\n\n await form.checkEmail(\"person@example.com\");\n\n expect(form.vm).toMatchObject({ mode: \"create\", emailError: null });\n });\n\n it(\"creates the user in create mode\", async () => {\n execute.mockResolvedValue(userResponse(user));\n const form = presenter();\n\n const result = await form.submit({\n email: user.email,\n firstName: \"Some\",\n lastName: \"Person\",\n password: \"SecurePass123!\"\n });\n\n expect(result).toEqual({ type: \"created\", user });\n expect(operations()).toEqual([\"CreateUser\"]);\n });\n\n it(\"links the account in link mode, sending only the email, roles and teams\", async () => {\n execute.mockResolvedValueOnce(emailStatus(\"EXISTS_ELSEWHERE\"));\n execute.mockResolvedValueOnce(userResponse(user));\n const form = presenter();\n await form.checkEmail(user.email);\n\n const result = await form.submit({\n email: user.email,\n firstName: \"Typed\",\n password: \"Ignored123!\",\n roles: [{ id: \"editors\" }],\n teams: []\n });\n\n expect(result).toEqual({ type: \"linked\", user });\n expect(operations()).toEqual([\"CheckEmail\", \"LinkUser\"]);\n expect(execute.mock.calls[1][0].variables).toEqual({\n data: { email: user.email, roles: [{ id: \"editors\" }], teams: [] }\n });\n expect(form.vm.saving).toBe(false);\n });\n\n it(\"switches to link mode when creating finds an account in another tenant\", async () => {\n execute.mockResolvedValue(\n userResponse(null, {\n code: \"Cognito/Account/ExistsInOtherTenant\",\n message: \"This email already has an account in another tenant. Link it instead.\",\n data: null\n })\n );\n const form = presenter();\n\n const result = await form.submit({ email: user.email, password: \"SecurePass123!\" });\n\n expect(result).toEqual({ type: \"linkRequired\" });\n expect(form.vm).toMatchObject({ mode: \"link\", emailError: null, saving: false });\n\n // The email is known now, so leaving the field doesn't check it again.\n await form.checkEmail(user.email);\n expect(operations()).toEqual([\"CreateUser\"]);\n });\n\n it(\"reports any other error and stays in create mode\", async () => {\n execute.mockResolvedValue(\n userResponse(null, { code: \"AdminUser/Validation\", message: \"Invalid.\", data: null })\n );\n const form = presenter();\n\n const result = await form.submit({ email: user.email, password: \"SecurePass123!\" });\n\n expect(result).toEqual({ type: \"failed\", message: \"Invalid.\" });\n expect(form.vm.mode).toBe(\"create\");\n });\n\n it(\"starts over in create mode after a reset\", async () => {\n execute.mockResolvedValue(emailStatus(\"EXISTS_ELSEWHERE\"));\n const form = presenter();\n await form.checkEmail(user.email);\n\n form.reset();\n\n expect(form.vm).toEqual({ mode: \"create\", emailError: null, saving: false });\n });\n});\n"],"names":["user","emailStatus","status","userResponse","data","error","describe","container","execute","presenter","UserFormFeature","operations","request","beforeEach","Container","vi","MainGraphQLClient","CreateUserFeature","LinkUserFeature","CheckEmailFeature","it","expect","form","EMAIL_EXISTS_HERE","answerFirst","Promise","resolve","first","Error","result"],"mappings":";;;;;;;;AASA,MAAMA,OAAO;IACT,IAAI;IACJ,OAAO;IACP,WAAW;IACX,UAAU;IACV,QAAQ;IACR,WAAW;IACX,UAAU;AACd;AAEA,MAAMC,cAAc,CAACC,SACV;QAAE,YAAY;YAAE,YAAY;gBAAE,MAAM;oBAAEA;gBAAO;gBAAG,OAAO;YAAK;QAAE;IAAE;AAG3E,MAAMC,eAAe,CAACC,MAA0BC,QAAoC,IAAI,GAC7E;QAAE,YAAY;YAAE,MAAM;gBAAED;gBAAMC;YAAM;QAAE;IAAE;AAGnDC,SAAS,iDAAiD;IACtD,IAAIC;IACJ,IAAIC;IAEJ,MAAMC,YAAY,IAAMC,gBAAgB,OAAO,CAACH,WAAW,SAAS;IAGpE,MAAMI,aAAa,IACRH,QAAQ,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAACI,QAAQ,GAC7B,yBAAyB,IAAI,CAACA,QAAQ,KAAK,GAAG,CAAC,EAAE;IAIhEC,WAAW;QACPN,YAAY,IAAIO;QAChBN,UAAUO,GAAG,EAAE;QACfR,UAAU,gBAAgB,CAACS,mBAAmB;YAC1CR;QACJ;QAEAS,kBAAkB,QAAQ,CAACV;QAC3BW,gBAAgB,QAAQ,CAACX;QACzBY,kBAAkB,QAAQ,C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,aAAa,MAAM;YAAE,MAAM;YAAwB,SAAS;YAAY,MAAM;QAAK;QAEvF,MAAMmB,OAAOb;QAEb,MAAMoB,SAAS,MAAMP,KAAK,MAAM,CAAC;YAAE,OAAOtB,KAAK,KAAK;YAAE,UAAU;QAAiB;QAEjFqB,OAAOQ,QAAQ,OAAO,CAAC;YAAE,MAAM;YAAU,SAAS;QAAW;QAC7DR,OAAOC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;IAC9B;IAEAF,GAAG,4CAA4C;QAC3CZ,QAAQ,iBAAiB,CAACP,YAAY;QACtC,MAAMqB,OAAOb;QACb,MAAMa,KAAK,UAAU,CAACtB,KAAK,KAAK;QAEhCsB,KAAK,KAAK;QAEVD,OAAOC,KAAK,EAAE,EAAE,OAAO,CAAC;YAAE,MAAM;YAAU,YAAY;YAAM,QAAQ;QAAM;IAC9E;AACJ"}
1
+ {"version":3,"file":"admin/presentation/users/UserForm/UserFormPresenter.test.js","sources":["../../../../../src/admin/presentation/users/UserForm/UserFormPresenter.test.ts"],"sourcesContent":["import { describe, it, expect, vi, beforeEach } from \"vitest\";\nimport { Container } from \"@webiny/di\";\nimport { MainGraphQLClient } from \"@webiny/app/features/mainGraphQLClient/index.js\";\nimport { CreateUserFeature } from \"~/admin/features/users/createUser/index.js\";\nimport { LinkUserFeature } from \"~/admin/features/users/linkUser/index.js\";\nimport { CheckEmailFeature } from \"~/admin/features/users/checkEmail/index.js\";\nimport { UserFormFeature } from \"./feature.js\";\nimport { EMAIL_EXISTS_HERE } from \"./UserFormPresenter.js\";\n\nconst user = {\n id: \"user-1\",\n email: \"person@example.com\",\n firstName: \"Some\",\n lastName: \"Person\",\n avatar: null,\n createdOn: \"2026-10-23T00:00:00.000Z\",\n external: false\n};\n\nconst emailStatus = (status: string) => {\n return { adminUsers: { checkEmail: { data: { status }, error: null } } };\n};\n\nconst userResponse = (data: typeof user | null, error: Record<string, any> | null = null) => {\n return { adminUsers: { user: { data, error } } };\n};\n\ndescribe(\"UserFormPresenter: creating or linking a user\", () => {\n let container: Container;\n let execute: ReturnType<typeof vi.fn>;\n\n const presenter = () => UserFormFeature.resolve(container).presenter;\n\n /** The GraphQL operations the presenter sent, by their operation name. */\n const operations = () => {\n return execute.mock.calls.map(([request]) => {\n return /(query|mutation) (\\w+)/.exec(request.query)?.[2];\n });\n };\n\n beforeEach(() => {\n container = new Container();\n execute = vi.fn();\n container.registerInstance(MainGraphQLClient, {\n execute\n } as unknown as MainGraphQLClient.Interface);\n\n CreateUserFeature.register(container);\n LinkUserFeature.register(container);\n CheckEmailFeature.register(container);\n UserFormFeature.register(container);\n });\n\n it(\"starts in create mode\", () => {\n expect(presenter().vm).toEqual({ mode: \"create\", emailError: null, saving: false });\n });\n\n it(\"stays in create mode for a new email\", async () => {\n execute.mockResolvedValue(emailStatus(\"AVAILABLE\"));\n const form = presenter();\n\n await form.checkEmail(\"new@example.com\");\n\n expect(form.vm).toMatchObject({ mode: \"create\", emailError: null });\n });\n\n it(\"switches to link mode for an email with an account in another tenant\", async () => {\n execute.mockResolvedValue(emailStatus(\"EXISTS_ELSEWHERE\"));\n const form = presenter();\n\n await form.checkEmail(\"person@example.com\");\n\n expect(form.vm).toMatchObject({ mode: \"link\", emailError: null });\n });\n\n it(\"shows an email error for a user already in this tenant\", async () => {\n execute.mockResolvedValue(emailStatus(\"EXISTS_HERE\"));\n const form = presenter();\n\n await form.checkEmail(\"person@example.com\");\n\n expect(form.vm).toMatchObject({ mode: \"create\", emailError: EMAIL_EXISTS_HERE });\n });\n\n it(\"goes back to create mode when the email changes to a new one\", async () => {\n execute.mockResolvedValueOnce(emailStatus(\"EXISTS_ELSEWHERE\"));\n execute.mockResolvedValueOnce(emailStatus(\"AVAILABLE\"));\n const form = presenter();\n\n await form.checkEmail(\"person@example.com\");\n await form.checkEmail(\"someone-new@example.com\");\n\n expect(form.vm).toMatchObject({ mode: \"create\", emailError: null });\n });\n\n it(\"doesn't check an incomplete email, or the same email twice\", async () => {\n execute.mockResolvedValue(emailStatus(\"EXISTS_ELSEWHERE\"));\n const form = presenter();\n\n await form.checkEmail(\"person@\");\n await form.checkEmail(\"person@example.com\");\n await form.checkEmail(\" Person@example.com \");\n\n expect(operations()).toEqual([\"CheckEmail\"]);\n expect(form.vm.mode).toBe(\"link\");\n });\n\n it(\"checks the email as typed, so a mixed-case email in this tenant is found\", async () => {\n execute.mockResolvedValue(emailStatus(\"EXISTS_HERE\"));\n const form = presenter();\n\n await form.checkEmail(\" Foo@X.com \");\n\n expect(execute.mock.calls[0][0].variables).toEqual({ email: \"Foo@X.com\" });\n expect(form.vm).toMatchObject({ mode: \"create\", emailError: EMAIL_EXISTS_HERE });\n });\n\n it(\"keeps the latest email's result when an earlier check answers last\", async () => {\n let answerFirst: (value: unknown) => void = () => {};\n execute.mockReturnValueOnce(new Promise(resolve => (answerFirst = resolve)));\n execute.mockResolvedValueOnce(emailStatus(\"AVAILABLE\"));\n const form = presenter();\n\n const first = form.checkEmail(\"person@example.com\");\n await form.checkEmail(\"someone-new@example.com\");\n answerFirst(emailStatus(\"EXISTS_ELSEWHERE\"));\n await first;\n\n expect(form.vm.mode).toBe(\"create\");\n });\n\n it(\"stays in create mode when the check fails\", async () => {\n execute.mockRejectedValue(new Error(\"Network error\"));\n const form = presenter();\n\n await form.checkEmail(\"person@example.com\");\n\n expect(form.vm).toMatchObject({ mode: \"create\", emailError: null });\n });\n\n it(\"creates the user in create mode\", async () => {\n execute.mockResolvedValue(userResponse(user));\n const form = presenter();\n\n const result = await form.submit({\n email: user.email,\n firstName: \"Some\",\n lastName: \"Person\",\n password: \"SecurePass123!\"\n });\n\n expect(result).toEqual({ type: \"created\", user });\n expect(operations()).toEqual([\"CreateUser\"]);\n });\n\n it(\"links the account in link mode, sending only the email, roles and teams\", async () => {\n execute.mockResolvedValueOnce(emailStatus(\"EXISTS_ELSEWHERE\"));\n execute.mockResolvedValueOnce(userResponse(user));\n const form = presenter();\n await form.checkEmail(user.email);\n\n const result = await form.submit({\n email: user.email,\n firstName: \"Typed\",\n password: \"Ignored123!\",\n roles: [{ id: \"editors\" }],\n teams: []\n });\n\n expect(result).toEqual({ type: \"linked\", user });\n expect(operations()).toEqual([\"CheckEmail\", \"LinkUser\"]);\n expect(execute.mock.calls[1][0].variables).toEqual({\n data: { email: user.email, roles: [{ id: \"editors\" }], teams: [] }\n });\n expect(form.vm.saving).toBe(false);\n });\n\n it(\"switches to link mode when creating finds an account in another tenant\", async () => {\n execute.mockResolvedValue(\n userResponse(null, {\n code: \"Cognito/Account/ExistsInOtherTenant\",\n message: \"This email already has an account in another tenant. Link it instead.\",\n data: null\n })\n );\n const form = presenter();\n\n const result = await form.submit({ email: user.email, password: \"SecurePass123!\" });\n\n expect(result).toEqual({ type: \"linkRequired\" });\n expect(form.vm).toMatchObject({ mode: \"link\", emailError: null, saving: false });\n\n // The email is known now, so leaving the field doesn't check it again.\n await form.checkEmail(user.email);\n expect(operations()).toEqual([\"CreateUser\"]);\n });\n\n it(\"reports any other error and stays in create mode\", async () => {\n execute.mockResolvedValue(\n userResponse(null, { code: \"AdminUser/Validation\", message: \"Invalid.\", data: null })\n );\n const form = presenter();\n\n const result = await form.submit({ email: user.email, password: \"SecurePass123!\" });\n\n expect(result).toEqual({ type: \"failed\", message: \"Invalid.\" });\n expect(form.vm.mode).toBe(\"create\");\n });\n\n it(\"starts over in create mode after a reset\", async () => {\n execute.mockResolvedValue(emailStatus(\"EXISTS_ELSEWHERE\"));\n const form = presenter();\n await form.checkEmail(user.email);\n\n form.reset();\n\n expect(form.vm).toEqual({ mode: \"create\", emailError: null, saving: false });\n });\n});\n"],"names":["user","emailStatus","status","userResponse","data","error","describe","container","execute","presenter","UserFormFeature","operations","request","beforeEach","Container","vi","MainGraphQLClient","CreateUserFeature","LinkUserFeature","CheckEmailFeature","it","expect","form","EMAIL_EXISTS_HERE","answerFirst","Promise","resolve","first","Error","result"],"mappings":";;;;;;;;AASA,MAAMA,OAAO;IACT,IAAI;IACJ,OAAO;IACP,WA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;YAAM,QAAQ;QAAM;IAC9E;AACJ"}
@@ -11,6 +11,7 @@ import { Accordion, Alert, Button, Grid, Input, Link, OverlayLoader } from "@web
11
11
  import { config } from "@webiny/app/config.js";
12
12
  import { AvatarImage } from "../../components/AvatarImage/index.js";
13
13
  import { LinkAccountAlert } from "./components/LinkAccountAlert.js";
14
+ import { ResetMfa } from "./components/ResetMfa.js";
14
15
  import { useUserForm } from "./hooks/useUserForm.js";
15
16
  import { usePasswordValidator } from "../../../presentation/shared/usePasswordValidator.js";
16
17
  import { Routes } from "../../../routes.js";
@@ -143,7 +144,10 @@ const UserForm = createReactiveComponent(({ teams })=>{
143
144
  type: "password",
144
145
  label: "Password",
145
146
  "data-testid": "account.password"
146
- }))))), /*#__PURE__*/ react.createElement(Accordion.Item, {
147
+ }))), !isNewUser && userForm.user ? /*#__PURE__*/ react.createElement(ResetMfa, {
148
+ key: userForm.user.id,
149
+ user: userForm.user
150
+ }) : null)), /*#__PURE__*/ react.createElement(Accordion.Item, {
147
151
  title: "Roles",
148
152
  description: "Assign to security roles",
149
153
  icon: /*#__PURE__*/ react.createElement(gpp_maybe_svg_ReactComponent, null)
@@ -1 +1 @@
1
- {"version":3,"file":"admin/ui/views/Users/UsersForm.js","sources":["../../../../../src/admin/ui/views/Users/UsersForm.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\nimport { i18n } from \"@webiny/app/i18n/index.js\";\nimport { Form } from \"@webiny/form\";\nimport { validation } from \"@webiny/validation\";\nimport {\n SimpleForm,\n SimpleFormHeader,\n SimpleFormFooter,\n SimpleFormContent,\n EmptyView,\n RolesMultiAutocomplete,\n TeamsMultiAutocomplete,\n useAuthentication,\n useRouter,\n createReactiveComponent\n} from \"@webiny/app-admin\";\nimport { ReactComponent as AddIcon } from \"@webiny/icons/add.svg\";\nimport { ReactComponent as SecurityIcon } from \"@webiny/icons/gpp_maybe.svg\";\nimport { ReactComponent as SecurityTeamsIcon } from \"@webiny/icons/admin_panel_settings.svg\";\nimport { ReactComponent as SettingsIcon } from \"@webiny/icons/settings.svg\";\nimport { Accordion, Alert, OverlayLoader, Button, Input, Grid, Link } from \"@webiny/admin-ui\";\nimport { config as appConfig } from \"@webiny/app/config.js\";\nimport { AvatarImage } from \"../../components/AvatarImage/index.js\";\nimport { LinkAccountAlert } from \"./components/LinkAccountAlert.js\";\nimport { useUserForm } from \"~/admin/ui/views/Users/hooks/useUserForm.js\";\nimport { usePasswordValidator } from \"~/admin/presentation/shared/usePasswordValidator.js\";\nimport { Routes } from \"~/admin/routes.js\";\n\nconst t = i18n.ns(\"app-security-admin-users/account-form\");\n\nexport interface UserFormProps {\n teams: boolean;\n}\n\nexport const UserForm = createReactiveComponent(({ teams }: UserFormProps) => {\n const { identity } = useAuthentication();\n const userForm = useUserForm();\n const passwordValidator = usePasswordValidator();\n const { getLink } = useRouter();\n\n const isExternal = userForm.user?.external === true;\n const formTitle = userForm.isNewUser ? \"New User\" : userForm.fullName;\n const isNewUser = userForm.isNewUser;\n\n const emailIsDisabled = appConfig.getKey(\n \"ADMIN_USER_CAN_CHANGE_EMAIL\",\n process.env.REACT_APP_ADMIN_USER_CAN_CHANGE_EMAIL === \"false\"\n );\n\n const groupValidators = useMemo(() => {\n return teams ? [] : [validation.create(\"required\")];\n }, [teams]);\n\n const { newUserForm } = userForm;\n const isLinking = isNewUser && newUserForm.vm.mode === \"link\";\n\n const emailValidators = useMemo(() => {\n const validators = [validation.create(\"required,email\")];\n if (!isNewUser) {\n return validators;\n }\n\n // Leaving the field checks whether the email is new, in this tenant, or in another one.\n const emailIsAvailable = async (value: string) => {\n await newUserForm.checkEmail(value);\n if (newUserForm.vm.emailError) {\n throw new Error(newUserForm.vm.emailError);\n }\n };\n\n return [...validators, emailIsAvailable];\n }, [isNewUser, newUserForm]);\n\n const accountLink = getLink(Routes.Users.Account);\n\n // Render \"No content\" selected view.\n if (userForm.showEmptyView) {\n return (\n <EmptyView\n icon={<SettingsIcon />}\n title={t`Click on the left side list to display user details or create a...`}\n action={\n <Button\n icon={<AddIcon />}\n text={t`New User`}\n data-testid=\"new-record-button\"\n onClick={userForm.createUser}\n />\n }\n />\n );\n }\n\n const isSelf = userForm.user?.id === identity.id;\n const isDisabled = isExternal || isSelf;\n\n return (\n <Form data={userForm.user} onSubmit={userForm.onSubmit}>\n {({ data, form, Bind }) => (\n <SimpleForm size={\"lg\"}>\n {userForm.loading && <OverlayLoader />}\n {isLinking ? null : (\n <div className={\"mb-xl\"}>\n <Bind name=\"avatar\">\n <AvatarImage round disabled={isDisabled} />\n </Bind>\n </div>\n )}\n <SimpleFormHeader title={formTitle} />\n <SimpleFormContent>\n {isExternal && (\n <Grid className={\"mb-lg\"}>\n <Grid.Column span={12}>\n <Alert type={\"info\"} title={\"External User\"}>\n This user is an external user and cannot be edited.\n </Alert>\n </Grid.Column>\n </Grid>\n )}\n <LinkAccountAlert presenter={newUserForm} isNewUser={isNewUser} />\n {isSelf && (\n <Grid className={\"mb-lg\"}>\n <Grid.Column span={12}>\n <Alert type={\"info\"} title={\"Own Profile\"}>\n You cannot edit your own profile using this form. Please use\n the <Link to={accountLink}>account settings</Link> instead.\n </Alert>\n </Grid.Column>\n </Grid>\n )}\n <Accordion variant={\"underline\"}>\n <Accordion.Item\n title={\"Bio\"}\n description={\"Account information\"}\n icon={<SettingsIcon />}\n defaultOpen={true}\n >\n <Grid>\n <Grid.Column span={12}>\n <Bind name=\"email\" validators={emailValidators}>\n <Input\n value={data.email}\n label={t`Email`}\n disabled={emailIsDisabled || isDisabled}\n data-testid=\"account.email\"\n autoComplete=\"new-password\"\n description={\n \"Email is your unique identifier used to login!\"\n }\n />\n </Bind>\n </Grid.Column>\n {isLinking ? null : (\n <Grid.Column span={12}>\n <Bind\n name=\"firstName\"\n validators={validation.create(\"required\")}\n >\n <Input\n label={t`First Name`}\n disabled={isDisabled}\n data-testid=\"account.firstname\"\n />\n </Bind>\n </Grid.Column>\n )}\n {isLinking ? null : (\n <Grid.Column span={12}>\n <Bind\n name=\"lastName\"\n validators={validation.create(\"required\")}\n >\n <Input\n label={t`Last Name`}\n disabled={isDisabled}\n data-testid=\"account.lastname\"\n />\n </Bind>\n </Grid.Column>\n )}\n {isLinking ? null : (\n <Grid.Column span={12}>\n <Bind name=\"password\" validators={passwordValidator}>\n <Input\n autoComplete=\"new-password\"\n disabled={isDisabled}\n description={\n data.id &&\n \"Type a new password to reset it.\"\n }\n type=\"password\"\n label={\"Password\"}\n data-testid=\"account.password\"\n />\n </Bind>\n </Grid.Column>\n )}\n </Grid>\n </Accordion.Item>\n <Accordion.Item\n title={\"Roles\"}\n description={\"Assign to security roles\"}\n icon={<SecurityIcon />}\n >\n <Grid>\n <Grid.Column span={12}>\n <Bind name={\"roles\"} validators={groupValidators}>\n {({ value, onChange, validation }) => (\n <RolesMultiAutocomplete\n values={value}\n onChange={onChange}\n validation={validation}\n label={\"Roles\"}\n data-testid=\"roles-autocomplete\"\n disabled={isDisabled}\n />\n )}\n </Bind>\n </Grid.Column>\n </Grid>\n </Accordion.Item>\n {teams ? (\n <Accordion.Item\n title={\"Teams\"}\n description={\"Assign to teams\"}\n icon={<SecurityTeamsIcon />}\n >\n <Grid>\n <Grid.Column span={12}>\n <Bind name={\"teams\"}>\n {({ value, onChange, validation }) => (\n <TeamsMultiAutocomplete\n values={value}\n onChange={onChange}\n validation={validation}\n label={\"Teams\"}\n data-testid=\"teams-autocomplete\"\n disabled={isDisabled}\n />\n )}\n </Bind>\n </Grid.Column>\n </Grid>\n </Accordion.Item>\n ) : null}\n </Accordion>\n </SimpleFormContent>\n <SimpleFormFooter data-testid={\"form-footer\"}>\n <Button\n variant={\"secondary\"}\n text={t`Cancel`}\n onClick={userForm.cancelEditing}\n />\n <Button\n variant={\"primary\"}\n text={\n isLinking\n ? t`Link existing user`\n : isNewUser\n ? t`Create user`\n : t`Update user`\n }\n disabled={isDisabled}\n onClick={form.submit}\n />\n </SimpleFormFooter>\n </SimpleForm>\n )}\n </Form>\n );\n});\n"],"names":["t","i18n","UserForm","createReactiveComponent","teams","identity","useAuthentication","userForm","useUserForm","passwordValidator","usePasswordValidator","getLink","useRouter","isExternal","formTitle","isNewUser","emailIsDisabled","appConfig","process","groupValidators","useMemo","validation","newUserForm","isLinking","emailValidators","validators","emailIsAvailable","value","Error","accountLink","Routes","EmptyView","SettingsIcon","Button","AddIcon","isSelf","isDisabled","Form","data","form","Bind","SimpleForm","OverlayLoader","AvatarImage","SimpleFormHeader","SimpleFormContent","Grid","Alert","LinkAccountAlert","Link","Accordion","Input","SecurityIcon","onChange","RolesMultiAutocomplete","SecurityTeamsIcon","TeamsMultiAutocomplete","SimpleFormFooter"],"mappings":";;;;;;;;;;;;;;;;AA4BA,MAAMA,IAAIC,KAAK,EAAE,CAAC;AAMX,MAAMC,WAAWC,wBAAwB,CAAC,EAAEC,KAAK,EAAiB;IACrE,MAAM,EAAEC,QAAQ,EAAE,GAAGC;IACrB,MAAMC,WAAWC;IACjB,MAAMC,oBAAoBC;IAC1B,MAAM,EAAEC,OAAO,EAAE,GAAGC;IAEpB,MAAMC,aAAaN,SAAS,IAAI,EAAE,aAAa;IAC/C,MAAMO,YAAYP,SAAS,SAAS,GAAG,aAAaA,SAAS,QAAQ;IACrE,MAAMQ,YAAYR,SAAS,SAAS;IAEpC,MAAMS,kBAAkBC,OAAAA,MAAgB,CACpC,+BACAC,AAAsD,YAAtDA,QAAQ,GAAG,CAAC,qCAAqC;IAGrD,MAAMC,kBAAkBC,QAAQ,IACrBhB,QAAQ,EAAE,GAAG;YAACiB,sBAAAA,MAAiB,CAAC;SAAY,EACpD;QAACjB;KAAM;IAEV,MAAM,EAAEkB,WAAW,EAAE,GAAGf;IACxB,MAAMgB,YAAYR,aAAaO,AAAwB,WAAxBA,YAAY,EAAE,CAAC,IAAI;IAElD,MAAME,kBAAkBJ,QAAQ;QAC5B,MAAMK,aAAa;YAACJ,sBAAAA,MAAiB,CAAC;SAAkB;QACxD,IAAI,CAACN,WACD,OAAOU;QAIX,MAAMC,mBAAmB,OAAOC;YA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P,eAAY;8BAOpC,oBAACY,UAAU,IAAI;YACX,OAAO;YACP,aAAa;YACb,oBAAM,oBAACE,8BAAYA;yBAEnB,oBAACN,MAAIA,MAAAA,WAAAA,GACD,oBAACA,KAAK,MAAM;YAAC,MAAM;yBACf,oBAACN,MAAAA;YAAK,MAAM;YAAS,YAAYrB;WAC5B,CAAC,EAAEQ,KAAK,EAAE0B,QAAQ,EAAEhC,UAAU,EAAE,iBAC7B,oBAACiC,wBAAsBA;gBACnB,QAAQ3B;gBACR,UAAU0B;gBACV,YAAYhC;gBACZ,OAAO;gBACP,eAAY;gBACZ,UAAUe;oBAOjChC,QAAQ,WAARA,GACG,oBAAC8C,UAAU,IAAI;YACX,OAAO;YACP,aAAa;YACb,oBAAM,oBAACK,yCAAiBA;yBAExB,oBAACT,MAAIA,MAAAA,WAAAA,GACD,oBAACA,KAAK,MAAM;YAAC,MAAM;yBACf,oBAACN,MAAAA;YAAK,MAAM;WACP,CAAC,EAAEb,KAAK,EAAE0B,QAAQ,EAAEhC,UAAU,EAAE,iBAC7B,oBAACmC,wBAAsBA;gBACnB,QAAQ7B;gBACR,UAAU0B;gBACV,YAAYhC;gBACZ,OAAO;gBACP,eAAY;gBACZ,UAAUe;qBAOlC,sBAGZ,oBAACqB,kBAAgBA;YAAC,eAAa;yBAC3B,oBAACxB,QAAMA;YACH,SAAS;YACT,MAAMjC,CAAC,CAAC,MAAM,CAAC;YACf,SAASO,SAAS,aAAa;0BAEnC,oBAAC0B,QAAMA;YACH,SAAS;YACT,MACIV,YACMvB,CAAC,CAAC,kBAAkB,CAAC,GACrBe,YACEf,CAAC,CAAC,WAAW,CAAC,GACdA,CAAC,CAAC,WAAW,CAAC;YAE1B,UAAUoC;YACV,SAASG,KAAK,MAAM;;AAOhD"}
1
+ {"version":3,"file":"admin/ui/views/Users/UsersForm.js","sources":["../../../../../src/admin/ui/views/Users/UsersForm.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\nimport { i18n } from \"@webiny/app/i18n/index.js\";\nimport { Form } from \"@webiny/form\";\nimport { validation } from \"@webiny/validation\";\nimport {\n SimpleForm,\n SimpleFormHeader,\n SimpleFormFooter,\n SimpleFormContent,\n EmptyView,\n RolesMultiAutocomplete,\n TeamsMultiAutocomplete,\n useAuthentication,\n useRouter,\n createReactiveComponent\n} from \"@webiny/app-admin\";\nimport { ReactComponent as AddIcon } from \"@webiny/icons/add.svg\";\nimport { ReactComponent as SecurityIcon } from \"@webiny/icons/gpp_maybe.svg\";\nimport { ReactComponent as SecurityTeamsIcon } from \"@webiny/icons/admin_panel_settings.svg\";\nimport { ReactComponent as SettingsIcon } from \"@webiny/icons/settings.svg\";\nimport { Accordion, Alert, OverlayLoader, Button, Input, Grid, Link } from \"@webiny/admin-ui\";\nimport { config as appConfig } from \"@webiny/app/config.js\";\nimport { AvatarImage } from \"../../components/AvatarImage/index.js\";\nimport { LinkAccountAlert } from \"./components/LinkAccountAlert.js\";\nimport { ResetMfa } from \"./components/ResetMfa.js\";\nimport { useUserForm } from \"~/admin/ui/views/Users/hooks/useUserForm.js\";\nimport { usePasswordValidator } from \"~/admin/presentation/shared/usePasswordValidator.js\";\nimport { Routes } from \"~/admin/routes.js\";\n\nconst t = i18n.ns(\"app-security-admin-users/account-form\");\n\nexport interface UserFormProps {\n teams: boolean;\n}\n\nexport const UserForm = createReactiveComponent(({ teams }: UserFormProps) => {\n const { identity } = useAuthentication();\n const userForm = useUserForm();\n const passwordValidator = usePasswordValidator();\n const { getLink } = useRouter();\n\n const isExternal = userForm.user?.external === true;\n const formTitle = userForm.isNewUser ? \"New User\" : userForm.fullName;\n const isNewUser = userForm.isNewUser;\n\n const emailIsDisabled = appConfig.getKey(\n \"ADMIN_USER_CAN_CHANGE_EMAIL\",\n process.env.REACT_APP_ADMIN_USER_CAN_CHANGE_EMAIL === \"false\"\n );\n\n const groupValidators = useMemo(() => {\n return teams ? [] : [validation.create(\"required\")];\n }, [teams]);\n\n const { newUserForm } = userForm;\n const isLinking = isNewUser && newUserForm.vm.mode === \"link\";\n\n const emailValidators = useMemo(() => {\n const validators = [validation.create(\"required,email\")];\n if (!isNewUser) {\n return validators;\n }\n\n // Leaving the field checks whether the email is new, in this tenant, or in another one.\n const emailIsAvailable = async (value: string) => {\n await newUserForm.checkEmail(value);\n if (newUserForm.vm.emailError) {\n throw new Error(newUserForm.vm.emailError);\n }\n };\n\n return [...validators, emailIsAvailable];\n }, [isNewUser, newUserForm]);\n\n const accountLink = getLink(Routes.Users.Account);\n\n // Render \"No content\" selected view.\n if (userForm.showEmptyView) {\n return (\n <EmptyView\n icon={<SettingsIcon />}\n title={t`Click on the left side list to display user details or create a...`}\n action={\n <Button\n icon={<AddIcon />}\n text={t`New User`}\n data-testid=\"new-record-button\"\n onClick={userForm.createUser}\n />\n }\n />\n );\n }\n\n const isSelf = userForm.user?.id === identity.id;\n const isDisabled = isExternal || isSelf;\n\n return (\n <Form data={userForm.user} onSubmit={userForm.onSubmit}>\n {({ data, form, Bind }) => (\n <SimpleForm size={\"lg\"}>\n {userForm.loading && <OverlayLoader />}\n {isLinking ? null : (\n <div className={\"mb-xl\"}>\n <Bind name=\"avatar\">\n <AvatarImage round disabled={isDisabled} />\n </Bind>\n </div>\n )}\n <SimpleFormHeader title={formTitle} />\n <SimpleFormContent>\n {isExternal && (\n <Grid className={\"mb-lg\"}>\n <Grid.Column span={12}>\n <Alert type={\"info\"} title={\"External User\"}>\n This user is an external user and cannot be edited.\n </Alert>\n </Grid.Column>\n </Grid>\n )}\n <LinkAccountAlert presenter={newUserForm} isNewUser={isNewUser} />\n {isSelf && (\n <Grid className={\"mb-lg\"}>\n <Grid.Column span={12}>\n <Alert type={\"info\"} title={\"Own Profile\"}>\n You cannot edit your own profile using this form. Please use\n the <Link to={accountLink}>account settings</Link> instead.\n </Alert>\n </Grid.Column>\n </Grid>\n )}\n <Accordion variant={\"underline\"}>\n <Accordion.Item\n title={\"Bio\"}\n description={\"Account information\"}\n icon={<SettingsIcon />}\n defaultOpen={true}\n >\n <Grid>\n <Grid.Column span={12}>\n <Bind name=\"email\" validators={emailValidators}>\n <Input\n value={data.email}\n label={t`Email`}\n disabled={emailIsDisabled || isDisabled}\n data-testid=\"account.email\"\n autoComplete=\"new-password\"\n description={\n \"Email is your unique identifier used to login!\"\n }\n />\n </Bind>\n </Grid.Column>\n {isLinking ? null : (\n <Grid.Column span={12}>\n <Bind\n name=\"firstName\"\n validators={validation.create(\"required\")}\n >\n <Input\n label={t`First Name`}\n disabled={isDisabled}\n data-testid=\"account.firstname\"\n />\n </Bind>\n </Grid.Column>\n )}\n {isLinking ? null : (\n <Grid.Column span={12}>\n <Bind\n name=\"lastName\"\n validators={validation.create(\"required\")}\n >\n <Input\n label={t`Last Name`}\n disabled={isDisabled}\n data-testid=\"account.lastname\"\n />\n </Bind>\n </Grid.Column>\n )}\n {isLinking ? null : (\n <Grid.Column span={12}>\n <Bind name=\"password\" validators={passwordValidator}>\n <Input\n autoComplete=\"new-password\"\n disabled={isDisabled}\n description={\n data.id &&\n \"Type a new password to reset it.\"\n }\n type=\"password\"\n label={\"Password\"}\n data-testid=\"account.password\"\n />\n </Bind>\n </Grid.Column>\n )}\n {!isNewUser && userForm.user ? (\n <ResetMfa key={userForm.user.id} user={userForm.user} />\n ) : null}\n </Grid>\n </Accordion.Item>\n <Accordion.Item\n title={\"Roles\"}\n description={\"Assign to security roles\"}\n icon={<SecurityIcon />}\n >\n <Grid>\n <Grid.Column span={12}>\n <Bind name={\"roles\"} validators={groupValidators}>\n {({ value, onChange, validation }) => (\n <RolesMultiAutocomplete\n values={value}\n onChange={onChange}\n validation={validation}\n label={\"Roles\"}\n data-testid=\"roles-autocomplete\"\n disabled={isDisabled}\n />\n )}\n </Bind>\n </Grid.Column>\n </Grid>\n </Accordion.Item>\n {teams ? (\n <Accordion.Item\n title={\"Teams\"}\n description={\"Assign to teams\"}\n icon={<SecurityTeamsIcon />}\n >\n <Grid>\n <Grid.Column span={12}>\n <Bind name={\"teams\"}>\n {({ value, onChange, validation }) => (\n <TeamsMultiAutocomplete\n values={value}\n onChange={onChange}\n validation={validation}\n label={\"Teams\"}\n data-testid=\"teams-autocomplete\"\n disabled={isDisabled}\n />\n )}\n </Bind>\n </Grid.Column>\n </Grid>\n </Accordion.Item>\n ) : null}\n </Accordion>\n </SimpleFormContent>\n <SimpleFormFooter data-testid={\"form-footer\"}>\n <Button\n variant={\"secondary\"}\n text={t`Cancel`}\n onClick={userForm.cancelEditing}\n />\n <Button\n variant={\"primary\"}\n text={\n isLinking\n ? t`Link existing user`\n : isNewUser\n ? t`Create user`\n : t`Update user`\n }\n disabled={isDisabled}\n onClick={form.submit}\n />\n </SimpleFormFooter>\n </SimpleForm>\n )}\n </Form>\n );\n});\n"],"names":["t","i18n","UserForm","createReactiveComponent","teams","identity","useAuthentication","userForm","useUserForm","passwordValidator","usePasswordValidator","getLink","useRouter","isExternal","formTitle","isNewUser","emailIsDisabled","appConfig","process","groupValidators","useMemo","validation","newUserForm","isLinking","emailValidators","validators","emailIsAvailable","value","Error","accountLink","Routes","EmptyView","SettingsIcon","Button","AddIcon","isSelf","isDisabled","Form","data","form","Bind","SimpleForm","OverlayLoader","AvatarImage","SimpleFormHeader","SimpleFormContent","Grid","Alert","LinkAccountAlert","Link","Accordion","Input","ResetMfa","SecurityIcon","onChange","RolesMultiAutocomplete","SecurityTeamsIcon","TeamsMultiAutocomplete","SimpleFormFooter"],"mappings":";;;;;;;;;;;;;;;;;AA6BA,MAAMA,IAAIC,KAAK,EAAE,CAAC;AAMX,MAAMC,WAAWC,wBAAwB,CAAC,EAAEC,KAAK,EAAiB;IACrE,MAAM,EAAEC,QAAQ,EAAE,GAAGC;IACrB,MAAMC,WAAWC;IACjB,MAAMC,oBAAoBC;IAC1B,MAAM,EAAEC,OAAO,EAAE,GAAGC;IAEpB,MAAMC,aAAaN,SAAS,IAAI,EAAE,aAAa;IAC/C,MAAMO,YAAYP,SAAS,SAAS,GAAG,aAAaA,SAAS,QAAQ;IACrE,MAAMQ,YAAYR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E2B,QAAQ,EAAEjC,UAAU,EAAE,iBAC7B,oBAACoC,wBAAsBA;gBACnB,QAAQ9B;gBACR,UAAU2B;gBACV,YAAYjC;gBACZ,OAAO;gBACP,eAAY;gBACZ,UAAUe;qBAOlC,sBAGZ,oBAACsB,kBAAgBA;YAAC,eAAa;yBAC3B,oBAACzB,QAAMA;YACH,SAAS;YACT,MAAMjC,CAAC,CAAC,MAAM,CAAC;YACf,SAASO,SAAS,aAAa;0BAEnC,oBAAC0B,QAAMA;YACH,SAAS;YACT,MACIV,YACMvB,CAAC,CAAC,kBAAkB,CAAC,GACrBe,YACEf,CAAC,CAAC,WAAW,CAAC,GACdA,CAAC,CAAC,WAAW,CAAC;YAE1B,UAAUoC;YACV,SAASG,KAAK,MAAM;;AAOhD"}
@@ -0,0 +1,12 @@
1
+ import React from "react";
2
+ import type { ResetMfaUser } from "../../../../../admin/presentation/users/ResetMfa/abstractions.js";
3
+ export interface ResetMfaProps {
4
+ user: ResetMfaUser;
5
+ }
6
+ /**
7
+ * Lets an administrator reset the MFA of a user who lost access to their authenticator app.
8
+ * Render it with `key={user.id}`, so it starts over for each user.
9
+ */
10
+ export declare const ResetMfa: (({ user }: ResetMfaProps) => React.JSX.Element | null) & React.NamedExoticComponent<ResetMfaProps> & {
11
+ readonly type: ({ user }: ResetMfaProps) => React.JSX.Element | null;
12
+ };
@@ -0,0 +1,61 @@
1
+ import react, { useEffect } from "react";
2
+ import { useFeature } from "@webiny/app";
3
+ import { createReactiveComponent, useAuthentication, useConfirmationDialog } from "@webiny/app-admin";
4
+ import { Button, Grid, Text, useToast } from "@webiny/admin-ui";
5
+ import { ResetMfaFeature } from "../../../../presentation/users/ResetMfa/feature.js";
6
+ import { RESET_MFA_TITLE, RESET_MFA_WARNING } from "../../../../presentation/users/ResetMfa/ResetMfaPresenter.js";
7
+ const ResetMfa = createReactiveComponent(({ user })=>{
8
+ const { identity } = useAuthentication();
9
+ const { presenter } = useFeature(ResetMfaFeature);
10
+ const toast = useToast();
11
+ const { showConfirmation } = useConfirmationDialog({
12
+ title: RESET_MFA_TITLE,
13
+ message: RESET_MFA_WARNING,
14
+ acceptLabel: "Reset MFA",
15
+ dataTestId: "users.reset-mfa-dialog"
16
+ });
17
+ useEffect(()=>{
18
+ presenter.init({
19
+ user,
20
+ currentIdentityId: identity?.id
21
+ });
22
+ }, [
23
+ user,
24
+ identity?.id
25
+ ]);
26
+ if (!presenter.vm.available) return null;
27
+ const onClick = ()=>{
28
+ showConfirmation(async ()=>{
29
+ const result = await presenter.reset();
30
+ if ("reset" === result.type) toast.showSuccessToast({
31
+ title: result.message
32
+ });
33
+ else toast.showWarningToast({
34
+ title: "Error resetting MFA",
35
+ description: result.message,
36
+ duration: 1 / 0
37
+ });
38
+ });
39
+ };
40
+ return /*#__PURE__*/ react.createElement(Grid.Column, {
41
+ span: 12
42
+ }, /*#__PURE__*/ react.createElement("div", {
43
+ className: "flex items-center justify-between gap-md"
44
+ }, /*#__PURE__*/ react.createElement("div", null, /*#__PURE__*/ react.createElement(Text, {
45
+ as: "div",
46
+ size: "md"
47
+ }, "Multi-factor authentication"), /*#__PURE__*/ react.createElement(Text, {
48
+ as: "div",
49
+ size: "sm",
50
+ className: "text-neutral-strong"
51
+ }, "If the user lost access to their authenticator app, reset MFA so they set it up again on their next sign-in.")), /*#__PURE__*/ react.createElement(Button, {
52
+ variant: "secondary",
53
+ text: "Reset MFA",
54
+ disabled: presenter.vm.resetting,
55
+ onClick: onClick,
56
+ "data-testid": "users.reset-mfa"
57
+ })));
58
+ });
59
+ export { ResetMfa };
60
+
61
+ //# sourceMappingURL=ResetMfa.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin/ui/views/Users/components/ResetMfa.js","sources":["../../../../../../src/admin/ui/views/Users/components/ResetMfa.tsx"],"sourcesContent":["import React, { useEffect } from \"react\";\nimport { useFeature } from \"@webiny/app\";\nimport {\n createReactiveComponent,\n useAuthentication,\n useConfirmationDialog\n} from \"@webiny/app-admin\";\nimport { Button, Grid, Text, useToast } from \"@webiny/admin-ui\";\nimport { ResetMfaFeature } from \"~/admin/presentation/users/ResetMfa/feature.js\";\nimport {\n RESET_MFA_TITLE,\n RESET_MFA_WARNING\n} from \"~/admin/presentation/users/ResetMfa/ResetMfaPresenter.js\";\nimport type { ResetMfaUser } from \"~/admin/presentation/users/ResetMfa/abstractions.js\";\n\nexport interface ResetMfaProps {\n user: ResetMfaUser;\n}\n\n/**\n * Lets an administrator reset the MFA of a user who lost access to their authenticator app.\n * Render it with `key={user.id}`, so it starts over for each user.\n */\nexport const ResetMfa = createReactiveComponent(({ user }: ResetMfaProps) => {\n const { identity } = useAuthentication();\n const { presenter } = useFeature(ResetMfaFeature);\n const toast = useToast();\n const { showConfirmation } = useConfirmationDialog({\n title: RESET_MFA_TITLE,\n message: RESET_MFA_WARNING,\n acceptLabel: \"Reset MFA\",\n dataTestId: \"users.reset-mfa-dialog\"\n });\n\n useEffect(() => {\n presenter.init({ user, currentIdentityId: identity?.id });\n }, [user, identity?.id]);\n\n if (!presenter.vm.available) {\n return null;\n }\n\n const onClick = () => {\n showConfirmation(async () => {\n const result = await presenter.reset();\n if (result.type === \"reset\") {\n toast.showSuccessToast({ title: result.message });\n } else {\n toast.showWarningToast({\n title: \"Error resetting MFA\",\n description: result.message,\n duration: Infinity\n });\n }\n });\n };\n\n return (\n <Grid.Column span={12}>\n <div className={\"flex items-center justify-between gap-md\"}>\n <div>\n <Text as={\"div\"} size={\"md\"}>\n Multi-factor authentication\n </Text>\n <Text as={\"div\"} size={\"sm\"} className={\"text-neutral-strong\"}>\n If the user lost access to their authenticator app, reset MFA so they set it\n up again on their next sign-in.\n </Text>\n </div>\n <Button\n variant={\"secondary\"}\n text={\"Reset MFA\"}\n disabled={presenter.vm.resetting}\n onClick={onClick}\n data-testid={\"users.reset-mfa\"}\n />\n </div>\n </Grid.Column>\n );\n});\n"],"names":["ResetMfa","createReactiveComponent","user","identity","useAuthentication","presenter","useFeature","ResetMfaFeature","toast","useToast","showConfirmation","useConfirmationDialog","RESET_MFA_TITLE","RESET_MFA_WARNING","useEffect","onClick","result","Infinity","Grid","Text","Button"],"mappings":";;;;;;AAuBO,MAAMA,WAAWC,wBAAwB,CAAC,EAAEC,IAAI,EAAiB;IACpE,MAAM,EAAEC,QAAQ,EAAE,GAAGC;IACrB,MAAM,EAAEC,SAAS,EAAE,GAAGC,WAAWC;IACjC,MAAMC,QAAQC;IACd,MAAM,EAAEC,gBAAgB,EAAE,GAAGC,sBAAsB;QAC/C,OAAOC;QACP,SAASC;QACT,aAAa;QACb,YAAY;IAChB;IAEAC,UAAU;QACNT,UAAU,IAAI,CAAC;YAAEH;YAAM,mBAAmBC,UAAU;QAAG;IAC3D,GAAG;QAACD;QAAMC,UAAU;KAAG;IAEvB,IAAI,CAACE,UAAU,EAAE,CAAC,SAAS,EACvB,OAAO;IAGX,MAAMU,UAAU;QACZL,iBAAiB;YACb,MAAMM,SAAS,MAAMX,UAAU,KAAK;YACpC,IAAIW,AAAgB,YAAhBA,OAAO,IAAI,EACXR,MAAM,gBAAgB,CAAC;gBAAE,OAAOQ,OAAO,OAAO;YAAC;iBAE/CR,MAAM,gBAAgB,CAAC;gBACnB,OAAO;gBACP,aAAaQ,OAAO,OAAO;gBAC3B,UAAUC,KAAQ;YACtB;QAER;IACJ;IAEA,OAAO,WAAP,GACI,oBAACC,KAAK,MAAM;QAAC,MAAM;qBACf,oBAAC;QAAI,WAAW;qBACZ,oBAAC,2BACG,oBAACC,MAAIA;QAAC,IAAI;QAAO,MAAM;OAAM,8CAG7B,oBAACA,MAAIA;QAAC,IAAI;QAAO,MAAM;QAAM,WAAW;OAAuB,gIAKnE,oBAACC,QAAMA;QACH,SAAS;QACT,MAAM;QACN,UAAUf,UAAU,EAAE,CAAC,SAAS;QAChC,SAASU;QACT,eAAa;;AAKjC"}
@@ -5,6 +5,7 @@ import { CognitoIdpFeature } from "./features/CognitoIdp/index.js";
5
5
  import { CreateUserFeature } from "./features/CreateUser/index.js";
6
6
  import { UpdateUserFeature } from "./features/UpdateUser/index.js";
7
7
  import { DeleteUserFeature } from "./features/DeleteUser/index.js";
8
+ import { ResetUserMfaFeature } from "./features/ResetUserMfa/index.js";
8
9
  import { LinkUserFeature } from "./features/LinkUser/index.js";
9
10
  import { CheckEmailFeature } from "./features/CheckEmail/index.js";
10
11
  import { CognitoServiceFeature } from "./features/CognitoService/feature.js";
@@ -14,6 +15,7 @@ const CognitoApiFeature = createFeature({
14
15
  CreateUserFeature.register(container);
15
16
  UpdateUserFeature.register(container);
16
17
  DeleteUserFeature.register(container);
18
+ ResetUserMfaFeature.register(container);
17
19
  LinkUserFeature.register(container);
18
20
  CheckEmailFeature.register(container);
19
21
  UserInstallerFeature.register(container);
@@ -1 +1 @@
1
- {"version":3,"file":"api/CognitoApiFeature.js","sources":["../../src/api/CognitoApiFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { AdminUsersSchema } from \"~/api/graphql/user.gql.js\";\nimport { UserInstallerFeature } from \"./features/UserInstaller/feature.js\";\nimport { CognitoIdpFeature } from \"./features/CognitoIdp/index.js\";\nimport { CreateUserFeature } from \"./features/CreateUser/index.js\";\nimport { UpdateUserFeature } from \"./features/UpdateUser/index.js\";\nimport { DeleteUserFeature } from \"./features/DeleteUser/index.js\";\nimport { LinkUserFeature } from \"./features/LinkUser/index.js\";\nimport { CheckEmailFeature } from \"./features/CheckEmail/index.js\";\nimport { CognitoServiceFeature } from \"~/api/features/CognitoService/feature.js\";\n\nexport const CognitoApiFeature = createFeature({\n name: \"CognitoApiFeature\",\n register(container) {\n // Register features\n CreateUserFeature.register(container);\n UpdateUserFeature.register(container);\n DeleteUserFeature.register(container);\n LinkUserFeature.register(container);\n CheckEmailFeature.register(container);\n UserInstallerFeature.register(container);\n CognitoIdpFeature.register(container);\n CognitoServiceFeature.register(container, {\n region: String(process.env.COGNITO_REGION),\n userPoolId: String(process.env.COGNITO_USER_POOL_ID)\n });\n\n // Register GraphQL schema\n container.register(AdminUsersSchema);\n }\n});\n"],"names":["CognitoApiFeature","createFeature","container","CreateUserFeature","UpdateUserFeature","DeleteUserFeature","LinkUserFeature","CheckEmailFeature","UserInstallerFeature","CognitoIdpFeature","CognitoServiceFeature","String","process","AdminUsersSchema"],"mappings":";;;;;;;;;;AAWO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QAEdC,kBAAkB,QAAQ,CAACD;QAC3BE,kBAAkB,QAAQ,CAACF;QAC3BG,kBAAkB,QAAQ,CAACH;QAC3BI,gBAAgB,QAAQ,CAACJ;QACzBK,kBAAkB,QAAQ,CAACL;QAC3BM,qBAAqB,QAAQ,CAACN;QAC9BO,kBAAkB,QAAQ,CAACP;QAC3BQ,sBAAsB,QAAQ,CAACR,WAAW;YACtC,QAAQS,OAAOC,QAAQ,GAAG,CAAC,cAAc;YACzC,YAAYD,OAAOC,QAAQ,GAAG,CAAC,oBAAoB;QACvD;QAGAV,UAAU,QAAQ,CAACW;IACvB;AACJ"}
1
+ {"version":3,"file":"api/CognitoApiFeature.js","sources":["../../src/api/CognitoApiFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { AdminUsersSchema } from \"~/api/graphql/user.gql.js\";\nimport { UserInstallerFeature } from \"./features/UserInstaller/feature.js\";\nimport { CognitoIdpFeature } from \"./features/CognitoIdp/index.js\";\nimport { CreateUserFeature } from \"./features/CreateUser/index.js\";\nimport { UpdateUserFeature } from \"./features/UpdateUser/index.js\";\nimport { DeleteUserFeature } from \"./features/DeleteUser/index.js\";\nimport { ResetUserMfaFeature } from \"./features/ResetUserMfa/index.js\";\nimport { LinkUserFeature } from \"./features/LinkUser/index.js\";\nimport { CheckEmailFeature } from \"./features/CheckEmail/index.js\";\nimport { CognitoServiceFeature } from \"~/api/features/CognitoService/feature.js\";\n\nexport const CognitoApiFeature = createFeature({\n name: \"CognitoApiFeature\",\n register(container) {\n // Register features\n CreateUserFeature.register(container);\n UpdateUserFeature.register(container);\n DeleteUserFeature.register(container);\n ResetUserMfaFeature.register(container);\n LinkUserFeature.register(container);\n CheckEmailFeature.register(container);\n UserInstallerFeature.register(container);\n CognitoIdpFeature.register(container);\n CognitoServiceFeature.register(container, {\n region: String(process.env.COGNITO_REGION),\n userPoolId: String(process.env.COGNITO_USER_POOL_ID)\n });\n\n // Register GraphQL schema\n container.register(AdminUsersSchema);\n }\n});\n"],"names":["CognitoApiFeature","createFeature","container","CreateUserFeature","UpdateUserFeature","DeleteUserFeature","ResetUserMfaFeature","LinkUserFeature","CheckEmailFeature","UserInstallerFeature","CognitoIdpFeature","CognitoServiceFeature","String","process","AdminUsersSchema"],"mappings":";;;;;;;;;;;AAYO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QAEdC,kBAAkB,QAAQ,CAACD;QAC3BE,kBAAkB,QAAQ,CAACF;QAC3BG,kBAAkB,QAAQ,CAACH;QAC3BI,oBAAoB,QAAQ,CAACJ;QAC7BK,gBAAgB,QAAQ,CAACL;QACzBM,kBAAkB,QAAQ,CAACN;QAC3BO,qBAAqB,QAAQ,CAACP;QAC9BQ,kBAAkB,QAAQ,CAACR;QAC3BS,sBAAsB,QAAQ,CAACT,WAAW;YACtC,QAAQU,OAAOC,QAAQ,GAAG,CAAC,cAAc;YACzC,YAAYD,OAAOC,QAAQ,GAAG,CAAC,oBAAoB;QACvD;QAGAX,UAAU,QAAQ,CAACY;IACvB;AACJ"}
@@ -75,6 +75,25 @@ export declare class CognitoDeleteUserError extends BaseError<{
75
75
  readonly code: "Cognito/User/Delete";
76
76
  constructor(error: Error);
77
77
  }
78
+ /**
79
+ * Error when resetting a user's MFA in Cognito fails
80
+ */
81
+ export declare class CognitoResetMfaError extends BaseError<{
82
+ error: Error;
83
+ }> {
84
+ readonly code: "Cognito/User/ResetMfa";
85
+ constructor(error: Error);
86
+ }
87
+ /**
88
+ * Error when resetting the MFA of a user who signs in through an external identity provider,
89
+ * which manages their MFA
90
+ */
91
+ export declare class CognitoExternalUserError extends BaseError<{
92
+ id: string;
93
+ }> {
94
+ readonly code: "Cognito/User/External";
95
+ constructor(id: string);
96
+ }
78
97
  /**
79
98
  * Error when an administrator changes the sign-in details of an account that other tenants share
80
99
  */