Skip to content

Commit

Permalink
Merge pull request #1005 from sap-labs-france/read_transaction
Browse files Browse the repository at this point in the history
Prevent reading connector transaction when not authorized
  • Loading branch information
AlixH authored May 15, 2023
2 parents bfcb60b + 869f364 commit dda4eb4
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
"react-native-elements": "^3.4.2",
"react-native-gesture-handler": "^2.8.0",
"react-native-keyboard-aware-scroll-view": "^0.9.5",
"react-native-localize": "^2.2.4",
"react-native-localize": "2.2.4",
"react-native-location": "^2.5.0",
"react-native-map-clustering": "^3.4.2",
"react-native-map-link": "^2.10.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export default class ChargingStationConnectorDetails extends BaseAutoRefreshScre
return transaction;
} catch (error) {
// Check if HTTP?
if (!error.request || error.request.status !== HTTPAuthError.FORBIDDEN) {
if (!error.request || error.request.status !== StatusCodes.FORBIDDEN) {
await Utils.handleHttpUnexpectedError(
this.centralServerProvider,
error,
Expand Down Expand Up @@ -367,7 +367,7 @@ export default class ChargingStationConnectorDetails extends BaseAutoRefreshScre
siteImage = await this.getSiteImage(chargingStation?.siteArea?.siteID);
}
// Get Current Transaction
if (connector?.currentTransactionID) {
if (connector?.currentTransactionID && connector?.canReadTransaction) {
transaction = await this.getTransaction(connector.currentTransactionID);
}
// // Compute Duration
Expand Down Expand Up @@ -1150,7 +1150,6 @@ export default class ChargingStationConnectorDetails extends BaseAutoRefreshScre
);
}

// TODO reload session context when changing car (at least to check again the availability of car connector)
private renderCarSelection(style: any) {
const { navigation } = this.props;
const { sessionContextLoading, selectedUser, selectedCar, connector } = this.state;
Expand Down
6 changes: 3 additions & 3 deletions src/screens/transactions/chart/TransactionChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import TransactionHeaderComponent from '../../../components/transaction/header/T
import BaseProps from '../../../types/BaseProps';
import ChargingStation, { Connector } from '../../../types/ChargingStation';
import Consumption from '../../../types/Consumption';
import { HTTPAuthError } from '../../../types/HTTPError';
import Transaction from '../../../types/Transaction';
import Constants from '../../../utils/Constants';
import Utils from '../../../utils/Utils';
Expand All @@ -19,6 +18,7 @@ import computeStyleSheet from './TransactionChartStyles';
import { HttpChargingStationRequest } from '../../../types/requests/HTTPChargingStationRequests';
import I18nManager, { NumberFormatStyleEnum } from '../../../I18n/I18nManager';
import DurationUnitFormat from 'intl-unofficial-duration-unit-format';
import {StatusCodes} from 'http-status-codes';

export interface Props extends BaseProps {}

Expand Down Expand Up @@ -90,7 +90,7 @@ export default class TransactionChart extends BaseAutoRefreshScreen<Props, State
if (chargingStation) {
connector = chargingStation ? chargingStation.connectors[Utils.convertToInt(connectorID) - 1] : null;
// Refresh Consumption
if (connector?.currentTransactionID && (!this.state.transaction || !this.state.transaction.stop)) {
if (connector?.currentTransactionID && (!this.state.transaction || !this.state.transaction.stop) && connector?.canReadTransaction) {
transactionWithConsumptions = await this.getTransactionWithConsumptions(connector?.currentTransactionID);
}
}
Expand Down Expand Up @@ -155,7 +155,7 @@ export default class TransactionChart extends BaseAutoRefreshScreen<Props, State
}
} catch (error) {
// Check if HTTP?
if (!error.request || error.request.status !== HTTPAuthError.FORBIDDEN) {
if (!error.request || error.request.status !== StatusCodes.FORBIDDEN) {
// Other common Error
await Utils.handleHttpUnexpectedError(
this.centralServerProvider,
Expand Down
1 change: 1 addition & 0 deletions src/types/ChargingStation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export interface Connector {
numberOfConnectedPhase?: number;
currentType?: CurrentType;
chargePointID?: number;
canReadTransaction?: boolean;
}

export enum ChargePointStatus {
Expand Down

0 comments on commit dda4eb4

Please sign in to comment.