Skip to content

Commit

Permalink
Merge pull request #4159 from sap-labs-france/master-qa
Browse files Browse the repository at this point in the history
Version 2.7.6 - CPMS domain name + fix
  • Loading branch information
Claude ROSSI authored Mar 27, 2023
2 parents 3afb296 + b1554f3 commit 6bc2945
Show file tree
Hide file tree
Showing 14 changed files with 361 additions and 224 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
39 changes: 35 additions & 4 deletions src/server/rest/v1/service/AuthorizationService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Action, AuthorizationActions, AuthorizationContext, AuthorizationFilter, DynamicAuthorizationsFilter, Entity } from '../../../../types/Authorization';
import { AssetDataResult, BillingAccountsDataResult, BillingInvoiceDataResult, BillingPaymentMethodDataResult, BillingTaxDataResult, BillingTransfersDataResult, CarCatalogDataResult, CarDataResult, ChargingProfileDataResult, ChargingStationDataResult, ChargingStationTemplateDataResult, CompanyDataResult, LogDataResult, OcpiEndpointDataResult, PricingDefinitionDataResult, RegistrationTokenDataResult, SettingDBDataResult, SiteAreaDataResult, SiteDataResult, SiteUserDataResult, TagDataResult, TransactionDataResult, TransactionInErrorDataResult, UserDataResult, UserSiteDataResult } from '../../../../types/DataResult';
import { AssetDataResult, BillingAccountsDataResult, BillingInvoiceDataResult, BillingPaymentMethodDataResult, BillingTaxDataResult, BillingTransfersDataResult, CarCatalogDataResult, CarDataResult, ChargingProfileDataResult, ChargingStationDataResult, ChargingStationTemplateDataResult, CompanyDataResult, LogDataResult, OcpiEndpointDataResult, PricingDefinitionDataResult, RegistrationTokenDataResult, SettingDBDataResult, SiteAreaDataResult, SiteDataResult, SiteUserDataResult, StatisticDataResult, TagDataResult, TransactionDataResult, TransactionInErrorDataResult, UserDataResult, UserSiteDataResult } from '../../../../types/DataResult';
import { BillingAccount, BillingInvoice, BillingPaymentMethod, BillingTax, BillingTransfer } from '../../../../types/Billing';
import { Car, CarCatalog } from '../../../../types/Car';
import { ChargePointStatus, OCPPProtocol, OCPPVersion } from '../../../../types/ocpp/OCPPServer';
Expand Down Expand Up @@ -31,6 +31,7 @@ import HttpByIDRequest from '../../../../types/requests/HttpByIDRequest';
import { HttpLogGetRequest } from '../../../../types/requests/HttpLogRequest';
import { HttpOCPIEndpointGetRequest } from '../../../../types/requests/HttpOCPIEndpointRequest';
import { HttpRegistrationTokenGetRequest } from '../../../../types/requests/HttpRegistrationToken';
import HttpStatisticsGetRequest from '../../../../types/requests/HttpStatisticRequest';
import { Log } from '../../../../types/Log';
import { OCPICapability } from '../../../../types/ocpi/OCPIEvse';
import OCPIEndpoint from '../../../../types/ocpi/OCPIEndpoint';
Expand Down Expand Up @@ -481,9 +482,9 @@ export default class AuthorizationService {
// Optimize data over the net
Utils.removeCanPropertiesWithFalseValue(registrationToken);
// Build OCPP URLs
registrationToken.ocpp15SOAPSecureUrl = Utils.buildOCPPServerSecureURL(tenant.id, OCPPVersion.VERSION_15, OCPPProtocol.SOAP, registrationToken.id);
registrationToken.ocpp16SOAPSecureUrl = Utils.buildOCPPServerSecureURL(tenant.id, OCPPVersion.VERSION_16, OCPPProtocol.SOAP, registrationToken.id);
registrationToken.ocpp16JSONSecureUrl = Utils.buildOCPPServerSecureURL(tenant.id, OCPPVersion.VERSION_16, OCPPProtocol.JSON, registrationToken.id);
registrationToken.ocpp15SOAPSecureUrl = Utils.buildOCPPServerSecureURL(tenant, OCPPVersion.VERSION_15, OCPPProtocol.SOAP, registrationToken.id);
registrationToken.ocpp16SOAPSecureUrl = Utils.buildOCPPServerSecureURL(tenant, OCPPVersion.VERSION_16, OCPPProtocol.SOAP, registrationToken.id);
registrationToken.ocpp16JSONSecureUrl = Utils.buildOCPPServerSecureURL(tenant, OCPPVersion.VERSION_16, OCPPProtocol.JSON, registrationToken.id);
}

public static async checkAndGetChargingStationTemplateAuthorizations(tenant: Tenant, userToken: UserToken,
Expand Down Expand Up @@ -1489,6 +1490,36 @@ export default class AuthorizationService {
return authorizations;
}

public static async checkAndGetStatisticsAuthorizations(tenant: Tenant, userToken: UserToken, authAction: Action,
filteredRequest?: Partial<HttpStatisticsGetRequest>, failsWithException = true): Promise<AuthorizationFilter> {
const authorizations: AuthorizationFilter = {
filters: {},
dataSources: new Map(),
projectFields: [],
authorized: false
};
// Check static & dynamic authorization
await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.STATISTIC, authAction, authorizations, filteredRequest, null, failsWithException);
return authorizations;
}

// Do not re-use this function for other authorizations, special case below for statistics
public static async addStatisticsAuthorizations(tenant: Tenant, userToken: UserToken,
statistics: StatisticDataResult, authorizationFilter: AuthorizationFilter): Promise<void> {
// Add Authorizations
statistics.canListUsers = await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.USER, Action.LIST, authorizationFilter);
statistics.canListChargingStations = await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.CHARGING_STATION, Action.LIST, authorizationFilter);
statistics.canListSites = await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.SITE, Action.LIST, authorizationFilter);
statistics.canListSiteAreas = await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.SITE_AREA, Action.LIST, authorizationFilter);
statistics.canExport = await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.STATISTIC, Action.EXPORT, authorizationFilter);
}

private static filterProjectFields(authFields: string[], httpProjectField: string): string[] {
// Init with authorization fields
let applicableProjectedFields = authFields;
Expand Down
Loading

0 comments on commit 6bc2945

Please sign in to comment.