Skip to content

Refactor/notification4#517

Open
theodorklauritzen wants to merge 13 commits intomainfrom
refactor/notification4
Open

Refactor/notification4#517
theodorklauritzen wants to merge 13 commits intomainfrom
refactor/notification4

Conversation

@theodorklauritzen
Copy link
Copy Markdown
Member

Refactor mailing lists to use the new convetions.

I have also make sure that the prisma client is closed after the test.

theodorklauritzen and others added 6 commits March 16, 2026 19:45
…permissions

Full migration of mail, alias, list, and mailAddressExternal services to
defineOperation/makeAction pattern. Old create/read/update/destroy/validation
files deleted. Permissions simplified to MAILALIAS_READ, MAILALIAS_ADMIN,
MAILINGLIST_CREATE, MAILINGLIST_ADMIN, MAILADDRESS_EXTERNAL_{CREATE,READ,UPDATE,DESTROY}.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Rename ConfigVars.ts -> constants.ts (root and mailAddressExternal merged)
- Move NTNUEmailDomain into root constants.ts
- Add `as const` to all operations objects
- Document service folder structure convention in CLAUDE.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ct operation calls

Document the convention in CLAUDE.md: frontend must always import from
actions.ts and use unwrapActionReturn for server-side data fetching.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace raw permissions.includes() calls with auth.<operation>.dynamicFields({}).auth(session).authorized,
following the same pattern as omegaquotes and other services.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…lobal prisma client, so that the client connection can be closed after the tests
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the mail/mailing-list domain to the repository’s newer ServiceOperation conventions (schemas/operations/actions), consolidates mail-related permissions, and moves email sending/templates into a shared src/lib/email module. It also adds Jest coverage for mail traversal/guards and improves test teardown by ensuring Prisma disconnects cleanly.

Changes:

  • Refactor mail alias, mailing list, external address, and relation logic to schemas.ts + operations.ts + actions.ts (removing legacy ValidationBase-based files).
  • Consolidate granular mail permissions into MAILALIAS_ADMIN and MAILINGLIST_ADMIN, updating auth, permission seeding, and Prisma schema enums accordingly.
  • Move email sending + templates to src/lib/email/*, update call sites, and add mail domain/Prisma test cleanup to reduce Jest open-handle issues.

Reviewed changes

Copilot reviewed 71 out of 80 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/services/mail.test.ts Adds integration tests for mail validation, traversal, deduplication, and relation-destroy guards.
tests/PrismaTestEnvironment.ts Ensures Jest environment teardown returns super.teardown() after dropping schema and disconnecting.
tests/cleanup.ts Adds afterAll Prisma disconnect to prevent Jest open handles.
src/typings/global.d.ts Updates global mail handler typing import to the new lib/email location.
src/services/users/operations.ts Updates verify/invitation mail imports and NTNU domain constant source.
src/services/serviceOperation.ts Suppresses parse debug logging in tests and includes formatting/indent fixes.
src/services/prismaCall.ts Avoids noisy console.error during tests while preserving error translation/logging.
src/services/permissions/constants.ts Replaces multiple mail permissions with consolidated *_ADMIN entries.
src/services/notifications/operations.ts Routes sendMail import through the new lib/email module.
src/services/notifications/email/dispatch.ts Switches bulk mail sending + default alias + HTML wrapping to src/lib/email/*.
src/services/notifications/channel/operations.ts Uses new DEFAULT_NOTIFICATION_ALIAS import path.
src/services/mail/validation.ts Removes legacy ValidationBase-based relation validation.
src/services/mail/schemas.ts Introduces Zod schemas for mail relations and traversal params.
src/services/mail/operations.ts Refactors mail relations + traversal into mailOperations ServiceOperations.
src/services/mail/mailAddressExternal/validation.ts Removes legacy ValidationBase schemas for external addresses.
src/services/mail/mailAddressExternal/update.ts Deletes old standalone update function in favor of operations.
src/services/mail/mailAddressExternal/schemas.ts Adds Zod schemas for create/update/destroy with domain restrictions.
src/services/mail/mailAddressExternal/read.ts Deletes old standalone read function in favor of operations.
src/services/mail/mailAddressExternal/operations.ts Adds ServiceOperations for external mail address CRUD.
src/services/mail/mailAddressExternal/destroy.ts Deletes old standalone destroy function in favor of operations.
src/services/mail/mailAddressExternal/create.ts Deletes old standalone create function in favor of operations.
src/services/mail/mailAddressExternal/ConfigVars.ts Removes old constant file; domain moved to mail/constants.ts.
src/services/mail/mailAddressExternal/auth.ts Cleans up auth module (removes TODO comment).
src/services/mail/mailAddressExternal/actions.ts Converts to makeAction(...) wrappers around operations.
src/services/mail/list/validation.ts Removes legacy ValidationBase schemas for mailing lists.
src/services/mail/list/update.ts Deletes old standalone update function in favor of operations.
src/services/mail/list/schemas.ts Adds Zod schemas for mailing list create/update/destroy.
src/services/mail/list/read.ts Deletes old standalone read function in favor of operations.
src/services/mail/list/operations.ts Adds ServiceOperations for mailing list CRUD.
src/services/mail/list/destroy.ts Deletes old standalone destroy function in favor of operations.
src/services/mail/list/create.ts Deletes old standalone create function in favor of operations.
src/services/mail/list/auth.ts Updates mailing list auth to use MAILINGLIST_ADMIN for read/update/destroy.
src/services/mail/list/actions.ts Converts to makeAction(...) wrappers around operations.
src/services/mail/destroy.ts Removes legacy standalone relation-destroy functions.
src/services/mail/create.ts Removes legacy standalone relation-create functions.
src/services/mail/constants.ts Adds NTNUEmailDomain and centralizes mail domain config/constants.
src/services/mail/auth.ts Updates mail relation auth to consolidated MAILINGLIST_ADMIN permissions.
src/services/mail/alias/validation.ts Removes legacy ValidationBase schemas for aliases.
src/services/mail/alias/update.ts Deletes old standalone update function in favor of operations.
src/services/mail/alias/schemas.ts Adds Zod schemas for alias create/update/destroy with domain validation.
src/services/mail/alias/read.ts Deletes old standalone read function in favor of operations.
src/services/mail/alias/operations.ts Adds ServiceOperations for alias CRUD, including notification-channel delete guard.
src/services/mail/alias/destroy.ts Deletes old standalone destroy function in favor of operations.
src/services/mail/alias/create.ts Deletes old standalone create function in favor of operations.
src/services/mail/alias/auth.ts Updates alias auth to consolidated MAILALIAS_ADMIN permissions.
src/services/mail/alias/actions.ts Converts to makeAction(...) wrappers around operations.
src/services/mail/actions.ts Refactors mail server actions to makeAction(mailOperations.*) wrappers.
src/services/events/registration/operations.ts Updates system mail sender import path.
src/services/cabin/booking/operations.ts Updates system mail sender import path.
src/services/auth/operations.ts Updates reset-password mail sender import path.
src/prisma/seeder/src/seedPermissions.ts Updates committee permissions to use MAILINGLIST_ADMIN.
src/prisma/seeder/src/seeder.ts Uses shared Prisma client module instead of constructing a new client.
src/prisma/schema/permission.prisma Consolidates mail permissions in the Prisma enum.
src/prisma/schema/group.prisma Minor formatting change in InterestGroup.name field.
src/prisma/client.ts Limits Prisma global caching to NODE_ENV=development and updates guidance comment.
src/lib/email/wrapInHTML.tsx Adds shared HTML-wrapping helper for notification emails.
src/lib/email/templates/verifyEmail.tsx Adds new Verify Email React Email template.
src/lib/email/templates/userInvitation.tsx Adds new user invitation React Email template.
src/lib/email/templates/resetPassword.tsx Adds new reset password React Email template.
src/lib/email/templates/default.tsx Adds default notification email wrapper template.
src/lib/email/systemMail/verifyEmail.tsx Updates verify email sender to use new lib email modules/constants/templates.
src/lib/email/systemMail/userInvitivation.tsx Updates invitation email sender to use new lib email modules/constants/templates.
src/lib/email/systemMail/resetPassword.tsx Updates reset password sender to use new lib email modules/templates.
src/lib/email/systemMail/constants.ts Introduces shared system-mail expiration constants.
src/lib/email/send.ts Introduces shared single/bulk/system email send helpers.
src/lib/email/mailHandler.ts Updates constants import path for transport options.
src/lib/email/constants.ts Introduces shared email constants/transport config.
src/app/admin/mail/page.tsx Refactors admin mail page to fetch via actions + unwrapActionReturn and uses authorizers for UI gating.
src/app/admin/mail/[filter]/[id]/page.tsx Updates mail flow action call signature to { params: ... }.
src/app/admin/mail/[filter]/[id]/page.module.scss Adds form border/padding styling in mail flow page.
src/app/admin/mail/[filter]/[id]/mailListItem.tsx Fixes editability logic so indirectly-reached (“via”) items aren’t deletable.
src/app/admin/mail/[filter]/[id]/MailFlow.tsx Updates destroy actions to new { data: ... } signature and gates UI via authorizers.
src/app/admin/mail/[filter]/[id]/(editComponents)/user.tsx Gates “add to list” UI via authorizer, not raw permission array.
src/app/admin/mail/[filter]/[id]/(editComponents)/mailingList.tsx Updates delete action signature and gates editing/relations via authorizers.
src/app/admin/mail/[filter]/[id]/(editComponents)/mailAlias.tsx Updates delete action signature and gates editing/relations via authorizers.
src/app/admin/mail/[filter]/[id]/(editComponents)/mailAddressExternal.tsx Fixes error message, updates delete action signature, and gates editing/relations via authorizers.
src/app/admin/mail/[filter]/[id]/(editComponents)/group.tsx Gates “add to list” UI via authorizer, not raw permission array.
jest.config.ts Adds tests/cleanup.ts to Jest setupFilesAfterEnv.
docker-compose.test.yml Sets DOMAIN and MAIL_DOMAIN env vars for test container runs.
CLAUDE.md Documents the service folder conventions and frontend rule to only import actions (not operations).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

import { mailOperations } from '@/services/mail/operations'
import { afterEach, describe, expect, test } from '@jest/globals'

// NOTE: This test doesn't check auth, since I think this should be testing in a seperate file -Theodor
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in comment: "seperate" should be "separate".

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ffe1ed4.

Agent-Logs-Url: https://github.com/vevcom/projectNext/sessions/582789df-bb40-4561-a67e-5233698da320

Co-authored-by: theodorklauritzen <19690242+theodorklauritzen@users.noreply.github.com>
// Read more about it in the section "Prevent hot reloading from creating new instances of PrismaClient" here:
// https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/databases-connections

// This is how the Prisma docs recommend doing it
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmmm did you ask it to change this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this myself, after chatting. This is done for hot reloading, which only happens in dev, not in test or prod. Therefore I changed this.

theodorklauritzen and others added 3 commits April 4, 2026 20:34
- Add readMany authorizers to alias, list, mailAddressExternal auth
- Update readMany operations to use readMany authorizer instead of read
- Replace manual session auth checks with useAuthorizer hook in client components
- Add dedicated destroy* schemas for all 4 destroy operations
- Add MAILINGLIST_READ to COMMITTEE_PERMISSIONS in seeder
- Document useAuthorizer pattern and identifier length rule in CLAUDE.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…rations

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants