feat: un miembro puede pertenecer a más de un grupo
- Nuevo modelo `Person` (`people`): contacto y notas por profe, con teléfono único (índice parcial `people_owner_phone_key`). `Attendee` pasa a ser la membresía (`group_id` + `person_id`, único por grupo). - La cuenta de la app de alumnos se vincula a la persona (`student_account_people`): una sola cuenta ve todos sus grupos. - Migración unifica attendees del mismo profe y teléfono, y fusiona sus cuentas de alumno (conserva la usada más recientemente). - `POST /groups/:gid/attendees/:aid/add-to-group` y `GET /people/lookup` para detectar personas existentes al cargar; el alta responde `409 person_exists` y acepta `personId`. Bulk, lista de espera y preinscripciones vinculan solas. - El límite del plan cuenta personas con al menos un grupo activo. - Web: "Agregar a otro grupo", sección "También está en" en la ficha y aviso "Ya tenés a esta persona" en el alta individual. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import type { FileStorage } from '@/lib/storage';
|
||||
import { CancelStudentAbsence, NotifyStudentAbsences } from '@/modules/student-portal/features/absences/use-case';
|
||||
import { GetStudentClasses } from '@/modules/student-portal/features/classes/use-case';
|
||||
import { GetStudentFees } from '@/modules/student-portal/features/fees/use-case';
|
||||
import { GetStudentMe } from '@/modules/student-portal/features/me/use-case';
|
||||
import { ReportStudentPayment } from '@/modules/student-portal/features/payment-reports/use-case';
|
||||
|
||||
const url = process.env.DB_TESTS === '1' ? process.env.DATABASE_URL : undefined;
|
||||
@@ -30,7 +31,12 @@ describe.skipIf(!url)('student portal (real database)', () => {
|
||||
const ids = {
|
||||
user: `t-user-${suffix}`,
|
||||
group: `t-group-${suffix}`,
|
||||
yoga: `t-yoga-${suffix}`,
|
||||
personAna: `t-p-ana-${suffix}`,
|
||||
personBeto: `t-p-beto-${suffix}`,
|
||||
ana: `t-ana-${suffix}`,
|
||||
anaYoga: `t-ana-yoga-${suffix}`,
|
||||
betoYoga: `t-beto-yoga-${suffix}`,
|
||||
beto: `t-beto-${suffix}`,
|
||||
accountAna: `t-acc-ana-${suffix}`,
|
||||
accountBeto: `t-acc-beto-${suffix}`,
|
||||
@@ -50,17 +56,29 @@ describe.skipIf(!url)('student portal (real database)', () => {
|
||||
await db.group.create({
|
||||
data: { id: ids.group, name: 'Natación', createdById: ids.user, days: ['MONDAY', 'WEDNESDAY', 'FRIDAY'], time: '18:00' },
|
||||
});
|
||||
await db.group.create({
|
||||
data: { id: ids.yoga, name: 'Yoga', createdById: ids.user, days: ['TUESDAY'], time: '10:00' },
|
||||
});
|
||||
await db.person.createMany({
|
||||
data: [
|
||||
{ id: ids.personAna, createdById: ids.user, fullName: 'Ana' },
|
||||
{ id: ids.personBeto, createdById: ids.user, fullName: 'Beto' },
|
||||
],
|
||||
});
|
||||
// Ana and Beto are in both groups.
|
||||
await db.attendee.createMany({
|
||||
data: [
|
||||
{ id: ids.ana, groupId: ids.group, fullName: 'Ana' },
|
||||
{ id: ids.beto, groupId: ids.group, fullName: 'Beto' },
|
||||
{ id: ids.ana, groupId: ids.group, personId: ids.personAna },
|
||||
{ id: ids.beto, groupId: ids.group, personId: ids.personBeto },
|
||||
{ id: ids.anaYoga, groupId: ids.yoga, personId: ids.personAna },
|
||||
{ id: ids.betoYoga, groupId: ids.yoga, personId: ids.personBeto },
|
||||
],
|
||||
});
|
||||
await db.studentAccount.create({
|
||||
data: { id: ids.accountAna, name: 'Ana', createdById: ids.user, attendees: { create: { attendeeId: ids.ana } } },
|
||||
data: { id: ids.accountAna, name: 'Ana', createdById: ids.user, people: { create: { personId: ids.personAna } } },
|
||||
});
|
||||
await db.studentAccount.create({
|
||||
data: { id: ids.accountBeto, name: 'Beto', createdById: ids.user, attendees: { create: { attendeeId: ids.beto } } },
|
||||
data: { id: ids.accountBeto, name: 'Beto', createdById: ids.user, people: { create: { personId: ids.personBeto } } },
|
||||
});
|
||||
await db.payment.createMany({
|
||||
data: [
|
||||
@@ -117,6 +135,21 @@ describe.skipIf(!url)('student portal (real database)', () => {
|
||||
expect(!invented.ok && invented.error.status).toBe(400);
|
||||
});
|
||||
|
||||
it('la cuenta de la persona ve todos sus grupos, y solo los suyos', async () => {
|
||||
const me = await new GetStudentMe({ db }).execute(ids.accountAna);
|
||||
if (!me.ok) throw new Error('me failed');
|
||||
expect(me.value.students.map((student) => [student.attendeeId, student.groupName])).toEqual([
|
||||
[ids.ana, 'Natación'],
|
||||
[ids.anaYoga, 'Yoga'],
|
||||
]);
|
||||
|
||||
// Her membership in the second group is reachable; Beto's in that group is not.
|
||||
expect((await new GetStudentFees({ db }).execute(ids.accountAna, ids.anaYoga)).ok).toBe(true);
|
||||
const foreign = await new GetStudentFees({ db }).execute(ids.accountAna, ids.betoYoga);
|
||||
expect(foreign.ok).toBe(false);
|
||||
if (!foreign.ok) expect(foreign.error.status).toBe(404);
|
||||
});
|
||||
|
||||
it('IDOR: una cuenta no ve ni toca datos de otro alumno', async () => {
|
||||
expect((await new GetStudentClasses({ db, now: NOW }).execute(ids.accountBeto, ids.ana)).ok).toBe(false);
|
||||
expect((await new GetStudentFees({ db, now: NOW }).execute(ids.accountBeto, ids.ana)).ok).toBe(false);
|
||||
|
||||
Reference in New Issue
Block a user