mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-29 20:34:28 +00:00
feat(settings): add team appearance setting to hide agent features (#411)
* feat(settings): add team appearance setting to hide agent features Add an Appearance subpage under Team Settings allowing team owners to toggle appearance.hideAgent for the team. Return appearance.hideAgent in the user-metadata API, and conditionally hide the AGENTS.md button, agent chatbot sidebar, and chatbot trigger button in the WebUI. * refactor(settings): add strongly typed TeamSettingsResponse to remove explicit any Introduce TeamSettingsResponse and TeamAppearanceSettings in @shumai/dtos, type TeamService.getSettings and updateSettings, and eliminate the explicit any cast in AppearanceSettings.tsx.
This commit is contained in:
@@ -45,13 +45,39 @@ describe('UserMetadataService', () => {
|
||||
await userMetadataService.upsertMetadata(user.id, team.id, 'key2', 'value2')
|
||||
|
||||
const list = await userMetadataService.listMetadata(user.id, team.id)
|
||||
expect(list).toHaveLength(2)
|
||||
expect(list).toHaveLength(3)
|
||||
expect(list).toEqual([
|
||||
{ key: 'key1', value: 'value1' },
|
||||
{ key: 'key2', value: 'value2' },
|
||||
{ key: 'appearance.hideAgent', value: false },
|
||||
])
|
||||
})
|
||||
|
||||
it('should return team appearance.hideAgent when configured', async () => {
|
||||
const user = await prisma.user.create({
|
||||
data: {
|
||||
name: 'Test User HideAgent',
|
||||
email: `testha-${Date.now()}@example.com`,
|
||||
password: 'pw',
|
||||
},
|
||||
})
|
||||
const team = await prisma.team.create({
|
||||
data: {
|
||||
name: 'Test Team HideAgent',
|
||||
settings: {
|
||||
transcode: { videoStrategy: 'best_match' },
|
||||
appearance: { hideAgent: true },
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const list = await userMetadataService.listMetadata(user.id, team.id)
|
||||
expect(list).toContainEqual({ key: 'appearance.hideAgent', value: true })
|
||||
|
||||
const meta = await userMetadataService.getMetadata(user.id, team.id, 'appearance.hideAgent')
|
||||
expect(meta).toEqual({ key: 'appearance.hideAgent', value: true })
|
||||
})
|
||||
|
||||
it('should return null if metadata not found', async () => {
|
||||
const user = await prisma.user.create({
|
||||
data: { name: 'Test User 3', email: `test3-${Date.now()}@example.com`, password: 'pw' },
|
||||
|
||||
@@ -24,23 +24,53 @@ export class UserMetadataService {
|
||||
}
|
||||
|
||||
async listMetadata(userId: string, teamId: string): Promise<UserMetadataItem[]> {
|
||||
const items = await prisma.userMetadata.findMany({
|
||||
where: {
|
||||
userId,
|
||||
teamId,
|
||||
},
|
||||
orderBy: {
|
||||
key: 'asc',
|
||||
},
|
||||
const [items, team] = await Promise.all([
|
||||
prisma.userMetadata.findMany({
|
||||
where: {
|
||||
userId,
|
||||
teamId,
|
||||
},
|
||||
orderBy: {
|
||||
key: 'asc',
|
||||
},
|
||||
}),
|
||||
prisma.team.findUnique({
|
||||
where: { id: teamId },
|
||||
select: { settings: true },
|
||||
}),
|
||||
])
|
||||
|
||||
const result: UserMetadataItem[] = items
|
||||
.filter((item) => item.key !== 'appearance.hideAgent')
|
||||
.map((item) => ({
|
||||
key: item.key,
|
||||
value: item.value,
|
||||
}))
|
||||
|
||||
const teamSettings = team?.settings as PrismaJson.Settings | null
|
||||
const hideAgent = teamSettings?.appearance?.hideAgent ?? false
|
||||
|
||||
result.push({
|
||||
key: 'appearance.hideAgent',
|
||||
value: hideAgent,
|
||||
})
|
||||
|
||||
return items.map((item) => ({
|
||||
key: item.key,
|
||||
value: item.value,
|
||||
}))
|
||||
return result
|
||||
}
|
||||
|
||||
async getMetadata(userId: string, teamId: string, key: string): Promise<UserMetadataItem | null> {
|
||||
if (key === 'appearance.hideAgent') {
|
||||
const team = await prisma.team.findUnique({
|
||||
where: { id: teamId },
|
||||
select: { settings: true },
|
||||
})
|
||||
const teamSettings = team?.settings as PrismaJson.Settings | null
|
||||
return {
|
||||
key: 'appearance.hideAgent',
|
||||
value: teamSettings?.appearance?.hideAgent ?? false,
|
||||
}
|
||||
}
|
||||
|
||||
const item = await prisma.userMetadata.findUnique({
|
||||
where: {
|
||||
userIdTeamIdKey: {
|
||||
|
||||
Reference in New Issue
Block a user