Get rid of role in Auth framework 1/2
MODIFY
src/authorization/DynamicAuthorizationFilter.ts
src/authorization/DynamicAuthorizationFilter.ts
-import { AuthorizationFilter } from '../types/Authorization';
+import { AuthorizationFilter, Entity } from '../types/Authorization';
+
import Tenant from '../types/Tenant';
import UserToken from '../types/UserToken';
export default interface DynamicAuthorizationFilter {
processFilter(tenant: Tenant, userToken: UserToken, authorizationFilters: AuthorizationFilter,
extraFilters: Record<string, any>): Promise<void>;
+
+ getEntities(): Entity[];
+
+ getDataSources(): string[];
}

MODIFY
src/authorization/dynamic-filters/AssignedSitesCompaniesDynamicAuthorizationFilter.ts
src/authorization/dynamic-filters/AssignedSitesCompaniesDynamicAuthorizationFilter.ts
-import { AuthorizationFilter } from '../../types/Authorization';
+import { AuthorizationFilter, Entity } from '../../types/Authorization';
+
import AuthorizationService from '../../server/rest/v1/service/AuthorizationService';
import DynamicAuthorizationFilter from '../DynamicAuthorizationFilter';
import Tenant from '../../types/Tenant';
@@ -7,6 +8,7 @@ import UserToken from '../../types/UserToken';
import Utils from '../../utils/Utils';
export default class AssignedSitesCompaniesDynamicAuthorizationFilter implements DynamicAuthorizationFilter {
+ // TODO: Process the assigned company IDs from the extraFilters (do not call the DB)
public async processFilter(tenant: Tenant, userToken: UserToken,
authorizationFilters: AuthorizationFilter, extraFilters: Record<string, any>): Promise<void> {
if (Utils.isTenantComponentActive(tenant, TenantComponents.ORGANIZATION)) {
@@ -31,4 +33,12 @@ export default class AssignedSitesCompaniesDynamicAuthorizationFilter implements
authorizationFilters.authorized = true;
}
}
+
+ public getEntities(): Entity[] {
+ return [Entity.COMPANY, Entity.COMPANIES];
+ }
+
+ getDataSources(): string[] {
+ return [];
+ }
}

MODIFY
src/server/rest/v1/service/AuthorizationService.ts
src/server/rest/v1/service/AuthorizationService.ts
@@ -454,6 +454,7 @@ export default class AuthorizationService {
}
public static async addCompanyAuthorizations(tenant: Tenant, userToken: UserToken, company: Company): Promise<void> {
+ // TODO: Use the Data Provider in the Extra context
// Enrich
if (!company.issuer) {
company.canRead = true;
@@ -503,6 +504,7 @@ export default class AuthorizationService {
authorized: false,
};
// Check static auth
+ // TODO: Can get here the Data Provider (AssignedCompanyIDs) + Intantiate them + Get the Data: JSon: { assignedCompanyIDs: [...]}
const authorizationContext: AuthorizationContext = {};
const authResult = await Authorizations.canReadCompany(userToken, authorizationContext);
authorizationFilters.authorized = authResult.authorized;
@@ -516,6 +518,7 @@ export default class AuthorizationService {
});
}
// Process dynamic filters
+ // TODO: Pass here the JSon Data from all the Data Provider to the extra filter
await AuthorizationService.processDynamicFilters(tenant, userToken, Action.READ, Entity.COMPANY,
authorizationFilters, authorizationContext, { CompanyID: filteredRequest.ID });
// Filter projected fields

MODIFY
src/server/rest/v1/service/CompanyService.ts
src/server/rest/v1/service/CompanyService.ts
@@ -57,8 +57,6 @@ export default class CompanyService {
req.tenant, req.user, filteredRequest.ID, Action.READ, action, {
withLogo: true
}, true);
- // Add authorizations
- await AuthorizationService.addCompanyAuthorizations(req.tenant, req.user, company);
// Return
res.json(company);
next();

MODIFY
src/server/rest/v1/service/UtilsService.ts
src/server/rest/v1/service/UtilsService.ts
@@ -106,6 +106,7 @@ export default class UtilsService {
// Check mandatory fields
UtilsService.assertIdIsProvided(action, companyID, MODULE_NAME, 'checkAndGetCompanyAuthorization', userToken);
// Get dynamic auth
+ // TODO: Should have Provider data in the authorizationFilter
const authorizationFilter = await AuthorizationService.checkAndGetCompanyAuthorizationFilters(
tenant, userToken, { ID: companyID });
if (!authorizationFilter.authorized) {
@@ -136,6 +137,7 @@ export default class UtilsService {
});
}
// Add actions
+ // TODO: Pass the data from Data Provider as extraFilters
await AuthorizationService.addCompanyAuthorizations(tenant, userToken, company);
// Check
const authorized = AuthorizationService.canPerfomAuthorizationAction(company, authAction);

Get rid of role in Auth framework 1/2