Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/change user role and delete #6960

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ const modalTitle = props.group
const handleSave = async () => {
try {
isSubmitting.value = true;
const existingGroupsResponse =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

包含了 #6959 中的更改,建议新的改动新开一个分支再提交 PR,可以看看这个文档:https://docs.halo.run/contribution/pr#%E4%BB%A3%E7%A0%81%E8%B4%A1%E7%8C%AE%E6%AD%A5%E9%AA%A4

await coreApiClient.storage.group.listGroup();
const existingGroups = existingGroupsResponse.data.items || [];
const nameExists = existingGroups.some(
(group) => group.spec.displayName === formState.value.spec.displayName
);

if (nameExists) {
alert("该分组名称已存在,请重新创建!");
return;
}

if (props.group) {
await coreApiClient.storage.group.updateGroup({
name: formState.value.metadata.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ const formState = ref<Policy>({

const isUpdateMode = !!props.policy;

const { data: policies } = useQuery({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

queryKey: ["core:attachment:policies"],
queryFn: async () => {
const { data } = await coreApiClient.storage.policy.listPolicy(); // 修改为 listPolicy
return data;
},
});

onMounted(async () => {
if (props.policy) {
formState.value = cloneDeep(props.policy);
Expand Down Expand Up @@ -135,6 +143,14 @@ const submitting = ref(false);
const handleSave = async () => {
try {
submitting.value = true;
const nameExists = policies.value?.items.some(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

(policy) => policy.spec.displayName === formState.value.spec.displayName
);

if (nameExists) {
alert("该存储策略名称已存在,请重新创建!");
return;
}

const configMapToUpdate = convertToSave();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ const onGroupEditingModalClose = async () => {
@click="selectedGroupName = group.metadata.name"
/>

<AttachmentGroupBadge @click="handleOpenCreateNewGroupModal">
<AttachmentPolicyBadge @click="handleOpenCreateNewGroupModal">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

<template #text>
<span>{{ $t("core.common.buttons.new") }}</span>
</template>
<template #actions>
<IconAddCircle />
</template>
</AttachmentGroupBadge>
</AttachmentPolicyBadge>
</div>
<UppyUpload
endpoint="/apis/api.console.halo.run/v1alpha1/attachments/upload"
Expand Down
49 changes: 45 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,12 @@ 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 type="danger" @click="handleDelete(user?.user)">
{{ $t("core.common.buttons.delete") }}
</VDropdownItem>
</template>
</VDropdown>
</div>
Expand Down
4 changes: 4 additions & 0 deletions ui/src/locales/zh-CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -990,10 +990,14 @@ core:
tabs:
detail: 详情
actions:
delete:
title: 删除
update_profile:
title: 修改资料
change_password:
title: 修改密码
grant_permission:
title: 分配角色
profile:
title: 个人中心
fields:
Expand Down