From ce7fb05a5e0ae6e72cbf8832c160ffcc74908894 Mon Sep 17 00:00:00 2001 From: Nancy <3510671794@qq.com> Date: Tue, 29 Oct 2024 10:04:37 +0800 Subject: [PATCH 1/4] change-user-role-and-delete --- .../modules/system/users/UserDetail.vue | 49 +++++++++++++++++-- ui/src/locales/zh-CN.yaml | 2 + 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/ui/console-src/modules/system/users/UserDetail.vue b/ui/console-src/modules/system/users/UserDetail.vue index 798d01d3c1..c0f3f222a7 100644 --- a/ui/console-src/modules/system/users/UserDetail.vue +++ b/ui/console-src/modules/system/users/UserDetail.vue @@ -3,8 +3,11 @@ import UserAvatar from "@/components/user-avatar/UserAvatar.vue"; import { usePluginModuleStore } from "@/stores/plugin"; import { useUserStore } from "@/stores/user"; import { usePermission } from "@/utils/permission"; -import { consoleApiClient } from "@halo-dev/api-client"; +import type { User } from "@halo-dev/api-client"; +import { consoleApiClient, coreApiClient } from "@halo-dev/api-client"; import { + Dialog, + Toast, VButton, VDropdown, VDropdownItem, @@ -23,7 +26,8 @@ import { type Ref, } from "vue"; import { useI18n } from "vue-i18n"; -import { useRoute } from "vue-router"; +import { useRoute, useRouter } from "vue-router"; +import GrantPermissionModal from "./components/GrantPermissionModal.vue"; import UserEditingModal from "./components/UserEditingModal.vue"; import UserPasswordChangeModal from "./components/UserPasswordChangeModal.vue"; import DetailTab from "./tabs/Detail.vue"; @@ -34,9 +38,9 @@ const { currentUser } = useUserStore(); const editingModal = ref(false); const passwordChangeModal = ref(false); - +const grantPermissionModal = ref(false); const { params } = useRoute(); - +const router = useRouter(); const { data: user, isLoading, @@ -97,6 +101,27 @@ const tabbarItems = computed(() => { })); }); +const handleDelete = async (userToDelete: User) => { + Dialog.warning({ + title: t("core.user.operations.delete.title"), + description: t("core.common.dialog.descriptions.cannot_be_recovered"), + confirmType: "danger", + confirmText: t("core.common.buttons.confirm"), + cancelText: t("core.common.buttons.cancel"), + onConfirm: async () => { + try { + await coreApiClient.user.deleteUser({ + name: userToDelete.metadata.name, + }); + Toast.success(t("core.common.toast.delete_success")); + router.push({ name: "Users" }); + } catch (e) { + console.error("Failed to delete user", e); + } + }, + }); +}; + function handleRouteToUC() { window.location.href = "/uc"; } @@ -105,6 +130,10 @@ function onPasswordChangeModalClose() { passwordChangeModal.value = false; refetch(); } +function onGrantPermissionModalClose() { + grantPermissionModal.value = false; + refetch(); +} diff --git a/ui/src/locales/zh-CN.yaml b/ui/src/locales/zh-CN.yaml index b59738465b..0f7eb2a9cc 100644 --- a/ui/src/locales/zh-CN.yaml +++ b/ui/src/locales/zh-CN.yaml @@ -994,6 +994,8 @@ core: title: 修改资料 change_password: title: 修改密码 + grant_permission: + title: 分配角色 profile: title: 个人中心 fields: From b0ad8907673cc467987804980f9ed5186bcac73c Mon Sep 17 00:00:00 2001 From: Nancy <3510671794@qq.com> Date: Tue, 29 Oct 2024 18:57:18 +0800 Subject: [PATCH 2/4] Refine i18n --- ui/src/locales/en.yaml | 2 ++ ui/src/locales/zh-TW.yaml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/ui/src/locales/en.yaml b/ui/src/locales/en.yaml index 1936b5beb5..250017d80b 100644 --- a/ui/src/locales/en.yaml +++ b/ui/src/locales/en.yaml @@ -1062,6 +1062,8 @@ core: title: Update profile change_password: title: Change password + grant_permission: + title: Assign roles profile: title: Profile fields: diff --git a/ui/src/locales/zh-TW.yaml b/ui/src/locales/zh-TW.yaml index fed0c13f2a..fdcbe05ac5 100644 --- a/ui/src/locales/zh-TW.yaml +++ b/ui/src/locales/zh-TW.yaml @@ -971,6 +971,8 @@ core: title: 修改資料 change_password: title: 修改密碼 + grant_permission: + title: 分配角色 profile: title: 個人中心 fields: From fe14334af6eaef3dbe998ac15e86727d29196d4d Mon Sep 17 00:00:00 2001 From: Nancy <3510671794@qq.com> Date: Wed, 30 Oct 2024 11:17:14 +0800 Subject: [PATCH 3/4] Update ui/src/locales/en.yaml --- ui/src/locales/en.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/locales/en.yaml b/ui/src/locales/en.yaml index 250017d80b..e2a409a3d4 100644 --- a/ui/src/locales/en.yaml +++ b/ui/src/locales/en.yaml @@ -1063,7 +1063,7 @@ core: change_password: title: Change password grant_permission: - title: Assign roles + title: Grant permission profile: title: Profile fields: From ea220d6f0442726b874d42c2251d70ee713f248c Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Wed, 30 Oct 2024 12:17:14 +0800 Subject: [PATCH 4/4] fix ts error --- ui/console-src/modules/system/users/UserDetail.vue | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ui/console-src/modules/system/users/UserDetail.vue b/ui/console-src/modules/system/users/UserDetail.vue index c0f3f222a7..e106ec860f 100644 --- a/ui/console-src/modules/system/users/UserDetail.vue +++ b/ui/console-src/modules/system/users/UserDetail.vue @@ -192,7 +192,11 @@ function onGrantPermissionModalClose() { {{ $t("core.user.detail.actions.grant_permission.title") }} - + {{ $t("core.common.buttons.delete") }}