diff --git a/apps/web/src/services/administration/components/UserManagementAddTag.vue b/apps/web/src/services/administration/components/UserManagementAddTag.vue index 9295e77a3b..354d098a1a 100644 --- a/apps/web/src/services/administration/components/UserManagementAddTag.vue +++ b/apps/web/src/services/administration/components/UserManagementAddTag.vue @@ -1,5 +1,7 @@ - - - - - - - - - - - - - - diff --git a/apps/web/src/services/administration/components/UserManagementFormModal.vue b/apps/web/src/services/administration/components/UserManagementFormModal.vue index bfefc395cb..56996e3439 100644 --- a/apps/web/src/services/administration/components/UserManagementFormModal.vue +++ b/apps/web/src/services/administration/components/UserManagementFormModal.vue @@ -90,7 +90,6 @@ const setForm = () => { formState.email = state.data.email || ''; formState.tags = state.data.tags || {}; }; - const handleChangeInputs = (value) => { if (value.email) formState.email = value.email; if (value.password) formState.password = value.password || ''; @@ -98,32 +97,48 @@ const handleChangeInputs = (value) => { if (value.role) formState.role = value.role; if (value.workspace) formState.workspace = value.workspace; }; - const handleChangeVerify = (status) => { state.data.email_verified = status; }; - -/* API */ -const handleConfirm = async () => { - const userInfoParams: UserManagementData = { - user_id: state.data.user_id || '', - name: formState.name, - email: formState.email || '', - tags: formState.tags || {}, - password: formState.password || '', +const buildUserInfoParams = (): UserManagementData => ({ + user_id: state.data.user_id || '', + name: formState.name, + email: formState.email || '', + tags: formState.tags || {}, + password: formState.password || '', + reset_password: state.data.auth_type === 'LOCAL' && formState.passwordType === PASSWORD_TYPE.RESET, +}); +const buildRoleParams = (item?: AddModalMenuItem): any => { + const baseRoleParams = { + role_id: formState.role.name || '', }; - if (state.data.auth_type === 'LOCAL') { - userInfoParams.reset_password = formState.passwordType === PASSWORD_TYPE.RESET; - } - - if (state.isChangedToggle) { - await fetchPostDisableMfa(); + if (isEmpty(formState.role)) { + return baseRoleParams; } + return { + ...baseRoleParams, + workspace_id: item?.name || '', + }; +}; +/* API */ +const handleConfirm = async () => { state.loading = true; + try { - await fetchRoleBinding(); + if (state.isChangedToggle) { + await fetchPostDisableMfa(); + } + + if (state.isSetAdminRole) { + await fetchRoleBinding(); + } else { + await Promise.all(formState.workspace.map(fetchRoleBinding)); + } + + const userInfoParams = buildUserInfoParams(); await SpaceConnector.clientV2.identity.user.update(userInfoParams); + showSuccessMessage(i18n.t('IAM.USER.MAIN.MODAL.ALT_S_UPDATE_USER'), ''); handleClose(); emit('confirm'); @@ -133,26 +148,26 @@ const handleConfirm = async () => { state.loading = false; } }; -const fetchRoleBinding = async () => { +const fetchRoleBinding = async (item?: AddModalMenuItem) => { if (isEmpty(formState.role)) return; - const baseRoleParams = { - role_id: formState.role.name || '', - }; - const roleParams = state.isSetAdminRole ? baseRoleParams : { - ...baseRoleParams, - workspace_id: formState.workspace.map((w) => w.name || ''), - }; - if (formState.roleBindingId) { - await SpaceConnector.clientV2.identity.roleBinding.update({ - ...roleParams, - role_binding_id: formState.roleBindingId, - }); - } else { - await SpaceConnector.clientV2.identity.roleBinding.create({ - ...roleParams, - user_id: state.data.user_id || '', - resource_group: state.isSetAdminRole ? RESOURCE_GROUP.DOMAIN : RESOURCE_GROUP.WORKSPACE, - }); + + const roleParams = buildRoleParams(item); + + try { + if (formState.roleBindingId) { + await SpaceConnector.clientV2.identity.roleBinding.update({ + ...roleParams, + role_binding_id: formState.roleBindingId, + }); + } else { + await SpaceConnector.clientV2.identity.roleBinding.create({ + ...roleParams, + user_id: state.data.user_id || '', + resource_group: state.isSetAdminRole ? RESOURCE_GROUP.DOMAIN : RESOURCE_GROUP.WORKSPACE, + }); + } + } catch (e: any) { + ErrorHandler.handleRequestError(e, e.message); } }; const fetchPostDisableMfa = async () => { @@ -222,6 +237,7 @@ watch(() => userPageState.modal.visible.form, async (visible) => { /> diff --git a/apps/web/src/services/administration/components/UserManagementFormTags.vue b/apps/web/src/services/administration/components/UserManagementFormTags.vue deleted file mode 100644 index 727dbdfbcb..0000000000 --- a/apps/web/src/services/administration/components/UserManagementFormTags.vue +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - {{ $t('IAM.USER.FORM.TAGS_HELP_TEXT1') }} - {{ $t('IAM.USER.FORM.TAGS_HELP_TEXT2') }} - - - - - - -