Skip to content

Commit

Permalink
Merge branch 'dependabot/npm_and_yarn/backend/axios-1.6.2' of github.…
Browse files Browse the repository at this point in the history
…com:cisagov/crossfeed into dependabot/npm_and_yarn/backend/axios-1.6.2
  • Loading branch information
Matthew-Grayson committed Dec 28, 2023
2 parents 28fd03a + 6b8485e commit dd7606f
Show file tree
Hide file tree
Showing 17 changed files with 18,493 additions and 8,301 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ jobs:
run: npm run lint
- name: Build
run: npm run build
- name: Deploy to GitHub Pages
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
uses: crazy-max/[email protected]
with:
keep_history: false
target_branch: gh-pages
build_dir: docs/public
fqdn: docs.crossfeed.cyber.dhs.gov
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# - name: Deploy to GitHub Pages
# if: github.event_name == 'push' && github.ref == 'refs/heads/master'
# uses: crazy-max/[email protected]
# with:
# keep_history: false
# target_branch: gh-pages
# build_dir: docs/public
# fqdn: docs.crossfeed.cyber.dhs.gov
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 4 additions & 4 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ jobs:
run: cp stage.env .env && npm run build

- name: Deploy Staging
run: aws s3 sync build s3://staging.crossfeed.cyber.dhs.gov --delete
run: npx sls deploy --stage=staging
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-1
SLS_DEBUG: '*'

deploy_prod:
needs: [lint, test]
Expand All @@ -115,8 +115,8 @@ jobs:
run: cp prod.env .env && npm run build

- name: Deploy Production
run: aws s3 sync build s3://crossfeed.cyber.dhs.gov --delete
run: npx sls deploy --stage=staging
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-1
SLS_DEBUG: '*'
2 changes: 2 additions & 0 deletions backend/env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ staging:
PE_CLUSTER_NAME: pe-staging-worker
SHODAN_QUEUE_URL: ${ssm:/crossfeed/staging/SHODAN_QUEUE_URL}
SHODAN_SERVICE_NAME: pe-staging-shodan
EMAIL_BUCKET_NAME: cisa-crossfeed-staging-html-email

prod:
DB_DIALECT: 'postgres'
Expand Down Expand Up @@ -86,6 +87,7 @@ prod:
PE_CLUSTER_NAME: pe-prod-worker
SHODAN_QUEUE_URL: ${ssm:/crossfeed/prod/SHODAN_QUEUE_URL}
SHODAN_SERVICE_NAME: pe-prod-shodan
EMAIL_BUCKET_NAME: cisa-crossfeed-staging-html-email

dev-vpc:
securityGroupIds:
Expand Down
87 changes: 47 additions & 40 deletions backend/src/api/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,48 @@ export const sendEmail = async (
});
};

export const sendRegistrationTextEmail = async (recipient: string) => {
const transporter = nodemailer.createTransport({
SES: new SES({ region: 'us-east-1' })
});

const mailOptions = {
from: process.env.CROSSFEED_SUPPORT_EMAIL_SENDER!,
to: recipient,
subject: 'Crossfeed Registration Pending',
text: 'Your registration is pending approval.',
replyTo: process.env.CROSSFEED_SUPPORT_EMAIL_REPLYTO!
};

await transporter.sendMail(mailOptions, (error, data) => {
console.log(data);
if (error) {
console.log(error);
}
});
};

export const sendRegistrationHtmlEmail = async (recipient: string) => {
const transporter = nodemailer.createTransport({
SES: new SES({ region: 'us-east-1' })
});

const mailOptions = {
from: process.env.CROSSFEED_SUPPORT_EMAIL_SENDER!,
to: recipient,
subject: 'Crossfeed Registration Pending',
html: '<p>Your registration is pending approval.</p>',
replyTo: process.env.CROSSFEED_SUPPORT_EMAIL_REPLYTO!
};

await transporter.sendMail(mailOptions, (error, data) => {
console.log(data);
if (error) {
console.log(error);
}
});
};

export const sendUserNotificationEmail = async (
recepient: string,
p_subject: string,
Expand All @@ -112,58 +154,23 @@ export const sendUserNotificationEmail = async (
SES: new SES({ region: 'us-east-1' })
});

const client = new S3Client();
/*const client = new S3Client();
const html = await client.getEmailAsset(template_file);
const template = handlebars.compile(html);
const data = {
first_name: p_firstName,
last_name: p_lastname
};
const htmlToSend = template(data);
const htmlToSend = template(data);*/

const mailOptions = {
from: process.env.CROSSFEED_SUPPORT_EMAIL_SENDER,
to: recepient,
subject: p_subject,
html: htmlToSend,
attachments: [
{
filename: 'banner.png',
content: await client.getEmailAsset('banner.png'),
cid: 'CISA Banner'
},
{
filename: 'web.png',
content: await client.getEmailAsset('banner.png'),
cid: 'CISA Web'
},
{
filename: 'email.png',
content: await client.getEmailAsset('email.png'),
cid: 'CISA Email'
},
{
filename: 'linkedin.png',
content: await client.getEmailAsset('linkedin.png'),
cid: 'CISA LinkedIn'
},
{
filename: 'twitter.png',
content: await client.getEmailAsset('twitter.png'),
cid: 'CISA Twitter'
},
{
filename: 'facebook.png',
content: await client.getEmailAsset('facebooK.png'),
cid: 'CISA Facebook'
},
{
filename: 'instagram.png',
content: await client.getEmailAsset('instagram.png'),
cid: 'CISA Instagram'
}
]
text: 'Testing'
};

await transporter.sendMail(mailOptions);
Expand Down
54 changes: 42 additions & 12 deletions backend/src/api/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import {
NotFound,
Unauthorized,
sendEmail,
sendUserNotificationEmail
sendUserNotificationEmail,
sendRegistrationTextEmail,
sendRegistrationHtmlEmail
} from './helpers';
import { UserType } from '../models/user';
import {
Expand Down Expand Up @@ -598,16 +600,23 @@ export const register = wrapHandler(async (event) => {
// id = createdUser.id;

// Send Registration confirmation email to user
// TODO: replace with html email function to user
sendUserNotificationEmail(
newUser.email,
'Crossfeed Registration Pending',
newUser.firstName,
newUser.lastName,
'/app/src/email_templates/crossfeed_registration_notification.html'
);
// TODO Commented out for testing - uncomment/cleanup for prod
// sendUserNotificationEmail(
// newUser.email,
// 'Crossfeed Registration Pending',
// newUser.firstName,
// newUser.lastName,
// '/app/src/email_templates/crossfeed_registration_notification.html'
// );

// Send Basic Text Registration confirmation email to user
await sendRegistrationTextEmail(newUser.email);
// Send Basic HTML Registration confirmation email to user
await sendRegistrationHtmlEmail(newUser.email);

// Send new user pending approval email to regionalAdmin
// TODO: replace with html email function to regianlAdmin
// TODO: replace with html email function to regianlAdmin if desired

const savedUser = await User.findOne(id, {
relations: ['roles', 'roles.organization']
});
Expand Down Expand Up @@ -823,29 +832,50 @@ export const inviteV2 = wrapHandler(async (event) => {
await connectToDatabase();

body.email = body.email.toLowerCase();
const userEmail = body.email.toLowerCase();

const sendRegisterEmail = async (email: string) => {
const staging = process.env.NODE_ENV !== 'production';

await sendEmail(
email,
'Crossfeed Registration',
`Hello,
Your Crossfeed registration is under review.
You will receive an email when your registration is approved.
Thank you!`
);
};

// Check if user already exists
let user = await User.findOne({
email: body.email
});

// Handle Organization assignment if provided
let organization: Organization | undefined;

if (body.organization) {
organization = await Organization.findOne(body.organization);
}

// Create user if not found
if (!user) {
// Create User object
user = await User.create({
invitePending: true,
...body
});
// Save User to DB
await User.save(user);
await sendInviteEmail(user.email, organization);

// Send Notification Email to user
await sendRegisterEmail(userEmail);
} else if (!user.firstName && !user.lastName) {
// Only set the user first name and last name the first time the user is invited.
user.firstName = body.firstName;
user.lastName = body.lastName;
// Save User to DB
await User.save(user);
}

Expand Down
Loading

0 comments on commit dd7606f

Please sign in to comment.