Skip to content

Commit

Permalink
Merge pull request #4185 from sap-labs-france/master-labs
Browse files Browse the repository at this point in the history
Version 2.7.7
  • Loading branch information
ClaudeROSSI authored Apr 13, 2023
2 parents a0ca039 + f8c63a7 commit f9dbfcf
Show file tree
Hide file tree
Showing 18 changed files with 228 additions and 113 deletions.
15 changes: 13 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ev-server",
"version": "2.7.6",
"version": "2.7.7",
"engines": {
"node": "16.x.x",
"npm": "8.x.x"
Expand Down Expand Up @@ -149,6 +149,7 @@
"pdfkit": "^0.13.0",
"prom-client": "^14.1.0",
"qrcode": "^1.5.1",
"rate-limiter-flexible": "^2.4.1",
"rfc2047": "^4.0.1",
"role-acl": "^4.5.4",
"simple-odata-server": "^1.1.2",
Expand Down
6 changes: 4 additions & 2 deletions src/assets/schemas/common/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,13 @@
},
"carStateOfCharge": {
"type": "integer",
"sanitize": "mongo"
"sanitize": "mongo",
"nullable": true
},
"targetStateOfCharge": {
"type": "integer",
"sanitize": "mongo"
"sanitize": "mongo",
"nullable": true
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
"carStateOfCharge": {
"type": "integer",
"sanitize": "mongo",
"minimum": 1,
"maximum": 100
"minimum": 0,
"maximum": 100,
"nullable": true
},
"carOdometer": {
"type": "integer",
Expand All @@ -27,13 +28,15 @@
"type": "string",
"format": "date-time",
"customType": "date",
"sanitize": "mongo"
"sanitize": "mongo",
"nullable": true
},
"targetStateOfCharge": {
"type": "integer",
"sanitize": "mongo",
"minimum": 1,
"maximum": 100
"maximum": 100,
"nullable": true
},
"args": {
"type": "object",
Expand Down
29 changes: 26 additions & 3 deletions src/assets/storage/schemas/configuration/configuration-save.json
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,7 @@
}
},
"required": [
"disableBackup",
"smtp",
"smtpBackup"
"smtp"
]
},
"Authorization": {
Expand Down Expand Up @@ -659,6 +657,31 @@
"nbrTasksInParallel"
]
},
"Shield": {
"type": "object",
"properties": {
"active": {
"type": "boolean"
},
"rateLimiters": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"numberOfPoints": {
"type": "number"
},
"numberOfSeconds": {
"type": "number"
}
}
}
}
}
},
"Scheduler": {
"type": "object",
"properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ export default class SapSmartChargingIntegration extends SmartChargingIntegratio
if (transaction.stateOfCharge > 0) {
customCar.startCapacity = (transaction.stateOfCharge / 100) * customCar.maxCapacity;
// Check if manual state of charge is available
} else if (transaction.carStateOfCharge > 0) {
} else if (transaction.carStateOfCharge >= 0) {
customCar.startCapacity = (transaction.carStateOfCharge / 100) * customCar.maxCapacity;
// Handle if no state of charge is available
} else {
Expand Down
66 changes: 5 additions & 61 deletions src/notification/email/EMailNotificationTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import LoggingHelper from '../../utils/LoggingHelper';
import NotificationTask from '../NotificationTask';
import { ServerAction } from '../../types/Server';
import Tenant from '../../types/Tenant';
import TenantStorage from '../../storage/mongodb/TenantStorage';
import User from '../../types/User';
import Utils from '../../utils/Utils';
import mjmlBuilder from './EmailMjmlBuilder';
Expand All @@ -25,7 +24,6 @@ const MODULE_NAME = 'EMailNotificationTask';
export default class EMailNotificationTask implements NotificationTask {
private emailConfig: EmailConfiguration = Configuration.getEmailConfig();
private smtpMainClientInstance: SMTPClient;
private smtpBackupClientInstance: SMTPClient;

public constructor() {
// Connect to the SMTP servers
Expand All @@ -39,16 +37,6 @@ export default class EMailNotificationTask implements NotificationTask {
ssl: this.emailConfig.smtp.secure
});
}
if (!this.emailConfig.disableBackup && !Utils.isUndefined(this.emailConfig.smtpBackup)) {
this.smtpBackupClientInstance = new SMTPClient({
user: this.emailConfig.smtpBackup.user,
password: this.emailConfig.smtpBackup.password,
host: this.emailConfig.smtpBackup.host,
port: this.emailConfig.smtpBackup.port,
tls: this.emailConfig.smtpBackup.requireTLS,
ssl: this.emailConfig.smtpBackup.secure
});
}
}

public async sendNewRegisteredUser(data: NewRegisteredUserNotification, user: User, tenant: Tenant, severity: NotificationSeverity): Promise<NotificationResult> {
Expand Down Expand Up @@ -239,7 +227,7 @@ export default class EMailNotificationTask implements NotificationTask {
return await this.prepareAndSendEmail('user-create-password', data, user, tenant, severity);
}

private async sendEmail(email: EmailNotificationMessage, data: any, tenant: Tenant, user: User, severity: NotificationSeverity, useSmtpClientBackup = false): Promise<void> {
private async sendEmail(email: EmailNotificationMessage, data: any, tenant: Tenant, user: User, severity: NotificationSeverity): Promise<void> {
// Email configuration sanity checks
if (!this.smtpMainClientInstance) {
// No suitable main SMTP server configuration found to send the email
Expand All @@ -256,25 +244,9 @@ export default class EMailNotificationTask implements NotificationTask {
});
return;
}
if (useSmtpClientBackup && !this.smtpBackupClientInstance) {
// No suitable backup SMTP server configuration found or activated to send the email
await Logging.logError({
tenantID: tenant.id,
siteID: data?.siteID,
siteAreaID: data?.siteAreaID,
companyID: data?.companyID,
chargingStationID: data?.chargeBoxID,
action: ServerAction.EMAIL_NOTIFICATION,
module: MODULE_NAME, method: 'sendEmail',
message: 'No suitable backup SMTP server configuration found or activated to send email after an error on the main SMTP server',
actionOnUser: user
});
return;
}
// Create the message
const messageToSend = new Message({
from: !this.emailConfig.disableBackup && !Utils.isUndefined(this.emailConfig.smtpBackup) && useSmtpClientBackup ?
this.emailConfig.smtpBackup.from : this.emailConfig.smtp.from,
from: this.emailConfig.smtp.from,
to: email.to,
cc: email.cc,
bcc: email.bccNeeded && email.bcc ? email.bcc : '',
Expand Down Expand Up @@ -302,7 +274,7 @@ export default class EMailNotificationTask implements NotificationTask {
}
try {
// Get the SMTP client
const smtpClient = this.getSMTPClient(useSmtpClientBackup);
const smtpClient = this.getSMTPClient();
// Send the message
const messageSent: Message = await smtpClient.sendAsync(messageToSend);
// Email sent successfully
Expand Down Expand Up @@ -341,29 +313,6 @@ export default class EMailNotificationTask implements NotificationTask {
error: error.stack,
}
});
// Second try
let smtpFailed = true;
if (error instanceof SMTPError) {
const err: SMTPError = error;
switch (err.smtp) {
case 421:
case 432:
case 450:
case 451:
case 452:
case 454:
case 455:
case 510:
case 511:
case 550:
smtpFailed = false;
break;
}
}
// Use email backup?
if (smtpFailed && !useSmtpClientBackup) {
await this.sendEmail(email, data, tenant, user, severity, true);
}
}
}

Expand All @@ -388,10 +337,8 @@ export default class EMailNotificationTask implements NotificationTask {
subject: `e-Mobility - ${tenant.name} - ${title}`,
html: html
};
// We may have a fallback - Not used anymore
const useSmtpClientFallback = false;
// Send the email
await this.sendEmail(emailContent, context, tenant, recipient, severity, useSmtpClientFallback);
await this.sendEmail(emailContent, context, tenant, recipient, severity);
return emailContent;
}

Expand Down Expand Up @@ -468,10 +415,7 @@ export default class EMailNotificationTask implements NotificationTask {
};
}

private getSMTPClient(useSmtpClientBackup: boolean): SMTPClient {
if (useSmtpClientBackup) {
return this.smtpBackupClientInstance;
}
private getSMTPClient(): SMTPClient {
return this.smtpMainClientInstance;
}
}
Loading

0 comments on commit f9dbfcf

Please sign in to comment.