Change handleGetCarMakers auth concept
MODIFY
src/authorization/Authorizations.ts
src/authorization/Authorizations.ts
@@ -566,8 +566,8 @@ export default class Authorizations {
return Authorizations.canPerformAction(loggedUser, Entity.CAR_CATALOGS, Action.LIST);
}
- public static async canReadCarCatalog(loggedUser: UserToken): Promise<boolean> {
- return Authorizations.canPerformAction(loggedUser, Entity.CAR_CATALOG, Action.READ);
+ public static async canReadCarCatalog(loggedUser: UserToken, authContext?: AuthorizationContext): Promise<AuthorizationResult> {
+ return Authorizations.can(loggedUser, Entity.CAR_CATALOG, Action.READ, authContext);
}
public static async canListCars(loggedUser: UserToken): Promise<boolean> {

MODIFY
src/server/rest/v1/service/CarService.ts
src/server/rest/v1/service/CarService.ts
@@ -107,7 +107,7 @@ export default class CarService {
const filteredRequest = CarSecurity.filterCarCatalogImagesRequest(req.query);
// Check mandatory fields
UtilsService.assertIdIsProvided(action, filteredRequest.ID, MODULE_NAME, 'handleGetCarCatalogImages', req.user);
- // Get dynamic auth
+ // Check dynamic auth
const authorizationFilter = await AuthorizationService.checkAndGetCarCatalogAuthorizationFilters(
req.tenant, req.user, { ID: filteredRequest.ID }, Action.READ);
if (!authorizationFilter.authorized) {
@@ -175,13 +175,12 @@ export default class CarService {
next();
}
- // todo: refactor
public static async handleGetCarMakers(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
- if (!Authorizations.isSuperAdmin(req.user)) {
// Check if component is active
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.CAR,
Action.READ, Entity.CAR_CATALOG, MODULE_NAME, 'handleGetCarMakers');
- }
+ // Filter
+ const filteredRequest = CarSecurity.filterCarMakersRequest(req.query);
// Check auth
if (!await Authorizations.canReadCarCatalog(req.user)) {
throw new AppAuthError({
@@ -191,16 +190,12 @@ export default class CarService {
module: MODULE_NAME, method: 'handleGetCarMakers'
});
}
- // Filter
- const filteredRequest = CarSecurity.filterCarMakersRequest(req.query);
// Get car makers
const carMakers = await CarStorage.getCarMakers({ search: filteredRequest.Search }, [ 'carMaker' ]);
res.json(carMakers);
next();
}
- // todo: above this are the car catalogs
-
public static async handleCreateCar(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
let newCar: Car;
// Check if component is active

Change handleGetCarMakers auth concept