fleet/website/api/controllers/admin/provision-sandbox-instance-and-deliver-email.js
Eric 46802ee56a
Website: Add admin page to manage the Fleet Sandbox waitlist (#13111)
Closes: #12954

Changes:
- Added an admin page that displays a table containing all of the users
that are currently on the Fleet Sandbox waitlist where admins can
approve waitlisted users.
- Added a new email template that tells users that their Fleet Sandbox
instance is ready.
- Added a new action:
`admin/provision-sandbox-instance-and-deliver-email.js`, an action that
provisions a Fleet sandbox instance for a single user and sends them an
email telling them that their Fleet Sandbox Instance is ready.
- Added a script that provisions a Fleet Sandbox instance for the user
who has been on the waitlist the longest and sends them an email telling
them that their Sandbox instance is ready.
2023-08-04 18:32:00 -05:00

66 lines
2.2 KiB
JavaScript
Vendored

module.exports = {
friendlyName: 'Provision sandbox instance and deliver email',
description: 'Provisions a Fleet sandbox for a user and delivers an email to a user letting them know their Fleet Sandbox instance is ready.',
inputs: {
userId: {
type: 'number',
description: 'The database ID of the user who is currently on the Fleet Sandbox waitlist',
required: true
}
},
exits: {
success: {
description: 'A user was successfully removed from the Fleet Sandbox waitlist.'
},
},
fn: async function ({userId}) {
let userToRemoveFromSandboxWaitlist = await User.findOne({id: userId});
if(!userToRemoveFromSandboxWaitlist.inSandboxWaitlist) {
throw new Error(`When attempting to provision a Fleet Sandbox instance for a user (id:${userId}) who is on the waitlist, the user record associated with the provided ID has already been removed from the waitlist.`);
}
let sandboxInstanceDetails = await sails.helpers.fleetSandboxCloudProvisioner.provisionNewFleetSandboxInstance.with({
firstName: userToRemoveFromSandboxWaitlist.firstName,
lastName: userToRemoveFromSandboxWaitlist.lastName,
emailAddress: userToRemoveFromSandboxWaitlist.emailAddress,
})
.intercept((err)=>{
return new Error(`When attempting to provision a new Fleet Sandbox instance for a User (id:${userToRemoveFromSandboxWaitlist.id}), an error occured. Full error: ${err}`);
});
await User.updateOne({id: userId}).set({
fleetSandboxURL: sandboxInstanceDetails.fleetSandboxURL,
fleetSandboxExpiresAt: sandboxInstanceDetails.fleetSandboxExpiresAt,
fleetSandboxDemoKey: sandboxInstanceDetails.fleetSandboxDemoKey,
inSandboxWaitlist: false,
});
// Send the user an email to let them know that their Fleet sandbox instance is ready.
await sails.helpers.sendTemplateEmail.with({
to: userToRemoveFromSandboxWaitlist.emailAddress,
from: sails.config.custom.fromEmailAddress,
fromName: sails.config.custom.fromName,
subject: 'Your Fleet Sandbox instance is ready!',
template: 'email-sandbox-ready-approved',
templateData: {},
});
// All done.
return;
}
};