Skip to content

Commit

Permalink
Merge branch release/v8.2.0 into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
papacarlo committed Oct 21, 2024
2 parents 76d3723 + b2ea17e commit 8814293
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 32 deletions.
14 changes: 7 additions & 7 deletions Common/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
"notification": {
"rules": {
"licenseExpirationWarning": {
"enable": true,
"enable": false,
"transportType": [
"email"
],
"template": {
"title": "License expiration warning",
"title": "%s Docs license expiration warning",
"body": "Attention! Your license is about to expire on %s.\nUpon reaching this date, you will no longer be entitled to receive personal technical support and install new Docs versions released after this date."
},
"policies": {
Expand All @@ -55,33 +55,33 @@
"email"
],
"template": {
"title": "License expiration warning",
"title": "%s Docs license expiration warning",
"body": "Attention! Your license expired on %s.\nYou are no longer entitled to receive personal technical support and install new Docs versions released after this date.\nPlease contact [email protected] to discuss license renewal."
},
"policies": {
"repeatInterval": "1d"
}
},
"licenseLimitEdit": {
"enable": true,
"enable": false,
"transportType": [
"email"
],
"template": {
"title": "License connection limit warning",
"title": "%s Docs license connection limit warning",
"body": "Attention! You have reached %s%% of the %s limit set by your license."
},
"policies": {
"repeatInterval": "1h"
}
},
"licenseLimitLiveViewer": {
"enable": true,
"enable": false,
"transportType": [
"email"
],
"template": {
"title": "License connection limit warning",
"title": "%s Docs license connection limit warning",
"body": "Attention! You have reached %s%% of the live viewer %s limit set by your license."
},
"policies": {
Expand Down
14 changes: 7 additions & 7 deletions Common/sources/notificationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const notificationTypes = {

class TransportInterface {
async send(ctx, message) {}
contentGeneration(template, message) {}
contentGeneration(title, message) {}
}

class MailTransport extends TransportInterface {
Expand All @@ -72,9 +72,9 @@ class MailTransport extends TransportInterface {
return mailService.send(this.host, this.auth.user, message);
}

contentGeneration(template, message) {
contentGeneration(title, message) {
return {
subject: template.title,
subject: title,
text: message
};
}
Expand Down Expand Up @@ -106,13 +106,13 @@ class Transport {
}
}

async function notify(ctx, notificationType, message, opt_cacheKey = undefined) {
async function notify(ctx, notificationType, title, message, opt_cacheKey = undefined) {
const tenRule = ctx.getCfg(`notification.rules.${notificationType}`, config.get(`notification.rules.${notificationType}`));
if (tenRule?.enable) {
ctx.logger.debug('Notification service: notify "%s"', notificationType);
let checkRes = await checkRulePolicies(ctx, notificationType, tenRule, opt_cacheKey);
if (checkRes) {
await notifyRule(ctx, tenRule, message);
await notifyRule(ctx, tenRule, title, message);
}
}
}
Expand All @@ -132,11 +132,11 @@ async function checkRulePolicies(ctx, notificationType, tenRule, opt_cacheKey) {
return isLock;
}

async function notifyRule(ctx, tenRule, message) {
async function notifyRule(ctx, tenRule, title, message) {
const transportObjects = tenRule.transportType.map(transport => new Transport(ctx, transport));
for (const transportObject of transportObjects) {
try {
const mail = transportObject.transport.contentGeneration(tenRule.template, message);
const mail = transportObject.transport.contentGeneration(title, message);
await transportObject.transport.send(ctx, mail);
} catch (error) {
ctx.logger.error('Notification service: error: %s', error.stack);
Expand Down
16 changes: 9 additions & 7 deletions DocService/sources/DocsCoServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ const cfgForgottenFiles = config.get('services.CoAuthoring.server.forgottenfiles
const cfgForgottenFilesName = config.get('services.CoAuthoring.server.forgottenfilesname');
const cfgMaxRequestChanges = config.get('services.CoAuthoring.server.maxRequestChanges');
const cfgWarningLimitPercents = config.get('license.warning_limit_percents');
const cfgNotificationRuleLicenseLimitEdit = config.get('notification.rules.licenseLimitEdit.template.body');
const cfgNotificationRuleLicenseLimitLiveViewer = config.get('notification.rules.licenseLimitLiveViewer.template.body');
const cfgNotificationRuleLicenseLimitEdit = config.get('notification.rules.licenseLimitEdit.template');
const cfgNotificationRuleLicenseLimitLiveViewer = config.get('notification.rules.licenseLimitLiveViewer.template');
const cfgErrorFiles = config.get('FileConverter.converter.errorfiles');
const cfgOpenProtectedFile = config.get('services.CoAuthoring.server.openProtectedFile');
const cfgIsAnonymousSupport = config.get('services.CoAuthoring.server.isAnonymousSupport');
Expand Down Expand Up @@ -3481,8 +3481,8 @@ exports.install = function(server, callbackFunction) {

function* _checkLicenseAuth(ctx, licenseInfo, userId, isLiveViewer) {
const tenWarningLimitPercents = ctx.getCfg('license.warning_limit_percents', cfgWarningLimitPercents) / 100;
const tenNotificationRuleLicenseLimitEdit = ctx.getCfg(`notification.rules.licenseLimitEdit.template.body`, cfgNotificationRuleLicenseLimitEdit);
const tenNotificationRuleLicenseLimitLiveViewer = ctx.getCfg(`notification.rules.licenseLimitLiveViewer.template.body`, cfgNotificationRuleLicenseLimitLiveViewer);
const tenNotificationRuleLicenseLimitEdit = ctx.getCfg(`notification.rules.licenseLimitEdit.template`, cfgNotificationRuleLicenseLimitEdit);
const tenNotificationRuleLicenseLimitLiveViewer = ctx.getCfg(`notification.rules.licenseLimitLiveViewer.template`, cfgNotificationRuleLicenseLimitLiveViewer);
const c_LR = constants.LICENSE_RESULT;
let licenseType = licenseInfo.type;
if (c_LR.Success === licenseType || c_LR.SuccessLimit === licenseType) {
Expand Down Expand Up @@ -3533,14 +3533,16 @@ exports.install = function(server, callbackFunction) {
}
}
if ((c_LR.Success !== licenseType && c_LR.SuccessLimit !== licenseType) || 100 !== notificationPercent) {
const message = util.format(notificationTemplate, notificationPercent, notificationLimit);
const applicationName = (process.env.APPLICATION_NAME || "").toUpperCase();
const title = util.format(notificationTemplate.title, applicationName);
const message = util.format(notificationTemplate.body, notificationPercent, notificationLimit);
if (100 !== notificationPercent) {
ctx.logger.warn(message);
} else {
ctx.logger.error(message);
}
//todo with yield service could throw error
void notificationService.notify(ctx, notificationType, message, notificationType + notificationPercent);
void notificationService.notify(ctx, notificationType, title, message, notificationType + notificationPercent);
}
}
return licenseType;
Expand Down Expand Up @@ -4257,7 +4259,7 @@ async function proxyCommand(ctx, req, params) {
//todo gen shardkey as in sdkjs
const shardkey = params.key;
const baseUrl = utils.getBaseUrlByRequest(ctx, req);
let url = `${baseUrl}/coauthoring/command?&${constants.SHARD_KEY_API_NAME}=${encodeURIComponent(shardkey)}`;
let url = `${baseUrl}/command?&${constants.SHARD_KEY_API_NAME}=${encodeURIComponent(shardkey)}`;
for (let name in req.query) {
url += `&${name}=${encodeURIComponent(req.query[name])}`;
}
Expand Down
8 changes: 5 additions & 3 deletions DocService/sources/canvasservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -880,9 +880,11 @@ function* commandSetPassword(ctx, conn, cmd, outputData) {
let documentPasswordCurEnc = sqlBase.DocumentPassword.prototype.getCurPassword(ctx, row.password);
if (documentPasswordCurEnc) {
hasDocumentPassword = true;
const passwordCurPlain = yield utils.decryptPassword(ctx, documentPasswordCurEnc);
const passwordPlain = yield utils.decryptPassword(ctx, cmd.getPassword());
isDocumentPasswordModified = passwordCurPlain !== passwordPlain;
if (cmd.getPassword()) {
const passwordCurPlain = yield utils.decryptPassword(ctx, documentPasswordCurEnc);
const passwordPlain = yield utils.decryptPassword(ctx, cmd.getPassword());
isDocumentPasswordModified = passwordCurPlain !== passwordPlain;
}
}
}
}
Expand Down
19 changes: 11 additions & 8 deletions DocService/sources/utilsDocService.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const tenantManager = require('../../Common/sources/tenantManager');
const { notificationTypes, ...notificationService } = require('../../Common/sources/notificationService');

const cfgStartNotifyFrom = ms(config.get('license.warning_license_expiration'));
const cfgNotificationRuleLicenseExpirationWarning = config.get('notification.rules.licenseExpirationWarning.template.body');
const cfgNotificationRuleLicenseExpirationError = config.get('notification.rules.licenseExpirationError.template.body');
const cfgNotificationRuleLicenseExpirationWarning = config.get('notification.rules.licenseExpirationWarning.template');
const cfgNotificationRuleLicenseExpirationError = config.get('notification.rules.licenseExpirationError.template');

async function fixImageExifRotation(ctx, buffer) {
if (!buffer) {
Expand Down Expand Up @@ -130,16 +130,19 @@ async function notifyLicenseExpiration(ctx, endDate) {
endDate = currentDate;
}
const formattedExpirationTime = humanFriendlyExpirationTime(endDate);
const applicationName = (process.env.APPLICATION_NAME || "").toUpperCase();
if (endDate <= currentDate) {
const tenNotificationRuleLicenseExpirationError = ctx.getCfg('notification.rules.licenseExpirationError.template.body', cfgNotificationRuleLicenseExpirationError);
const message = util.format(tenNotificationRuleLicenseExpirationError, formattedExpirationTime);
const tenNotificationRuleLicenseExpirationError = ctx.getCfg('notification.rules.licenseExpirationError.template', cfgNotificationRuleLicenseExpirationError);
const title = util.format(tenNotificationRuleLicenseExpirationError.title, applicationName);
const message = util.format(tenNotificationRuleLicenseExpirationError.body, formattedExpirationTime);
ctx.logger.error(message);
await notificationService.notify(ctx, notificationTypes.LICENSE_EXPIRATION_ERROR, message);
await notificationService.notify(ctx, notificationTypes.LICENSE_EXPIRATION_ERROR, title, message);
} else {
const tenNotificationRuleLicenseExpirationWarning = ctx.getCfg('notification.rules.licenseExpirationWarning.template.body', cfgNotificationRuleLicenseExpirationWarning);
const message = util.format(tenNotificationRuleLicenseExpirationWarning, formattedExpirationTime);
const tenNotificationRuleLicenseExpirationWarning = ctx.getCfg('notification.rules.licenseExpirationWarning.template', cfgNotificationRuleLicenseExpirationWarning);
const title = util.format(tenNotificationRuleLicenseExpirationWarning.title, applicationName);
const message = util.format(tenNotificationRuleLicenseExpirationWarning.body, formattedExpirationTime);
ctx.logger.warn(message);
await notificationService.notify(ctx, notificationTypes.LICENSE_EXPIRATION_WARNING, message);
await notificationService.notify(ctx, notificationTypes.LICENSE_EXPIRATION_WARNING, title, message);
}
}
}
Expand Down

0 comments on commit 8814293

Please sign in to comment.