fixed cp authorization
MODIFY
src/authorization/Authorizations.ts
src/authorization/Authorizations.ts
@@ -186,7 +186,7 @@ export default class Authorizations {
}
public static async isAuthorizedToStopTransaction(tenantID: string, chargingStation: ChargingStation,
- transaction: Transaction, tagId: string): Promise<{ user: User, alternateUser: User }> {
+ transaction: Transaction, tagId: string): Promise<{ user: User; alternateUser: User }> {
let user: User, alternateUser: User;
// Check if same user
if (tagId !== transaction.tagID) {
@@ -422,8 +422,11 @@ export default class Authorizations {
return Authorizations.canPerformAction(loggedUser, Entity.CHARGING_PROFILES, Action.LIST);
}
- public static canReadChargingProfile(loggedUser: UserToken): boolean {
- return Authorizations.canPerformAction(loggedUser, Entity.CHARGING_PROFILE, Action.READ);
+ public static canReadChargingProfile(loggedUser: UserToken, siteID: string): boolean {
+ return Authorizations.canPerformAction(loggedUser, Entity.CHARGING_PROFILE, Action.READ,{
+ site: siteID,
+ sitesAdmin: loggedUser.sitesAdmin
+ });
}
public static canListSiteAreas(loggedUser: UserToken): boolean {

MODIFY
src/server/rest/service/security/ChargingStationSecurity.ts
src/server/rest/service/security/ChargingStationSecurity.ts
@@ -196,9 +196,10 @@ export default class ChargingStationSecurity {
}
for (const chargingProfile of chargingProfiles.result) {
const filteredChargingProfile = this.filterChargingProfileResponse(chargingProfile, loggedUser);
- if (filteredChargingProfile) {
+ if (filteredChargingProfile && Object.entries(filteredChargingProfile).length !== 0) {
filteredChargingProfiles.push(filteredChargingProfile);
}
+ chargingProfiles.count = chargingProfiles.result.length;
}
chargingProfiles.result = filteredChargingProfiles;
}
@@ -209,7 +210,7 @@ export default class ChargingStationSecurity {
return null;
}
// Check auth
- if (Authorizations.canReadChargingProfile(loggedUser)) {
+ if (Authorizations.canReadChargingProfile(loggedUser, chargingProfile.chargingStation.siteArea.siteID)) {
filteredChargingProfile.id = chargingProfile.id;
filteredChargingProfile.chargingStationID = chargingProfile.chargingStationID;
filteredChargingProfile.chargePointID = chargingProfile.chargePointID;

fixed cp authorization