Skip to content

Commit

Permalink
feat: modify workspace role binding (#2555)
Browse files Browse the repository at this point in the history
* refactor: delete unnecessary files

Signed-off-by: NaYeong,Kim <[email protected]>

* feat: setting tags during user modification

Signed-off-by: NaYeong,Kim <[email protected]>

* feat: modify workspace role binding

Signed-off-by: NaYeong,Kim <[email protected]>

* chore: remove log

Signed-off-by: NaYeong,Kim <[email protected]>

---------

Signed-off-by: NaYeong,Kim <[email protected]>
  • Loading branch information
skdud4659 authored Dec 21, 2023
1 parent 34ae6fa commit fc63678
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 260 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script setup lang="ts">
import { reactive, watch } from 'vue';
import {
reactive, ref, watch,
} from 'vue';
import { PFieldGroup, PTextButton, PTextInput } from '@spaceone/design-system';
import type { InputItem } from '@spaceone/design-system/types/inputs/input/text-input/type';
Expand All @@ -10,11 +12,13 @@ import { useProxyValue } from '@/common/composables/proxy-state';
interface Props {
tags: Tags;
isEdit?: boolean;
isFormVisible?: boolean;
}
const props = withDefaults(defineProps<Props>(), {
tags: undefined,
isEdit: false,
isFormVisible: false,
});
Expand All @@ -30,7 +34,13 @@ const state = reactive({
const handleClickButton = () => {
state.formVisible = true;
};
const handleChangeTags = (items: InputItem[]) => {
const getInputItemsFromTagKeys = (keys: Tags): InputItem[] => Object.keys(keys).map((key) => ({
label: `${key}: ${props.tags[key]}`,
name: `${key}: ${props.tags[key]}`,
}));
const selected = ref<InputItem[]>(getInputItemsFromTagKeys(props.tags));
const handleUpdateSelected = (items: InputItem[]) => {
selected.value = items;
const refinedTags = items.map((item) => {
if (item.name.includes(':')) {
const tags = item.name.split(':').map((tag) => tag.trim());
Expand Down Expand Up @@ -66,9 +76,10 @@ watch(() => props.isFormVisible, (value) => {
>
<p-text-input class="text-input"
multi-input
:selected="selected"
appearance-type="stack"
block
@update:selected="handleChangeTags"
@update:selected="handleUpdateSelected"
/>
</p-field-group>
</div>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -90,40 +90,55 @@ 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 || '';
if (value.passwordType) formState.passwordType = value.passwordType;
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<UserUpdateParameters, UserModel>(userInfoParams);
showSuccessMessage(i18n.t('IAM.USER.MAIN.MODAL.ALT_S_UPDATE_USER'), '');
handleClose();
emit('confirm');
Expand All @@ -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<RoleUpdateParameters, RoleBindingModel>({
...roleParams,
role_binding_id: formState.roleBindingId,
});
} else {
await SpaceConnector.clientV2.identity.roleBinding.create<RoleCreateParameters, RoleBindingModel>({
...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<RoleUpdateParameters, RoleBindingModel>({
...roleParams,
role_binding_id: formState.roleBindingId,
});
} else {
await SpaceConnector.clientV2.identity.roleBinding.create<RoleCreateParameters, RoleBindingModel>({
...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 () => {
Expand Down Expand Up @@ -222,6 +237,7 @@ watch(() => userPageState.modal.visible.form, async (visible) => {
/>
<user-management-add-tag v-if="userPageState.isAdminMode"
:tags.sync="formState.tags"
is-edit
is-form-visible
/>
</div>
Expand Down

This file was deleted.

0 comments on commit fc63678

Please sign in to comment.