Allow configured feedback DingTalk recipients to read feedback detail

This commit is contained in:
WuYongJie 2026-12-02 19:00:58 +08:00
parent 0974156cf6
commit 6b19b4d7d4
2 changed files with 19 additions and 6 deletions

View File

@ -182,6 +182,7 @@ describe('GET /feedback/[id]', () => {
['admin', { ...active, role: 'ADMIN' as const }],
['system-admin', { ...active, role: 'SYSTEM_ADMIN' as const }],
['super-admin', { ...active, isSuperAdmin: true }],
['configured-recipient', { ...active, dingtalkUserId: 'recipient-test' }],
])('serves escaped, private HTML to %s', async (viewerId, identity) => {
jest.mocked(getServerSession).mockResolvedValue({ user: { id: viewerId } })
userStore.findUnique.mockResolvedValue(identity as never)
@ -197,9 +198,13 @@ describe('GET /feedback/[id]', () => {
expect(feedbackStore.findFirst).toHaveBeenCalledWith(expect.objectContaining({ where: viewerId === ownerId ? { feedbackId: id, ownerId } : { feedbackId: id } }))
})
it.each(['USER', 'DEPT_ADMIN'] as const)('returns a real 403 to another %s and checks only metadata', async role => {
it.each([
['USER', undefined],
['DEPT_ADMIN', undefined],
['USER', 'other-ding-user'],
] as const)('returns a real 403 to another %s (%s) and checks only metadata', async (role, dingtalkUserId) => {
jest.mocked(getServerSession).mockResolvedValue({ user: { id: 'another', role: 'ADMIN' } })
userStore.findUnique.mockResolvedValue({ ...active, role } as never)
userStore.findUnique.mockResolvedValue({ ...active, role, dingtalkUserId } as never)
feedbackStore.findFirst.mockResolvedValue(null)
feedbackStore.findUnique.mockResolvedValue({ feedbackId: id } as never)
const response = await get()

View File

@ -5,12 +5,17 @@ import { submitYouyidianNotification } from '@/lib/youyidian-notification-center
import { DesktopClientError } from './contract.mjs'
import { feedbackIdSchema, parseDesktopFeedback } from './feedback-contract'
async function feedbackNotificationRecipients() {
function configuredFeedbackRecipients(): string[] {
const configured = [
process.env.YYD_DESKTOP_FEEDBACK_RECIPIENT_USER_ID ?? '',
...(process.env.YYD_DESKTOP_FEEDBACK_RECIPIENT_USER_IDS ?? '').split(','),
].map(id => id.trim()).filter(Boolean)
if (configured.length) return Array.from(new Set(configured))
return Array.from(new Set(configured))
}
async function feedbackNotificationRecipients() {
const configured = configuredFeedbackRecipients()
if (configured.length) return configured
const admins = await prisma.user.findMany({
where: {
@ -87,12 +92,15 @@ export async function loadDesktopFeedback(id: string, viewerId: string) {
const viewer = await prisma.user.findUnique({
where: { id: viewerId },
select: { role: true, isSuperAdmin: true, isActive: true, status: true, archivedAt: true },
select: { role: true, isSuperAdmin: true, isActive: true, status: true, archivedAt: true, dingtalkUserId: true },
})
if (!viewer?.isActive || viewer.status !== 'active' || viewer.archivedAt) return { status: 403 } as const
const feedbackId = parsedId.data
const canReadAll = viewer.isSuperAdmin || isSystemAdmin(viewer.role)
const dingtalkId = viewer.dingtalkUserId?.trim()
const canReadAll = viewer.isSuperAdmin
|| isSystemAdmin(viewer.role)
|| (Boolean(dingtalkId) && configuredFeedbackRecipients().includes(dingtalkId!))
const feedback = await prisma.desktopClientFeedback.findFirst({
where: { feedbackId, ...(canReadAll ? {} : { ownerId: viewerId }) },
include: { owner: { select: { realName: true, username: true } } },