Website: Create admin page for resetting Fleet Premium trials (#39980)
Changes: - Added /admin/reset-trial, a page where website admins can reset local Fleet Premium trials. - Added a link to the reset trial page to the navigation on admin pages.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
module.exports = {
|
||||
|
||||
|
||||
friendlyName: 'Reset one fleet premium local trial',
|
||||
|
||||
|
||||
description: '',
|
||||
|
||||
|
||||
inputs: {
|
||||
emailAddress: { type: 'string', required: true, },
|
||||
},
|
||||
|
||||
|
||||
exits: {
|
||||
success: {description: 'A user\'s Fleet premium trial was successfully reset.'},
|
||||
userNotFound: {description: 'No user account was found using the provided email address.', responseType: 'notFound'},
|
||||
trialTypeUnsupported: {description: 'This user has a Render trial.', responseType: 'badRequest'}
|
||||
},
|
||||
|
||||
|
||||
fn: async function ({emailAddress}) {
|
||||
|
||||
let thisUser = await User.findOne({emailAddress});
|
||||
|
||||
if(!thisUser) {
|
||||
throw 'userNotFound';
|
||||
}
|
||||
|
||||
if(thisUser.fleetPremiumTrialType === 'render trial') {
|
||||
throw 'trialTypeUnsupported';
|
||||
}
|
||||
|
||||
let thirtyDaysFromNowAt = Date.now() + (1000 * 60 * 60 * 24 * 30);
|
||||
|
||||
let newTrialLicenseKeyForThisUser = await sails.helpers.createLicenseKey.with({
|
||||
numberOfHosts: 10,
|
||||
organization: thisUser.organization,
|
||||
expiresAt: thirtyDaysFromNowAt,
|
||||
});
|
||||
|
||||
await User.updateOne({id: thisUser.id}).set({
|
||||
fleetPremiumTrialLicenseKeyExpiresAt: thirtyDaysFromNowAt,
|
||||
fleetPremiumTrialLicenseKey: newTrialLicenseKeyForThisUser,
|
||||
});
|
||||
|
||||
// All done.
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
module.exports = {
|
||||
|
||||
|
||||
friendlyName: 'View reset trial',
|
||||
|
||||
|
||||
description: 'Display "Reset trial" page.',
|
||||
|
||||
|
||||
exits: {
|
||||
|
||||
success: {
|
||||
viewTemplatePath: 'pages/admin/reset-trial'
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
fn: async function () {
|
||||
|
||||
// Respond with view.
|
||||
return {};
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user