-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for delete or revoke a personal access token
Signed-off-by: Ryan Wang <[email protected]>
- Loading branch information
Showing
2 changed files
with
106 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
console/src/modules/system/users/components/PersonalAccessTokenListItem.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<script lang="ts" setup> | ||
import { apiClient } from "@/utils/api-client"; | ||
import { formatDatetime, relativeTimeTo } from "@/utils/date"; | ||
import type { PersonalAccessToken } from "@halo-dev/api-client"; | ||
import { | ||
Dialog, | ||
Toast, | ||
VDropdownDivider, | ||
VDropdownItem, | ||
VEntity, | ||
VEntityField, | ||
VStatusDot, | ||
} from "@halo-dev/components"; | ||
import { useQueryClient } from "@tanstack/vue-query"; | ||
const props = withDefaults( | ||
defineProps<{ | ||
token: PersonalAccessToken; | ||
}>(), | ||
{} | ||
); | ||
const queryClient = useQueryClient(); | ||
function handleDelete() { | ||
Dialog.warning({ | ||
title: "删除个人令牌", | ||
description: "确定要删除该个人令牌吗?", | ||
async onConfirm() { | ||
await apiClient.pat.deletePat({ | ||
name: props.token.metadata.name, | ||
}); | ||
Toast.success("删除成功"); | ||
queryClient.invalidateQueries({ queryKey: ["personal-access-tokens"] }); | ||
}, | ||
}); | ||
} | ||
function handleRevoke() { | ||
Dialog.warning({ | ||
title: "撤销个人令牌", | ||
description: "确定要撤销该个人令牌吗?", | ||
async onConfirm() { | ||
await apiClient.pat.revokePat({ | ||
name: props.token.metadata.name, | ||
}); | ||
Toast.success("撤销成功"); | ||
queryClient.invalidateQueries({ queryKey: ["personal-access-tokens"] }); | ||
}, | ||
}); | ||
} | ||
</script> | ||
|
||
<template> | ||
<VEntity> | ||
<template #start> | ||
<VEntityField | ||
:title="token.metadata.name" | ||
:description="token.spec?.description" | ||
></VEntityField> | ||
</template> | ||
<template #end> | ||
<VEntityField v-if="token.metadata.deletionTimestamp"> | ||
<template #description> | ||
<VStatusDot | ||
v-tooltip="$t('core.common.status.deleting')" | ||
state="warning" | ||
animate | ||
/> | ||
</template> | ||
</VEntityField> | ||
<VEntityField> | ||
<template #description> | ||
<span class="truncate text-xs tabular-nums text-gray-500"> | ||
{{ relativeTimeTo(token.spec?.expiresAt) }} | ||
</span> | ||
</template> | ||
</VEntityField> | ||
<VEntityField | ||
:description="formatDatetime(token.metadata.creationTimestamp)" | ||
></VEntityField> | ||
</template> | ||
<template #dropdownItems> | ||
<VDropdownItem | ||
v-if="!token.spec?.revoked" | ||
type="danger" | ||
@click="handleRevoke" | ||
> | ||
撤销 | ||
</VDropdownItem> | ||
<VDropdownItem v-else @click="handleDelete">恢复</VDropdownItem> | ||
<VDropdownDivider /> | ||
<VDropdownItem type="danger" @click="handleDelete">删除</VDropdownItem> | ||
</template> | ||
</VEntity> | ||
</template> |