fleet/website/api/controllers/deliver-webinar-access-request.js
Eric 275e21bcda
Website: Update partners form, update action input validation (#43954)
Changes:
- Updated the input validation and added an invalidEmailDomain exit to
the deliver-deal-registration-submission and
deliver-partner-registration-submission actions
- Updated the input validation in the
deliver-whitepaper-download-request and deliver-webinar-access-request
actions
- Added error messages to the forms on the partners page for the added
exits
- Updated the `bannedEmailDomainsForCSRSigning` and
`bannedEmailDomainsForWebsiteSubmissions` config values

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Blocked submissions from restricted email domains with a clear error
response and a prompt to use a work email.
* **Bug Fixes**
* Strengthened email-format and required-field validation across
registration and request forms.
  * Restricted partner registration type options to accepted values.
* **Chores**
  * Added a domain to the denylist used for website submissions.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-04-22 11:02:06 -05:00

77 lines
2.9 KiB
JavaScript
Vendored

module.exports = {
friendlyName: 'Deliver webinar access request',
description: '',
inputs: {
firstName: {type: 'string', required: true },
lastName: {type: 'string', required: true },
emailAddress: {type: 'string', required: true, isEmail: true, },
webinarName: {type: 'string', required: true },
},
exits: {
success: {description: 'A users webinar access request was successfully submitted.'},
invalidEmailDomain: {
description: 'This email address is on a denylist of domains and was not delivered.',
responseType: 'badRequest'
},
},
fn: async function ({firstName, lastName, emailAddress, webinarName}) {
let emailDomain = emailAddress.split('@')[1];
if(_.includes(sails.config.custom.bannedEmailDomainsForWebsiteSubmissions, emailDomain.toLowerCase())){
throw 'invalidEmailDomain';
}
// If the submitter has a marketing attribution cookie, send the details when creating/updating a contact/account/historical record.
let attributionCookieOrUndefined = this.req.cookies.marketingAttribution;
sails.helpers.flow.build(async ()=>{
let recordIds = await sails.helpers.salesforce.updateOrCreateContactAndAccount.with({
emailAddress: emailAddress,
firstName: firstName,
lastName: lastName,
contactSource: 'Webinar',
description: `Submitted a form to watch the ${webinarName} webinar.`,
marketingAttributionCookie: attributionCookieOrUndefined
}).intercept((err)=>{
return new Error(`Could not create/update a contact or account. Full error: ${require('util').inspect(err)}`);
});
// If the Contact record returned by the updateOrCreateContactAndAccount does not have a parent Account record, throw an error to stop the build helper.
if(!recordIds.salesforceAccountId) {
throw new Error(`Could not create historical event. The contact record (ID: ${recordIds.salesforceContactId}) returned by the updateOrCreateContactAndAccount helper is missing a parent account record.`);
}
// Create the new Fleet website page view record.
await sails.helpers.salesforce.createHistoricalEvent.with({
salesforceAccountId: recordIds.salesforceAccountId,
salesforceContactId: recordIds.salesforceContactId,
eventType: 'Intent signal',
intentSignal: 'Requested webinar recording',
eventContent: webinarName,
}).intercept((err)=>{
return new Error(`Could not create an historical event. Full error: ${require('util').inspect(err)}`);
});
}).exec((err)=>{
if(err){
sails.log.warn(`Background task failed: When a user (email: ${emailAddress} submitted a form to watch the ${webinarName} webinar, a Contact/Account/website activity record could not be created/updated in the CRM.`, require('util').inspect(err));
}
return;
});//_∏_
// All done.
return;
}
};