No carriage return after the parenthesis.
MODIFY
src/server/rest/v1/service/AuthorizationService.ts
src/server/rest/v1/service/AuthorizationService.ts
@@ -2,7 +2,7 @@ import { Action, AuthorizationActions, AuthorizationContext, AuthorizationFilter
import { CompanyDataResult, SiteAreaDataResult, SiteDataResult } from '../../../../types/DataResult';
import { HttpAssignAssetsToSiteAreaRequest, HttpAssignChargingStationToSiteAreaRequest, HttpSiteAreaRequest, HttpSiteAreasRequest } from '../../../../types/requests/HttpSiteAreaRequest';
import { HttpCompaniesRequest, HttpCompanyRequest } from '../../../../types/requests/HttpCompanyRequest';
-import { HttpSiteAssignUsersRequest, HttpSiteRequest, HttpSiteUsersRequest } from '../../../../types/requests/HttpSiteRequest';
+import { HttpSiteAssignUsersRequest, HttpSiteUsersRequest } from '../../../../types/requests/HttpSiteRequest';
import { HttpTagsRequest, HttpUserAssignSitesRequest, HttpUserRequest, HttpUserSitesRequest, HttpUsersRequest } from '../../../../types/requests/HttpUserRequest';
import User, { UserRole } from '../../../../types/User';
@@ -57,15 +57,16 @@ export default class AuthorizationService {
authorized: false,
};
- await this.canPerformAuthorizationAction(tenant, userToken, Entity.SITE, authAction, authorizationFilters, filteredRequest);
+ await this.canPerformAuthorizationAction(tenant, userToken, Entity.SITE, authAction,
+ authorizationFilters, filteredRequest);
return authorizationFilters;
}
public static async addSitesAuthorizations(tenant: Tenant, userToken: UserToken, sites: SiteDataResult, authorizationFilter: AuthorizationFilter,
filteredRequest: Record<string, any>): Promise<void> {
// Add canCreate flag to root
- sites.canCreate = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.SITE, Action.CREATE, authorizationFilter);
-
+ sites.canCreate = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.SITE, Action.CREATE,
+ authorizationFilter);
// Enrich
for (const site of sites.result) {
await AuthorizationService.addSiteAuthorizations(tenant, userToken, site, authorizationFilter, filteredRequest);
@@ -83,9 +84,12 @@ export default class AuthorizationService {
site.canUnassignUsers = false;
} else {
filteredRequest.SiteID = site.id;
- site.canRead = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.SITE, Action.READ, authorizationFilter, filteredRequest);
- site.canDelete = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.SITE, Action.DELETE, authorizationFilter, filteredRequest);
- site.canUpdate = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.SITE, Action.UPDATE, authorizationFilter, filteredRequest);
+ site.canRead = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.SITE, Action.READ,
+ authorizationFilter, filteredRequest);
+ site.canDelete = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.SITE, Action.DELETE,
+ authorizationFilter, filteredRequest);
+ site.canUpdate = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.SITE, Action.UPDATE,
+ authorizationFilter, filteredRequest);
site.canAssignUsers = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.USERS_SITES, Action.ASSIGN,
authorizationFilter, filteredRequest);
site.canUnassignUsers = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.USERS_SITES, Action.UNASSIGN,
@@ -93,8 +97,8 @@ export default class AuthorizationService {
}
}
- public static async checkAndGetSitesAuthorizationFilters(
- tenant: Tenant, userToken: UserToken, filteredRequest: HttpSiteUsersRequest): Promise<AuthorizationFilter> {
+ public static async checkAndGetSitesAuthorizationFilters(tenant: Tenant, userToken: UserToken,
+ filteredRequest: HttpSiteUsersRequest): Promise<AuthorizationFilter> {
const authorizationFilters: AuthorizationFilter = {
filters: {},
dataSources: new Map(),
@@ -102,8 +106,8 @@ export default class AuthorizationService {
authorized: false,
};
// Check static & dynamic authorization
- await this.canPerformAuthorizationAction(
- tenant, userToken, Entity.SITES, Action.LIST, authorizationFilters, filteredRequest);
+ await this.canPerformAuthorizationAction(tenant, userToken, Entity.SITES, Action.LIST,
+ authorizationFilters, filteredRequest);
return authorizationFilters;
}
@@ -115,14 +119,14 @@ export default class AuthorizationService {
projectFields: [ ],
authorized: false,
};
-
- await this.canPerformAuthorizationAction(
- tenant, userToken, Entity.USERS_SITES, Action.LIST, authorizationFilters, filteredRequest);
+ // Check static & dynamic authorization
+ await this.canPerformAuthorizationAction(tenant, userToken, Entity.USERS_SITES, Action.LIST,
+ authorizationFilters, filteredRequest);
return authorizationFilters;
}
- public static async checkAndGetUserSitesAuthorizationFilters(
- tenant: Tenant, userToken: UserToken, filteredRequest: HttpUserSitesRequest): Promise<AuthorizationFilter> {
+ public static async checkAndGetUserSitesAuthorizationFilters(tenant: Tenant, userToken: UserToken,
+ filteredRequest: HttpUserSitesRequest): Promise<AuthorizationFilter> {
const authorizationFilters: AuthorizationFilter = {
filters: {},
dataSources: new Map(),
@@ -132,16 +136,14 @@ export default class AuthorizationService {
authorized: userToken.role === UserRole.ADMIN,
};
// Filter projected fields
- authorizationFilters.projectFields = AuthorizationService.filterProjectFields(
- authorizationFilters.projectFields, filteredRequest.ProjectFields);
+ authorizationFilters.projectFields = AuthorizationService.filterProjectFields(authorizationFilters.projectFields, filteredRequest.ProjectFields);
// Handle Sites
- await AuthorizationService.checkAssignedSiteAdminsAndOwners(
- tenant, userToken, null, authorizationFilters);
+ await AuthorizationService.checkAssignedSiteAdminsAndOwners(tenant, userToken, null, authorizationFilters);
return authorizationFilters;
}
- public static async checkAssignSiteUsersAuthorizationFilters(
- tenant: Tenant, action: ServerAction, userToken: UserToken, filteredRequest: HttpSiteAssignUsersRequest): Promise<AuthorizationFilter> {
+ public static async checkAssignSiteUsersAuthorizationFilters(tenant: Tenant, action: ServerAction, userToken: UserToken,
+ filteredRequest: HttpSiteAssignUsersRequest): Promise<AuthorizationFilter> {
const authorizationFilters: AuthorizationFilter = {
filters: {},
dataSources: new Map(),
@@ -150,13 +152,13 @@ export default class AuthorizationService {
};
// Check static & dynamic authorization
const authAction = action === ServerAction.ADD_USERS_TO_SITE ? Action.ASSIGN : Action.UNASSIGN;
- await this.canPerformAuthorizationAction(
- tenant, userToken, Entity.USERS_SITES, authAction, authorizationFilters, filteredRequest);
+ await this.canPerformAuthorizationAction(tenant, userToken, Entity.USERS_SITES, authAction,
+ authorizationFilters, filteredRequest);
return authorizationFilters;
}
- public static async checkAssignSiteAreaAssetsAuthorizationFilters(
- tenant: Tenant, action: ServerAction, userToken: UserToken, siteArea: SiteArea, filteredRequest: HttpAssignAssetsToSiteAreaRequest): Promise<AuthorizationFilter> {
+ public static async checkAssignSiteAreaAssetsAuthorizationFilters(tenant: Tenant, action: ServerAction, userToken: UserToken,
+ siteArea: SiteArea, filteredRequest: HttpAssignAssetsToSiteAreaRequest): Promise<AuthorizationFilter> {
const authorizationFilters: AuthorizationFilter = {
filters: {},
dataSources: new Map(),
@@ -198,9 +200,8 @@ export default class AuthorizationService {
return authorizationFilters;
}
- public static async checkAssignSiteAreaChargingStationsAuthorizationFilters(
- tenant: Tenant, action: ServerAction, userToken: UserToken, siteArea: SiteArea,
- filteredRequest: HttpAssignChargingStationToSiteAreaRequest): Promise<AuthorizationFilter> {
+ public static async checkAssignSiteAreaChargingStationsAuthorizationFilters(tenant: Tenant, action: ServerAction, userToken: UserToken,
+ siteArea: SiteArea, filteredRequest: HttpAssignChargingStationToSiteAreaRequest): Promise<AuthorizationFilter> {
const authorizationFilters: AuthorizationFilter = {
filters: {},
dataSources: new Map(),
@@ -242,8 +243,8 @@ export default class AuthorizationService {
return authorizationFilters;
}
- public static async checkAndAssignUserSitesAuthorizationFilters(
- tenant: Tenant, action: ServerAction, userToken: UserToken, filteredRequest: HttpUserAssignSitesRequest): Promise<AuthorizationFilter> {
+ public static async checkAndAssignUserSitesAuthorizationFilters(tenant: Tenant, action: ServerAction, userToken: UserToken,
+ filteredRequest: HttpUserAssignSitesRequest): Promise<AuthorizationFilter> {
const authorizationFilters: AuthorizationFilter = {
filters: {},
dataSources: new Map(),
@@ -279,8 +280,8 @@ export default class AuthorizationService {
return authorizationFilters;
}
- public static async checkAndGetUsersInErrorAuthorizationFilters(
- tenant: Tenant, userToken: UserToken, filteredRequest: HttpUsersRequest): Promise<AuthorizationFilter> {
+ public static async checkAndGetUsersInErrorAuthorizationFilters(tenant: Tenant, userToken: UserToken,
+ filteredRequest: HttpUsersRequest): Promise<AuthorizationFilter> {
const authorizationFilters: AuthorizationFilter = {
filters: {},
dataSources: new Map(),
@@ -291,39 +292,42 @@ export default class AuthorizationService {
authorized: userToken.role === UserRole.ADMIN,
};
// Filter projected fields
- authorizationFilters.projectFields = AuthorizationService.filterProjectFields(
- authorizationFilters.projectFields, filteredRequest.ProjectFields);
+ authorizationFilters.projectFields = AuthorizationService.filterProjectFields(authorizationFilters.projectFields,
+ filteredRequest.ProjectFields);
// Get authorization filters from users
- const usersAuthorizationFilters = await AuthorizationService.checkAndGetUsersAuthorizationFilters(
- tenant, userToken, filteredRequest);
+ const usersAuthorizationFilters = await AuthorizationService.checkAndGetUsersAuthorizationFilters(tenant,
+ userToken, filteredRequest);
// Override
authorizationFilters.authorized = usersAuthorizationFilters.authorized;
authorizationFilters.filters = usersAuthorizationFilters.filters;
return authorizationFilters;
}
- public static async addUsersAuthorizations(tenant: Tenant, userToken: UserToken, users: User[], authorizationFilter: AuthorizationFilter): Promise<void> {
+ public static async addUsersAuthorizations(tenant: Tenant, userToken: UserToken, users: User[],
+ authorizationFilter: AuthorizationFilter): Promise<void> {
// Enrich
for (const user of users) {
await AuthorizationService.addUserAuthorizations(tenant, userToken, user, authorizationFilter);
}
}
- public static async addUserAuthorizations(tenant: Tenant, userToken: UserToken, user: User, authorizationFilter: AuthorizationFilter): Promise<void> {
+ public static async addUserAuthorizations(tenant: Tenant, userToken: UserToken, user: User,
+ authorizationFilter: AuthorizationFilter): Promise<void> {
// Enrich
if (!user.issuer) {
user.canRead = true;
user.canUpdate = false;
user.canDelete = false;
} else {
- user.canRead = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.USER, Action.READ, authorizationFilter);
+ user.canRead = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.USER, Action.READ,
+ authorizationFilter);
user.canUpdate = await Authorizations.canUpdateUser(userToken, user.id);
user.canDelete = await Authorizations.canDeleteUser(userToken, user.id);
}
}
- public static async checkAndGetUsersAuthorizationFilters(
- tenant: Tenant, userToken: UserToken, filteredRequest: Record<string, any>): Promise<AuthorizationFilter> {
+ public static async checkAndGetUsersAuthorizationFilters(tenant: Tenant, userToken: UserToken,
+ filteredRequest: Record<string, any>): Promise<AuthorizationFilter> {
const authorizationFilters: AuthorizationFilter = {
filters: {},
dataSources: new Map(),
@@ -338,13 +342,13 @@ export default class AuthorizationService {
authorizationFilters.projectFields = AuthorizationService.filterProjectFields(
authorizationFilters.projectFields, filteredRequest.ProjectFields);
// Handle Sites
- await AuthorizationService.checkAssignedSiteAdminsAndOwners(
- tenant, userToken, filteredRequest, authorizationFilters);
+ await AuthorizationService.checkAssignedSiteAdminsAndOwners(tenant, userToken, filteredRequest,
+ authorizationFilters);
return authorizationFilters;
}
- public static async checkAndGetAssetsAuthorizationFilters(
- tenant: Tenant, userToken: UserToken, filteredRequest: HttpAssetsRequest): Promise<AuthorizationFilter> {
+ public static async checkAndGetAssetsAuthorizationFilters(tenant: Tenant, userToken: UserToken,
+ filteredRequest: HttpAssetsRequest): Promise<AuthorizationFilter> {
const authorizationFilters: AuthorizationFilter = {
filters: {},
dataSources: new Map(),
@@ -355,16 +359,15 @@ export default class AuthorizationService {
authorized: userToken.role === UserRole.ADMIN,
};
// Filter projected fields
- authorizationFilters.projectFields = AuthorizationService.filterProjectFields(
- authorizationFilters.projectFields, filteredRequest.ProjectFields);
+ authorizationFilters.projectFields = AuthorizationService.filterProjectFields(authorizationFilters.projectFields,
+ filteredRequest.ProjectFields);
// Handle Sites
- await AuthorizationService.checkAssignedSites(
- tenant, userToken, filteredRequest, authorizationFilters);
+ await AuthorizationService.checkAssignedSites(tenant, userToken, filteredRequest, authorizationFilters);
return authorizationFilters;
}
- public static async checkAndGetUserAuthorizationFilters(
- tenant: Tenant, userToken: UserToken, filteredRequest: HttpUserRequest): Promise<AuthorizationFilter> {
+ public static async checkAndGetUserAuthorizationFilters(tenant: Tenant, userToken: UserToken,
+ filteredRequest: HttpUserRequest): Promise<AuthorizationFilter> {
const authorizationFilters: AuthorizationFilter = {
filters: {},
dataSources: new Map(),
@@ -388,13 +391,13 @@ export default class AuthorizationService {
await AuthorizationService.processDynamicFilters(tenant, userToken, Action.READ, Entity.USER,
authorizationFilters, authorizationContext, { UserID: filteredRequest.ID });
// Filter projected fields
- authorizationFilters.projectFields = AuthorizationService.filterProjectFields(
- authResult.fields, filteredRequest.ProjectFields);
+ authorizationFilters.projectFields = AuthorizationService.filterProjectFields(authResult.fields,
+ filteredRequest.ProjectFields);
return authorizationFilters;
}
- public static async checkAndGetTagsAuthorizationFilters(
- tenant: Tenant, userToken: UserToken, filteredRequest: HttpTagsRequest): Promise<AuthorizationFilter> {
+ public static async checkAndGetTagsAuthorizationFilters(tenant: Tenant, userToken: UserToken,
+ filteredRequest: HttpTagsRequest): Promise<AuthorizationFilter> {
const authorizationFilters: AuthorizationFilter = {
filters: {},
dataSources: new Map(),
@@ -409,16 +412,15 @@ export default class AuthorizationService {
'createdBy.name', 'createdBy.firstName', 'lastChangedBy.name', 'lastChangedBy.firstName');
}
// Filter projected fields
- authorizationFilters.projectFields = AuthorizationService.filterProjectFields(
- authorizationFilters.projectFields, filteredRequest.ProjectFields);
+ authorizationFilters.projectFields = AuthorizationService.filterProjectFields(authorizationFilters.projectFields,
+ filteredRequest.ProjectFields);
// Handle Sites
- await AuthorizationService.checkAssignedSiteAdminsAndOwners(
- tenant, userToken, null, authorizationFilters);
+ await AuthorizationService.checkAssignedSiteAdminsAndOwners(tenant, userToken, null, authorizationFilters);
return authorizationFilters;
}
- public static async checkAndGetTagAuthorizationFilters(
- tenant: Tenant, userToken: UserToken, filteredRequest: HttpByIDRequest): Promise<AuthorizationFilter> {
+ public static async checkAndGetTagAuthorizationFilters(tenant: Tenant, userToken: UserToken,
+ filteredRequest: HttpByIDRequest): Promise<AuthorizationFilter> {
const authorizationFilters: AuthorizationFilter = {
filters: {},
dataSources: new Map(),
@@ -426,11 +428,10 @@ export default class AuthorizationService {
authorized: userToken.role === UserRole.ADMIN || userToken.role === UserRole.SUPER_ADMIN,
};
// Filter projected fields
- authorizationFilters.projectFields = AuthorizationService.filterProjectFields(
- authorizationFilters.projectFields, filteredRequest.ProjectFields);
+ authorizationFilters.projectFields = AuthorizationService.filterProjectFields(authorizationFilters.projectFields,
+ filteredRequest.ProjectFields);
// Handle Sites
- await AuthorizationService.checkAssignedSiteAdminsAndOwners(
- tenant, userToken, null, authorizationFilters);
+ await AuthorizationService.checkAssignedSiteAdminsAndOwners(tenant, userToken, null, authorizationFilters);
return authorizationFilters;
}
@@ -443,15 +444,16 @@ export default class AuthorizationService {
authorized: false,
};
// Check static & dynamic authorization
- await this.canPerformAuthorizationAction(
- tenant, userToken, Entity.COMPANIES, Action.LIST, authorizationFilters, filteredRequest);
+ await this.canPerformAuthorizationAction(tenant, userToken, Entity.COMPANIES, Action.LIST,
+ authorizationFilters, filteredRequest);
return authorizationFilters;
}
public static async addCompaniesAuthorizations(tenant: Tenant, userToken: UserToken,
companies: CompanyDataResult, authorizationFilter: AuthorizationFilter): Promise<void> {
// Add canCreate flag to root
- companies.canCreate = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.COMPANY, Action.CREATE, authorizationFilter);
+ companies.canCreate = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.COMPANY, Action.CREATE, ]
+ authorizationFilter);
// Enrich
for (const company of companies.result) {
await AuthorizationService.addCompanyAuthorizations(tenant, userToken, company, authorizationFilter);
@@ -496,8 +498,8 @@ export default class AuthorizationService {
await AuthorizationService.processDynamicFilters(tenant, userToken, Action.READ, Entity.COMPANY,
authorizationFilters, authorizationContext, { CompanyID: filteredRequest.ID });
// Filter projected fields
- authorizationFilters.projectFields = AuthorizationService.filterProjectFields(
- authResult.fields, filteredRequest.ProjectFields);
+ authorizationFilters.projectFields = AuthorizationService.filterProjectFields(authResult.fields,
+ filteredRequest.ProjectFields);
return authorizationFilters;
}
@@ -512,8 +514,8 @@ export default class AuthorizationService {
authorized: userToken.role === UserRole.ADMIN,
};
// Filter projected fields
- authorizationFilters.projectFields = AuthorizationService.filterProjectFields(
- authorizationFilters.projectFields, filteredRequest.ProjectFields);
+ authorizationFilters.projectFields = AuthorizationService.filterProjectFields(authorizationFilters.projectFields,
+ filteredRequest.ProjectFields);
// Not an Admin?
if (userToken.role !== UserRole.ADMIN) {
const siteAreaIDs = await AuthorizationService.getAssignedSiteAreaIDs(tenant.id, userToken);
@@ -535,8 +537,8 @@ export default class AuthorizationService {
authorized: userToken.role === UserRole.ADMIN,
};
// Filter projected fields
- authorizationFilters.projectFields = AuthorizationService.filterProjectFields(
- authorizationFilters.projectFields, filteredRequest.ProjectFields);
+ authorizationFilters.projectFields = AuthorizationService.filterProjectFields(authorizationFilters.projectFields,
+ filteredRequest.ProjectFields);
// Not an Admin?
if (userToken.role !== UserRole.ADMIN) {
// Get assigned SiteArea IDs

No carriage return after the parenthesis.