Skip to content

Commit 1e2bfb2

Browse files
fix(admin): restrict created users to normal role
1 parent 9392bb9 commit 1e2bfb2

4 files changed

Lines changed: 8 additions & 36 deletions

File tree

apps/sim/app/workspace/[workspaceId]/settings/components/admin/add-user-modal.test.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ describe('AddUserModal', () => {
204204
name: 'Canary Writer',
205205
email: 'writer@synthetics.example.com',
206206
password: 'canary-password',
207-
role: 'user',
208207
emailVerified: true,
209208
},
210209
{ onSuccess: expect.any(Function) }
@@ -213,15 +212,14 @@ describe('AddUserModal', () => {
213212
expect(onCreated).toHaveBeenCalledWith(CREATED_USER)
214213
})
215214

216-
it('supports platform-admin and unverified accounts', async () => {
215+
it('supports unverified accounts without exposing a platform-role control', async () => {
217216
mockMutate.mockImplementation(
218217
(_input: AddUserInput, options: { onSuccess: (user: AdminUser) => void }) => {
219-
options.onSuccess({ ...CREATED_USER, role: 'admin' })
218+
options.onSuccess(CREATED_USER)
220219
}
221220
)
222221
await renderModal()
223222
await fillRequiredFields()
224-
await changeField('Platform role', 'admin')
225223
await changeField('Email status', 'unverified')
226224

227225
await act(async () => {
@@ -230,10 +228,10 @@ describe('AddUserModal', () => {
230228
await Promise.resolve()
231229
})
232230

233-
expect(mockMutate).toHaveBeenCalledWith(
234-
expect.objectContaining({ role: 'admin', emailVerified: false }),
235-
{ onSuccess: expect.any(Function) }
236-
)
231+
expect(container.querySelector('[aria-label="Platform role"]')).toBeNull()
232+
expect(mockMutate).toHaveBeenCalledWith(expect.objectContaining({ emailVerified: false }), {
233+
onSuccess: expect.any(Function),
234+
})
237235
})
238236

239237
it('shows Better Auth failures without closing the modal', async () => {

apps/sim/app/workspace/[workspaceId]/settings/components/admin/add-user-modal.tsx

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ import {
1111
} from '@sim/emcn'
1212
import { getErrorMessage } from '@sim/utils/errors'
1313
import { isValidEmailSyntax } from '@sim/utils/string'
14-
import { type AddUserInput, type AdminUser, useAddUser } from '@/hooks/queries/admin-users'
15-
16-
const ROLE_OPTIONS = [
17-
{ value: 'user', label: 'User' },
18-
{ value: 'admin', label: 'Platform admin' },
19-
] as const
14+
import { type AdminUser, useAddUser } from '@/hooks/queries/admin-users'
2015

2116
const EMAIL_STATUS_OPTIONS = [
2217
{ value: 'verified', label: 'Verified' },
@@ -34,7 +29,6 @@ export function AddUserModal({ open, onOpenChange, onCreated }: AddUserModalProp
3429
const [name, setName] = useState('')
3530
const [email, setEmail] = useState('')
3631
const [password, setPassword] = useState('')
37-
const [role, setRole] = useState<AddUserInput['role']>('user')
3832
const [emailVerified, setEmailVerified] = useState(true)
3933

4034
const normalizedName = name.trim()
@@ -56,7 +50,6 @@ export function AddUserModal({ open, onOpenChange, onCreated }: AddUserModalProp
5650
setName('')
5751
setEmail('')
5852
setPassword('')
59-
setRole('user')
6053
setEmailVerified(true)
6154
addUser.reset()
6255
}
@@ -75,7 +68,6 @@ export function AddUserModal({ open, onOpenChange, onCreated }: AddUserModalProp
7568
name: normalizedName,
7669
email: normalizedEmail,
7770
password,
78-
role,
7971
emailVerified,
8072
},
8173
{
@@ -143,19 +135,6 @@ export function AddUserModal({ open, onOpenChange, onCreated }: AddUserModalProp
143135
disabled={addUser.isPending}
144136
required
145137
/>
146-
<ChipModalField
147-
type='dropdown'
148-
title='Platform role'
149-
value={role}
150-
onChange={(value) => {
151-
setRole(value as AddUserInput['role'])
152-
addUser.reset()
153-
}}
154-
options={ROLE_OPTIONS}
155-
align='start'
156-
disabled={addUser.isPending}
157-
required
158-
/>
159138
<ChipModalField
160139
type='dropdown'
161140
title='Email status'

apps/sim/hooks/queries/admin-users.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ describe('addUser', () => {
4242
name: ' Canary Writer ',
4343
email: ' Writer@Synthetics.Example.com ',
4444
password: 'canary-password',
45-
role: 'user',
4645
emailVerified: true,
4746
})
4847
).resolves.toEqual({
@@ -73,7 +72,6 @@ describe('addUser', () => {
7372
name: 'Canary Writer',
7473
email: 'writer@synthetics.example.com',
7574
password: 'canary-password',
76-
role: 'user',
7775
emailVerified: true,
7876
})
7977
).rejects.toThrow('A user with that email already exists')
@@ -87,7 +85,6 @@ describe('addUser', () => {
8785
name: 'Canary Writer',
8886
email: 'writer@synthetics.example.com',
8987
password: 'canary-password',
90-
role: 'user',
9188
emailVerified: true,
9289
})
9390
).rejects.toThrow('Better Auth did not return the created user')

apps/sim/hooks/queries/admin-users.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export interface AddUserInput {
2828
name: string
2929
email: string
3030
password: string
31-
role: 'user' | 'admin'
3231
emailVerified: boolean
3332
}
3433

@@ -59,14 +58,13 @@ export async function addUser({
5958
name,
6059
email,
6160
password,
62-
role,
6361
emailVerified,
6462
}: AddUserInput): Promise<AdminUser> {
6563
const { data, error } = await client.admin.createUser({
6664
name: name.trim(),
6765
email: email.trim().toLowerCase(),
6866
password,
69-
role,
67+
role: 'user',
7068
data: { emailVerified },
7169
})
7270
if (error) throw new Error(error.message ?? 'Failed to add user')

0 commit comments

Comments
 (0)