Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add email function for post update #4582

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion bin/scripts/version_marks.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
const fs = require('fs'),
pluginManager = require('../../plugins/pluginManager.js');
mail = require('../../api/parts/mgmt/mail'),
localize = require('../../api/utils/localization.js'),
common = require('../../api/utils/common'),
pluginManager = require('../../plugins/pluginManager.js'),
Promise = require("bluebird");

const fsMarkedVersionPath = __dirname + "/../../countly_marked_version.json";

function sendEmailToGlobalAdmins(oldVersion, newVersion) {
Promise.all([pluginManager.dbConnection("countly")]).spread(async function(countlyDb) {
pluginManager.loadConfigs(countlyDb, async function() {
let conf = pluginManager.getConfig('api'),
serverLink = conf && conf.domain ? `<a href="${conf.domain}">${conf.domain}</a>` : 'Countly Server',
admins = await countlyDb.collection('members').find({global_admin: true}).toArray();

try {
await Promise.all(
admins.map((admin) => {
localize.getProperties(admin.lang, function(err2, properties) {
var subject = localize.format(properties["mail.server-upgrade-to-global-admins-subject"], oldVersion, newVersion);
var message = localize.format(properties["mail.server-upgrade-to-global-admins"], oldVersion, newVersion, serverLink);
mail.sendMessage(admin.email, subject, message);
});
})
);
}
catch (e) {
common.log('core:mark_version').e('Error while sending update emails', e);
return 0;
}
finally {
countlyDb.close();
}
});
});
}

function writeMsg(type, msg) {
process.stdout.write(JSON.stringify(msg));
}
Expand Down Expand Up @@ -99,13 +132,15 @@ function writeFsVersion(targetVersion) {
try {
fs.writeFileSync(fsMarkedVersionPath, JSON.stringify(olderVersions));
writeMsg("info", 1);
sendEmailToGlobalAdmins(olderVersions[olderVersions.length - 1].version, targetVersion);
}
catch (error) {
writeMsg("error", error);
}
}
else {
writeMsg("info", 0);
sendEmailToGlobalAdmins(olderVersions[olderVersions.length - 1].version, targetVersion);
}
}

Expand Down
4 changes: 3 additions & 1 deletion frontend/express/public/localization/mail/mail.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ mail.password-change = Hi {0},<br/><br/>Your password for your Countly account o
mail.password-reset-subject = Countly Account - Password Reset
mail.password-reset = Hi {0},<br/><br/>You can reset your Countly account password by following <a href="{1}/reset/{2}">this link</a>.<br/><br/>If you did not request to reset your password ignore this email.<br/><br/>Best,<br/>A fellow Countly Admin
mail.time-ban-subject = {0}: Your account is locked
mail.time-ban = Hi {0},<br/><br/>Due to excess number of failed login attempts, your account has been blocked. You can use <a href="{1}/login/token/{2}">this link</a> to unlock your user and login to your dashboard for once.<br/><br/>Best<br/>A fellow admin
mail.time-ban = Hi {0},<br/><br/>Due to excess number of failed login attempts, your account has been blocked. You can use <a href="{1}/login/token/{2}">this link</a> to unlock your user and login to your dashboard for once.<br/><br/>Best<br/>A fellow admin
mail.server-upgrade-to-global-admins-subject = Countly Has Been Upgraded: {0} to {1}
mail.server-upgrade-to-global-admins = Dear Data Captain,<br/>We are delighted to inform you that the Countly server upgrade has been successfully completed.<br/><br/>Server Details:<br/>Server Name: {2}<br/>Previous Version: {0}<br/>New Version: {1}<br/>This upgrade introduces several improvements and optimizations, enhancing the performance and reliability of our Countly platform. Here you can find the release notes https://github.com/Countly/countly-server/releases/tag/{1}<br/>If you have any questions or require further information, please feel free to reach out to our support team. We appreciate your continued support and look forward to providing you with an even better user experience.<br/><br/>Best regards,<br/>Countly Team
Loading