Change getSiteArea logic
MODIFY
src/authorization/Authorizations.ts
src/authorization/Authorizations.ts
@@ -521,26 +521,24 @@ export default class Authorizations {
});
}
- public static async canListSiteAreas(loggedUser: UserToken): Promise<boolean> {
- return Authorizations.canPerformAction(loggedUser, Entity.SITE_AREAS, Action.LIST);
+ public static async canListSiteAreas(loggedUser: UserToken, authContext?: AuthorizationContext): Promise<AuthorizationResult> {
+ return Authorizations.can(loggedUser, Entity.SITE_AREAS, Action.LIST, authContext);
}
- public static async canReadSiteArea(loggedUser: UserToken): Promise<boolean> {
- return Authorizations.canPerformAction(loggedUser, Entity.SITE_AREA, Action.READ);
+ public static async canReadSiteArea(loggedUser: UserToken, authContext?: AuthorizationContext): Promise<AuthorizationResult> {
+ return Authorizations.can(loggedUser, Entity.SITE_AREA, Action.READ, authContext);
}
- public static async canCreateSiteArea(loggedUser: UserToken): Promise<boolean> {
- return Authorizations.canPerformAction(loggedUser, Entity.SITE_AREA, Action.CREATE);
+ public static async canCreateSiteArea(loggedUser: UserToken, authContext?: AuthorizationContext): Promise<AuthorizationResult> {
+ return Authorizations.can(loggedUser, Entity.SITE_AREA, Action.CREATE, authContext);
}
- public static async canUpdateSiteArea(loggedUser: UserToken, siteID?: string): Promise<boolean> {
- return Authorizations.canPerformAction(loggedUser, Entity.SITE_AREA, Action.UPDATE, {
- site: siteID, sites: loggedUser.sitesAdmin
- });
+ public static async canUpdateSiteArea(loggedUser: UserToken, authContext?: AuthorizationContext): Promise<AuthorizationResult> {
+ return Authorizations.can(loggedUser, Entity.SITE_AREA, Action.UPDATE, authContext);
}
- public static async canDeleteSiteArea(loggedUser: UserToken): Promise<boolean> {
- return Authorizations.canPerformAction(loggedUser, Entity.SITE_AREA, Action.DELETE);
+ public static async canDeleteSiteArea(loggedUser: UserToken, authContext?: AuthorizationContext): Promise<AuthorizationResult> {
+ return Authorizations.can(loggedUser, Entity.SITE_AREA, Action.DELETE, authContext);
}
public static async canListCompanies(loggedUser: UserToken, authContext?: AuthorizationContext): Promise<AuthorizationResult> {

MODIFY
src/authorization/AuthorizationsDefinition.ts
src/authorization/AuthorizationsDefinition.ts
@@ -30,9 +30,12 @@ const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
resource: Entity.USER, action: Action.DELETE, attributes: ['*'],
condition: { Fn: 'NOT_EQUALS', args: { 'user': '$.owner' } },
},
- { resource: Entity.COMPANIES, action: Action.LIST, attributes: [
+ {
+ resource: Entity.COMPANIES, action: Action.LIST, attributes: [
'id', 'name', 'address', 'logo', 'issuer', 'distanceMeters', 'createdOn', 'lastChangedOn',
- 'createdBy.name', 'createdBy.firstName', 'lastChangedBy.name', 'lastChangedBy.firstName' ] },
+ 'createdBy.name', 'createdBy.firstName', 'lastChangedBy.name', 'lastChangedBy.firstName'
+ ]
+ },
{ resource: Entity.TAGS, action: [Action.LIST, Action.IMPORT], attributes: ['*'] },
{ resource: Entity.TAG, action: [Action.CREATE, Action.UPDATE, Action.DELETE, Action.READ], attributes: ['*'] },
{ resource: Entity.CHARGING_PROFILES, action: Action.LIST, attributes: ['*'] },
@@ -41,11 +44,19 @@ const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
{ resource: Entity.COMPANY, action: [Action.CREATE, Action.UPDATE, Action.DELETE], attributes: ['*'] },
{ resource: Entity.SITES, action: Action.LIST, attributes: ['*'] },
{ resource: Entity.SITE, action: [Action.CREATE, Action.READ, Action.UPDATE, Action.DELETE], attributes: ['*'] },
- { resource: Entity.SITE_AREAS, action: Action.LIST, attributes: [
+ {
+ resource: Entity.SITE_AREAS, action: Action.LIST, attributes: [
'id', 'name', 'siteID', 'maximumPower', 'voltage', 'numberOfPhases', 'accessControl', 'smartCharging', 'address',
'site.id', 'site.name', 'issuer', 'distanceMeters', 'createdOn', 'createdBy', 'lastChangedOn', 'lastChangedBy'
- ] },
- { resource: Entity.SITE_AREA, action: [Action.CREATE, Action.READ, Action.UPDATE, Action.DELETE], attributes: ['*'] },
+ ]
+ },
+ {
+ resource: Entity.SITE_AREA, action: Action.READ, attributes: [
+ 'id', 'name', 'issuer', 'image', 'address', 'maximumPower', 'numberOfPhases',
+ 'voltage', 'smartCharging', 'accessControl', 'connectorStats', 'siteID', 'site.name'
+ ]
+ },
+ { resource: Entity.SITE_AREA, action: [Action.CREATE, Action.UPDATE, Action.DELETE], attributes: ['*'] },
{ resource: Entity.CHARGING_STATIONS, action: [Action.LIST, Action.IN_ERROR], attributes: ['*'] },
{
resource: Entity.CHARGING_STATION, action: [Action.CREATE, Action.READ, Action.UPDATE, Action.DELETE,
@@ -158,16 +169,28 @@ const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
// -----------------------------------------------------------------------------------------------
{ resource: Entity.SITES, action: Action.LIST, attributes: ['*'] },
{ resource: Entity.SITE, action: Action.READ, attributes: ['*'] },
- { resource: Entity.SITE_AREAS, action: Action.LIST,
+ {
+ resource: Entity.SITE_AREAS, action: Action.LIST,
condition: {
Fn: 'custom:dynamicAuthorizationFilters',
- args: { filters: ['AssignedSites'] }
+ args: { filters: ['AssignedSiteAreas'] }
},
attributes: [
'id', 'name', 'siteID', 'maximumPower', 'voltage', 'numberOfPhases', 'accessControl', 'smartCharging', 'address',
'site.id', 'site.name', 'issuer', 'distanceMeters', 'createdOn', 'createdBy', 'lastChangedOn', 'lastChangedBy'
- ] },
- { resource: Entity.SITE_AREA, action: Action.READ, attributes: ['*'] },
+ ]
+ },
+ {
+ resource: Entity.SITE_AREA, action: Action.READ,
+ condition: {
+ Fn: 'custom:dynamicAuthorizationFilters',
+ args: { filters: ['AssignedSiteAreas'] }
+ },
+ attributes: [
+ 'id', 'name', 'issuer', 'image', 'address', 'maximumPower', 'numberOfPhases',
+ 'voltage', 'smartCharging', 'accessControl', 'connectorStats', 'siteID', 'site.name'
+ ]
+ },
{ resource: Entity.CHARGING_STATIONS, action: Action.LIST, attributes: ['*'] },
{ resource: Entity.CHARGING_STATION, action: [Action.READ], attributes: ['*'] },
{
@@ -258,11 +281,18 @@ const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
'id', 'name', 'issuer', 'logo', 'address'] },
{ resource: Entity.SITES, action: Action.LIST, attributes: ['*'] },
{ resource: Entity.SITE, action: Action.READ, attributes: ['*'] },
- { resource: Entity.SITE_AREAS, action: Action.LIST, attributes: [
+ {
+ resource: Entity.SITE_AREAS, action: Action.LIST, attributes: [
'id', 'name', 'siteID', 'maximumPower', 'voltage', 'numberOfPhases', 'accessControl', 'smartCharging', 'address',
'site.id', 'site.name', 'issuer', 'distanceMeters', 'createdOn', 'createdBy', 'lastChangedOn', 'lastChangedBy'
- ] },
- { resource: Entity.SITE_AREA, action: Action.READ, attributes: ['*'] },
+ ]
+ },
+ {
+ resource: Entity.SITE_AREA, action: Action.READ, attributes: [
+ 'id', 'name', 'issuer', 'image', 'address', 'maximumPower', 'numberOfPhases',
+ 'voltage', 'smartCharging', 'accessControl', 'connectorStats', 'siteID', 'site.name'
+ ]
+ },
{ resource: Entity.CHARGING_STATIONS, action: Action.LIST, attributes: ['*'] },
{ resource: Entity.CHARGING_STATION, action: Action.READ, attributes: ['*'] },
{ resource: Entity.TRANSACTIONS, action: Action.LIST, attributes: ['*'] },

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';
-import AssignedSitesDynamicAuthorizationFilter from './dynamic-filters/AssignedSitesDynamicAuthorizationFilter';
import DynamicAuthorizationDataSource from './DynamicAuthorizationDataSource';
import DynamicAuthorizationFilter from './DynamicAuthorizationFilter';
import Tenant from '../types/Tenant';
@@ -19,8 +19,8 @@ export default class DynamicAuthorizationFactory {
case DynamicAuthorizationFilterName.ASSIGNED_SITES_COMPANIES:
dynamicFilter = new AssignedSitesCompaniesDynamicAuthorizationFilter(tenant, userToken);
break;
- case DynamicAuthorizationFilterName.ASSIGNED_SITES:
- dynamicFilter = new AssignedSitesDynamicAuthorizationFilter(tenant, userToken);
+ case DynamicAuthorizationFilterName.ASSIGNED_SITE_AREAS:
+ dynamicFilter = new AssignedSiteAreasDynamicAuthorizationFilter(tenant, userToken);
break;
}
// Init Data Source
@@ -56,8 +56,8 @@ export default class DynamicAuthorizationFactory {
switch (dataSource) {
case DynamicAuthorizationDataSourceName.ASSIGNED_SITES_COMPANIES:
return new AssignedSitesCompaniesDynamicAuthorizationDataSource(tenant, user);
- case DynamicAuthorizationDataSourceName.ASSIGNED_SITES:
- return new AssignedSitesDynamicAuthorizationDataSource(tenant, user);
+ case DynamicAuthorizationDataSourceName.ASSIGNED_SITE_AREAS:
+ return new AssignedSiteAreasDynamicAuthorizationDataSource(tenant, user);
}
}
}

ADD
src/authorization/dynamic-data-source/AssignedSiteAreasDynamicAuthorizationDataSource.ts
+import { AssignedSiteAreasDynamicAuthorizationDataSourceData, DynamicAuthorizationDataSourceName } from '../../types/Authorization';
+
+import Authorizations from '../Authorizations';
+import Constants from '../../utils/Constants';
+import DynamicAuthorizationDataSource from '../DynamicAuthorizationDataSource';
+import SiteAreaStorage from '../../storage/mongodb/SiteAreaStorage';
+import SiteStorage from '../../storage/mongodb/SiteStorage';
+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'));
+ const siteAreas = await SiteAreaStorage.getSiteAreas(this.tenant.id,
+ {
+ siteIDs: siteIDs,
+ issuer: true,
+ }, Constants.DB_PARAMS_MAX_LIMIT,
+ ['id']
+ );
+ return _.uniq(_.map(siteAreas.result, 'id'));
+ }
+}

DELETE
src/authorization/dynamic-data-source/AssignedSitesDynamicAuthorizationDataSource.ts
-import { AssignedSitesDynamicAuthorizationDataSourceData, DynamicAuthorizationDataSourceName } from '../../types/Authorization';
-
-import Constants from '../../utils/Constants';
-import DynamicAuthorizationDataSource from '../DynamicAuthorizationDataSource';
-import SiteStorage from '../../storage/mongodb/SiteStorage';
-import _ from 'lodash';
-
-export default class AssignedSitesDynamicAuthorizationDataSource
- extends DynamicAuthorizationDataSource<AssignedSitesDynamicAuthorizationDataSourceData> {
-
- public getName(): DynamicAuthorizationDataSourceName {
- return DynamicAuthorizationDataSourceName.ASSIGNED_SITES;
- }
-
- public async loadData(): Promise<void> {
- const assignedSitesCompaniesData: AssignedSitesDynamicAuthorizationDataSourceData = {};
- // Get Site IDs from Site Admin flag
- assignedSitesCompaniesData.siteIDs = await this.getAssignedSiteIDs();
- // Set
- this.setData(assignedSitesCompaniesData);
- }
-
- private async getAssignedSiteIDs(): Promise<string[]> {
- // Get the Site IDs of the assigned Sites
- const sites = await SiteStorage.getSites(this.tenant.id,
- {
- userID: this.userToken.id,
- issuer: true,
- }, Constants.DB_PARAMS_MAX_LIMIT,
- ['id']
- );
- return _.uniq(_.map(sites.result, 'id'));
- }
-}

ADD
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
+ ];
+ }
+}

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

MODIFY
src/server/rest/v1/service/AuthorizationService.ts
src/server/rest/v1/service/AuthorizationService.ts
@@ -548,22 +548,30 @@ export default class AuthorizationService {
const authorizationFilters: AuthorizationFilter = {
filters: {},
dataSources: new Map(),
- projectFields: [
- 'id', 'name', 'issuer', 'image', 'address', 'maximumPower', 'numberOfPhases',
- 'voltage', 'smartCharging', 'accessControl', 'connectorStats', 'siteID', 'site.name'
- ],
- authorized: userToken.role === UserRole.ADMIN,
+ projectFields: [],
+ authorized: false,
};
+
+ // Check static auth
+ const authorizationContext: AuthorizationContext = {};
+ const authResult = await Authorizations.canReadSiteArea(userToken, authorizationContext);
+ authorizationFilters.authorized = authResult.authorized;
+ // Check
+ if (!authorizationFilters.authorized) {
+ throw new AppAuthError({
+ errorCode: HTTPAuthError.FORBIDDEN,
+ user: userToken,
+ action: Action.READ, entity: Entity.SITE_AREA,
+ module: MODULE_NAME, method: 'checkAndGetSiteAreaAuthorizationFilters',
+ });
+ }
+
+ // Process dynamic filters
+ await AuthorizationService.processDynamicFilters(tenant, userToken, Action.READ, Entity.SITE,
+ authorizationFilters, authorizationContext, { SiteAreaID: filteredRequest.ID });
// Filter projected fields
authorizationFilters.projectFields = AuthorizationService.filterProjectFields(
- authorizationFilters.projectFields, filteredRequest.ProjectFields);
- // Not an Admin?
- if (userToken.role !== UserRole.ADMIN) {
- const siteAreaIDs = await AuthorizationService.getAssignedSiteAreaIDs(tenant.id, userToken);
- if (!Utils.isEmptyArray(siteAreaIDs) && siteAreaIDs.includes(filteredRequest.ID)) {
- authorizationFilters.authorized = true;
- }
- }
+ authResult.fields, filteredRequest.ProjectFields);
return authorizationFilters;
}
@@ -599,7 +607,7 @@ export default class AuthorizationService {
siteArea.canUpdate = false;
siteArea.canDelete = false;
} else {
- // todo: add id?
+ filteredRequest.SiteAreaID = siteArea.id;
siteArea.canRead = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.SITE_AREA, Action.READ, authorizationFilter, filteredRequest);
siteArea.canUpdate = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.SITE_AREA, Action.DELETE, authorizationFilter, filteredRequest);
siteArea.canDelete = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.SITE_AREA, Action.UPDATE, authorizationFilter, filteredRequest);

MODIFY
src/server/rest/v1/service/ChargingStationService.ts
src/server/rest/v1/service/ChargingStationService.ts
@@ -529,7 +529,7 @@ export default class ChargingStationService {
UtilsService.assertObjectExists(action, siteArea, `Site Area ID '${filteredRequest.SiteAreaID}' does not exist`,
MODULE_NAME, 'handleTriggerSmartCharging', req.user);
// Check auth
- if (!await Authorizations.canUpdateSiteArea(req.user, siteArea.siteID)) {
+ if (!await Authorizations.canUpdateSiteArea(req.user)) {
throw new AppAuthError({
errorCode: HTTPAuthError.FORBIDDEN,
user: req.user,

MODIFY
src/server/rest/v1/service/SiteAreaService.ts
src/server/rest/v1/service/SiteAreaService.ts
@@ -168,8 +168,6 @@ export default class SiteAreaService {
Action.READ, Entity.SITE_AREA, MODULE_NAME, 'handleGetSiteArea');
// Filter request
const filteredRequest = SiteAreaSecurity.filterSiteAreaRequest(req.query);
- // Check mandatory fields
- UtilsService.assertIdIsProvided(action, filteredRequest.ID, MODULE_NAME, 'handleGetSiteArea', req.user);
// Check and Get Site Area
const siteArea = await UtilsService.checkAndGetSiteAreaAuthorization(
req.tenant, req.user, filteredRequest.ID, Action.READ, action, {
@@ -177,8 +175,6 @@ export default class SiteAreaService {
withChargingStations: filteredRequest.WithChargingStations,
withImage: true,
}, true);
- // Add authorizations
- await AuthorizationService.addSiteAreaAuthorizations(req.tenant, req.user, siteArea);
// Return
res.json(siteArea);
next();

MODIFY
src/server/rest/v1/service/UtilsService.ts
src/server/rest/v1/service/UtilsService.ts
@@ -430,16 +430,6 @@ export default class UtilsService {
public static async checkAndGetSiteAreaAuthorization(tenant: Tenant, userToken: UserToken, siteAreaID: string, authAction: Action,
action: ServerAction, additionalFilters: Record<string, any>, applyProjectFields = false): Promise<SiteArea> {
- // Check static auth for reading site area
- if (!await Authorizations.canReadSiteArea(userToken)) {
- throw new AppAuthError({
- errorCode: HTTPAuthError.FORBIDDEN,
- user: userToken,
- action: Action.READ, entity: Entity.SITE_AREA,
- module: MODULE_NAME, method: 'checkAndGetSiteAreaAuthorization',
- value: siteAreaID
- });
- }
// Check mandatory fields
UtilsService.assertIdIsProvided(action, siteAreaID, MODULE_NAME, 'checkAndGetSiteAreaAuthorization', userToken);
// Get dynamic auth
@@ -476,7 +466,7 @@ export default class UtilsService {
});
}
// Add actions
- await AuthorizationService.addSiteAreaAuthorizations(tenant, userToken, siteArea);
+ await AuthorizationService.addSiteAreaAuthorizations(tenant, userToken, siteArea, authorizationFilter, { ID: siteAreaID });
// Check
const authorized = AuthorizationService.canPerfomAction(siteArea, authAction);
if (!authorized) {

MODIFY
src/types/Authorization.ts
src/types/Authorization.ts
@@ -177,12 +177,12 @@ export interface AuthorizationActions {
export enum DynamicAuthorizationFilterName {
ASSIGNED_SITES_COMPANIES = 'AssignedSitesCompanies',
- ASSIGNED_SITES = 'AssignedSites',
+ ASSIGNED_SITE_AREAS = 'AssignedSiteAreas',
}
export enum DynamicAuthorizationDataSourceName {
ASSIGNED_SITES_COMPANIES = 'AssignedSitesCompanies',
- ASSIGNED_SITES = 'AssignedSites',
+ ASSIGNED_SITE_AREAS = 'AssignedSiteAreas',
}
export interface DynamicAuthorizationDataSourceData {}
@@ -191,6 +191,6 @@ export interface AssignedSitesCompaniesDynamicAuthorizationDataSourceData extend
companyIDs?: string[];
}
-export interface AssignedSitesDynamicAuthorizationDataSourceData extends DynamicAuthorizationDataSourceData {
- siteIDs?: string[];
+export interface AssignedSiteAreasDynamicAuthorizationDataSourceData extends DynamicAuthorizationDataSourceData {
+ siteAreaIDs?: string[];
}

Change getSiteArea logic