From ca4f13a5561a3e7fc76451685ce3060d2846564f Mon Sep 17 00:00:00 2001 From: Jake Turner Date: Mon, 6 Jan 2025 13:47:27 -0800 Subject: [PATCH] fix(VerificationRequest): remove ADAPT-specific messages --- .../VerificationRequestController.ts | 48 +------------------ 1 file changed, 1 insertion(+), 47 deletions(-) diff --git a/server/controllers/VerificationRequestController.ts b/server/controllers/VerificationRequestController.ts index d529c41..15d9035 100644 --- a/server/controllers/VerificationRequestController.ts +++ b/server/controllers/VerificationRequestController.ts @@ -271,15 +271,10 @@ export class VerificationRequestController { await Promise.all(webhookPromises); // Both calls return false and log if failed, so one shouldn't affect the other - // Generate ADAPT access code if it was requested (and approved) - const foundADAPTApp = approvedApps.find((a) => a.get('name') === 'ADAPT'); - const adaptAccessCode = foundADAPTApp ? await this._generateADAPTAccessCode() : null; - await this.sendUserRequestApprovedNotification( foundUser.get('email'), props.reason, approvedApps.map((a) => a.get('name')), - adaptAccessCode || undefined, ); return foundReq; }); @@ -364,7 +359,7 @@ export class VerificationRequestController { return true; } - public async sendUserRequestApprovedNotification(userEmail: string, comment?: string, applicationNames?: string[], adaptAccessCode?: string | null) { + public async sendUserRequestApprovedNotification(userEmail: string, comment?: string, applicationNames?: string[]) { const mailSender = new MailController(); if (mailSender.isReady()) { const emailRes = await mailSender.send({ @@ -383,13 +378,6 @@ export class VerificationRequestController { ${applicationNames.map((a) => `
  • ${a}
  • `).join('')} ` : ''} - ${adaptAccessCode && adaptAccessCode !== 'error' ? ` -

    IMPORTANT: ADAPT isn't fully integrated with LibreOne yet, but your email address has been automatically sent to ADAPT. You'll need to reset your ADAPT password using your email address first to access your account.

    - ` : - adaptAccessCode === 'error' ? ` -

    There was an issue provisioning your ADAPT account. Please contact support.

    - ` : '' - }

    If you have further questions, please feel free to submit a ticket in our Support Center.

    Best,

    The LibreTexts Team

    @@ -464,38 +452,4 @@ export class VerificationRequestController { } return true; } - - /** - * Generates an ADAPT access code for a user. - * @returns ADAPT access code or false if failed. - */ - private async _generateADAPTAccessCode(): Promise { - try { - if (!process.env.ADAPT_ACCESS_TOKEN) { - throw new Error('Missing required environment variable.'); - } - - const encoded = new TextEncoder().encode(process.env.ADAPT_ACCESS_TOKEN); - const jwtToSend = await new SignJWT({}).setProtectedHeader({ alg: 'HS256', typ: 'JWT' }).setIssuedAt().setExpirationTime('1h').sign(encoded); - - const adaptRes = await axios.get<{ type: 'success', access_code: string } | { type: 'error', message: string }>('https://adapt.libretexts.org/api/access-code/instructor', { - headers: { - Authorization: `Bearer ${jwtToSend}`, - }, - }); - - if (adaptRes.data.type === 'error') { - throw new Error(adaptRes.data.message); - } - - if (!adaptRes.data.access_code) { - throw new Error('No access code returned from ADAPT.'); - } - - return adaptRes.data.access_code; - } catch (err) { - console.error('Error generating ADAPT access code:', err); - return 'error'; - } - } }