Skip to content

Commit

Permalink
Merge pull request #11 from CBIIT/develop
Browse files Browse the repository at this point in the history
Relase email function and storing sessions in DB
  • Loading branch information
n2iw committed Jun 24, 2022
2 parents d4685c0 + f0486be commit ddbb019
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 147 deletions.
37 changes: 32 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,43 @@ Following environmental variables are needed

- VERSION : version number
- DATE : build date
- IDP : Identification provider, e.g., "google"
- CLIENT_ID : IDP's client ID
- CLIENT_SECRET : IDP's client secret
- REDIRECT_URL : valid redirect URL set with IDP
- COOKIE_SECRET : secret used to sign cookies
- SESSION_TIMEOUT : session timeout in seconds, default is 30 minutes
- AUTHORIZATION_ENABLED : If not set to "true", then the authorization components will be disabled
- EMAILS_ENABLED : If not set to "true", then the email notifications will be disabled
# Neo4j configuration
- NEO4J_URI: Bolt URI of the Neo4j database
- NEO4J_USER: Neo4j username
- NEO4J_PASSWORD: Neo4j password
# Test-data loading configuration
- DATA_LOADING_MODE : (for testing only) set to "overwrite" to wipe the database before loading
- DATA_FILE : (for testing only) file containing data to load into the database for testing
- DATA_FILE : (for testing only) file containing data to load into the database for testing
# Testing
- TEST_EMAIL : The email to be logged in if "test-idp" is specified as the IDP
# MYSQL configuration
- MYSQL_HOST : The host URL of the MYSQL database
- MYSQL_PORT : The port of the MYSQL database
- MYSQL_USER : The service user of the MYSQL database
- MYSQL_PASSWORD : The password for the service user of the MYSQL database
- MYSQL_DATABASE : The MYSQL database name
# Email notification configuration
- EMAIL_SMTP_HOST: email server hostname
- EMAIL_SMTP_PORT: email server port number
# Additional configuration for email server
- EMAIL_USER: email server's username as an additional parameter
- EMAIL_PASSWORD: email server's password as an additional parameter
# Google login configuration
- GOOGLE_CLIENT_ID: Google cloud client id
- GOOGLE_CLIENT_SECRET: Google cloud client secret
- GOOGLE_REDIRECT_URL: redirecting url after successful authentication
# NIH login configuration
- NIH_CLIENT_ID: NIH login server client id
- NIH_CLIENT_SECRET: NIH login client secret
- NIH_BASE_URL: NIH login server url
- NIH_REDIRECT_URL: redirecting url after successful authentication
- NIH_USERINFO_URL: NIH API address to search user information
- NIH_AUTHORIZE_URL: NIH API address to authenticate for login
- NIH_TOKEN_URL: NIH API address to create token for login
- NIH_LOGOUT_URL: NIH API address to invalidate token for logout
- NIH_SCOPE: space-separated lists of identifiers to specify access privileges
- NIH_PRO
29 changes: 22 additions & 7 deletions config.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,34 @@ COOKIE_SECRET=XXXXX
SESSION_TIMEOUT=1200
VERSION=1.0
DATE=2022.05.19
# NEO4J Configuration
NEO4J_URI=bolt://localhost:XXXX
NEO4J_USER=neo4j
NEO4J_PASSWORD=xxxxx
# MySQL Configuration
MY_SQL_HOST=127.0.0.1
MY_SQL_PORT=3306
MY_SQL_PASSWORD=Dbtldud1
MY_SQL_PASSWORD=XXXX
MY_SQL_USER=root
MY_SQL_DATABASE=session
# Email Notification Config
EMAIL_SERVICE_EMAIL=XXXX@nih.gov
EMAIL_SMTP_HOST=mailfwd.nih.gov
EMAIL_SMTP_HOST=XXXX@XXXX
EMAIL_SMTP_PORT=25
# If Sent From AWS SMTP
# Additional Email Server Configuration
#EMAIL_USER=XXXX
#EMAIL_PASSWORD=XXXX
NEO4J_URI=bolt://localhost:XXXX
NEO4J_USER=neo4j
NEO4J_PASSWORD=xxxxx
# GOOGLE LOGIN Config
GOOGLE_CLIENT_ID=XXXX
GOOGLE_CLIENT_SECRET=XXXX
GOOGLE_REDIRECT_URL=http://localhost:4010
# NIH LOGIN Config
NIH_CLIENT_ID=XXXX
NIH_CLIENT_SECRET=XXXX
NIH_BASE_URL=https://stsstg.nih.gov
NIH_REDIRECT_URL=http://localhost:4010/profile
NIH_USERINFO_URL=https://stsstg.nih.gov/openid/connect/v1/userinfo
NIH_AUTHORIZE_URL=https://stsstg.nih.gov/auth/oauth/v2/authorize
NIH_TOKEN_URL=https://stsstg.nih.gov/auth/oauth/v2/token
NIH_LOGOUT_URL=https://stsstg.nih.gov/connect/session/logout
NIH_SCOPE=openid email profile
NIH_PROMPT=login
12 changes: 6 additions & 6 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const config = {
cookie_secret: process.env.COOKIE_SECRET,
session_timeout: process.env.SESSION_TIMEOUT ? parseInt(process.env.SESSION_TIMEOUT) : 30 * 60, // 30 minutes
authorization_enabled: process.env.AUTHORIZATION_ENABLED ? process.env.AUTHORIZATION_ENABLED.toLowerCase() === 'true' : true,
emails_enabled: process.env.EMAILS_ENABLED ? process.env.EMAILS_ENABLED.toLowerCase() === 'true' : true,

//Neo4j connection
NEO4J_URI: process.env.NEO4J_URI,
Expand All @@ -22,13 +23,12 @@ const config = {
//Testing
TEST_EMAIL: process.env.TEST_EMAIL,
// MySQL Session
mysql_host: process.env.MY_SQL_HOST,
mysql_port: process.env.MY_SQL_PORT,
mysql_user: process.env.MY_SQL_USER,
mysql_password: process.env.MY_SQL_PASSWORD,
mysql_database: process.env.MY_SQL_DATABASE,
mysql_host: process.env.MYSQL_HOST,
mysql_port: process.env.MYSQL_PORT,
mysql_user: process.env.MYSQL_USER,
mysql_password: process.env.MYSQL_PASSWORD,
mysql_database: process.env.MYSQL_DATABASE,
// Email settings
email_service_email: process.env.EMAIL_SERVICE_EMAIL,
email_transport: getTransportConfig()
};

Expand Down
41 changes: 29 additions & 12 deletions data-management/data-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,20 @@ const registerUser = async (input, context) => {
...input.userInfo,
...generatedInfo
};
let result = await neo4j.registerUser(registrationInfo);
let adminEmails = await getAdminEmails();
await sendAdminNotification(adminEmails);
await sendRegistrationConfirmation(input.userInfo.email)
return result;
let response = await neo4j.registerUser(registrationInfo);
if (response) {
let adminEmails = await getAdminEmails();
let template_params = {
firstName: response.firstName,
lastName: response.lastName
}
await sendAdminNotification(adminEmails, template_params);
await sendRegistrationConfirmation(response.email, template_params)
return response;
}
else {
return new Error(errorName.UNABLE_TO_REGISTER_USER);
}
} catch (err) {
return err;
}
Expand All @@ -145,9 +154,11 @@ const approveUser = async (parameters, context) => {
parameters.approvalDate = (new Date()).toString()
let response = await neo4j.approveUser(parameters)
if (response) {
if (response.email) {
await sendApprovalNotification(response.email);
}
let template_params = {
firstName: response.firstName,
lastName: response.lastName
};
await sendApprovalNotification(response.email, template_params);
return response;
} else {
return new Error(errorName.USER_NOT_FOUND);
Expand All @@ -172,9 +183,12 @@ const rejectUser = async (parameters, context) => {
parameters.rejectionDate = (new Date()).toString()
let response = await neo4j.rejectUser(parameters)
if (response) {
if (response.email) {
await sendRejectionNotification(response.email, response.comment);
let template_params = {
firstName: response.firstName,
lastName: response.lastName,
comment: response.comment
}
await sendRejectionNotification(response.email, template_params);
return response;
} else {
return new Error(errorName.USER_NOT_FOUND);
Expand Down Expand Up @@ -230,9 +244,12 @@ const editUser = async (parameters, context) => {
}
let response = await neo4j.editUser(parameters)
if (response) {
if (response.email) {
await sendEditNotification(response.email, response.comment);
let template_params = {
firstName: response.firstName,
lastName: response.lastName,
comment: response.comment
}
await sendEditNotification(response.email, template_params);
return response;
} else {
return new Error(errorName.USER_NOT_FOUND);
Expand Down
14 changes: 0 additions & 14 deletions data-management/email.js

This file was deleted.

5 changes: 5 additions & 0 deletions data-management/graphql-api-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports.errorName = {
ALREADY_REJECTED: "ALREADY_REJECTED",
INVALID_ROLE: "INVALID_ROLE",
INVALID_STATUS: "INVALID_STATUS",
UNABLE_TO_REGISTER_USER: 'UNABLE_TO_REGISTER_USER'
};

exports.errorType = {
Expand Down Expand Up @@ -58,5 +59,9 @@ exports.errorType = {
ALREADY_REJECTED: {
message: "The specified user has already been rejected",
statusCode: 409
},
UNABLE_TO_REGISTER_USER: {
message: "Something went wrong while registering the user",
statusCode: 409
}
};
95 changes: 48 additions & 47 deletions data-management/notifications.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,84 @@
const {sendEmail} = require("./email");
const yaml = require('js-yaml');
const fs = require('fs');
const fs = require('fs');
const {sendNotification} = require("../services/notify");
const {createEmailTemplate} = require("../lib/create-email-template");

let email_constants = undefined
try{
try {
email_constants = yaml.load(fs.readFileSync('yaml/notification_email_values.yaml', 'utf8'));
}
catch (e) {
} catch (e) {
console.error(e)
}


module.exports = {
sendAdminNotification: async (admins) => {
if (email_constants){
if (Array.isArray(admins)){
admins.forEach((adminEmail) => {
sendEmail(
adminEmail,
email_constants.ADMIN_NOTIFICATION_SUBJECT,
email_constants.ADMIN_NOTIFICATION_CONTENT
);
})
}
else {
console.error('send email failed, admins parameter of sendAdminNotification is not an array');
}
}
else{
sendAdminNotification: async (admins, template_params) => {
if (email_constants) {
await sendNotification(
email_constants.NOTIFICATION_SENDER,
email_constants.ADMIN_NOTIFICATION_SUBJECT,
await createEmailTemplate("notification-template.html", {
message: email_constants.ADMIN_NOTIFICATION_CONTENT, ...template_params
}),
admins
);
} else {
console.error("Unable to load email constants from file, email not sent")
}

},
sendRegistrationConfirmation: async (email) => {
sendRegistrationConfirmation: async (email, template_params) => {
if (email_constants) {
sendEmail(
email,
await sendNotification(
email_constants.NOTIFICATION_SENDER,
email_constants.CONFIRMATION_SUBJECT,
email_constants.CONFIRMATION_CONTENT
await createEmailTemplate("notification-template.html", {
message: email_constants.CONFIRMATION_CONTENT, ...template_params
}),
email
);
}
else{
} else {
console.error("Unable to load email constants from file, email not sent")
}

},
sendApprovalNotification: async (email) => {
sendApprovalNotification: async (email, template_params) => {
if (email_constants) {
sendEmail(
email,
await sendNotification(
email_constants.NOTIFICATION_SENDER,
email_constants.APPROVAL_SUBJECT,
email_constants.APPROVAL_CONTENT
await createEmailTemplate("notification-template.html", {
message: email_constants.APPROVAL_CONTENT, ...template_params
}),
email
);
}
else{
} else {
console.error("Unable to load email constants from file, email not sent")
}
},
sendRejectionNotification: async (email, comment) => {
sendRejectionNotification: async (email, template_params) => {
if (email_constants) {
sendEmail(
email,
await sendNotification(
email_constants.NOTIFICATION_SENDER,
email_constants.REJECTION_SUBJECT,
email_constants.REJECTION_CONTENT_PRE_COMMENT + comment + email_constants.REJECTION_CONTENT_POST_COMMENT
await createEmailTemplate("notification-template.html", {
message: email_constants.REJECTION_CONTENT_PRE_COMMENT + template_params.comment + email_constants.REJECTION_CONTENT_POST_COMMENT, ...template_params
}),
email
);
}
else {
} else {
console.error("Unable to load email constants from file, email not sent")
}
},
sendEditNotification: async (email, comment) => {
sendEditNotification: async (email, template_params) => {
if (email_constants) {
sendEmail(
email,
await sendNotification(
email_constants.NOTIFICATION_SENDER,
email_constants.EDIT_SUBJECT,
email_constants.EDIT_CONTENT_PRE_COMMENT + comment + email_constants.EDIT_CONTENT_POST_COMMENT
await createEmailTemplate("notification-template.html", {
message: email_constants.EDIT_CONTENT_PRE_COMMENT + template_params.comment + email_constants.EDIT_CONTENT_POST_COMMENT, ...template_params
}),
email
);
}
else {
} else {
console.error("Unable to load email constants from file, email not sent")
}
}
Expand Down
35 changes: 0 additions & 35 deletions mailer/index.js

This file was deleted.

Loading

0 comments on commit ddbb019

Please sign in to comment.