feat(tenant): expose API Key reset from the API Info page
Add a danger-themed reset button next to the existing copy/eye buttons on the API Info settings page. Confirmation dialog warns that the old key is revoked immediately; on success the new plaintext key replaces the displayed value and is auto-revealed so the user can copy it. Backend: new POST /api/v1/tenants/:id/api-key handler that wraps the existing TenantService.UpdateAPIKey; access is gated by the same authorizeTenantAccess check as other tenant endpoints. The handler returns the freshly generated plaintext key, while the encrypted form is persisted to the database. Frontend: new resetTenantApiKey API client, reset button + confirm dialog wiring in ApiInfo.vue, plus matching i18n entries for zh-CN, en-US, ko-KR, and ru-RU.
This commit is contained in:
@@ -51,6 +51,16 @@
|
||||
>
|
||||
<t-icon name="file-copy" />
|
||||
</t-button>
|
||||
<t-button
|
||||
size="small"
|
||||
variant="text"
|
||||
theme="danger"
|
||||
:loading="resetting"
|
||||
:title="$t('tenant.api.resetTitle')"
|
||||
@click="confirmResetApiKey"
|
||||
>
|
||||
<t-icon name="refresh" />
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -213,8 +223,9 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { getCurrentUser, type TenantInfo, type UserInfo } from '@/api/auth'
|
||||
import { resetTenantApiKey } from '@/api/tenant'
|
||||
import { getApiBaseUrl } from '@/utils/api-base'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { DialogPlugin, MessagePlugin } from 'tdesign-vue-next'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { t, locale } = useI18n()
|
||||
@@ -225,6 +236,7 @@ const userInfo = ref<UserInfo | null>(null)
|
||||
const loading = ref(true)
|
||||
const error = ref('')
|
||||
const showApiKey = ref(false)
|
||||
const resetting = ref(false)
|
||||
/** WeKnora Lite (Wails): real API origin is loopback + dynamic port, not window.location.origin */
|
||||
const wailsApiBaseURL = ref<string | null>(null)
|
||||
const showDesktopPortSetting = ref(false)
|
||||
@@ -441,6 +453,43 @@ const fallbackCopyText = (text: string) => {
|
||||
document.body.removeChild(textArea)
|
||||
}
|
||||
|
||||
const confirmResetApiKey = () => {
|
||||
if (!tenantInfo.value?.id) {
|
||||
MessagePlugin.warning(t('tenant.api.noKey'))
|
||||
return
|
||||
}
|
||||
const dialog = DialogPlugin.confirm({
|
||||
header: t('tenant.api.resetConfirmTitle'),
|
||||
body: t('tenant.api.resetConfirmBody'),
|
||||
confirmBtn: { content: t('tenant.api.resetConfirmOk'), theme: 'danger' },
|
||||
cancelBtn: t('tenant.api.resetConfirmCancel'),
|
||||
onConfirm: async () => {
|
||||
await performResetApiKey()
|
||||
dialog.destroy()
|
||||
},
|
||||
onClose: () => dialog.destroy(),
|
||||
})
|
||||
}
|
||||
|
||||
const performResetApiKey = async () => {
|
||||
if (!tenantInfo.value?.id) return
|
||||
resetting.value = true
|
||||
try {
|
||||
const resp = await resetTenantApiKey(tenantInfo.value.id)
|
||||
if (resp.success && resp.data?.api_key) {
|
||||
tenantInfo.value = { ...tenantInfo.value, api_key: resp.data.api_key }
|
||||
showApiKey.value = true
|
||||
MessagePlugin.success(t('tenant.api.resetSuccess'))
|
||||
} else {
|
||||
MessagePlugin.error(resp.message || t('tenant.api.resetFailed'))
|
||||
}
|
||||
} catch (err: any) {
|
||||
MessagePlugin.error(err?.message || t('tenant.api.resetFailed'))
|
||||
} finally {
|
||||
resetting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const copyApiKey = async () => {
|
||||
if (!tenantInfo.value?.api_key) {
|
||||
MessagePlugin.warning(t('tenant.api.noKey'))
|
||||
|
||||
Reference in New Issue
Block a user