AladiaDocs

Requests and the course button

Slice a of the academy website: course offer (free, checkout, request), request form with anti-spam, /grazie and conversions, Requests section, settings, notifications, webhooks and permissions.

Status: branch release/checkout-leads (06/10/2026). Owner-approved spec of 06/10 (points 1–3 and 5). User guide: Information requests. Paths are relative to backend/ and web-next/.

1. Course offer

One rule picks the button of the public page, offerModeOf in libs/common/src/common/leads/course-sales.rules.ts:133 (with the course sales mode: sales modes):

CourseSellerMode
paymentModel free, or no model and price 0—free
paid, with productIdconnect with isOnboardedcheckout
paidno connect, not verified, or no productIdrequest

guestCheckoutAllowed (course-sales.rules.ts:151) adds whether checkout can start without signing in: only with a Standard account (direct charges) and a single payment (instalments on Standard come with slice c).

GET /v2/public/courses/:id/offer (apps/gateway/src/gateway/controllers/profile/leads/leads.service.ts:72, public) reads the course (retrieveCourseById, published states only), the owner's connect (getOwnerConnectAccount, 404 = none) and the public settings (leads.retrieve-public-settings), and answers { courseId, mode, guestCheckout, formOnPage, requestLabel, privacyUrl?, privacyText?, thankYou }.

web-next: PurchaseBox (components/courses/player/purchase-box.tsx) takes the offer and shows offerCtaLabel (lib/lead-form.ts); the course page (app/(course)/courses/[courseId]/page.tsx, onBuy) routes:

  • free: with a session POST courses/:id/start at once; as a guest /register?redirect=/courses/:id?enroll=1&cycleId=… and on return the ?enroll=1 effect enrolls once and drops the parameter (enrollReturnPath in lib/course-purchase.ts);
  • checkout: today's path (price dialog → /checkout; guests sign in) until slice c;
  • request: LeadDialog (components/leads/lead-dialog.tsx) or /courses/:id/richiedi when formOnPage.

2. Data model

leads (libs/common/src/common/models/microservices/profile/lead.model.ts): owner {id,type} (the receiving workspace: always the course's, never chosen by the client), course {id,title,cycleId}, name, email (lowercase), phone, message, consent {acceptedAt, privacyUrl, text} (copied from the settings of that moment), fields (custom fields, slice b), status (new|contacted|enrolled|lost), assigneeId, notes[] {_id,text,authorId,createdAt}, profileId, source {url,referrer,utm}, language, ipHash (select:false). Indexes: owner.id+createdAt, owner.id+status+createdAt, owner.id+email+course.id+createdAt, ipHash+createdAt (sparse).

lead_settings (lead-settings.model.ts), one per workspace (unique owner.id): requestLabel (request-info|enroll), notifyCategory (billing|teaching), privacyUrl, privacyText, thankYou {mode page|redirect, title, text, action none|courses|link, linkUrl, linkLabel, redirectUrl}, formFields[] and courseForms[] (slice b). Missing document = defaults.

3. Routes

RouteGuardWhat
GET /v2/public/courses/:id/offer@Publicoffer (§1)
POST /v2/public/leads@Publicform submission
GET /v2/leads?status,courseId,assigneeId,q,from,to,page,limitleads.readlist of the active workspace
PATCH /v2/leads/:id {status?, assigneeId? (null = nobody), profileId?}leads.updatestatus and assignee
POST /v2/leads/:id/notes {text}leads.updateinternal note
GET /v2/leads/settingsleads.readsettings
PUT /v2/leads/settingsmarketplace.updatesettings (the workspace storefront)

Controllers in apps/gateway/src/gateway/controllers/profile/leads/leads.controller.ts (staff :58, public :97); profile microservice apps/profile/src/app/leads/leads.controller.ts, patterns leads.create|search|update|add-lead-note|retrieve-settings|update-settings|retrieve-public-settings.

4. Submission and anti-spam

LeadsService.create (apps/profile/src/app/leads/leads.service.ts:85):

  1. workspace settings and resolved thank you page (resolveThankYou, lead.rules.ts:100: external only https, link only https, otherwise action none);
  2. isSpam (lead.rules.ts:173): trap field website filled or elapsedMs < 2000 → an answer identical to a saved one ({ ok: true, thankYou }), nothing written, no notices;
  3. validateLead (:197): name ≥ 2, valid email (lowercased), optional phone 6–20 digits, required consent → 400 lead-invalid with the fields in details;
  4. limits (assertWithinLimits, :137): 5 saved requests per ipHash in 10 minutes, 3 per email+course in 24 hours → 429 lead-rate-limited. The IP is the first x-forwarded-for value (clientIpOf, controller :46) and travels only as sha256('lead:'+ip);
  5. save, then leads.lead-created (notices) and webhook lead.created, neither blocking the answer.

No captcha: the project has none (survey of 06/10), and trap+time+limits cover form bots. If needed, invisible Turnstile would go in LeadForm and be verified in the gateway before submit.

5. Thank you page and conversions

finishLead (web-next/lib/lead-sent.ts): stores the summary in sessionStorage['aladia-lead-sent'] (never in the URL), then /grazie?course=<id> or, with redirect, track(leadEvent(…)) and location.assign after 400 ms. /grazie (app/(course)/grazie/page.tsx, public in proxy.ts) reads the summary (valid 30 minutes, readLeadSent), pushes generate_lead once (tracked: true) and, without a summary, takes text and action from the course offer. Event: generate_lead from web-next/lib/tracking.ts (leadEvent in lib/lead-sent.ts), forwarded to the tools the academy turned on (Settings › Integrations › Marketing) according to cookie consent; in the GTM dataLayer it stays { event: 'generate_lead', lead_source: 'course_page', course_id, course_name?, items, event_id, workspace? }. See Tracking and cookies.

6. Notifications and email

LeadCreatedDto on leads.lead-created (registered for notification in microservice-to-patterns.constant.ts), receivers from receiversOf (leads.service.ts:163): Owner and Admins of the academy (+ assignee), the holder in a personal workspace.

  • In app: NotificationType.LEAD_CREATED (lead-created), sender the workspace, placeholders name = sender, text = course; web-next components/shell/notification-format.ts (New request from {x} about {y}, link /leads?lead=<id>).
  • Email: sendLeadCreatedEmail (apps/notification/.../notifications-mail.service.ts:431) through the MailSenderResolver (team/email-sender §7): resolve({id, type}, {audience: notifyCategory}); the recipient is the area mailbox (context.sender.replyTo: confirmed area mailbox → main → Owner; no mailbox, no email), with the academy's sender (its Email domain when verified), theme and link base (context.baseUrl), Reply-To = the sender, counted in the workspace emails meter. Copy in mail/layout/email-copy/lead.copy.ts (data as details, message as a literal segment: no markers interpreted).

Confirmation to the requester

LeadsService.create (apps/profile/src/app/leads/leads.service.ts:137): shouldSendConfirmation (libs/common/src/common/leads/lead.rules.ts:142) = setting on (confirmationEnabled, default true) and no request from the same email for the same course in the previous 24 hours (the same count as the limit). Trap, speed and limits stop the request earlier: no confirmation. LeadCreatedDto.confirmation carries the academy text (confirmationText) and the edition dates (from the gateway, cycleDates, not stored). Notification sendLeadConfirmationEmail (notifications-mail.service.ts:457) through the MailSenderResolver with the notifyCategory area: academy sender (email domain when verified), Reply-To = academy mailbox, theme, links on context.baseUrl (course page, /marketplace), signed with the academy name, no mention of Aladia; copy mail/layout/email-copy/lead-confirmation.copy.ts (IT/EN from the request language, message and academy text as literal segments). Counted in the workspace emails meter. Settings: confirmationEnabled, confirmationText (max 2000) in lead_settings, no migration (missing = on).

7. Webhooks

emitWebhook (leads.service.ts:201) queues webhooks.webhook-sent with resource {id, type: 'lead', owner} and event lead.created/lead.updated. The webhook service delivers { event: <resource.type>, data }: that's why data carries event too ({ event: 'lead.created', lead }). Internal notes don't go out. The events exist only after the migration (documents in webhook_events).

8. Requests section and settings (web-next)

  • /leads (app/(app)/leads/page.tsx, "Requests" entry in components/shell/nav-teaching.tsx for staff only) → LeadsView (components/leads/leads-view.tsx): TanStack legacy like Students, the kit Filters with matchesFilterQuery, views tableKey: 'leads', columns, CSV leadsCsv (BOM, quotes, no formulas). Up to 2000 rows read in pages of 200.
  • Detail LeadDetailDialog (components/leads/lead-detail-dialog.tsx): status, assignee (staff from organizationMembersApi.search), notes, Enroll = POST /courses/:id/members/invite (membersWithEmail as course-student with the edition, or membersWithId when the request has a profileId), then PATCH status: enrolled. The invitation permission stays the course's.
  • Settings: /settings/leads (app/(app)/settings/leads/page.tsx), entry "Requests and sales" (workspace manager).
  • 403 on /leads → empty state "You can't see the requests".

9. Permissions

ResourceType.LEADS = 'leads', entity Leads (libs/core/src/core/iam/entity/leads.entity.ts, owningOrganizationId = workspace), in the AbilityFactory subjectMapping and the ScopeAbilityGuard map. Keys leads.read, leads.update to Admin (the Owner inherits) via the migration; in a personal workspace the scope guard passes and the service filters by OwnerDto.fromActiveUser.

10. Configuration, in order

  1. Deploy backend.
  2. scripts/migrations/2026-10-leads.js (PHASE=plan, then PHASE=apply): indexes, leads.* keys to Admin (backup in _bak_202610_leads_roles), webhook events. Then flush the privilege cache on Redis.
  3. Deploy web-next.
  4. Check: node web-next/e2e/help/flows/run.mjs leads/requests --shots (a paid demo course without Stripe; LEADS_COURSE to pick it).

11. Tests

Backend tests/unit/leads.spec.ts: rules (offer, guest checkout, validation, spam, thank you page, settings), service with in-memory models (tests/unit/helpers/memory-model.ts): save + notice + webhook, silent spam, errors, IP and email limits, list filtered per workspace, status/assignee staff only, notes, settings and public answer; gateway (offer per mode, unpublished courses, IP only as a hash, edition of another course); email (area mailbox, text not interpreted). web-next lib/lead-form.test.mjs.

On this page