Remove AssignedSiteAreas authorization filter - not needed anymore
MODIFY
src/authorization/DynamicAuthorizationFactory.ts
src/authorization/DynamicAuthorizationFactory.ts
import { DynamicAuthorizationDataSourceData, DynamicAuthorizationDataSourceName, DynamicAuthorizationFilterName } from '../types/Authorization';
-import AssignedSiteAreasDynamicAuthorizationDataSource from './dynamic-data-source/AssignedSiteAreasDynamicAuthorizationDataSource';
-import AssignedSiteAreasDynamicAuthorizationFilter from './dynamic-filters/AssignedSiteAreasDynamicAuthorizationFilter';
import AssignedSitesCompaniesDynamicAuthorizationDataSource from './dynamic-data-source/AssignedSitesCompaniesDynamicAuthorizationDataSource';
import AssignedSitesCompaniesDynamicAuthorizationFilter from './dynamic-filters/AssignedSitesCompaniesDynamicAuthorizationFilter';
import AssignedSitesDynamicAuthorizationDataSource from './dynamic-data-source/AssignedSitesDynamicAuthorizationDataSource';
@@ -30,9 +28,6 @@ export default class DynamicAuthorizationFactory {
case DynamicAuthorizationFilterName.SITES_ADMIN:
dynamicFilter = new SitesAdminDynamicAuthorizationFilter(tenant, userToken);
break;
- case DynamicAuthorizationFilterName.ASSIGNED_SITE_AREAS:
- dynamicFilter = new AssignedSiteAreasDynamicAuthorizationFilter(tenant, userToken);
- break;
case DynamicAuthorizationFilterName.ASSIGNED_SITES:
dynamicFilter = new AssignedSitesDynamicAuthorizationFilter(tenant, userToken);
break;
@@ -78,8 +73,6 @@ export default class DynamicAuthorizationFactory {
return new AssignedSitesCompaniesDynamicAuthorizationDataSource(tenant, user);
case DynamicAuthorizationDataSourceName.SITES_ADMIN:
return new SitesAdminDynamicAuthorizationDataSource(tenant, user);
- case DynamicAuthorizationDataSourceName.ASSIGNED_SITE_AREAS:
- return new AssignedSiteAreasDynamicAuthorizationDataSource(tenant, user);
case DynamicAuthorizationDataSourceName.ASSIGNED_SITES:
return new AssignedSitesDynamicAuthorizationDataSource(tenant, user);
case DynamicAuthorizationDataSourceName.SITE_ADMIN_USERS:

DELETE
src/authorization/dynamic-data-source/AssignedSiteAreasDynamicAuthorizationDataSource.ts
-import { AssignedSiteAreasDynamicAuthorizationDataSourceData, DynamicAuthorizationDataSourceName } from '../../types/Authorization';
-
-import Constants from '../../utils/Constants';
-import DynamicAuthorizationDataSource from '../DynamicAuthorizationDataSource';
-import SiteAreaStorage from '../../storage/mongodb/SiteAreaStorage';
-import SiteStorage from '../../storage/mongodb/SiteStorage';
-import Utils from '../../utils/Utils';
-import _ from 'lodash';
-
-export default class AssignedSiteAreasDynamicAuthorizationDataSource
- extends DynamicAuthorizationDataSource<AssignedSiteAreasDynamicAuthorizationDataSourceData> {
-
- public getName(): DynamicAuthorizationDataSourceName {
- return DynamicAuthorizationDataSourceName.ASSIGNED_SITE_AREAS;
- }
-
- public async loadData(): Promise<void> {
- const assignedSiteAreasData: AssignedSiteAreasDynamicAuthorizationDataSourceData = {};
- // Get SiteArea IDs
- assignedSiteAreasData.siteAreaIDs = await this.getAssignedSiteAreaIDs();
- // Set
- this.setData(assignedSiteAreasData);
- }
-
- private async getAssignedSiteAreaIDs(): Promise<string[]> {
- // Get the SiteArea IDs from Sites assigned to the user
- const sites = await SiteStorage.getSites(this.tenant.id,
- {
- userID: this.userToken.id,
- issuer: true,
- }, Constants.DB_PARAMS_MAX_LIMIT,
- ['id']
- );
- const siteIDs = _.uniq(_.map(sites.result, 'id'));
- if (!Utils.isEmptyArray(siteIDs)) {
- const siteAreas = await SiteAreaStorage.getSiteAreas(this.tenant.id,
- {
- siteIDs: siteIDs,
- issuer: true,
- }, Constants.DB_PARAMS_MAX_LIMIT,
- ['id']
- );
- return _.uniq(_.map(siteAreas.result, 'id'));
- }
- return [];
- }
-}

DELETE
src/authorization/dynamic-filters/AssignedSiteAreasDynamicAuthorizationFilter.ts
-import { AuthorizationFilter, DynamicAuthorizationDataSourceName, Entity } from '../../types/Authorization';
-
-import AssignedSiteAreasDynamicAuthorizationDataSource from '../dynamic-data-source/AssignedSiteAreasDynamicAuthorizationDataSource';
-import DynamicAuthorizationFilter from '../DynamicAuthorizationFilter';
-import Utils from '../../utils/Utils';
-
-export default class AssignedSiteAreasDynamicAuthorizationFilter extends DynamicAuthorizationFilter {
- public processFilter(authorizationFilters: AuthorizationFilter, extraFilters: Record<string, any>): void {
- // Get Site IDs
- const assignedSiteAreasDataSource = this.getDataSource(
- DynamicAuthorizationDataSourceName.ASSIGNED_SITE_AREAS) as AssignedSiteAreasDynamicAuthorizationDataSource;
- const { siteAreaIDs } = assignedSiteAreasDataSource.getData();
- // Check
- if (!Utils.isEmptyArray(siteAreaIDs)) {
- // Force the filter
- authorizationFilters.filters.siteAreaIDs = siteAreaIDs;
- // Check if filter is provided
- if (Utils.objectHasProperty(extraFilters, 'SiteAreaID') &&
- !Utils.isNullOrUndefined(extraFilters['SiteAreaID'])) {
- const filteredSiteAreaIDs: string[] = extraFilters['SiteAreaID'].split('|');
- // Override
- authorizationFilters.filters.siteAreaIDs = filteredSiteAreaIDs.filter(
- (siteID) => authorizationFilters.filters.siteAreaIDs.includes(siteID));
- }
- }
- if (!Utils.isEmptyArray(authorizationFilters.filters.siteAreaIDs)) {
- authorizationFilters.authorized = true;
- }
- }
-
- public getApplicableEntities(): Entity[] {
- return [
- Entity.SITE_AREAS
- ];
- }
-
- public getApplicableDataSources(): DynamicAuthorizationDataSourceName[] {
- return [
- DynamicAuthorizationDataSourceName.ASSIGNED_SITE_AREAS
- ];
- }
-}

MODIFY
src/types/Authorization.ts
src/types/Authorization.ts
@@ -199,7 +199,6 @@ export interface SiteAuthorizationActions extends AuthorizationActions {
export enum DynamicAuthorizationFilterName {
ASSIGNED_SITES_COMPANIES = 'AssignedSitesCompanies',
SITES_ADMIN = 'SitesAdmin',
- ASSIGNED_SITE_AREAS = 'AssignedSiteAreas',
ASSIGNED_SITES = 'AssignedSites',
SITE_ADMIN_USERS = 'SiteAdminUsers',
OWN_USER = 'OwnUser',
@@ -208,7 +207,6 @@ export enum DynamicAuthorizationFilterName {
export enum DynamicAuthorizationDataSourceName {
ASSIGNED_SITES_COMPANIES = 'AssignedSitesCompanies',
SITES_ADMIN = 'SitesAdmin',
- ASSIGNED_SITE_AREAS = 'AssignedSiteAreas',
ASSIGNED_SITES = 'AssignedSites',
SITE_ADMIN_USERS = 'SiteAdminUsers',
OWN_USER = 'OwnUser',
@@ -224,10 +222,6 @@ export interface SitesAdminDynamicAuthorizationDataSourceData extends DynamicAut
siteIDs?: string[];
}
-export interface AssignedSiteAreasDynamicAuthorizationDataSourceData extends DynamicAuthorizationDataSourceData {
- siteAreaIDs?: string[];
-}
-
export interface AssignedSitesDynamicAuthorizationDataSourceData extends DynamicAuthorizationDataSourceData {
siteIDs?: string[];
}

Remove AssignedSiteAreas authorization filter - not needed anymore