Skip to content

Commit

Permalink
Adding unsubscription Link
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminSsempala committed Feb 17, 2024
1 parent f438919 commit f27d5c8
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 131 deletions.
33 changes: 20 additions & 13 deletions src/auth-service/config/global/email-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,25 @@ const emailTemplates = {
`;
},
EMAIL_FOOTER_TEMPLATE: function (email, product, type, paramString) {
const unSubsciptionUrl = `${baseUrl}/api/v2/users/unsubscribe/${product}/${type}?${paramString}`;
let subscriptionBlock = ``;

Check warning on line 29 in src/auth-service/config/global/email-templates.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/config/global/email-templates.js#L28-L29

Added lines #L28 - L29 were not covered by tests
if (product && type && paramString) {
const unSubsciptionUrl = `${baseUrl}/api/v2/users/unsubscribe/${product}/${type}?${paramString}`;
subscriptionBlock = `

Check warning on line 32 in src/auth-service/config/global/email-templates.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/config/global/email-templates.js#L31-L32

Added lines #L31 - L32 were not covered by tests
<span
style="color: #667085; font-size: 14px; font-family: Inter; font-weight: 400; line-height: 20px; word-wrap: break-word;">.
If you'd rather not receive this kind of email, you can </span>
<a href=${unSubsciptionUrl} target="_blank" <span
style="color: #135DFF; font-size: 14px; font-family: Inter; font-weight: 400; line-height: 20px; word-wrap: break-word;">unsubscribe</span>
</a>
<span
style="color: #667085; font-size: 14px; font-family: Inter; font-weight: 400; line-height: 20px; word-wrap: break-word;">
or </span>
<span
style="color: #135DFF; font-size: 14px; font-family: Inter; font-weight: 400; line-height: 20px; word-wrap: break-word;">manage
your email preferences.</span><br /><br />
`;
}

return `
<table style="width: 100%; text-align: center; padding-top: 32px; padding-bottom: 32px;">
<tr>
Expand Down Expand Up @@ -56,18 +74,7 @@ const emailTemplates = {
email was sent to</span>
<span
style="color: #135DFF; font-size: 14px; font-family: Inter; font-weight: 400; line-height: 20px; word-wrap: break-word;">${email}</span>
<span
style="color: #667085; font-size: 14px; font-family: Inter; font-weight: 400; line-height: 20px; word-wrap: break-word;">.
If you'd rather not receive this kind of email, you can </span>
<a href =${unSubsciptionUrl} target = "_blank" <span
style="color: #135DFF; font-size: 14px; font-family: Inter; font-weight: 400; line-height: 20px; word-wrap: break-word;">unsubscribe</span>
</a>
<span
style="color: #667085; font-size: 14px; font-family: Inter; font-weight: 400; line-height: 20px; word-wrap: break-word;">
or </span>
<span
style="color: #135DFF; font-size: 14px; font-family: Inter; font-weight: 400; line-height: 20px; word-wrap: break-word;">manage
your email preferences.</span><br /><br />
${subscriptionBlock}
<span
style="color: #667085; font-size: 14px; font-family: Inter; font-weight: 400; line-height: 20px; word-wrap: break-word;">©
2023 AirQo<br /><br />
Expand Down
4 changes: 4 additions & 0 deletions src/auth-service/utils/control-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ const isIPBlacklistedHelper = async (
token = "",
name = "",
client_id = "",
user_id = "",
} = (accessToken && accessToken._doc) || {};

const BLOCKED_IP_PREFIXES =
Expand Down Expand Up @@ -390,6 +391,7 @@ const isIPBlacklistedHelper = async (
firstName,
lastName,
ip,
user_id
},
next
);
Expand Down Expand Up @@ -579,6 +581,7 @@ const controlAccess = {
firstName: userDetails[0].firstName,
username: userDetails[0].userName,
email: userDetails[0].email,
user_id: userDetails[0]._id,
},
next
);
Expand Down Expand Up @@ -1057,6 +1060,7 @@ const controlAccess = {
username: user.userName,
password,
email: user.email,
user_id: user._id,
},
next
);
Expand Down
1 change: 1 addition & 0 deletions src/auth-service/utils/create-candidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const createCandidate = {
email,
firstName,
lastName,
user_id: userExists._id,
},
next
);
Expand Down
1 change: 1 addition & 0 deletions src/auth-service/utils/create-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ const createAccessRequest = {
username: email,
email,
entity_title,
user_id: newUser._id,
},
next
);
Expand Down
16 changes: 14 additions & 2 deletions src/auth-service/utils/create-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ const createUserModule = {
const lastName = user[0].lastName;

const responseFromSendEmail = await mailer.update(
{ email, firstName, lastName, updatedUserDetails },
{ email, firstName, lastName, updatedUserDetails, user_id: _id },
next
);

Expand Down Expand Up @@ -865,6 +865,7 @@ const createUserModule = {
password,
tenant,
type: "user",
user_id: createdUser._id,
},
next
);
Expand Down Expand Up @@ -1709,6 +1710,7 @@ const createUserModule = {
password,
tenant,
type: "user",
user_id: createdUser._id,
},
next
);
Expand Down Expand Up @@ -1876,6 +1878,7 @@ const createUserModule = {
email,
firstName,
lastName,
user_id: userDetails._id,
},
next
);
Expand Down Expand Up @@ -1972,6 +1975,7 @@ const createUserModule = {
email,
firstName,
lastName,
user_id: user[0]._id,
},
next
);
Expand Down Expand Up @@ -2279,7 +2283,15 @@ const createUserModule = {
switch (product) {
case "mobile":

const userRef = db.collection(constants.FIREBASE_COLLECTION_USERS).doc(firebase_user_id);
let userRef;
if (!isEmpty(firebase_user_id)) {
userRef = db.collection(constants.FIREBASE_COLLECTION_USERS).doc(firebase_user_id);
}
else {
const querySnapshot = await db.collection(constants.FIREBASE_COLLECTION_USERS).where("emailAddress", "==", email).get();
userRef = querySnapshot.docs[0].ref;
}

const userDoc = await userRef.get();
let firebase_result, mongo_result;
let updateField = {};
Expand Down
30 changes: 16 additions & 14 deletions src/auth-service/utils/email.msgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ module.exports = {
return constants.EMAIL_BODY(email, content, fullName, "analytics", "email", `email=${email}&mongo_user_id=${user_id}`);

Check warning on line 150 in src/auth-service/utils/email.msgs.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/utils/email.msgs.js#L150

Added line #L150 was not covered by tests
},

welcome_kcca: (firstName, lastName, password, email) => {
welcome_kcca: (firstName, lastName, password, email, user_id) => {

Check warning on line 153 in src/auth-service/utils/email.msgs.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/utils/email.msgs.js#L153

Added line #L153 was not covered by tests
const name = firstName + " " + lastName;
const content = ` <tr>
<td
Expand Down Expand Up @@ -181,9 +181,9 @@ module.exports = {
style="color: #135DFF; font-size: 14px; font-family: Inter; font-weight: 400; line-height: 20px; word-wrap: break-word;">[email protected]</span>
</td>
</tr>`;
return constants.EMAIL_BODY(email, content, name);
return constants.EMAIL_BODY(email, content, name, "analytics", "email", `email=${email}&mongo_user_id=${user_id}`);

Check warning on line 184 in src/auth-service/utils/email.msgs.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/utils/email.msgs.js#L184

Added line #L184 was not covered by tests
},
welcome_general: (firstName, lastName, password, email) => {
welcome_general: (firstName, lastName, password, email, user_id) => {

Check warning on line 186 in src/auth-service/utils/email.msgs.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/utils/email.msgs.js#L186

Added line #L186 was not covered by tests
const name = firstName + " " + lastName;
const content = `<tr>
<td
Expand Down Expand Up @@ -218,13 +218,14 @@ module.exports = {
AirQo Data Team
</td>
</tr>`;
return constants.EMAIL_BODY(email, content, name);
return constants.EMAIL_BODY(email, content, name, "analytics", "email", `email=${email}&mongo_user_id=${user_id}`);

Check warning on line 221 in src/auth-service/utils/email.msgs.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/utils/email.msgs.js#L221

Added line #L221 was not covered by tests
},
user_updated: ({
firstName = "",
lastName = "",
updatedUserDetails = {},
email = "",
user_id
} = {}) => {
let updatedFields = "<ol>\n";
Object.keys(updatedUserDetails).forEach((field) => {
Expand All @@ -251,7 +252,7 @@ module.exports = {
</tr>`;
const name = firstName + " " + lastName;

return constants.EMAIL_BODY(email, content, name);
return constants.EMAIL_BODY(email, content, name, "analytics", "email", `email=${email}&mongo_user_id=${user_id}`);

Check warning on line 255 in src/auth-service/utils/email.msgs.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/utils/email.msgs.js#L255

Added line #L255 was not covered by tests
},
site_activity: ({
firstName = "",
Expand Down Expand Up @@ -290,6 +291,7 @@ module.exports = {
lastName = "",
ip = "",
email = "",
user_id
} = {}) => {
const name = firstName + " " + lastName;
const content = `
Expand All @@ -303,9 +305,9 @@ module.exports = {
</tr>
`;

return constants.EMAIL_BODY(email, content, name);
return constants.EMAIL_BODY(email, content, name, "analytics", "email", `email=${email}&mongo_user_id=${user_id}`);

Check warning on line 308 in src/auth-service/utils/email.msgs.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/utils/email.msgs.js#L308

Added line #L308 was not covered by tests
},
existing_user: ({ firstName = "", lastName = "", email = "" } = {}) => {
existing_user: ({ firstName = "", lastName = "", email = "", user_id = "" } = {}) => {

Check warning on line 310 in src/auth-service/utils/email.msgs.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/utils/email.msgs.js#L310

Added line #L310 was not covered by tests
const name = firstName + " " + lastName;
const content = `
<tr>
Expand All @@ -316,7 +318,7 @@ module.exports = {
</tr>
`;

return constants.EMAIL_BODY(email, content, name);
return constants.EMAIL_BODY(email, content, name, "analytics", "email", `email=${email}&mongo_user_id=${user_id}`);

Check warning on line 321 in src/auth-service/utils/email.msgs.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/utils/email.msgs.js#L321

Added line #L321 was not covered by tests
},

user_assigned: (firstName, lastName, assignedTo, email) => {
Expand All @@ -339,7 +341,7 @@ module.exports = {

return constants.EMAIL_BODY(email, content, `${firstName} ${lastName}`);
},
forgotten_password_updated: (firstName, lastName, email) => {
forgotten_password_updated: (firstName, lastName, email, user_id) => {

Check warning on line 344 in src/auth-service/utils/email.msgs.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/utils/email.msgs.js#L344

Added line #L344 was not covered by tests
const name = firstName + " " + lastName;
const content = ` <tr>
<td
Expand All @@ -356,9 +358,9 @@ module.exports = {
<br />
</td>
</tr>`;
return constants.EMAIL_BODY(email, content, name);
return constants.EMAIL_BODY(email, content, name, "analytics", "email", `email=${email}&mongo_user_id=${user_id}`);

Check warning on line 361 in src/auth-service/utils/email.msgs.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/utils/email.msgs.js#L361

Added line #L361 was not covered by tests
},
known_password_updated: (firstName, lastName, email) => {
known_password_updated: (firstName, lastName, email, user_id) => {

Check warning on line 363 in src/auth-service/utils/email.msgs.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/utils/email.msgs.js#L363

Added line #L363 was not covered by tests
const name = firstName + " " + lastName;
const content = `<tr>
<td
Expand All @@ -375,7 +377,7 @@ module.exports = {
<br />
</td>
</tr>`;
return constants.EMAIL_BODY(email, content, name);
return constants.EMAIL_BODY(email, content, name, "analytics", "email", `email=${email}&mongo_user_id=${user_id}`);

Check warning on line 380 in src/auth-service/utils/email.msgs.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/utils/email.msgs.js#L380

Added line #L380 was not covered by tests
},
join_by_email: (email, token) => {
const content = `<tr>
Expand All @@ -392,7 +394,7 @@ module.exports = {
<br />
</td>
</tr>`;
return constants.EMAIL_BODY(email, content);
return constants.EMAIL_BODY(email, content, "", "mobile", "email", `email=${email}`);

Check warning on line 397 in src/auth-service/utils/email.msgs.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/utils/email.msgs.js#L397

Added line #L397 was not covered by tests
},
authenticate_email: (token, email) => {
const content = ` <tr>
Expand All @@ -409,7 +411,7 @@ module.exports = {
<br />
</td>
</tr>`;
return constants.EMAIL_BODY(email, content);
return constants.EMAIL_BODY(email, content, "", "mobile", "email", `email=${email}`);

Check warning on line 414 in src/auth-service/utils/email.msgs.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/utils/email.msgs.js#L414

Added line #L414 was not covered by tests
},

report: (senderEmail, recepientEmail, formart) => {
Expand Down
12 changes: 6 additions & 6 deletions src/auth-service/utils/email.templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ module.exports = {
<br />
</td>
</tr>`;
return constants.EMAIL_BODY(email, content);
return constants.EMAIL_BODY(email, content, "", "analytics", "email", `email=${email}&mongo_user_id=${user_id}`);

Check warning on line 100 in src/auth-service/utils/email.templates.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/utils/email.templates.js#L100

Added line #L100 was not covered by tests
},

acceptInvitation: ({
Expand Down Expand Up @@ -149,7 +149,7 @@ module.exports = {
return constants.EMAIL_BODY(email, content);
},

afterEmailVerification: (firstName, username, email) => {
afterEmailVerification: (firstName, username, email, user_id) => {

Check warning on line 152 in src/auth-service/utils/email.templates.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/utils/email.templates.js#L152

Added line #L152 was not covered by tests
const name = firstName;
const content = ` <tr>
<td
Expand All @@ -174,10 +174,10 @@ module.exports = {
The AirQo Data Team
</td>
</tr>`;
return constants.EMAIL_BODY(email, content, name);
return constants.EMAIL_BODY(email, content, name, "analytics", "email", `email=${email}&mongo_user_id=${user_id}`);

Check warning on line 177 in src/auth-service/utils/email.templates.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/utils/email.templates.js#L177

Added line #L177 was not covered by tests
},

afterAcceptingInvitation: ({ firstName, username, email, entity_title }) => {
afterAcceptingInvitation: ({ firstName, username, email, entity_title, user_id }) => {

Check warning on line 180 in src/auth-service/utils/email.templates.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/utils/email.templates.js#L180

Added line #L180 was not covered by tests
const name = firstName;
const content = ` <tr>
<td
Expand All @@ -202,7 +202,7 @@ module.exports = {
The AirQo Data Team
</td>
</tr>`;
return constants.EMAIL_BODY(email, content, name);
return constants.EMAIL_BODY(email, content, name, "analytics", "email", `email=${email}&mongo_user_id=${user_id}`);

Check warning on line 205 in src/auth-service/utils/email.templates.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/utils/email.templates.js#L205

Added line #L205 was not covered by tests
},

deleteMobileAccountEmail: (email, token) => {
Expand All @@ -227,6 +227,6 @@ module.exports = {
<br />
</td>
</tr>`;
return constants.EMAIL_BODY(email, content);
return constants.EMAIL_BODY(email, content, "", "mobile", "email", `email=${email}`);

Check warning on line 230 in src/auth-service/utils/email.templates.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/utils/email.templates.js#L230

Added line #L230 was not covered by tests
},
};
Loading

0 comments on commit f27d5c8

Please sign in to comment.