Add canUpdate on getCompany
MODIFY
src/server/rest/v1/service/CompanyService.ts
src/server/rest/v1/service/CompanyService.ts
@@ -14,6 +14,7 @@ import Constants from '../../../../utils/Constants';
import Logging from '../../../../utils/Logging';
import { ServerAction } from '../../../../types/Server';
import TenantComponents from '../../../../types/TenantComponents';
+import { UserRole } from '../../../../types/User';
import Utils from '../../../../utils/Utils';
import UtilsService from './UtilsService';
@@ -99,6 +100,9 @@ export default class CompanyService {
// Check Company exists
UtilsService.assertObjectExists(action, company, `Company with ID '${filteredRequest.ID}' does not exist`,
MODULE_NAME, 'handleGetCompany', req.user);
+ // Add authorization
+ const assignedCompanies = await AuthorizationService.getAssignedSitesCompanyIDs(req.tenant.id, req.user);
+ company.canUpdate = req.user.role === UserRole.ADMIN || (Authorizations.canUpdateCompany(req.user) && assignedCompanies.includes(company.id));
// Return
res.json(company);
next();

Add canUpdate on getCompany