Updated auth for Basic and Demo
MODIFY
src/authorization/Authorizations.ts
src/authorization/Authorizations.ts
@@ -313,23 +313,23 @@ export default class Authorizations {
return Authorizations.canPerformAction(loggedUser, Entity.TAG, Action.UPDATE);
}
- public static canReadUser(loggedUser: UserToken, userId: string): boolean {
+ public static canReadUser(loggedUser: UserToken, userID: string): boolean {
return Authorizations.canPerformAction(loggedUser, Entity.USER, Action.READ,
- { user: userId, owner: loggedUser.id });
+ { user: userID, owner: loggedUser.id });
}
public static canCreateUser(loggedUser: UserToken): boolean {
return Authorizations.canPerformAction(loggedUser, Entity.USER, Action.CREATE);
}
- public static canUpdateUser(loggedUser: UserToken, userId: string): boolean {
+ public static canUpdateUser(loggedUser: UserToken, userID: string): boolean {
return Authorizations.canPerformAction(loggedUser, Entity.USER, Action.UPDATE,
- { user: userId, owner: loggedUser.id });
+ { user: userID, owner: loggedUser.id });
}
- public static canDeleteUser(loggedUser: UserToken, userId: string): boolean {
+ public static canDeleteUser(loggedUser: UserToken, userID: string): boolean {
return Authorizations.canPerformAction(loggedUser, Entity.USER, Action.DELETE,
- { user: userId, owner: loggedUser.id });
+ { user: userID, owner: loggedUser.id });
}
public static canListSites(loggedUser: UserToken): boolean {
@@ -483,9 +483,9 @@ export default class Authorizations {
return Authorizations.canPerformAction(loggedUser, Entity.COMPANIES, Action.LIST);
}
- public static canReadCompany(loggedUser: UserToken, companyId: string): boolean {
+ public static canReadCompany(loggedUser: UserToken, companyID: string): boolean {
return Authorizations.canPerformAction(loggedUser, Entity.COMPANY, Action.READ,
- { company: companyId, companies: loggedUser.companies });
+ { company: companyID, companies: loggedUser.companies });
}
public static canCreateCompany(loggedUser: UserToken): boolean {
@@ -584,14 +584,14 @@ export default class Authorizations {
return Authorizations.canPerformAction(loggedUser, Entity.CONNECTION, Action.CREATE);
}
- public static canDeleteConnection(loggedUser: UserToken, userId: string): boolean {
+ public static canDeleteConnection(loggedUser: UserToken, userID: string): boolean {
return Authorizations.canPerformAction(loggedUser, Entity.CONNECTION, Action.DELETE,
- { user: userId, owner: loggedUser.id });
+ { user: userID, owner: loggedUser.id });
}
- public static canReadConnection(loggedUser: UserToken, userId: string): boolean {
+ public static canReadConnection(loggedUser: UserToken, userID: string): boolean {
return Authorizations.canPerformAction(loggedUser, Entity.CONNECTION, Action.READ,
- { user: userId, owner: loggedUser.id });
+ { user: userID, owner: loggedUser.id });
}
public static canListConnections(loggedUser: UserToken): boolean {
@@ -634,9 +634,9 @@ export default class Authorizations {
return Authorizations.canPerformAction(loggedUser, Entity.INVOICE, Action.CREATE);
}
- public static canDownloadInvoiceBilling(loggedUser: UserToken, userId: string): boolean {
+ public static canDownloadInvoiceBilling(loggedUser: UserToken, userID: string): boolean {
return Authorizations.canPerformAction(loggedUser, Entity.INVOICE, Action.DOWNLOAD,
- { user: userId, owner: loggedUser.id });
+ { user: userID, owner: loggedUser.id });
}
public static canCheckAssetConnection(loggedUser: UserToken): boolean {

MODIFY
src/server/rest/v1/service/CarService.ts
src/server/rest/v1/service/CarService.ts
@@ -443,7 +443,7 @@ export default class CarService {
UtilsService.assertIdIsProvided(action, filteredRequest.ID, MODULE_NAME, 'handleGetCar', req.user);
// Check User
let userProject: string[] = [];
- if (Authorizations.canListUsers(req.user)) {
+ if (Authorizations.canReadUser(req.user, req.user.id)) {
userProject = [ 'createdBy.name', 'createdBy.firstName', 'lastChangedBy.name', 'lastChangedBy.firstName',
'carUsers.user.id', 'carUsers.user.name', 'carUsers.user.firstName', 'carUsers.user.email', 'carUsers.default', 'carUsers.owner'
];

MODIFY
src/server/rest/v1/service/TransactionService.ts
src/server/rest/v1/service/TransactionService.ts
@@ -461,12 +461,20 @@ export default class TransactionService {
];
// Check Cars
if (Utils.isComponentActiveFromToken(req.user, TenantComponents.CAR)) {
+ if (Authorizations.canListCars(req.user)) {
projectFields = [
...projectFields,
- 'car.licensePlate', 'carCatalog.vehicleMake', 'carCatalog.vehicleModel',
+ 'carCatalog.vehicleMake', 'carCatalog.vehicleModel',
'carCatalog.vehicleModelVersion', 'carCatalog.image',
];
}
+ if (Authorizations.canUpdateCar(req.user)) {
+ projectFields = [
+ ...projectFields,
+ 'car.licensePlate',
+ ];
+ }
+ }
// Get Transaction
const transaction = await TransactionStorage.getTransaction(req.user.tenantID, filteredRequest.TransactionId, projectFields);
UtilsService.assertObjectExists(action, transaction, `Transaction with ID '${filteredRequest.TransactionId}' does not exist`,
@@ -493,12 +501,6 @@ export default class TransactionService {
delete transaction.stop.tagID;
}
}
- // Check Car
- if (!Authorizations.canReadCar(req.user)) {
- // Remove Car
- delete transaction.car;
- delete transaction.carID;
- }
// Check Dates
if (filteredRequest.StartDateTime && filteredRequest.EndDateTime &&
moment(filteredRequest.StartDateTime).isAfter(moment(filteredRequest.EndDateTime))) {
@@ -916,13 +918,20 @@ export default class TransactionService {
}
}
// Check Cars
- if (Utils.isComponentActiveFromToken(req.user, TenantComponents.CAR) &&
- Authorizations.canListCars(req.user)) {
+ if (Utils.isComponentActiveFromToken(req.user, TenantComponents.CAR)) {
+ if (Authorizations.canListCars(req.user)) {
+ projectFields = [
+ ...projectFields,
+ 'carCatalog.vehicleMake', 'carCatalog.vehicleModel', 'carCatalog.vehicleModelVersion',
+ ];
+ }
+ if (Authorizations.canUpdateCar(req.user)) {
projectFields = [
...projectFields,
- 'car.licensePlate', 'carCatalog.vehicleMake', 'carCatalog.vehicleModel', 'carCatalog.vehicleModelVersion',
+ 'car.licensePlate',
];
}
+ }
// Filter
const filteredRequest = TransactionSecurity.filterTransactionsRequest(req.query);
// Build

Updated auth for Basic and Demo