Skip to content

Commit 45fe468

Browse files
committed
chore: only superadmins can manage agents settings
1 parent 441b3b0 commit 45fe468

20 files changed

Lines changed: 99 additions & 84 deletions

File tree

api/src/settings/router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import mongo from '#mongo'
88
import { Router } from 'express'
9-
import { type AccountKeys, assertAccountRole, reqSessionAuthenticated } from '@data-fair/lib-express'
9+
import { type AccountKeys, assertAccountRole, reqAdminMode, reqSessionAuthenticated } from '@data-fair/lib-express'
1010
import eventsLog from '@data-fair/lib-express/events-log.js'
1111
import * as putReqBody from '#doc/settings/put-req/index.ts'
1212
import { type Settings } from '#types'
@@ -43,7 +43,7 @@ router.get('/:type/:id', async (req, res, next) => {
4343
})
4444

4545
router.put('/:type/:id', async (req, res, next) => {
46-
const session = reqSessionAuthenticated(req)
46+
const session = reqAdminMode(req)
4747
const owner = req.params as AccountKeys
4848
assertAccountRole(session, owner, 'admin')
4949
const body = putReqBody.returnValid(req.body, { name: 'body' })

api/types/settings/schema.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ export default {
484484
title: null,
485485
if: 'parent.data.providers?.length'
486486
},
487+
default: {},
487488
properties: {
488489
assistant: {
489490
type: 'object',

tests/features/agents/agents.api.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import { test } from 'playwright/test'
66
import assert from 'node:assert/strict'
77
import { generateText } from 'ai'
88
import { createOpenAI } from '@ai-sdk/openai'
9-
import { axiosAuth, clean, directoryUrl, defaultQuotas } from '../../support/axios.ts'
9+
import { axiosAuth, superAdmin, clean, directoryUrl, defaultQuotas } from '../../support/axios.ts'
1010

1111
const user = await axiosAuth('test-standalone1')
12+
const admin = await superAdmin
1213

1314
const settingsData = {
1415
providers: [
@@ -38,7 +39,7 @@ const settingsData = {
3839
test.describe('Chat API', () => {
3940
test.beforeEach(async () => {
4041
await clean()
41-
await user.put('/api/settings/user/test-standalone1', settingsData)
42+
await admin.put('/api/settings/user/test-standalone1', settingsData)
4243
})
4344

4445
test('should exchange messages through the gateway', async () => {

tests/features/agents/agents.e2e.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
import { expect } from '@playwright/test'
66
import { test } from '../../fixtures/login.ts'
7-
import { clean, axiosAuth, defaultQuotas } from '../../support/axios.ts'
7+
import { clean, superAdmin, defaultQuotas } from '../../support/axios.ts'
88

9-
const user = await axiosAuth('test-standalone1')
9+
const admin = await superAdmin
1010

1111
const settingsData = {
1212
providers: [
@@ -36,7 +36,7 @@ const settingsData = {
3636
test.describe('Chat UI', () => {
3737
test.beforeEach(async () => {
3838
await clean()
39-
await user.put('/api/settings/user/test-standalone1', settingsData)
39+
await admin.put('/api/settings/user/test-standalone1', settingsData)
4040
})
4141

4242
test('Page loads with input field', async ({ page, goToWithAuth }) => {

tests/features/chat-action/chat-action.e2e.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
import { expect, type Page } from '@playwright/test'
77
import { test } from '../../fixtures/login.ts'
8-
import { clean, axiosAuth, defaultQuotas } from '../../support/axios.ts'
8+
import { clean, superAdmin, defaultQuotas } from '../../support/axios.ts'
99

10-
const user = await axiosAuth('test-standalone1')
10+
const admin = await superAdmin
1111

1212
const settingsData = {
1313
providers: [
@@ -39,7 +39,7 @@ async function waitForChatFrame (page: Page) {
3939
test.describe('Agent Chat Action Button', () => {
4040
test.beforeEach(async () => {
4141
await clean()
42-
await user.put('/api/settings/user/test-standalone1', settingsData)
42+
await admin.put('/api/settings/user/test-standalone1', settingsData)
4343
})
4444

4545
test('Clicking action button opens drawer with visible prompt', async ({ page, goToWithAuth }) => {

tests/features/chat-drawer/chat-drawer.e2e.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
import { expect, type Page } from '@playwright/test'
77
import { test } from '../../fixtures/login.ts'
8-
import { clean, axiosAuth, defaultQuotas } from '../../support/axios.ts'
8+
import { clean, superAdmin, defaultQuotas } from '../../support/axios.ts'
99

10-
const user = await axiosAuth('test-standalone1')
10+
const admin = await superAdmin
1111

1212
const settingsData = {
1313
providers: [
@@ -50,7 +50,7 @@ async function waitForChatFrame (page: Page) {
5050
test.describe('Chat Drawer Integration', () => {
5151
test.beforeEach(async () => {
5252
await clean()
53-
await user.put('/api/settings/user/test-standalone1', settingsData)
53+
await admin.put('/api/settings/user/test-standalone1', settingsData)
5454
})
5555

5656
test('FAB is visible and opens the drawer', async ({ page, goToWithAuth }) => {

tests/features/chat-mcp/chat-mcp.e2e.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import { expect } from '@playwright/test'
66
import { test } from '../../fixtures/login.ts'
7-
import { clean, axiosAuth, defaultQuotas } from '../../support/axios.ts'
7+
import { clean, superAdmin, defaultQuotas } from '../../support/axios.ts'
88

99
test.describe('Chat MCP UI', () => {
1010
test.beforeEach(async () => {
@@ -22,8 +22,8 @@ test.describe('Chat MCP UI', () => {
2222
})
2323

2424
test('Agent can call set_data tool', async ({ page, goToWithAuth }) => {
25-
const user = await axiosAuth('test-standalone1')
26-
await user.put('/api/settings/user/test-standalone1', {
25+
const admin = await superAdmin
26+
await admin.put('/api/settings/user/test-standalone1', {
2727
providers: [{ id: 'mock', type: 'mock', name: 'Mock', enabled: true }],
2828
models: { assistant: { model: { id: 'mock-model', name: 'Mock Model', provider: { type: 'mock', id: 'mock', name: 'Mock' } } } },
2929
quotas: defaultQuotas

tests/features/chat-subagent/chat-subagent.e2e.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
import { expect } from '@playwright/test'
1111
import { test } from '../../fixtures/login.ts'
12-
import { clean, axiosAuth, defaultQuotas } from '../../support/axios.ts'
12+
import { clean, superAdmin, defaultQuotas } from '../../support/axios.ts'
1313

14-
const user = await axiosAuth('test-standalone1')
14+
const admin = await superAdmin
1515

1616
const settingsData = {
1717
providers: [
@@ -48,7 +48,7 @@ async function waitForToolsReady (page: import('@playwright/test').Page, toolNam
4848
test.describe('Chat Sub-Agent UI', () => {
4949
test.beforeEach(async () => {
5050
await clean()
51-
await user.put('/api/settings/user/test-standalone1', settingsData)
51+
await admin.put('/api/settings/user/test-standalone1', settingsData)
5252
})
5353

5454
test('Page loads with correct title and UI elements', async ({ page, goToWithAuth }) => {

tests/features/gateway/gateway.api.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import { test } from 'playwright/test'
77
import assert from 'node:assert/strict'
88
import { generateText, streamText } from 'ai'
99
import { createOpenAI } from '@ai-sdk/openai'
10-
import { axiosAuth, clean, directoryUrl, defaultQuotas } from '../../support/axios.ts'
10+
import { axiosAuth, superAdmin, clean, directoryUrl, defaultQuotas } from '../../support/axios.ts'
1111

1212
const user = await axiosAuth('test-standalone1')
13+
const admin = await superAdmin
1314
const externalUser = await axiosAuth('test1-user1')
1415

1516
const settingsData = {
@@ -50,7 +51,7 @@ async function createGatewayProvider (ax: any, ownerType = 'user', ownerId = 'te
5051
test.describe('Gateway API - OpenAI-compatible proxy', () => {
5152
test.beforeEach(async () => {
5253
await clean()
53-
await user.put('/api/settings/user/test-standalone1', settingsData)
54+
await admin.put('/api/settings/user/test-standalone1', settingsData)
5455
})
5556

5657
test('generateText through gateway', async () => {
@@ -101,7 +102,7 @@ test.describe('Gateway API - OpenAI-compatible proxy', () => {
101102
})
102103

103104
test('external user can use gateway when external quota is positive', async () => {
104-
await user.put('/api/settings/user/test-standalone1', {
105+
await admin.put('/api/settings/user/test-standalone1', {
105106
...settingsData,
106107
quotas: {
107108
...defaultQuotas,

tests/features/gateway/gateway.tools.api.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import { test } from 'playwright/test'
77
import assert from 'node:assert/strict'
88
import { generateText } from 'ai'
99
import { createOpenAI } from '@ai-sdk/openai'
10-
import { axiosAuth, clean, directoryUrl, baseURL, defaultQuotas } from '../../support/axios.ts'
10+
import { axiosAuth, superAdmin, clean, directoryUrl, baseURL, defaultQuotas } from '../../support/axios.ts'
1111

1212
const user = await axiosAuth('test-standalone1')
13+
const admin = await superAdmin
1314

1415
const settingsData = {
1516
providers: [
@@ -49,7 +50,7 @@ async function createGatewayProvider () {
4950
test.describe('Gateway API - Tool forwarding', () => {
5051
test.beforeEach(async () => {
5152
await clean()
52-
await user.put('/api/settings/user/test-standalone1', settingsData)
53+
await admin.put('/api/settings/user/test-standalone1', settingsData)
5354
})
5455

5556
test('send tool definitions and receive tool call back', async () => {

0 commit comments

Comments
 (0)