UDT-009: Overrides de PermisosJson por usuario — cierre módulo Auth #12
@@ -8,6 +8,7 @@ import { AlertCircle } from 'lucide-react'
|
|||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { Input } from '@/components/ui/input'
|
import { Input } from '@/components/ui/input'
|
||||||
import { Alert, AlertDescription } from '@/components/ui/alert'
|
import { Alert, AlertDescription } from '@/components/ui/alert'
|
||||||
|
import { Tabs, TabsList, TabsTrigger, TabsContent } from '@/components/ui/tabs'
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormControl,
|
FormControl,
|
||||||
@@ -19,6 +20,7 @@ import {
|
|||||||
import { useUser } from '../hooks/useUser'
|
import { useUser } from '../hooks/useUser'
|
||||||
import { useUpdateUser } from '../hooks/useUpdateUser'
|
import { useUpdateUser } from '../hooks/useUpdateUser'
|
||||||
import { ResetPasswordModal } from '../components/ResetPasswordModal'
|
import { ResetPasswordModal } from '../components/ResetPasswordModal'
|
||||||
|
import { PermisosEditor } from '../components/PermisosEditor'
|
||||||
import { useAuthStore } from '@/stores/authStore'
|
import { useAuthStore } from '@/stores/authStore'
|
||||||
|
|
||||||
const editSchema = z.object({
|
const editSchema = z.object({
|
||||||
@@ -111,12 +113,14 @@ export function UserEditPage() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isSelf = loggedUserId === userId
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="max-w-xl space-y-6">
|
<div className="max-w-xl space-y-6">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<h1 className="text-xl font-semibold">Editar Usuario</h1>
|
<h1 className="text-xl font-semibold">Editar Usuario</h1>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
{loggedUserId !== userId && <ResetPasswordModal userId={userId} />}
|
{!isSelf && <ResetPasswordModal userId={userId} />}
|
||||||
<Button variant="ghost" size="sm" onClick={() => navigate('/usuarios')}>
|
<Button variant="ghost" size="sm" onClick={() => navigate('/usuarios')}>
|
||||||
Volver
|
Volver
|
||||||
</Button>
|
</Button>
|
||||||
@@ -129,6 +133,15 @@ export function UserEditPage() {
|
|||||||
<p className="text-sm font-mono bg-muted rounded px-3 py-2">{user.username}</p>
|
<p className="text-sm font-mono bg-muted rounded px-3 py-2">{user.username}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Tabs defaultValue="perfil">
|
||||||
|
<TabsList>
|
||||||
|
<TabsTrigger value="perfil">Perfil</TabsTrigger>
|
||||||
|
<TabsTrigger value="permisos" disabled={isSelf}>
|
||||||
|
Permisos
|
||||||
|
</TabsTrigger>
|
||||||
|
</TabsList>
|
||||||
|
|
||||||
|
<TabsContent value="perfil">
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form onSubmit={form.handleSubmit(handleSubmit)} className="space-y-4" noValidate>
|
<form onSubmit={form.handleSubmit(handleSubmit)} className="space-y-4" noValidate>
|
||||||
{backendError && (
|
{backendError && (
|
||||||
@@ -228,6 +241,12 @@ export function UserEditPage() {
|
|||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
|
</TabsContent>
|
||||||
|
|
||||||
|
<TabsContent value="permisos">
|
||||||
|
<PermisosEditor userId={userId} />
|
||||||
|
</TabsContent>
|
||||||
|
</Tabs>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,4 +162,40 @@ describe('UserEditPage', () => {
|
|||||||
await waitFor(() => expect(screen.getByDisplayValue('Juan')).toBeInTheDocument())
|
await waitFor(() => expect(screen.getByDisplayValue('Juan')).toBeInTheDocument())
|
||||||
expect(screen.queryByRole('button', { name: /resetear contraseña/i })).not.toBeInTheDocument()
|
expect(screen.queryByRole('button', { name: /resetear contraseña/i })).not.toBeInTheDocument()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// FP-01: tabs Perfil and Permisos visible when editing another user
|
||||||
|
it('shows tabs "Perfil" and "Permisos" when editing another user', async () => {
|
||||||
|
server.use(
|
||||||
|
http.get(`${API_URL}/api/v1/users/5`, () => HttpResponse.json(mockUserDetail)),
|
||||||
|
http.get(`${API_URL}/api/v1/users/5/permisos`, () =>
|
||||||
|
HttpResponse.json({
|
||||||
|
usuarioId: 5, rol: 'cajero', rolPermisos: [], grant: [], deny: [], effective: [],
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
http.get(`${API_URL}/api/v1/permisos`, () => HttpResponse.json([])),
|
||||||
|
)
|
||||||
|
|
||||||
|
renderEditPage(5)
|
||||||
|
|
||||||
|
await waitFor(() => expect(screen.getByDisplayValue('Juan')).toBeInTheDocument())
|
||||||
|
|
||||||
|
expect(screen.getByRole('tab', { name: /perfil/i })).toBeInTheDocument()
|
||||||
|
expect(screen.getByRole('tab', { name: /permisos/i })).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
// FP-10: self-edit — tab Permisos is disabled
|
||||||
|
it('disables tab "Permisos" when editing own profile (self-edit)', async () => {
|
||||||
|
server.use(
|
||||||
|
http.get(`${API_URL}/api/v1/users/1`, () =>
|
||||||
|
HttpResponse.json({ ...mockUserDetail, id: 1, username: 'admin' }),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
renderEditPage(1)
|
||||||
|
|
||||||
|
await waitFor(() => expect(screen.getByDisplayValue('Juan')).toBeInTheDocument())
|
||||||
|
|
||||||
|
const permisosTab = screen.getByRole('tab', { name: /permisos/i })
|
||||||
|
expect(permisosTab).toBeDisabled()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user