mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-01 17:00:21 +08:00
fix(oauth): 系统导入时清理失效标记并强制刷新 refresh_token,前端徽章优先使用 account_id
- 后端 admin 系统导入 OAuth 凭据时重置 expires_at 与失效标记,并在存在 refresh_token 时触发一次本地刷新 - 前端 OAuth 徽章改为优先展示 account_id,采用去前缀后 5 字符的紧凑格式
This commit is contained in:
@@ -3,7 +3,7 @@ import { describe, expect, it } from 'vitest'
|
||||
import { getOAuthOrgBadge } from '../oauthIdentity'
|
||||
|
||||
describe('getOAuthOrgBadge', () => {
|
||||
it('prefers organization identity over account display name', () => {
|
||||
it('prefers compact account id over organization badge when available', () => {
|
||||
const badge = getOAuthOrgBadge({
|
||||
oauth_account_id: 'acct-demo-001',
|
||||
oauth_account_name: 'Workspace Alpha',
|
||||
@@ -14,8 +14,8 @@ describe('getOAuthOrgBadge', () => {
|
||||
})
|
||||
|
||||
expect(badge).toEqual({
|
||||
id: 'org-personal-1234',
|
||||
label: 'org:person...1234',
|
||||
id: 'acct-demo-001',
|
||||
label: 'demo0',
|
||||
title: 'name: Workspace Alpha | account_id: acct-demo-001 | account_user_id: user-1__acct-demo-001 | org_id: org-personal-1234 | org_title: Personal',
|
||||
})
|
||||
})
|
||||
@@ -28,11 +28,23 @@ describe('getOAuthOrgBadge', () => {
|
||||
|
||||
expect(badge).toEqual({
|
||||
id: 'acct-demo-001',
|
||||
label: 'acct-dem',
|
||||
label: 'demo0',
|
||||
title: 'name: Workspace Alpha | account_id: acct-demo-001',
|
||||
})
|
||||
})
|
||||
|
||||
it('drops the leading prefix before taking the 5-character account badge', () => {
|
||||
const badge = getOAuthOrgBadge({
|
||||
oauth_account_id: 'org-HUone5DwhkDWrgXpDR3JJbGi',
|
||||
})
|
||||
|
||||
expect(badge).toEqual({
|
||||
id: 'org-HUone5DwhkDWrgXpDR3JJbGi',
|
||||
label: 'HUone',
|
||||
title: 'account_id: org-HUone5DwhkDWrgXpDR3JJbGi',
|
||||
})
|
||||
})
|
||||
|
||||
it('does not create an identity badge from account name alone', () => {
|
||||
const badge = getOAuthOrgBadge({
|
||||
oauth_account_name: 'Free',
|
||||
@@ -74,8 +86,8 @@ describe('getOAuthOrgBadge', () => {
|
||||
|
||||
expect(first).not.toBe(second)
|
||||
expect(second).toEqual({
|
||||
id: 'org-team-5678',
|
||||
label: 'org:team-5678',
|
||||
id: 'acct-demo-001',
|
||||
label: 'demo0',
|
||||
title: 'account_id: acct-demo-001 | org_id: org-team-5678 | org_title: Team',
|
||||
})
|
||||
})
|
||||
|
||||
@@ -77,8 +77,18 @@ function formatOAuthOrganizationBadge(orgId: string): string {
|
||||
return `org:${normalized.slice(0, 6)}...${normalized.slice(-4)}`
|
||||
}
|
||||
|
||||
function compactOAuthAccountId(accountId: string): string {
|
||||
const normalized = accountId.trim()
|
||||
if (!normalized) return ''
|
||||
|
||||
const withoutPrefix = normalized.replace(/^[^:_-]+[-_:]+/, '')
|
||||
const compact = withoutPrefix.replace(/[-_:]+/g, '')
|
||||
|
||||
return compact || withoutPrefix || normalized
|
||||
}
|
||||
|
||||
function formatOAuthAccountBadge(accountId: string): string {
|
||||
return accountId.slice(0, 8)
|
||||
return compactOAuthAccountId(accountId).slice(0, 5)
|
||||
}
|
||||
|
||||
function formatOAuthAccountUserBadge(accountUserId: string): string {
|
||||
@@ -211,18 +221,18 @@ export function getOAuthOrgBadge(
|
||||
const accountName = readStr(value?.oauth_account_name)
|
||||
const accountUserId = readStr(value?.oauth_account_user_id)
|
||||
|
||||
const badgeId = org?.id || accountId || accountUserId || ''
|
||||
const badgeId = accountId || accountUserId || org?.id || ''
|
||||
if (!badgeId) {
|
||||
setCachedOAuthOrgBadge(value, org, null)
|
||||
return null
|
||||
}
|
||||
|
||||
const label = org
|
||||
? formatOAuthOrganizationBadge(org.id)
|
||||
: accountId
|
||||
? formatOAuthAccountBadge(accountId)
|
||||
: accountUserId
|
||||
? formatOAuthAccountUserBadge(accountUserId)
|
||||
const label = accountId
|
||||
? formatOAuthAccountBadge(accountId)
|
||||
: accountUserId
|
||||
? formatOAuthAccountUserBadge(accountUserId)
|
||||
: org
|
||||
? formatOAuthOrganizationBadge(org.id)
|
||||
: ''
|
||||
if (!label) {
|
||||
setCachedOAuthOrgBadge(value, org, null)
|
||||
|
||||
Reference in New Issue
Block a user