feat(session): gate IM/embed/API channel sessions behind admin
Restrict channel-managed sessions (API keys, IM, embed) to tenant admin in the Web console for list/read paths, hide channel sidebar buckets from non-admins, and add CountSessionsBySource for aggregate stats without exposing session rows to viewers.
This commit is contained in:
@@ -167,27 +167,26 @@
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 批量管理底部操作条 -->
|
||||
<div v-if="batchMode && !uiStore.sidebarCollapsed" class="batch-inline-footer">
|
||||
<div class="batch-footer-left">
|
||||
<t-checkbox :checked="isAllBatchSelected" :indeterminate="isBatchIndeterminate"
|
||||
@change="toggleBatchSelectAll">
|
||||
{{ t('batchManage.selectAll') }}
|
||||
</t-checkbox>
|
||||
</div>
|
||||
<div class="batch-footer-right">
|
||||
<t-button size="small" variant="text" @click="exitBatchMode">
|
||||
{{ t('batchManage.cancel') }}
|
||||
</t-button>
|
||||
<t-button size="small" theme="danger" variant="base" :disabled="batchSelectedIds.length === 0"
|
||||
:loading="batchDeleting" @click="handleInlineBatchDelete">
|
||||
{{ t('batchManage.delete') }}{{ batchSelectedIds.length > 0 ? `(${batchDisplayCount})` : '' }}
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 批量管理底部操作条:固定在侧栏底部、用户头像上方 -->
|
||||
<div v-if="batchMode && !uiStore.sidebarCollapsed" class="batch-inline-footer">
|
||||
<div class="batch-footer-left">
|
||||
<t-checkbox :checked="isAllBatchSelected" :indeterminate="isBatchIndeterminate"
|
||||
@change="toggleBatchSelectAll">
|
||||
{{ t('batchManage.selectAll') }}
|
||||
</t-checkbox>
|
||||
</div>
|
||||
<div class="batch-footer-right">
|
||||
<t-button size="small" variant="text" @click="exitBatchMode">
|
||||
{{ t('batchManage.cancel') }}
|
||||
</t-button>
|
||||
<t-button size="small" theme="danger" variant="base" :disabled="batchSelectedIds.length === 0"
|
||||
:loading="batchDeleting" @click="handleInlineBatchDelete">
|
||||
{{ t('batchManage.delete') }}{{ batchSelectedIds.length > 0 ? `(${batchDisplayCount})` : '' }}
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 下半部分:用户菜单 -->
|
||||
<div class="menu_bottom">
|
||||
@@ -748,7 +747,7 @@ const rebuildBucketDefinitions = () => buildBucketDefinitions(
|
||||
embedChannel: (name) => name,
|
||||
api: t('menu.apiChats'),
|
||||
},
|
||||
{ includeApiBucket: authStore.hasRole('admin') },
|
||||
{ includeAdminChannelBuckets: authStore.hasRole('admin') },
|
||||
);
|
||||
|
||||
/** 首屏轻量探测各渠道是否有会话(page_size=1 只取 total),避免展示空文件夹 */
|
||||
@@ -1705,9 +1704,6 @@ const onDragHandleMouseDown = (e: MouseEvent) => {
|
||||
}
|
||||
|
||||
.batch-inline-footer {
|
||||
position: sticky;
|
||||
bottom: 0;
|
||||
z-index: 2;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -4,6 +4,7 @@ import test from 'node:test'
|
||||
import {
|
||||
applyBucketCountProbe,
|
||||
bucketVisible,
|
||||
buildBucketDefinitions,
|
||||
createEmptyBucket,
|
||||
prependSessionToWebBucket,
|
||||
type BucketDefinition,
|
||||
@@ -56,3 +57,33 @@ test('prependSessionToWebBucket is idempotent for existing session', () => {
|
||||
const next = prependSessionToWebBucket(bucket, { id: 'a', title: 'Same' })
|
||||
assert.equal(next, bucket)
|
||||
})
|
||||
|
||||
test('buildBucketDefinitions hides channel buckets unless admin', () => {
|
||||
const defs = buildBucketDefinitions(
|
||||
['feishu'],
|
||||
{ ch1: 'Embed' },
|
||||
{
|
||||
web: 'Chats',
|
||||
imPlatform: (platform) => platform,
|
||||
embedChannel: (name) => name,
|
||||
api: 'API',
|
||||
},
|
||||
)
|
||||
assert.deepEqual(defs.map((def) => def.key), ['web'])
|
||||
|
||||
const adminDefs = buildBucketDefinitions(
|
||||
['feishu'],
|
||||
{ ch1: 'Embed' },
|
||||
{
|
||||
web: 'Chats',
|
||||
imPlatform: (platform) => platform,
|
||||
embedChannel: (name) => name,
|
||||
api: 'API',
|
||||
},
|
||||
{ includeAdminChannelBuckets: true },
|
||||
)
|
||||
assert.deepEqual(
|
||||
adminDefs.map((def) => def.key),
|
||||
['im:feishu', 'embed:ch1', 'api', 'web'],
|
||||
)
|
||||
})
|
||||
|
||||
@@ -68,8 +68,8 @@ export function isChannelBucketKey(key: string): boolean {
|
||||
}
|
||||
|
||||
// API_SESSION_BUCKET_KEY is the admin-only bucket that lists every API-key
|
||||
// session in the tenant. It is treated like a channel folder: probed for a
|
||||
// count first and only surfaced in the source filter when it has sessions.
|
||||
// session in the tenant. IM and embed folders are also admin-only; they are
|
||||
// probed for a count first and only surfaced when they have sessions.
|
||||
export const API_SESSION_BUCKET_KEY = 'api'
|
||||
|
||||
export function buildBucketDefinitions(
|
||||
@@ -81,22 +81,27 @@ export function buildBucketDefinitions(
|
||||
embedChannel: (name: string) => string
|
||||
api: string
|
||||
},
|
||||
options: { includeApiBucket?: boolean } = {},
|
||||
options: { includeAdminChannelBuckets?: boolean } = {},
|
||||
): BucketDefinition[] {
|
||||
const imDefs = imPlatforms.map((platform) => ({
|
||||
key: `im:${platform}`,
|
||||
apiSource: platform,
|
||||
label: labels.imPlatform(platform),
|
||||
kind: 'im' as const,
|
||||
platform,
|
||||
}))
|
||||
const embedDefs = Object.entries(embedChannels).map(([id, name]) => ({
|
||||
key: `embed:${id}`,
|
||||
apiSource: `embed:${id}`,
|
||||
label: labels.embedChannel(name || id.slice(0, 8)),
|
||||
kind: 'embed' as const,
|
||||
}))
|
||||
const apiDefs: BucketDefinition[] = options.includeApiBucket
|
||||
const includeChannels = options.includeAdminChannelBuckets ?? options.includeApiBucket ?? false
|
||||
const imDefs = includeChannels
|
||||
? imPlatforms.map((platform) => ({
|
||||
key: `im:${platform}`,
|
||||
apiSource: platform,
|
||||
label: labels.imPlatform(platform),
|
||||
kind: 'im' as const,
|
||||
platform,
|
||||
}))
|
||||
: []
|
||||
const embedDefs = includeChannels
|
||||
? Object.entries(embedChannels).map(([id, name]) => ({
|
||||
key: `embed:${id}`,
|
||||
apiSource: `embed:${id}`,
|
||||
label: labels.embedChannel(name || id.slice(0, 8)),
|
||||
kind: 'embed' as const,
|
||||
}))
|
||||
: []
|
||||
const apiDefs: BucketDefinition[] = includeChannels
|
||||
? [
|
||||
{
|
||||
key: API_SESSION_BUCKET_KEY,
|
||||
|
||||
Reference in New Issue
Block a user