@webiny/app-admin 6.6.0-alpha.12 → 6.6.0-alpha.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base/Base/FieldRenderers/ObjectRenderer/KeyValueTagsRenderer.js.map +1 -1
- package/base/Base/FieldRenderers/ObjectRenderer/MultiValueDynamicZone/MultiValueDynamicZone.js.map +1 -1
- package/base/Base/FieldRenderers/ObjectRenderer/ObjectAccordionMultipleRenderer.js.map +1 -1
- package/base/Base/FieldRenderers/ObjectRenderer/ObjectFieldComponents.js.map +1 -1
- package/base/Base/LexicalPreset.js +1 -1
- package/base/Base/LexicalPreset.js.map +1 -1
- package/base/Base/Menus.js.map +1 -1
- package/base/Base/RoutesConfig.js.map +1 -1
- package/base/Base/Tenant.js.map +1 -1
- package/base/Base/UserMenu/SwitchTenant.d.ts +20 -0
- package/base/Base/UserMenu/SwitchTenant.js +45 -0
- package/base/Base/UserMenu/SwitchTenant.js.map +1 -0
- package/base/Base/UserMenu.js +4 -0
- package/base/Base/UserMenu.js.map +1 -1
- package/base/Base.js.map +1 -1
- package/base/ui/AssumedPermissionsSelector.js.map +1 -1
- package/base/ui/Brand.js.map +1 -1
- package/base/ui/Dashboard.js.map +1 -1
- package/base/ui/FileManager.js.map +1 -1
- package/base/ui/LoginScreen.js.map +1 -1
- package/base/ui/Logo.js.map +1 -1
- package/base/ui/Navigation.js.map +1 -1
- package/base/ui/NotFound.js.map +1 -1
- package/base/ui/Tags.js.map +1 -1
- package/base/ui/TenantSelector.js.map +1 -1
- package/base/ui/UserMenu/UserMenu.js.map +1 -1
- package/base/ui/UserMenu/UserMenuHandle.js.map +1 -1
- package/base/ui/UserMenu.js.map +1 -1
- package/components/Buttons/useButtons.js.map +1 -1
- package/components/Dialogs/DialogParamsContext.js.map +1 -1
- package/components/Dialogs/DialogsContext.js.map +1 -1
- package/components/Drawers/DrawerParamsContext.js.map +1 -1
- package/components/Drawers/DrawersContext.js.map +1 -1
- package/components/Filters/FiltersToggle.js.map +1 -1
- package/components/IconPicker/IconPickerPresenterProvider.js.map +1 -1
- package/components/IconPicker/IconPickerTab.js.map +1 -1
- package/components/IconPicker/IconRenderer.js.map +1 -1
- package/components/IconPicker/config/IconType.js.map +1 -1
- package/components/IconPicker/config/index.js.map +1 -1
- package/components/IconPicker/plugins/customPlugin.js.map +1 -1
- package/components/IconPicker/plugins/emojisPlugin.js.map +1 -1
- package/components/IconPicker/plugins/iconsPlugin.js.map +1 -1
- package/components/IconPicker/types.js.map +1 -1
- package/components/LexicalEditor/DefaultLexicalEditorConfig.js +1 -1
- package/components/LexicalEditor/DefaultLexicalEditorConfig.js.map +1 -1
- package/components/LexicalEditor/LexicalEditor.d.ts +3 -1
- package/components/LexicalEditor/LexicalEditor.js +3 -2
- package/components/LexicalEditor/LexicalEditor.js.map +1 -1
- package/components/LexicalEditor/LexicalLinkForm.js.map +1 -1
- package/components/ListView/ListViewBottomBar.js.map +1 -1
- package/components/ListView/ListViewHeader.js.map +1 -1
- package/components/OptionsMenu/useOptionsMenuItem.js.map +1 -1
- package/components/Table/useTableRow.js.map +1 -1
- package/config/AdminConfig/LexicalTheme/Typography.js +4 -4
- package/config/AdminConfig/LexicalTheme/Typography.js.map +1 -1
- package/config/AdminConfig/Menu.js.map +1 -1
- package/config/AdminConfig/Theme.js +1 -1
- package/config/AdminConfig/Theme.js.map +1 -1
- package/config/AdminConfig.js +2 -2
- package/config/AdminConfig.js.map +1 -1
- package/config/createAdminConfig.js.map +1 -1
- package/domain/Identity.d.ts +8 -0
- package/domain/Identity.js +6 -0
- package/domain/Identity.js.map +1 -1
- package/exports/admin/security.d.ts +4 -1
- package/exports/admin/security.js +4 -1
- package/exports/admin.d.ts +2 -0
- package/exports/admin.js +2 -0
- package/features/accessManagement/constants.js.map +1 -1
- package/features/adminUsers/capabilities/abstractions.d.ts +18 -0
- package/features/adminUsers/capabilities/abstractions.js +5 -0
- package/features/adminUsers/capabilities/abstractions.js.map +1 -0
- package/features/adminUsers/capabilities/feature.d.ts +4 -0
- package/features/adminUsers/capabilities/feature.js +19 -0
- package/features/adminUsers/capabilities/feature.js.map +1 -0
- package/features/adminUsers/capabilities/index.d.ts +3 -0
- package/features/adminUsers/capabilities/index.js +2 -0
- package/features/adminUsers/users/checkEmail/CheckEmailGateway.d.ts +11 -0
- package/features/adminUsers/users/checkEmail/CheckEmailGateway.js +44 -0
- package/features/adminUsers/users/checkEmail/CheckEmailGateway.js.map +1 -0
- package/features/adminUsers/users/checkEmail/CheckEmailUseCase.d.ts +10 -0
- package/features/adminUsers/users/checkEmail/CheckEmailUseCase.js +18 -0
- package/features/adminUsers/users/checkEmail/CheckEmailUseCase.js.map +1 -0
- package/features/adminUsers/users/checkEmail/abstractions/CheckEmailGateway.d.ts +14 -0
- package/features/adminUsers/users/checkEmail/abstractions/CheckEmailGateway.js +5 -0
- package/features/adminUsers/users/checkEmail/abstractions/CheckEmailGateway.js.map +1 -0
- package/features/adminUsers/users/checkEmail/abstractions/CheckEmailUseCase.d.ts +9 -0
- package/features/adminUsers/users/checkEmail/abstractions/CheckEmailUseCase.js +5 -0
- package/features/adminUsers/users/checkEmail/abstractions/CheckEmailUseCase.js.map +1 -0
- package/features/adminUsers/users/checkEmail/abstractions/index.d.ts +2 -0
- package/features/adminUsers/users/checkEmail/abstractions/index.js +2 -0
- package/features/adminUsers/users/checkEmail/feature.d.ts +3 -0
- package/features/adminUsers/users/checkEmail/feature.js +19 -0
- package/features/adminUsers/users/checkEmail/feature.js.map +1 -0
- package/features/adminUsers/users/checkEmail/index.d.ts +2 -0
- package/features/adminUsers/users/checkEmail/index.js +2 -0
- package/features/adminUsers/users/createUser/CreateUserGateway.js +2 -1
- package/features/adminUsers/users/createUser/CreateUserGateway.js.map +1 -1
- package/features/adminUsers/users/createUser/CreateUserUseCase.test.d.ts +1 -0
- package/features/adminUsers/users/createUser/CreateUserUseCase.test.js +65 -0
- package/features/adminUsers/users/createUser/CreateUserUseCase.test.js.map +1 -0
- package/features/adminUsers/users/linkUser/LinkUserGateway.d.ts +11 -0
- package/features/adminUsers/users/linkUser/LinkUserGateway.js +50 -0
- package/features/adminUsers/users/linkUser/LinkUserGateway.js.map +1 -0
- package/features/adminUsers/users/linkUser/LinkUserUseCase.d.ts +10 -0
- package/features/adminUsers/users/linkUser/LinkUserUseCase.js +18 -0
- package/features/adminUsers/users/linkUser/LinkUserUseCase.js.map +1 -0
- package/features/adminUsers/users/linkUser/abstractions/LinkUserGateway.d.ts +18 -0
- package/features/adminUsers/users/linkUser/abstractions/LinkUserGateway.js +5 -0
- package/features/adminUsers/users/linkUser/abstractions/LinkUserGateway.js.map +1 -0
- package/features/adminUsers/users/linkUser/abstractions/LinkUserUseCase.d.ts +15 -0
- package/features/adminUsers/users/linkUser/abstractions/LinkUserUseCase.js +5 -0
- package/features/adminUsers/users/linkUser/abstractions/LinkUserUseCase.js.map +1 -0
- package/features/adminUsers/users/linkUser/abstractions/index.d.ts +2 -0
- package/features/adminUsers/users/linkUser/abstractions/index.js +2 -0
- package/features/adminUsers/users/linkUser/feature.d.ts +3 -0
- package/features/adminUsers/users/linkUser/feature.js +19 -0
- package/features/adminUsers/users/linkUser/feature.js.map +1 -0
- package/features/adminUsers/users/linkUser/index.d.ts +2 -0
- package/features/adminUsers/users/linkUser/index.js +2 -0
- package/features/adminUsers/users/resetUserMfa/ResetUserMfaGateway.d.ts +11 -0
- package/features/adminUsers/users/resetUserMfa/ResetUserMfaGateway.js +42 -0
- package/features/adminUsers/users/resetUserMfa/ResetUserMfaGateway.js.map +1 -0
- package/features/adminUsers/users/resetUserMfa/ResetUserMfaUseCase.d.ts +10 -0
- package/features/adminUsers/users/resetUserMfa/ResetUserMfaUseCase.js +18 -0
- package/features/adminUsers/users/resetUserMfa/ResetUserMfaUseCase.js.map +1 -0
- package/features/adminUsers/users/resetUserMfa/abstractions/ResetUserMfaGateway.d.ts +11 -0
- package/features/adminUsers/users/resetUserMfa/abstractions/ResetUserMfaGateway.js +5 -0
- package/features/adminUsers/users/resetUserMfa/abstractions/ResetUserMfaGateway.js.map +1 -0
- package/features/adminUsers/users/resetUserMfa/abstractions/ResetUserMfaUseCase.d.ts +12 -0
- package/features/adminUsers/users/resetUserMfa/abstractions/ResetUserMfaUseCase.js +5 -0
- package/features/adminUsers/users/resetUserMfa/abstractions/ResetUserMfaUseCase.js.map +1 -0
- package/features/adminUsers/users/resetUserMfa/abstractions/index.d.ts +2 -0
- package/features/adminUsers/users/resetUserMfa/abstractions/index.js +2 -0
- package/features/adminUsers/users/resetUserMfa/feature.d.ts +3 -0
- package/features/adminUsers/users/resetUserMfa/feature.js +19 -0
- package/features/adminUsers/users/resetUserMfa/feature.js.map +1 -0
- package/features/adminUsers/users/resetUserMfa/index.d.ts +2 -0
- package/features/adminUsers/users/resetUserMfa/index.js +2 -0
- package/features/adminUsers/users/shared/AdminUsersError.d.ts +13 -0
- package/features/adminUsers/users/shared/AdminUsersError.js +11 -0
- package/features/adminUsers/users/shared/AdminUsersError.js.map +1 -0
- package/features/assumePermissions/AssumePermissionsUseCase.js +2 -2
- package/features/assumePermissions/AssumePermissionsUseCase.js.map +1 -1
- package/features/assumePermissions/LogInUseCaseDecorator.d.ts +1 -1
- package/features/assumePermissions/LogInUseCaseDecorator.js +8 -6
- package/features/assumePermissions/LogInUseCaseDecorator.js.map +1 -1
- package/features/formModel/FormView.js.map +1 -1
- package/features/formModel/createFieldRenderer.js.map +1 -1
- package/features/formModel/demo/FormModelDemo.js.map +1 -1
- package/features/formModel/fieldTypes/dateLimits.js.map +1 -1
- package/features/security/LogIn/LogInError.d.ts +15 -0
- package/features/security/LogIn/LogInError.js +25 -0
- package/features/security/LogIn/LogInError.js.map +1 -0
- package/features/security/LogIn/LogInGateway.d.ts +2 -2
- package/features/security/LogIn/LogInGateway.js +22 -5
- package/features/security/LogIn/LogInGateway.js.map +1 -1
- package/features/security/LogIn/LogInRepository.d.ts +1 -2
- package/features/security/LogIn/LogInRepository.js +6 -2
- package/features/security/LogIn/LogInRepository.js.map +1 -1
- package/features/security/LogIn/LogInUseCase.d.ts +7 -2
- package/features/security/LogIn/LogInUseCase.js +53 -3
- package/features/security/LogIn/LogInUseCase.js.map +1 -1
- package/features/security/LogIn/LogInUseCase.test.d.ts +1 -0
- package/features/security/LogIn/LogInUseCase.test.js +321 -0
- package/features/security/LogIn/LogInUseCase.test.js.map +1 -0
- package/features/security/LogIn/abstractions.d.ts +48 -3
- package/features/security/LogIn/abstractions.js.map +1 -1
- package/features/security/LogIn/createLoginMutation.js +40 -27
- package/features/security/LogIn/createLoginMutation.js.map +1 -1
- package/features/security/LogIn/feature.js +2 -0
- package/features/security/LogIn/feature.js.map +1 -1
- package/features/security/LogIn/index.d.ts +1 -0
- package/features/security/LogIn/index.js +1 -0
- package/features/security/LoginTenantResolver/LoginTenantResolver.d.ts +14 -0
- package/features/security/LoginTenantResolver/LoginTenantResolver.js +52 -0
- package/features/security/LoginTenantResolver/LoginTenantResolver.js.map +1 -0
- package/features/security/LoginTenantResolver/abstractions.d.ts +38 -0
- package/features/security/LoginTenantResolver/abstractions.js +5 -0
- package/features/security/LoginTenantResolver/abstractions.js.map +1 -0
- package/features/security/LoginTenantResolver/feature.d.ts +3 -0
- package/features/security/LoginTenantResolver/feature.js +17 -0
- package/features/security/LoginTenantResolver/feature.js.map +1 -0
- package/features/security/LoginTenantResolver/index.d.ts +2 -0
- package/features/security/LoginTenantResolver/index.js +2 -0
- package/features/webinySdk/WebinySdk.d.ts +2 -1
- package/features/webinySdk/WebinySdk.js +14 -2
- package/features/webinySdk/WebinySdk.js.map +1 -1
- package/features/webinySdk/__tests__/WebinySdk.test.d.ts +1 -0
- package/features/webinySdk/__tests__/WebinySdk.test.js +89 -0
- package/features/webinySdk/__tests__/WebinySdk.test.js.map +1 -0
- package/modules/AccessManagementExtension.js +1 -1
- package/modules/AccessManagementExtension.js.map +1 -1
- package/modules/DebuggerExtension.js +1 -1
- package/modules/DebuggerExtension.js.map +1 -1
- package/package.json +30 -30
- package/permissions/PermissionRenderer.js.map +1 -1
- package/permissions/PermissionValueContext.js.map +1 -1
- package/presentation/accessManagement/SecurityPermissions.js +1 -1
- package/presentation/accessManagement/SecurityPermissions.js.map +1 -1
- package/presentation/accessManagement/apiKeys/components/ApiKeysView.js.map +1 -1
- package/presentation/adminUsers/AdminUsers.d.ts +8 -1
- package/presentation/adminUsers/AdminUsers.js +22 -2
- package/presentation/adminUsers/AdminUsers.js.map +1 -1
- package/presentation/adminUsers/SecurityPermission.js +1 -1
- package/presentation/adminUsers/SecurityPermission.js.map +1 -1
- package/presentation/adminUsers/resetMfa/ResetMfaPresenter.d.ts +27 -0
- package/presentation/adminUsers/resetMfa/ResetMfaPresenter.js +67 -0
- package/presentation/adminUsers/resetMfa/ResetMfaPresenter.js.map +1 -0
- package/presentation/adminUsers/resetMfa/ResetMfaPresenter.test.d.ts +1 -0
- package/presentation/adminUsers/resetMfa/ResetMfaPresenter.test.js +150 -0
- package/presentation/adminUsers/resetMfa/ResetMfaPresenter.test.js.map +1 -0
- package/presentation/adminUsers/resetMfa/abstractions.d.ts +38 -0
- package/presentation/adminUsers/resetMfa/abstractions.js +5 -0
- package/presentation/adminUsers/resetMfa/abstractions.js.map +1 -0
- package/presentation/adminUsers/resetMfa/feature.d.ts +6 -0
- package/presentation/adminUsers/resetMfa/feature.js +17 -0
- package/presentation/adminUsers/resetMfa/feature.js.map +1 -0
- package/presentation/adminUsers/userForm/UserFormPresenter.d.ts +32 -0
- package/presentation/adminUsers/userForm/UserFormPresenter.js +124 -0
- package/presentation/adminUsers/userForm/UserFormPresenter.js.map +1 -0
- package/presentation/adminUsers/userForm/UserFormPresenter.test.d.ts +1 -0
- package/presentation/adminUsers/userForm/UserFormPresenter.test.js +264 -0
- package/presentation/adminUsers/userForm/UserFormPresenter.test.js.map +1 -0
- package/presentation/adminUsers/userForm/abstractions.d.ts +52 -0
- package/presentation/adminUsers/userForm/abstractions.js +5 -0
- package/presentation/adminUsers/userForm/abstractions.js.map +1 -0
- package/presentation/adminUsers/userForm/feature.d.ts +7 -0
- package/presentation/adminUsers/userForm/feature.js +17 -0
- package/presentation/adminUsers/userForm/feature.js.map +1 -0
- package/presentation/adminUsers/userMenu/AccountDetails.js +1 -1
- package/presentation/adminUsers/userMenu/AccountDetails.js.map +1 -1
- package/presentation/adminUsers/views/Users/UsersForm.d.ts +3 -1
- package/presentation/adminUsers/views/Users/UsersForm.js +51 -20
- package/presentation/adminUsers/views/Users/UsersForm.js.map +1 -1
- package/presentation/adminUsers/views/Users/components/LinkAccountAlert.d.ts +10 -0
- package/presentation/adminUsers/views/Users/components/LinkAccountAlert.js +17 -0
- package/presentation/adminUsers/views/Users/components/LinkAccountAlert.js.map +1 -0
- package/presentation/adminUsers/views/Users/components/ResetMfa.d.ts +12 -0
- package/presentation/adminUsers/views/Users/components/ResetMfa.js +63 -0
- package/presentation/adminUsers/views/Users/components/ResetMfa.js.map +1 -0
- package/presentation/adminUsers/views/Users/hooks/useUserForm.d.ts +1 -0
- package/presentation/adminUsers/views/Users/hooks/useUserForm.js +31 -18
- package/presentation/adminUsers/views/Users/hooks/useUserForm.js.map +1 -1
- package/presentation/adminUsers/views/Users/hooks/useUserForm.test.js +9 -0
- package/presentation/adminUsers/views/Users/hooks/useUserForm.test.js.map +1 -1
- package/presentation/assumePermissions/components/AssumedPermissionsSelector.js.map +1 -1
- package/presentation/debugger/components/DebuggerIndicator.js.map +1 -1
- package/presentation/installation/components/SystemInstaller/steps/AdminUserStep.js.map +1 -1
- package/presentation/installation/components/SystemInstaller/steps/BasicInfoStep.js.map +1 -1
- package/presentation/listPresenter/ListPresenter.js +1 -1
- package/presentation/listPresenter/ListPresenter.js.map +1 -1
- package/presentation/listPresenter/ListPresenter.test.js +28 -0
- package/presentation/listPresenter/ListPresenter.test.js.map +1 -1
- package/presentation/security/components/LoginNoTenantAccess.d.ts +27 -0
- package/presentation/security/components/LoginNoTenantAccess.js +22 -0
- package/presentation/security/components/LoginNoTenantAccess.js.map +1 -0
- package/presentation/security/components/LoginTenantPicker.d.ts +30 -0
- package/presentation/security/components/LoginTenantPicker.js +32 -0
- package/presentation/security/components/LoginTenantPicker.js.map +1 -0
- package/presentation/security/hooks/useAuthentication.d.ts +2 -2
- package/presentation/security/hooks/useAuthentication.js.map +1 -1
- package/presentation/security/hooks/useSecurity.js +2 -2
- package/presentation/security/hooks/useSecurity.js.map +1 -1
- package/presentation/sortable/SortablePresenter.js +3 -2
- package/presentation/sortable/SortablePresenter.js.map +1 -1
- package/presentation/trashBin/components/BulkActions/DeleteItems.test.js +1 -1
- package/presentation/trashBin/components/BulkActions/DeleteItems.test.js.map +1 -1
- package/presentation/trashBin/components/TrashBinConfigs.js +1 -1
- package/presentation/trashBin/components/TrashBinConfigs.js.map +1 -1
- package/presentation/trashBin/components/TrashBinOverlay.js.map +1 -1
- package/presentation/trashBin/configs/Browser/BulkAction.js +1 -1
- package/presentation/trashBin/configs/Browser/BulkAction.js.map +1 -1
- package/presentation/trashBin/hooks/useTrashBinItem.js +1 -1
- package/presentation/trashBin/hooks/useTrashBinItem.js.map +1 -1
- package/presentation/trashBin/hooks/useTrashBinPresenter.js +1 -1
- package/presentation/trashBin/hooks/useTrashBinPresenter.js.map +1 -1
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { makeAutoObservable, runInAction } from "mobx";
|
|
2
|
+
import { CreateUserUseCase } from "../../../features/adminUsers/users/createUser/index.js";
|
|
3
|
+
import { LinkUserUseCase } from "../../../features/adminUsers/users/linkUser/index.js";
|
|
4
|
+
import { CheckEmailUseCase } from "../../../features/adminUsers/users/checkEmail/index.js";
|
|
5
|
+
import { AdminUsersError } from "../../../features/adminUsers/users/shared/AdminUsersError.js";
|
|
6
|
+
import { AdminUsersCapabilities } from "../../../features/adminUsers/capabilities/index.js";
|
|
7
|
+
import { UserFormPresenter } from "./abstractions.js";
|
|
8
|
+
const EMAIL_EXISTS_HERE = "A user with this email already exists in this tenant.";
|
|
9
|
+
const EXISTS_IN_OTHER_TENANT = "Cognito/Account/ExistsInOtherTenant";
|
|
10
|
+
const looksLikeEmail = (email)=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
|
11
|
+
class UserFormPresenterImpl {
|
|
12
|
+
constructor(createUser, linkUser, checkEmailUseCase, capabilities){
|
|
13
|
+
this.createUser = createUser;
|
|
14
|
+
this.linkUser = linkUser;
|
|
15
|
+
this.checkEmailUseCase = checkEmailUseCase;
|
|
16
|
+
this.capabilities = capabilities;
|
|
17
|
+
this.mode = "create";
|
|
18
|
+
this.emailError = null;
|
|
19
|
+
this.saving = false;
|
|
20
|
+
this.checkedEmail = null;
|
|
21
|
+
this.checkCount = 0;
|
|
22
|
+
makeAutoObservable(this, {
|
|
23
|
+
capabilities: false
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
get vm() {
|
|
27
|
+
return {
|
|
28
|
+
mode: this.mode,
|
|
29
|
+
emailError: this.emailError,
|
|
30
|
+
saving: this.saving
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
reset() {
|
|
34
|
+
this.mode = "create";
|
|
35
|
+
this.emailError = null;
|
|
36
|
+
this.saving = false;
|
|
37
|
+
this.checkedEmail = null;
|
|
38
|
+
}
|
|
39
|
+
async checkEmail(value) {
|
|
40
|
+
if (!this.capabilities.linkAccounts) return;
|
|
41
|
+
const email = (value ?? "").trim();
|
|
42
|
+
const key = email.toLowerCase();
|
|
43
|
+
if (key === this.checkedEmail) return;
|
|
44
|
+
const check = ++this.checkCount;
|
|
45
|
+
this.checkedEmail = key;
|
|
46
|
+
if (!looksLikeEmail(email)) return void this.setStatus("create", null);
|
|
47
|
+
let status;
|
|
48
|
+
try {
|
|
49
|
+
status = await this.checkEmailUseCase.execute(email);
|
|
50
|
+
} catch {
|
|
51
|
+
status = "AVAILABLE";
|
|
52
|
+
runInAction(()=>{
|
|
53
|
+
if (check === this.checkCount) this.checkedEmail = null;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (check !== this.checkCount) return;
|
|
57
|
+
if ("EXISTS_ELSEWHERE" === status) this.setStatus("link", null);
|
|
58
|
+
else if ("EXISTS_HERE" === status) this.setStatus("create", EMAIL_EXISTS_HERE);
|
|
59
|
+
else this.setStatus("create", null);
|
|
60
|
+
}
|
|
61
|
+
async submit(data) {
|
|
62
|
+
this.saving = true;
|
|
63
|
+
try {
|
|
64
|
+
if ("link" === this.mode) {
|
|
65
|
+
const user = await this.linkUser.execute({
|
|
66
|
+
data: {
|
|
67
|
+
email: data.email,
|
|
68
|
+
roles: data.roles,
|
|
69
|
+
teams: data.teams
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
type: "linked",
|
|
74
|
+
user
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const user = await this.createUser.execute({
|
|
79
|
+
data
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
type: "created",
|
|
83
|
+
user
|
|
84
|
+
};
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (error instanceof AdminUsersError && error.code === EXISTS_IN_OTHER_TENANT) {
|
|
87
|
+
runInAction(()=>{
|
|
88
|
+
this.checkedEmail = (data.email ?? "").trim().toLowerCase();
|
|
89
|
+
this.setStatus("link", null);
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
type: "linkRequired"
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
} catch (error) {
|
|
98
|
+
return {
|
|
99
|
+
type: "failed",
|
|
100
|
+
message: error instanceof Error ? error.message : "Unknown error"
|
|
101
|
+
};
|
|
102
|
+
} finally{
|
|
103
|
+
runInAction(()=>{
|
|
104
|
+
this.saving = false;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
setStatus(mode, emailError) {
|
|
109
|
+
this.mode = mode;
|
|
110
|
+
this.emailError = emailError;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const UserFormPresenter_UserFormPresenter = UserFormPresenter.createImplementation({
|
|
114
|
+
implementation: UserFormPresenterImpl,
|
|
115
|
+
dependencies: [
|
|
116
|
+
CreateUserUseCase,
|
|
117
|
+
LinkUserUseCase,
|
|
118
|
+
CheckEmailUseCase,
|
|
119
|
+
AdminUsersCapabilities
|
|
120
|
+
]
|
|
121
|
+
});
|
|
122
|
+
export { EMAIL_EXISTS_HERE, UserFormPresenter_UserFormPresenter as UserFormPresenter };
|
|
123
|
+
|
|
124
|
+
//# sourceMappingURL=UserFormPresenter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presentation/adminUsers/userForm/UserFormPresenter.js","sources":["../../../../src/presentation/adminUsers/userForm/UserFormPresenter.ts"],"sourcesContent":["import { makeAutoObservable, runInAction } from \"mobx\";\nimport { CreateUserUseCase } from \"~/features/adminUsers/users/createUser/index.js\";\nimport { LinkUserUseCase } from \"~/features/adminUsers/users/linkUser/index.js\";\nimport { CheckEmailUseCase } from \"~/features/adminUsers/users/checkEmail/index.js\";\nimport { AdminUsersError } from \"~/features/adminUsers/users/shared/AdminUsersError.js\";\nimport { AdminUsersCapabilities } from \"~/features/adminUsers/capabilities/index.js\";\nimport {\n UserFormPresenter as PresenterAbstraction,\n type NewUserFormData,\n type UserFormMode,\n type UserFormSubmitResult\n} from \"./abstractions.js\";\n\nexport const EMAIL_EXISTS_HERE = \"A user with this email already exists in this tenant.\";\n\nconst EXISTS_IN_OTHER_TENANT = \"Cognito/Account/ExistsInOtherTenant\";\n\nconst looksLikeEmail = (email: string) => /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(email);\n\nclass UserFormPresenterImpl implements PresenterAbstraction.Interface {\n private mode: UserFormMode = \"create\";\n private emailError: string | null = null;\n private saving = false;\n /** The email `mode` and `emailError` belong to. */\n private checkedEmail: string | null = null;\n private checkCount = 0;\n\n constructor(\n private createUser: CreateUserUseCase.Interface,\n private linkUser: LinkUserUseCase.Interface,\n private checkEmailUseCase: CheckEmailUseCase.Interface,\n private capabilities: AdminUsersCapabilities.Interface\n ) {\n makeAutoObservable<UserFormPresenterImpl, \"capabilities\">(this, { capabilities: false });\n }\n\n get vm() {\n return {\n mode: this.mode,\n emailError: this.emailError,\n saving: this.saving\n };\n }\n\n reset() {\n this.mode = \"create\";\n this.emailError = null;\n this.saving = false;\n this.checkedEmail = null;\n }\n\n async checkEmail(value: string) {\n // Without shared accounts there is nothing to link, and creating the user reports a taken email.\n if (!this.capabilities.linkAccounts) {\n return;\n }\n\n // The API finds this tenant's user by the email as stored, so send it as typed.\n const email = (value ?? \"\").trim();\n const key = email.toLowerCase();\n if (key === this.checkedEmail) {\n return;\n }\n\n const check = ++this.checkCount;\n this.checkedEmail = key;\n\n if (!looksLikeEmail(email)) {\n this.setStatus(\"create\", null);\n return;\n }\n\n let status: CheckEmailUseCase.Status;\n try {\n status = await this.checkEmailUseCase.execute(email);\n } catch {\n // Creating the user reports any problem with the email. Check it again next time.\n status = \"AVAILABLE\";\n runInAction(() => {\n if (check === this.checkCount) {\n this.checkedEmail = null;\n }\n });\n }\n\n // A newer email was entered while this one was being checked.\n if (check !== this.checkCount) {\n return;\n }\n\n if (status === \"EXISTS_ELSEWHERE\") {\n this.setStatus(\"link\", null);\n } else if (status === \"EXISTS_HERE\") {\n this.setStatus(\"create\", EMAIL_EXISTS_HERE);\n } else {\n this.setStatus(\"create\", null);\n }\n }\n\n async submit(data: NewUserFormData): Promise<UserFormSubmitResult> {\n this.saving = true;\n\n try {\n if (this.mode === \"link\") {\n const user = await this.linkUser.execute({\n data: { email: data.email, roles: data.roles, teams: data.teams }\n });\n return { type: \"linked\", user };\n }\n\n try {\n const user = await this.createUser.execute({ data });\n return { type: \"created\", user };\n } catch (error) {\n if (error instanceof AdminUsersError && error.code === EXISTS_IN_OTHER_TENANT) {\n runInAction(() => {\n this.checkedEmail = (data.email ?? \"\").trim().toLowerCase();\n this.setStatus(\"link\", null);\n });\n return { type: \"linkRequired\" };\n }\n throw error;\n }\n } catch (error) {\n return {\n type: \"failed\",\n message: error instanceof Error ? error.message : \"Unknown error\"\n };\n } finally {\n runInAction(() => {\n this.saving = false;\n });\n }\n }\n\n private setStatus(mode: UserFormMode, emailError: string | null) {\n this.mode = mode;\n this.emailError = emailError;\n }\n}\n\nexport const UserFormPresenter = PresenterAbstraction.createImplementation({\n implementation: UserFormPresenterImpl,\n dependencies: [CreateUserUseCase, LinkUserUseCase, CheckEmailUseCase, AdminUsersCapabilities]\n});\n"],"names":["EMAIL_EXISTS_HERE","EXISTS_IN_OTHER_TENANT","looksLikeEmail","email","UserFormPresenterImpl","createUser","linkUser","checkEmailUseCase","capabilities","makeAutoObservable","value","key","check","status","runInAction","data","user","error","AdminUsersError","Error","mode","emailError","UserFormPresenter","PresenterAbstraction","CreateUserUseCase","LinkUserUseCase","CheckEmailUseCase","AdminUsersCapabilities"],"mappings":";;;;;;;AAaO,MAAMA,oBAAoB;AAEjC,MAAMC,yBAAyB;AAE/B,MAAMC,iBAAiB,CAACC,QAAkB,6BAA6B,IAAI,CAACA;AAE5E,MAAMC;IAQF,YACYC,UAAuC,EACvCC,QAAmC,EACnCC,iBAA8C,EAC9CC,YAA8C,CACxD;aAJUH,UAAU,GAAVA;aACAC,QAAQ,GAARA;aACAC,iBAAiB,GAAjBA;aACAC,YAAY,GAAZA;aAXJ,IAAI,GAAiB;aACrB,UAAU,GAAkB;aAC5B,MAAM,GAAG;QACgC,KACzC,YAAY,GAAkB;aAC9B,UAAU,GAAG;QAQjBC,mBAA0D,IAAI,EAAE;YAAE,cAAc;QAAM;IAC1F;IAEA,IAAI,KAAK;QACL,OAAO;YACH,MAAM,IAAI,CAAC,IAAI;YACf,YAAY,IAAI,CAAC,UAAU;YAC3B,QAAQ,IAAI,CAAC,MAAM;QACvB;IACJ;IAEA,QAAQ;QACJ,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,UAAU,GAAG;QAClB,IAAI,CAAC,MAAM,GAAG;QAC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,OAAO,CAAC;oBAAED;gBAAK;gBAClD,OAAO;oBAAE,MAAM;oBAAWC;gBAAK;YACnC,EAAE,OAAOC,OAAO;gBACZ,IAAIA,iBAAiBC,mBAAmBD,MAAM,IAAI,KAAKhB,wBAAwB;oBAC3Ea,YAAY;wBACR,IAAI,CAAC,YAAY,GAAIC,AAAAA,CAAAA,KAAK,KAAK,IAAI,EAAC,EAAG,IAAI,GAAG,WAAW;wBACzD,IAAI,CAAC,SAAS,CAAC,QAAQ;oBAC3B;oBACA,OAAO;wBAAE,MAAM;oBAAe;gBAClC;gBACA,MAAME;YACV;QACJ,EAAE,OAAOA,OAAO;YACZ,OAAO;gBACH,MAAM;gBACN,SAASA,iBAAiBE,QAAQF,MAAM,OAAO,GAAG;YACtD;QACJ,SAAU;YACNH,YAAY;gBACR,IAAI,CAAC,MAAM,GAAG;YAClB;QACJ;IACJ;IAEQ,UAAUM,IAAkB,EAAEC,UAAyB,EAAE;QAC7D,IAAI,CAAC,IAAI,GAAGD;QACZ,IAAI,CAAC,UAAU,GAAGC;IACtB;AACJ;AAEO,MAAMC,sCAAoBC,kBAAAA,oBAAyC,CAAC;IACvE,gBAAgBnB;IAChB,cAAc;QAACoB;QAAmBC;QAAiBC;QAAmBC;KAAuB;AACjG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,264 @@
|
|
|
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 { CreateUserFeature } from "../../../features/adminUsers/users/createUser/index.js";
|
|
5
|
+
import { LinkUserFeature } from "../../../features/adminUsers/users/linkUser/index.js";
|
|
6
|
+
import { CheckEmailFeature } from "../../../features/adminUsers/users/checkEmail/index.js";
|
|
7
|
+
import { AdminUsersCapabilitiesFeature } from "../../../features/adminUsers/capabilities/index.js";
|
|
8
|
+
import { UserFormFeature } from "./feature.js";
|
|
9
|
+
import { EMAIL_EXISTS_HERE } from "./UserFormPresenter.js";
|
|
10
|
+
const user = {
|
|
11
|
+
id: "user-1",
|
|
12
|
+
email: "person@example.com",
|
|
13
|
+
firstName: "Some",
|
|
14
|
+
lastName: "Person",
|
|
15
|
+
avatar: null,
|
|
16
|
+
createdOn: "2026-10-23T00:00:00.000Z",
|
|
17
|
+
external: false
|
|
18
|
+
};
|
|
19
|
+
const emailStatus = (status)=>({
|
|
20
|
+
adminUsers: {
|
|
21
|
+
checkEmail: {
|
|
22
|
+
data: {
|
|
23
|
+
status
|
|
24
|
+
},
|
|
25
|
+
error: null
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const userResponse = (data, error = null)=>({
|
|
30
|
+
adminUsers: {
|
|
31
|
+
user: {
|
|
32
|
+
data,
|
|
33
|
+
error
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
describe("UserFormPresenter: creating or linking a user", ()=>{
|
|
38
|
+
let container;
|
|
39
|
+
let execute;
|
|
40
|
+
const presenter = ()=>UserFormFeature.resolve(container).presenter;
|
|
41
|
+
const operations = ()=>execute.mock.calls.map(([request])=>/(query|mutation) (\w+)/.exec(request.query)?.[2]);
|
|
42
|
+
beforeEach(()=>{
|
|
43
|
+
container = new Container();
|
|
44
|
+
execute = vi.fn();
|
|
45
|
+
container.registerInstance(MainGraphQLClient, {
|
|
46
|
+
execute
|
|
47
|
+
});
|
|
48
|
+
AdminUsersCapabilitiesFeature.register(container, {
|
|
49
|
+
linkAccounts: true
|
|
50
|
+
});
|
|
51
|
+
CreateUserFeature.register(container);
|
|
52
|
+
LinkUserFeature.register(container);
|
|
53
|
+
CheckEmailFeature.register(container);
|
|
54
|
+
UserFormFeature.register(container);
|
|
55
|
+
});
|
|
56
|
+
it("starts in create mode", ()=>{
|
|
57
|
+
expect(presenter().vm).toEqual({
|
|
58
|
+
mode: "create",
|
|
59
|
+
emailError: null,
|
|
60
|
+
saving: false
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
it("stays in create mode for a new email", async ()=>{
|
|
64
|
+
execute.mockResolvedValue(emailStatus("AVAILABLE"));
|
|
65
|
+
const form = presenter();
|
|
66
|
+
await form.checkEmail("new@example.com");
|
|
67
|
+
expect(form.vm).toMatchObject({
|
|
68
|
+
mode: "create",
|
|
69
|
+
emailError: null
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
it("doesn't look the email up when the identity provider can't link accounts", async ()=>{
|
|
73
|
+
AdminUsersCapabilitiesFeature.register(container, {
|
|
74
|
+
linkAccounts: false
|
|
75
|
+
});
|
|
76
|
+
const form = presenter();
|
|
77
|
+
await form.checkEmail("person@example.com");
|
|
78
|
+
expect(execute).not.toHaveBeenCalled();
|
|
79
|
+
expect(form.vm).toMatchObject({
|
|
80
|
+
mode: "create",
|
|
81
|
+
emailError: null
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
it("switches to link mode for an email with an account in another tenant", async ()=>{
|
|
85
|
+
execute.mockResolvedValue(emailStatus("EXISTS_ELSEWHERE"));
|
|
86
|
+
const form = presenter();
|
|
87
|
+
await form.checkEmail("person@example.com");
|
|
88
|
+
expect(form.vm).toMatchObject({
|
|
89
|
+
mode: "link",
|
|
90
|
+
emailError: null
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
it("shows an email error for a user already in this tenant", async ()=>{
|
|
94
|
+
execute.mockResolvedValue(emailStatus("EXISTS_HERE"));
|
|
95
|
+
const form = presenter();
|
|
96
|
+
await form.checkEmail("person@example.com");
|
|
97
|
+
expect(form.vm).toMatchObject({
|
|
98
|
+
mode: "create",
|
|
99
|
+
emailError: EMAIL_EXISTS_HERE
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
it("goes back to create mode when the email changes to a new one", async ()=>{
|
|
103
|
+
execute.mockResolvedValueOnce(emailStatus("EXISTS_ELSEWHERE"));
|
|
104
|
+
execute.mockResolvedValueOnce(emailStatus("AVAILABLE"));
|
|
105
|
+
const form = presenter();
|
|
106
|
+
await form.checkEmail("person@example.com");
|
|
107
|
+
await form.checkEmail("someone-new@example.com");
|
|
108
|
+
expect(form.vm).toMatchObject({
|
|
109
|
+
mode: "create",
|
|
110
|
+
emailError: null
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
it("doesn't check an incomplete email, or the same email twice", async ()=>{
|
|
114
|
+
execute.mockResolvedValue(emailStatus("EXISTS_ELSEWHERE"));
|
|
115
|
+
const form = presenter();
|
|
116
|
+
await form.checkEmail("person@");
|
|
117
|
+
await form.checkEmail("person@example.com");
|
|
118
|
+
await form.checkEmail(" Person@example.com ");
|
|
119
|
+
expect(operations()).toEqual([
|
|
120
|
+
"CheckEmail"
|
|
121
|
+
]);
|
|
122
|
+
expect(form.vm.mode).toBe("link");
|
|
123
|
+
});
|
|
124
|
+
it("checks the email as typed, so a mixed-case email in this tenant is found", async ()=>{
|
|
125
|
+
execute.mockResolvedValue(emailStatus("EXISTS_HERE"));
|
|
126
|
+
const form = presenter();
|
|
127
|
+
await form.checkEmail(" Foo@X.com ");
|
|
128
|
+
expect(execute.mock.calls[0][0].variables).toEqual({
|
|
129
|
+
email: "Foo@X.com"
|
|
130
|
+
});
|
|
131
|
+
expect(form.vm).toMatchObject({
|
|
132
|
+
mode: "create",
|
|
133
|
+
emailError: EMAIL_EXISTS_HERE
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
it("keeps the latest email's result when an earlier check answers last", async ()=>{
|
|
137
|
+
let answerFirst = ()=>{};
|
|
138
|
+
execute.mockReturnValueOnce(new Promise((resolve)=>answerFirst = resolve));
|
|
139
|
+
execute.mockResolvedValueOnce(emailStatus("AVAILABLE"));
|
|
140
|
+
const form = presenter();
|
|
141
|
+
const first = form.checkEmail("person@example.com");
|
|
142
|
+
await form.checkEmail("someone-new@example.com");
|
|
143
|
+
answerFirst(emailStatus("EXISTS_ELSEWHERE"));
|
|
144
|
+
await first;
|
|
145
|
+
expect(form.vm.mode).toBe("create");
|
|
146
|
+
});
|
|
147
|
+
it("stays in create mode when the check fails", async ()=>{
|
|
148
|
+
execute.mockRejectedValue(new Error("Network error"));
|
|
149
|
+
const form = presenter();
|
|
150
|
+
await form.checkEmail("person@example.com");
|
|
151
|
+
expect(form.vm).toMatchObject({
|
|
152
|
+
mode: "create",
|
|
153
|
+
emailError: null
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
it("creates the user in create mode", async ()=>{
|
|
157
|
+
execute.mockResolvedValue(userResponse(user));
|
|
158
|
+
const form = presenter();
|
|
159
|
+
const result = await form.submit({
|
|
160
|
+
email: user.email,
|
|
161
|
+
firstName: "Some",
|
|
162
|
+
lastName: "Person",
|
|
163
|
+
password: "SecurePass123!"
|
|
164
|
+
});
|
|
165
|
+
expect(result).toEqual({
|
|
166
|
+
type: "created",
|
|
167
|
+
user
|
|
168
|
+
});
|
|
169
|
+
expect(operations()).toEqual([
|
|
170
|
+
"CreateUser"
|
|
171
|
+
]);
|
|
172
|
+
});
|
|
173
|
+
it("links the account in link mode, sending only the email, roles and teams", async ()=>{
|
|
174
|
+
execute.mockResolvedValueOnce(emailStatus("EXISTS_ELSEWHERE"));
|
|
175
|
+
execute.mockResolvedValueOnce(userResponse(user));
|
|
176
|
+
const form = presenter();
|
|
177
|
+
await form.checkEmail(user.email);
|
|
178
|
+
const result = await form.submit({
|
|
179
|
+
email: user.email,
|
|
180
|
+
firstName: "Typed",
|
|
181
|
+
password: "Ignored123!",
|
|
182
|
+
roles: [
|
|
183
|
+
{
|
|
184
|
+
id: "editors"
|
|
185
|
+
}
|
|
186
|
+
],
|
|
187
|
+
teams: []
|
|
188
|
+
});
|
|
189
|
+
expect(result).toEqual({
|
|
190
|
+
type: "linked",
|
|
191
|
+
user
|
|
192
|
+
});
|
|
193
|
+
expect(operations()).toEqual([
|
|
194
|
+
"CheckEmail",
|
|
195
|
+
"LinkUser"
|
|
196
|
+
]);
|
|
197
|
+
expect(execute.mock.calls[1][0].variables).toEqual({
|
|
198
|
+
data: {
|
|
199
|
+
email: user.email,
|
|
200
|
+
roles: [
|
|
201
|
+
{
|
|
202
|
+
id: "editors"
|
|
203
|
+
}
|
|
204
|
+
],
|
|
205
|
+
teams: []
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
expect(form.vm.saving).toBe(false);
|
|
209
|
+
});
|
|
210
|
+
it("switches to link mode when creating finds an account in another tenant", async ()=>{
|
|
211
|
+
execute.mockResolvedValue(userResponse(null, {
|
|
212
|
+
code: "Cognito/Account/ExistsInOtherTenant",
|
|
213
|
+
message: "This email already has an account in another tenant. Link it instead.",
|
|
214
|
+
data: null
|
|
215
|
+
}));
|
|
216
|
+
const form = presenter();
|
|
217
|
+
const result = await form.submit({
|
|
218
|
+
email: user.email,
|
|
219
|
+
password: "SecurePass123!"
|
|
220
|
+
});
|
|
221
|
+
expect(result).toEqual({
|
|
222
|
+
type: "linkRequired"
|
|
223
|
+
});
|
|
224
|
+
expect(form.vm).toMatchObject({
|
|
225
|
+
mode: "link",
|
|
226
|
+
emailError: null,
|
|
227
|
+
saving: false
|
|
228
|
+
});
|
|
229
|
+
await form.checkEmail(user.email);
|
|
230
|
+
expect(operations()).toEqual([
|
|
231
|
+
"CreateUser"
|
|
232
|
+
]);
|
|
233
|
+
});
|
|
234
|
+
it("reports any other error and stays in create mode", async ()=>{
|
|
235
|
+
execute.mockResolvedValue(userResponse(null, {
|
|
236
|
+
code: "AdminUser/Validation",
|
|
237
|
+
message: "Invalid.",
|
|
238
|
+
data: null
|
|
239
|
+
}));
|
|
240
|
+
const form = presenter();
|
|
241
|
+
const result = await form.submit({
|
|
242
|
+
email: user.email,
|
|
243
|
+
password: "SecurePass123!"
|
|
244
|
+
});
|
|
245
|
+
expect(result).toEqual({
|
|
246
|
+
type: "failed",
|
|
247
|
+
message: "Invalid."
|
|
248
|
+
});
|
|
249
|
+
expect(form.vm.mode).toBe("create");
|
|
250
|
+
});
|
|
251
|
+
it("starts over in create mode after a reset", async ()=>{
|
|
252
|
+
execute.mockResolvedValue(emailStatus("EXISTS_ELSEWHERE"));
|
|
253
|
+
const form = presenter();
|
|
254
|
+
await form.checkEmail(user.email);
|
|
255
|
+
form.reset();
|
|
256
|
+
expect(form.vm).toEqual({
|
|
257
|
+
mode: "create",
|
|
258
|
+
emailError: null,
|
|
259
|
+
saving: false
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
//# sourceMappingURL=UserFormPresenter.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presentation/adminUsers/userForm/UserFormPresenter.test.js","sources":["../../../../src/presentation/adminUsers/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 \"~/features/adminUsers/users/createUser/index.js\";\nimport { LinkUserFeature } from \"~/features/adminUsers/users/linkUser/index.js\";\nimport { CheckEmailFeature } from \"~/features/adminUsers/users/checkEmail/index.js\";\nimport { AdminUsersCapabilitiesFeature } from \"~/features/adminUsers/capabilities/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 AdminUsersCapabilitiesFeature.register(container, { linkAccounts: true });\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(\"doesn't look the email up when the identity provider can't link accounts\", async () => {\n AdminUsersCapabilitiesFeature.register(container, { linkAccounts: false });\n const form = presenter();\n\n await form.checkEmail(\"person@example.com\");\n\n expect(execute).not.toHaveBeenCalled();\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","AdminUsersCapabilitiesFeature","CreateUserFeature","LinkUser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b,MAAMqB,SAAS,MAAMP,KAAK,MAAM,CAAC;YAAE,OAAOvB,KAAK,KAAK;YAAE,UAAU;QAAiB;QAEjFsB,OAAOQ,QAAQ,OAAO,CAAC;YAAE,MAAM;YAAU,SAAS;QAAW;QAC7DR,OAAOC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;IAC9B;IAEAF,GAAG,4CAA4C;QAC3Cb,QAAQ,iBAAiB,CAACP,YAAY;QACtC,MAAMsB,OAAOd;QACb,MAAMc,KAAK,UAAU,CAACvB,KAAK,KAAK;QAEhCuB,KAAK,KAAK;QAEVD,OAAOC,KAAK,EAAE,EAAE,OAAO,CAAC;YAAE,MAAM;YAAU,YAAY;YAAM,QAAQ;QAAM;IAC9E;AACJ"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ICreateUserGatewayResult } from "../../../features/adminUsers/users/createUser/abstractions/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* - `create`: a new person; the form asks for their name and password.
|
|
4
|
+
* - `link`: the email has an account in another tenant; the form only asks for roles and teams.
|
|
5
|
+
*/
|
|
6
|
+
export type UserFormMode = "create" | "link";
|
|
7
|
+
export interface UserFormVM {
|
|
8
|
+
mode: UserFormMode;
|
|
9
|
+
/** Set when the email can't be used in this tenant. */
|
|
10
|
+
emailError: string | null;
|
|
11
|
+
saving: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface NewUserFormData {
|
|
14
|
+
email: string;
|
|
15
|
+
firstName?: string;
|
|
16
|
+
lastName?: string;
|
|
17
|
+
password?: string;
|
|
18
|
+
avatar?: any;
|
|
19
|
+
roles?: unknown[];
|
|
20
|
+
teams?: unknown[];
|
|
21
|
+
}
|
|
22
|
+
export type UserFormUser = ICreateUserGatewayResult;
|
|
23
|
+
export type UserFormSubmitResult = {
|
|
24
|
+
type: "created";
|
|
25
|
+
user: UserFormUser;
|
|
26
|
+
} | {
|
|
27
|
+
type: "linked";
|
|
28
|
+
user: UserFormUser;
|
|
29
|
+
}
|
|
30
|
+
/** The email turned out to have an account in another tenant: the form is now in `link` mode. */
|
|
31
|
+
| {
|
|
32
|
+
type: "linkRequired";
|
|
33
|
+
} | {
|
|
34
|
+
type: "failed";
|
|
35
|
+
message: string;
|
|
36
|
+
};
|
|
37
|
+
export interface IUserFormPresenter {
|
|
38
|
+
vm: UserFormVM;
|
|
39
|
+
/** Back to an empty New User form. */
|
|
40
|
+
reset(): void;
|
|
41
|
+
/** Looks up the email and sets `mode` and `emailError` from it. */
|
|
42
|
+
checkEmail(email: string): Promise<void>;
|
|
43
|
+
submit(data: NewUserFormData): Promise<UserFormSubmitResult>;
|
|
44
|
+
}
|
|
45
|
+
export declare const UserFormPresenter: import("@webiny/di").Abstraction<IUserFormPresenter>;
|
|
46
|
+
export declare namespace UserFormPresenter {
|
|
47
|
+
type Interface = IUserFormPresenter;
|
|
48
|
+
type VM = UserFormVM;
|
|
49
|
+
type Mode = UserFormMode;
|
|
50
|
+
type Data = NewUserFormData;
|
|
51
|
+
type SubmitResult = UserFormSubmitResult;
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presentation/adminUsers/userForm/abstractions.js","sources":["../../../../src/presentation/adminUsers/userForm/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport type { ICreateUserGatewayResult } from \"~/features/adminUsers/users/createUser/abstractions/index.js\";\n\n/**\n * - `create`: a new person; the form asks for their name and password.\n * - `link`: the email has an account in another tenant; the form only asks for roles and teams.\n */\nexport type UserFormMode = \"create\" | \"link\";\n\nexport interface UserFormVM {\n mode: UserFormMode;\n /** Set when the email can't be used in this tenant. */\n emailError: string | null;\n saving: boolean;\n}\n\nexport interface NewUserFormData {\n email: string;\n firstName?: string;\n lastName?: string;\n password?: string;\n avatar?: any;\n roles?: unknown[];\n teams?: unknown[];\n}\n\nexport type UserFormUser = ICreateUserGatewayResult;\n\nexport type UserFormSubmitResult =\n | { type: \"created\"; user: UserFormUser }\n | { type: \"linked\"; user: UserFormUser }\n /** The email turned out to have an account in another tenant: the form is now in `link` mode. */\n | { type: \"linkRequired\" }\n | { type: \"failed\"; message: string };\n\nexport interface IUserFormPresenter {\n vm: UserFormVM;\n\n /** Back to an empty New User form. */\n reset(): void;\n\n /** Looks up the email and sets `mode` and `emailError` from it. */\n checkEmail(email: string): Promise<void>;\n\n submit(data: NewUserFormData): Promise<UserFormSubmitResult>;\n}\n\nexport const UserFormPresenter = createAbstraction<IUserFormPresenter>(\n \"AdminUsers/UserFormPresenter\"\n);\n\nexport namespace UserFormPresenter {\n export type Interface = IUserFormPresenter;\n export type VM = UserFormVM;\n export type Mode = UserFormMode;\n export type Data = NewUserFormData;\n export type SubmitResult = UserFormSubmitResult;\n}\n"],"names":["UserFormPresenter","createAbstraction"],"mappings":";AA+CO,MAAMA,oBAAoBC,kBAC7B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The New User form: creates a user, or links an account from another tenant.
|
|
3
|
+
* Needs the CreateUser, LinkUser and CheckEmail features.
|
|
4
|
+
*/
|
|
5
|
+
export declare const UserFormFeature: import("@webiny/feature/admin").FeatureDefinition<{
|
|
6
|
+
presenter: import("./abstractions.js").IUserFormPresenter;
|
|
7
|
+
}, []>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/admin";
|
|
2
|
+
import { UserFormPresenter } from "./abstractions.js";
|
|
3
|
+
import { UserFormPresenter as external_UserFormPresenter_js_UserFormPresenter } from "./UserFormPresenter.js";
|
|
4
|
+
const UserFormFeature = createFeature({
|
|
5
|
+
name: "AdminUsers/UserForm",
|
|
6
|
+
register (container) {
|
|
7
|
+
container.register(external_UserFormPresenter_js_UserFormPresenter);
|
|
8
|
+
},
|
|
9
|
+
resolve (container) {
|
|
10
|
+
return {
|
|
11
|
+
presenter: container.resolve(UserFormPresenter)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
export { UserFormFeature };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presentation/adminUsers/userForm/feature.js","sources":["../../../../src/presentation/adminUsers/userForm/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/admin\";\nimport { UserFormPresenter as PresenterAbstraction } from \"./abstractions.js\";\nimport { UserFormPresenter } from \"./UserFormPresenter.js\";\n\n/**\n * The New User form: creates a user, or links an account from another tenant.\n * Needs the CreateUser, LinkUser and CheckEmail features.\n */\nexport const UserFormFeature = createFeature({\n name: \"AdminUsers/UserForm\",\n register(container) {\n container.register(UserFormPresenter);\n },\n resolve(container) {\n return {\n presenter: container.resolve(PresenterAbstraction)\n };\n }\n});\n"],"names":["UserFormFeature","createFeature","container","UserFormPresenter","PresenterAbstraction"],"mappings":";;;AAQO,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"}
|
|
@@ -2,7 +2,7 @@ import react from "react";
|
|
|
2
2
|
import { ReactComponent } from "@webiny/icons/account_circle.svg";
|
|
3
3
|
import { AdminConfig } from "../../../config/AdminConfig.js";
|
|
4
4
|
import { useIsDefaultTenant } from "./useIsDefaultTenant.js";
|
|
5
|
-
const { Menu
|
|
5
|
+
const { Menu } = AdminConfig;
|
|
6
6
|
const AccountDetails = (props)=>{
|
|
7
7
|
const isDefaultTenant = useIsDefaultTenant();
|
|
8
8
|
if (!isDefaultTenant) return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation/adminUsers/userMenu/AccountDetails.js","sources":["../../../../src/presentation/adminUsers/userMenu/AccountDetails.tsx"],"sourcesContent":["import React from \"react\";\nimport { ReactComponent as AccountIcon } from \"@webiny/icons/account_circle.svg\";\nimport { AdminConfig } from \"~/config/AdminConfig.js\";\nimport { useIsDefaultTenant } from \"./useIsDefaultTenant.js\";\n\nconst { Menu } = AdminConfig;\n\ninterface AccountDetailsProps {\n accountRoute: string;\n}\n\nexport const AccountDetails = (props: AccountDetailsProps) => {\n const isDefaultTenant = useIsDefaultTenant();\n\n if (!isDefaultTenant) {\n return null;\n }\n return (\n <Menu.User.Link\n icon={<Menu.User.Item.Icon element={<AccountIcon />} label={\"Account settings\"} />}\n text={\"Account settings\"}\n to={props.accountRoute}\n />\n );\n};\n"],"names":["Menu","AdminConfig","AccountDetails","props","isDefaultTenant","useIsDefaultTenant","AccountIcon"],"mappings":";;;;AAKA,MAAM,EAAEA,
|
|
1
|
+
{"version":3,"file":"presentation/adminUsers/userMenu/AccountDetails.js","sources":["../../../../src/presentation/adminUsers/userMenu/AccountDetails.tsx"],"sourcesContent":["import React from \"react\";\nimport { ReactComponent as AccountIcon } from \"@webiny/icons/account_circle.svg\";\nimport { AdminConfig } from \"~/config/AdminConfig.js\";\nimport { useIsDefaultTenant } from \"./useIsDefaultTenant.js\";\n\nconst { Menu } = AdminConfig;\n\ninterface AccountDetailsProps {\n accountRoute: string;\n}\n\nexport const AccountDetails = (props: AccountDetailsProps) => {\n const isDefaultTenant = useIsDefaultTenant();\n\n if (!isDefaultTenant) {\n return null;\n }\n return (\n <Menu.User.Link\n icon={<Menu.User.Item.Icon element={<AccountIcon />} label={\"Account settings\"} />}\n text={\"Account settings\"}\n to={props.accountRoute}\n />\n );\n};\n"],"names":["Menu","AdminConfig","AccountDetails","props","isDefaultTenant","useIsDefaultTenant","AccountIcon"],"mappings":";;;;AAKA,MAAM,EAAEA,IAAI,EAAE,GAAGC;AAMV,MAAMC,iBAAiB,CAACC;IAC3B,MAAMC,kBAAkBC;IAExB,IAAI,CAACD,iBACD,OAAO;IAEX,OAAO,WAAP,GACI,oBAACJ,KAAK,IAAI,CAAC,IAAI;QACX,oBAAM,oBAACA,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI;YAAC,uBAAS,oBAACM,gBAAWA;YAAK,OAAO;;QAC5D,MAAM;QACN,IAAIH,MAAM,YAAY;;AAGlC"}
|
|
@@ -2,4 +2,6 @@ import React from "react";
|
|
|
2
2
|
export interface UserFormProps {
|
|
3
3
|
teams: boolean;
|
|
4
4
|
}
|
|
5
|
-
export declare const UserForm: ({ teams }: UserFormProps) => React.JSX.Element
|
|
5
|
+
export declare const UserForm: (({ teams }: UserFormProps) => React.JSX.Element) & React.NamedExoticComponent<UserFormProps> & {
|
|
6
|
+
readonly type: ({ teams }: UserFormProps) => React.JSX.Element;
|
|
7
|
+
};
|