Skip to content

Commit

Permalink
feat: add grant permission and user deletion features to user detail …
Browse files Browse the repository at this point in the history
…page (#6963)

What type of PR is this?

/area ui
/kind improvement
/milestone 2.20.x

What this PR does / why we need it:

期望支持在用户详情页面支持变更用户角色及删除用户 。

Which issue(s) this PR fixes:

Fixes #6944

Special notes for your reviewer:

Does this PR introduce a user-facing change?
```release-note
支持在用户详情页面支持变更用户角色及删除用户 。
```
  • Loading branch information
LEIYOUSU authored Oct 30, 2024
1 parent 77548ec commit 2c4e85f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
53 changes: 49 additions & 4 deletions ui/console-src/modules/system/users/UserDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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";
Expand All @@ -34,9 +38,9 @@ const { currentUser } = useUserStore();
const editingModal = ref(false);
const passwordChangeModal = ref(false);
const grantPermissionModal = ref<boolean>(false);
const { params } = useRoute();
const router = useRouter();
const {
data: user,
isLoading,
Expand Down Expand Up @@ -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";
}
Expand All @@ -105,6 +130,10 @@ function onPasswordChangeModalClose() {
passwordChangeModal.value = false;
refetch();
}
function onGrantPermissionModalClose() {
grantPermissionModal.value = false;
refetch();
}
</script>
<template>
<UserEditingModal
Expand All @@ -119,6 +148,12 @@ function onPasswordChangeModalClose() {
@close="onPasswordChangeModalClose"
/>
<GrantPermissionModal
v-if="grantPermissionModal"
:user="user?.user"
@close="onGrantPermissionModalClose"
/>
<header class="bg-white">
<div class="p-4">
<div class="flex items-center justify-between">
Expand Down Expand Up @@ -154,6 +189,16 @@ function onPasswordChangeModalClose() {
<VDropdownItem @click="passwordChangeModal = true">
{{ $t("core.user.detail.actions.change_password.title") }}
</VDropdownItem>
<VDropdownItem @click="grantPermissionModal = true">
{{ $t("core.user.detail.actions.grant_permission.title") }}
</VDropdownItem>
<VDropdownItem
v-if="user?.user"
type="danger"
@click="handleDelete(user.user)"
>
{{ $t("core.common.buttons.delete") }}
</VDropdownItem>
</template>
</VDropdown>
</div>
Expand Down
2 changes: 2 additions & 0 deletions ui/src/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,8 @@ core:
title: Update profile
change_password:
title: Change password
grant_permission:
title: Grant permission
profile:
title: Profile
fields:
Expand Down
2 changes: 2 additions & 0 deletions ui/src/locales/zh-CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,8 @@ core:
title: 修改资料
change_password:
title: 修改密码
grant_permission:
title: 分配角色
profile:
title: 个人中心
fields:
Expand Down
2 changes: 2 additions & 0 deletions ui/src/locales/zh-TW.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,8 @@ core:
title: 修改資料
change_password:
title: 修改密碼
grant_permission:
title: 分配角色
profile:
title: 個人中心
fields:
Expand Down

0 comments on commit 2c4e85f

Please sign in to comment.