diff --git a/common/notification/hooks.ts b/common/notification/hooks.ts index e79d695d5..3016fb1eb 100644 --- a/common/notification/hooks.ts +++ b/common/notification/hooks.ts @@ -8,12 +8,13 @@ import { prisma } from '../prisma'; import { userForStudent } from '../user'; import * as Notification from '../../common/notification'; import { SpecificNotificationContext } from './actions'; +import { dissolve_reason } from '@prisma/client'; registerStudentHook( 'deactivate-student', 'Account gets deactivated, matches are dissolved, courses are cancelled', async (student) => { - await deactivateStudent(student, true, 'missing coc'); + await deactivateStudent(student, true, 'missing coc', [dissolve_reason.accountDeactivatedNoCoC]); } // the hook does not send out a notification again, the user already knows that their account was deactivated ); diff --git a/common/student/activation.ts b/common/student/activation.ts index fdeb4567e..4420c8fef 100644 --- a/common/student/activation.ts +++ b/common/student/activation.ts @@ -11,7 +11,12 @@ import { userForStudent } from '../user'; import { CertificateState } from '../certificate'; import { removeAllPushSubcriptions } from '../notification/channels/push'; -export async function deactivateStudent(student: Student, silent = false, reason?: string) { +export async function deactivateStudent( + student: Student, + silent = false, + reason?: string, + dissolveReasons: dissolve_reason[] = [dissolve_reason.accountDeactivated] +) { if (!student.active) { throw new Error('Student was already deactivated'); } @@ -32,7 +37,7 @@ export async function deactivateStudent(student: Student, silent = false, reason }, }); for (const match of matches) { - await dissolveMatch(match, [dissolve_reason.accountDeactivated], student, dissolved_by_enum.student); + await dissolveMatch(match, dissolveReasons, student, dissolved_by_enum.student); } // Remove any pending certificates, so that they no longer show up in pupil dashboards diff --git a/prisma/migrations/20250120143543_no_co_c_dissolve_reason/migration.sql b/prisma/migrations/20250120143543_no_co_c_dissolve_reason/migration.sql new file mode 100644 index 000000000..a29c67431 --- /dev/null +++ b/prisma/migrations/20250120143543_no_co_c_dissolve_reason/migration.sql @@ -0,0 +1,2 @@ +-- AlterEnum +ALTER TYPE "dissolve_reason" ADD VALUE 'accountDeactivatedNoCoC'; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index fe0c451f0..b70cfd4b5 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -1555,6 +1555,7 @@ enum dissolved_by_enum { enum dissolve_reason { accountDeactivated // The account was deactivated, causing any active matches to be dissolved automatically + accountDeactivatedNoCoC // The account was deactivated because the student did not hand in a Certificate of Conduct ghosted // "Mein:e Lernpartner:in hat sich nicht zurückgemeldet" noMoreHelpNeeded // "Mein:e Lernpartner:in benötigt keine Unterstützung mehr" and "Ich benötige keine Unterstützung mehr" isOfNoHelp // "Ich konnte meinem/meiner Lernpartner:in nicht behilflich sein" and "Mein:e Lernpartner:in konnte mir nicht behilflich sein"