Skip to content

Commit

Permalink
Merge pull request #4169 from sap-labs-france/master-labs
Browse files Browse the repository at this point in the history
Version 2.7.6 - additional changes
  • Loading branch information
ClaudeROSSI authored Apr 4, 2023
2 parents 14309d9 + 3bf5d43 commit a0ca039
Show file tree
Hide file tree
Showing 17 changed files with 425 additions and 275 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"typescriptreact"
],
"jest.jestCommandLine": "npm run test -- ",
"jest.autoRun": "false"
"jest.autoRun": { "watch": "false" }
}

24 changes: 24 additions & 0 deletions src/assets/server/rest/v1/schemas/statistic/statistics-export.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@
],
"sanitize": "mongo"
},
"StartDateTime": {
"type": "string",
"format": "date-time",
"customType": "date",
"sanitize": "mongo"
},
"EndDateTime": {
"type": "string",
"format": "date-time",
"customType": "date",
"sanitize": "mongo"
},
"SiteAreaID": {
"$ref": "common#/definitions/ids"
},
"ChargingStationID": {
"$ref": "common#/definitions/string-ids"
},
"UserID": {
"$ref": "common#/definitions/ids"
},
"SiteID": {
"$ref": "common#/definitions/ids"
},
"DataCategory": {
"type": "string",
"enum": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"SiteID": {
"$ref": "common#/definitions/ids"
},
"WithAuth": {
"$ref": "common#/definitions/withAuth",
"default": false
},
"DataScope": {
"type": "string",
"enum": [
Expand Down
100 changes: 100 additions & 0 deletions src/authorization/AuthorizationsDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
'miscSegment', 'miscIsofixSeats', 'chargeStandardPower', 'chargeStandardPhase', 'hash', 'image'
]
},
{
resource: Entity.STATISTIC, action: Action.READ,
},
{
resource: Entity.STATISTIC, action: Action.EXPORT,
},
]
},
admin: {
Expand Down Expand Up @@ -553,6 +559,12 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
}
},
},
{
resource: Entity.STATISTIC, action: Action.READ,
},
{
resource: Entity.STATISTIC, action: Action.EXPORT,
},
{
resource: Entity.TRANSACTION, action: Action.LIST,
condition: {
Expand Down Expand Up @@ -1518,6 +1530,28 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
'user.name', 'user.firstName', 'user.email', 'createdOn', 'lastChangedOn'
]
},
{
resource: Entity.STATISTIC, action: Action.READ,
condition: {
Fn: 'custom:dynamicAuthorizations',
args: {
asserts: [],
filters: ['OwnUser']
}
},
attributes: ['*']
},
{
resource: Entity.STATISTIC, action: Action.EXPORT,
condition: {
Fn: 'custom:dynamicAuthorizations',
args: {
asserts: [],
filters: ['OwnUser']
}
},
attributes: ['*']
},
{
resource: Entity.TRANSACTION, action: Action.LIST,
condition: {
Expand Down Expand Up @@ -1926,6 +1960,28 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
}
},
},
{
resource: Entity.STATISTIC, action: Action.READ,
condition: {
Fn: 'custom:dynamicAuthorizations',
args: {
asserts: [],
filters: ['AssignedSites']
}
},
attributes: ['*']
},
{
resource: Entity.STATISTIC, action: Action.EXPORT,
condition: {
Fn: 'custom:dynamicAuthorizations',
args: {
asserts: [],
filters: ['AssignedSites']
}
},
attributes: ['*']
},
{
resource: Entity.TRANSACTION, action: Action.LIST,
condition: {
Expand Down Expand Up @@ -2632,6 +2688,28 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
}
},
},
{
resource: Entity.STATISTIC, action: Action.READ,
condition: {
Fn: 'custom:dynamicAuthorizations',
args: {
asserts: [],
filters: ['SitesAdmin']
}
},
attributes: ['*']
},
{
resource: Entity.STATISTIC, action: Action.EXPORT,
condition: {
Fn: 'custom:dynamicAuthorizations',
args: {
asserts: [],
filters: ['SitesAdmin']
}
},
attributes: ['*']
},
{
resource: Entity.TRANSACTION, action: Action.LIST,
condition: {
Expand Down Expand Up @@ -3120,6 +3198,28 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
'user.id', 'user.name', 'user.firstName', 'user.email', 'user.role', 'siteID', 'siteAdmin', 'siteOwner',
]
},
{
resource: Entity.STATISTIC, action: Action.READ,
condition: {
Fn: 'custom:dynamicAuthorizations',
args: {
asserts: [],
filters: ['SitesOwner']
}
},
attributes: ['*']
},
{
resource: Entity.STATISTIC, action: Action.EXPORT,
condition: {
Fn: 'custom:dynamicAuthorizations',
args: {
asserts: [],
filters: ['SitesOwner']
}
},
attributes: ['*']
},
{
resource: Entity.TRANSACTION, action: Action.READ,
condition: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ export default class SapSmartChargingIntegration extends SmartChargingIntegratio
if (chargePoint?.efficiency > 0) {
return Utils.roundTo(currentLimit * chargePoint.efficiency / 100 * numberOfConnectedPhase, 1);
}
return Utils.roundTo(currentLimit * Constants.DC_CHARGING_STATION_DEFAULT_EFFICIENCY_PERCENT * numberOfConnectedPhase, 1);
return Utils.roundTo(currentLimit * Constants.DC_CHARGING_STATION_DEFAULT_EFFICIENCY_PERCENT / 100 * numberOfConnectedPhase, 1);
}
return Utils.roundTo((currentLimit * numberOfConnectedPhase), 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,20 +491,24 @@ export default class RemotePushNotificationTask implements NotificationTask {
// Do it
startTime = Logging.traceNotificationStart();
if (!user?.mobileData?.mobileToken) {
await Logging.logDebug({
tenantID: tenant.id,
siteID: data?.siteID,
siteAreaID: data?.siteAreaID,
companyID: data?.companyID,
chargingStationID: data?.chargeBoxID,
action: ServerAction.REMOTE_PUSH_NOTIFICATION,
module: MODULE_NAME, method: 'sendRemotePushNotificationToUsers',
message: `'${notificationType}': No mobile token found for this User`,
actionOnUser: user.id,
});
// await Logging.logDebug({
// tenantID: tenant.id,
// siteID: data?.siteID,
// siteAreaID: data?.siteAreaID,
// companyID: data?.companyID,
// chargingStationID: data?.chargeBoxID,
// action: ServerAction.REMOTE_PUSH_NOTIFICATION,
// module: MODULE_NAME, method: 'sendRemotePushNotificationToUsers',
// message: `'${notificationType}': No mobile token found for this User`,
// actionOnUser: user.id,
// });
// Send nothing
return Promise.resolve();
}
if (!user?.mobileData?.mobileVersion) {
// Stop sending notifications to old version of the mobile app
return Promise.resolve();
}
// Create message
message = this.createMessage(tenant, notificationType, title, body, data, severity);
// Get the right firebase apps
Expand All @@ -524,47 +528,47 @@ export default class RemotePushNotificationTask implements NotificationTask {
);
// Error
if (response.failureCount > 0) {
void Logging.logError({
Logging.logError({
tenantID: tenant.id,
siteID: data?.siteID,
siteAreaID: data?.siteAreaID,
companyID: data?.companyID,
chargingStationID: data?.chargeBoxID,
action: ServerAction.REMOTE_PUSH_NOTIFICATION,
module: MODULE_NAME, method: 'sendRemotePushNotificationToUsers',
message: `Error when sending Notification: '${notificationType}' - Error code: '${response.results[0]?.error?.code}'`,
message: `Notification: '${notificationType}' - Error code: '${response.results[0]?.error?.code}'`,
actionOnUser: user.id,
detailedMessages: { response }
});
detailedMessages: { response, mobileData: user.mobileData }
}).catch((error) => Logging.logPromiseError(error));
// Success
} else {
// Stop sending notification
notificationSent = true;
void Logging.logDebug({
tenantID: tenant.id,
siteID: data?.siteID,
siteAreaID: data?.siteAreaID,
companyID: data?.companyID,
chargingStationID: data?.chargeBoxID,
action: ServerAction.REMOTE_PUSH_NOTIFICATION,
module: MODULE_NAME, method: 'sendRemotePushNotificationToUsers',
message: `Notification Sent: '${notificationType}' - '${title}'`,
actionOnUser: user.id,
});
// Logging.logDebug({
// tenantID: tenant.id,
// siteID: data?.siteID,
// siteAreaID: data?.siteAreaID,
// companyID: data?.companyID,
// chargingStationID: data?.chargeBoxID,
// action: ServerAction.REMOTE_PUSH_NOTIFICATION,
// module: MODULE_NAME, method: 'sendRemotePushNotificationToUsers',
// message: `Notification Sent: '${notificationType}' - '${title}'`,
// actionOnUser: user.id,
// }).catch((error) => Logging.logPromiseError(error));
}
} catch (error) {
void Logging.logError({
Logging.logError({
tenantID: tenant.id,
siteID: data?.siteID,
siteAreaID: data?.siteAreaID,
companyID: data?.companyID,
chargingStationID: data?.chargeBoxID,
action: ServerAction.REMOTE_PUSH_NOTIFICATION,
module: MODULE_NAME, method: 'sendRemotePushNotificationToUsers',
message: `Error when sending Notification: '${notificationType}' - '${error.message as string}'`,
message: `Notification: '${notificationType}' - '${error.message as string}'`,
actionOnUser: user.id,
detailedMessages: { error: error.stack }
});
}).catch((error2) => Logging.logPromiseError(error2));
}
}
} finally {
Expand Down
Loading

0 comments on commit a0ca039

Please sign in to comment.