fix(settings): 仅展示只读DWS凭证状态
build / build (push) Successful in 1m10s

This commit is contained in:
姚章浩
2026-10-27 09:56:19 +08:00
parent 5b6e154459
commit f0b12412a1
8 changed files with 149 additions and 32 deletions
+25 -31
View File
@@ -1,7 +1,5 @@
import './SourceManagement.css'
import { useEffect, useState } from 'react'
import { DingtalkSessionControl } from './DingtalkSessionControl'
import { fetchAvailableDingtalkSources } from './dingtalkSources'
import { archiveSourceConnection, fetchSourceConnectionList, fetchSourceSettingsRevisions } from './sourceConnections'
import { useOptionalAuth } from './auth'
import type { SourceConnectionListItem, SourceSettingsRevision } from './sourceConnections'
@@ -22,42 +20,38 @@ const choices = [
const errorText = (error: unknown) => (error instanceof Error ? error.message : '操作失败,请重试')
export function DingtalkAccountStatus() {
const [status, setStatus] = useState('检查中…')
const [error, setError] = useState('')
const [revision, setRevision] = useState(0)
const [expanded, setExpanded] = useState(false)
const [status, setStatus] = useState('读取中…')
const [expires, setExpires] = useState('')
useEffect(() => {
const controller = new AbortController()
setStatus('检查中…')
setError('')
void fetchAvailableDingtalkSources(controller.signal)
.then((data) => {
if (!controller.signal.aborted)
setStatus(data.knowledge_notice || data.drive_notice ? '已连接,部分目录受限' : '已连接')
void fetch('/api/v1/dingtalk-spaces/credential-status', {
headers: { Accept: 'application/json' },
signal: controller.signal,
})
.then(async (response) => {
if (!response.ok) throw new Error('读取失败')
const value = await response.json()
const data = value.data
if (!data || typeof data.authenticated !== 'boolean' || typeof data.refresh_token_valid !== 'boolean')
throw new Error('状态格式错误')
if (controller.signal.aborted) return
setStatus(!data.authenticated ? '未登录' : data.refresh_token_valid ? '已登录' : '凭证需更新')
setExpires(data.authenticated && typeof data.refresh_expires_at === 'string' ? data.refresh_expires_at : '')
})
.catch((cause) => {
if (!controller.signal.aborted) {
setStatus('状态暂不可用')
setError(errorText(cause))
}
.catch(() => {
if (!controller.signal.aborted) setStatus('状态读取失败')
})
return () => controller.abort()
}, [revision])
}, [])
return (
<div className="source-account">
<button className="link" aria-expanded={expanded} onClick={() => setExpanded(!expanded)}>
钉钉账号 · {status}
</button>
{expanded ? (
<div className="source-account-detail">
<p>此账号授权由所有钉钉来源共享。</p>
{error ? <p role="alert">{error}</p> : null}
<DingtalkSessionControl triggerLabel="重新授权" onSuccess={() => setRevision((value) => value + 1)} />
<button className="link" onClick={() => setRevision((value) => value + 1)}>
重新检查
</button>
</div>
<div className="source-account" role="status">
<span>DWS 凭证 · {status}</span>
{expires ? (
<small> · 续期凭证有效期至 {new Date(expires).toLocaleString('zh-CN', { hour12: false })}</small>
) : null}
<div>
<small>仅显示本地凭证状态,不检测目录权限或业务接口。</small>
</div>
</div>
)
}
+1 -1
View File
@@ -567,7 +567,7 @@ describe('SystemSettingsView 数据源配置的默认清单', () => {
expect(html).toContain('aria-expanded="false"')
expect(html).toContain('仅手动刷新')
expect(html).toContain('数据源设置审计')
expect((html.match(/钉钉账号 ·/g) ?? []).length).toBe(1)
expect((html.match(/DWS 凭证 ·/g) ?? []).length).toBe(1)
for (const removed of ['+ 新增钉钉知识库', '文件格式筛选']) expect(html).not.toContain(removed)
// 文档工程师看不到添加向导与「去掉来源」:两者都是管理员动作。
const engineer = view('engineer')