Fixed auth on Companies
MODIFY
src/server/rest/v1/service/AuthorizationService.ts
src/server/rest/v1/service/AuthorizationService.ts
@@ -69,6 +69,7 @@ export default class AuthorizationService {
public static async addSitesAuthorizations(tenant: Tenant, userToken: UserToken, sites: Site[]): Promise<void> {
// Get Site Admins
+ // TODO: Should be done like company
const { siteAdminIDs, siteOwnerIDs } = await AuthorizationService.getSiteAdminOwnerIDs(tenant, userToken);
// Set to user
userToken.sitesAdmin = siteAdminIDs;
@@ -377,11 +378,17 @@ export default class AuthorizationService {
const assignedCompanies = await AuthorizationService.getAssignedSitesCompanyIDs(tenant.id, userToken);
// Enrich
for (const company of companies) {
+ if (userToken.role === UserRole.ADMIN) {
+ company.canRead = true;
+ company.canUpdate = true;
+ company.canDelete = true;
+ } else {
company.canRead = Authorizations.canReadCompany(userToken) && assignedCompanies.includes(company.id);
company.canUpdate = Authorizations.canUpdateCompany(userToken) && assignedCompanies.includes(company.id);
company.canDelete = Authorizations.canDeleteCompany(userToken) && assignedCompanies.includes(company.id);
}
}
+ }
public static async checkAndGetCompaniesAuthorizationFilters(tenant: Tenant, userToken: UserToken, filteredRequest: HttpCompaniesRequest): Promise<AuthorizationFilter> {
const authorizationFilters: AuthorizationFilter = {

Fixed auth on Companies