diff --git a/bin/scripts/version_marks.js b/bin/scripts/version_marks.js index 6945ffbd033..99242090e85 100644 --- a/bin/scripts/version_marks.js +++ b/bin/scripts/version_marks.js @@ -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 ? `${conf.domain}` : '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)); } @@ -99,6 +132,7 @@ 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); @@ -106,6 +140,7 @@ function writeFsVersion(targetVersion) { } else { writeMsg("info", 0); + sendEmailToGlobalAdmins(olderVersions[olderVersions.length - 1].version, targetVersion); } } diff --git a/frontend/express/public/localization/mail/mail.properties b/frontend/express/public/localization/mail/mail.properties index 4057182d877..1e58a5d1f3c 100644 --- a/frontend/express/public/localization/mail/mail.properties +++ b/frontend/express/public/localization/mail/mail.properties @@ -7,4 +7,6 @@ mail.password-change = Hi {0},

Your password for your Countly account o mail.password-reset-subject = Countly Account - Password Reset mail.password-reset = Hi {0},

You can reset your Countly account password by following this link.

If you did not request to reset your password ignore this email.

Best,
A fellow Countly Admin mail.time-ban-subject = {0}: Your account is locked -mail.time-ban = Hi {0},

Due to excess number of failed login attempts, your account has been blocked. You can use this link to unlock your user and login to your dashboard for once.

Best
A fellow admin \ No newline at end of file +mail.time-ban = Hi {0},

Due to excess number of failed login attempts, your account has been blocked. You can use this link to unlock your user and login to your dashboard for once.

Best
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,
We are delighted to inform you that the Countly server upgrade has been successfully completed.

Server Details:
Server Name: {2}
Previous Version: {0}
New Version: {1}
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}
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.

Best regards,
Countly Team \ No newline at end of file