Renaming in auth service
MODIFY
src/server/rest/v1/service/AuthorizationService.ts
src/server/rest/v1/service/AuthorizationService.ts
@@ -132,7 +132,7 @@ export default class AuthorizationService {
authorizationFilters.projectFields = authorizationFilters.projectFields.filter((projectField) => filteredRequest.ProjectFields.includes(projectField));
}
// Handle Sites
- await AuthorizationService.checkAssignedSites(
+ await AuthorizationService.checkAssignedSiteAdmins(
tenant, userToken, filteredRequest, authorizationFilters);
return authorizationFilters;
}
@@ -151,7 +151,7 @@ export default class AuthorizationService {
authorizationFilters.projectFields = authorizationFilters.projectFields.filter((projectField) => filteredRequest.ProjectFields.includes(projectField));
}
// Handle Sites
- await AuthorizationService.checkAssignedSites(
+ await AuthorizationService.checkAssignedSiteAdmins(
tenant, userToken, filteredRequest, authorizationFilters);
return authorizationFilters;
}
@@ -298,7 +298,7 @@ export default class AuthorizationService {
authorizationFilters.projectFields = authorizationFilters.projectFields.filter((projectField) => filteredRequest.ProjectFields.includes(projectField));
}
// Handle Sites
- await AuthorizationService.checkAssignedSites(
+ await AuthorizationService.checkAssignedSiteAdmins(
tenant, userToken, filteredRequest, authorizationFilters);
return authorizationFilters;
}
@@ -318,7 +318,7 @@ export default class AuthorizationService {
authorizationFilters.projectFields = authorizationFilters.projectFields.filter((projectField) => filteredRequest.ProjectFields.includes(projectField));
}
// Handle Sites
- await AuthorizationService.checkAssignedSites(
+ await AuthorizationService.checkAssignedSiteAdmins(
tenant, userToken, filteredRequest, authorizationFilters);
return authorizationFilters;
}
@@ -378,15 +378,15 @@ export default class AuthorizationService {
};
}
- private static async checkAssignedSites(tenant: Tenant, userToken: UserToken,
+ private static async checkAssignedSiteAdmins(tenant: Tenant, userToken: UserToken,
filteredRequest: HttpSiteUsersRequest|HttpUserSitesRequest|HttpUserRequest|HttpUserAssignSitesRequest, authorizationFilters: AuthorizationFilter): Promise<void> {
if (userToken.role !== UserRole.ADMIN) {
if (Utils.isTenantComponentActive(tenant, TenantComponents.ORGANIZATION)) {
// Get Site IDs from Site Admin flag
- const siteIDs = await AuthorizationService.getSiteAdminSiteIDs(tenant.id, userToken);
- if (!Utils.isEmptyArray(siteIDs)) {
+ const siteAdminSiteIDs = await AuthorizationService.getSiteAdminSiteIDs(tenant.id, userToken);
+ if (!Utils.isEmptyArray(siteAdminSiteIDs)) {
// Force the filter
- authorizationFilters.filters.siteIDs = siteIDs;
+ authorizationFilters.filters.siteIDs = siteAdminSiteIDs;
// Check if filter is provided
if (Utils.objectHasProperty(filteredRequest, 'SiteID') &&
!Utils.isNullOrUndefined(filteredRequest['SiteID'])) {

MODIFY
src/server/rest/v1/service/SiteService.ts
src/server/rest/v1/service/SiteService.ts
@@ -455,8 +455,8 @@ export default class SiteService {
search: filteredRequest.Search,
userID: filteredRequest.UserID,
issuer: filteredRequest.Issuer,
- companyIDs: (filteredRequest.CompanyID ? filteredRequest.CompanyID.split('|') : null),
- siteIDs: Authorizations.getAuthorizedSiteIDs(req.user, filteredRequest.SiteID ? filteredRequest.SiteID.split('|') : null),
+ companyIDs: filteredRequest.CompanyID ? filteredRequest.CompanyID.split('|') : null,
+ siteIDs: filteredRequest.SiteID ? filteredRequest.SiteID.split('|') : null,
withCompany: filteredRequest.WithCompany,
excludeSitesOfUserID: filteredRequest.ExcludeSitesOfUserID,
withAvailableChargingStations: filteredRequest.WithAvailableChargers,
@@ -570,6 +570,7 @@ export default class SiteService {
Action.UPDATE, Entity.SITE, MODULE_NAME, 'handleUpdateSite');
// Filter
const filteredRequest = SiteSecurity.filterSiteUpdateRequest(req.body);
+ UtilsService.assertIdIsProvided(action, filteredRequest.id, MODULE_NAME, 'handleUpdateSite', req.user);
// Check auth
if (!Authorizations.canUpdateSite(req.user, filteredRequest.id)) {
throw new AppAuthError({
@@ -584,6 +585,16 @@ export default class SiteService {
const company = await CompanyStorage.getCompany(req.user.tenantID, filteredRequest.companyID);
UtilsService.assertObjectExists(action, company, `Company ID '${filteredRequest.companyID}' does not exist`,
MODULE_NAME, 'handleUpdateSite', req.user);
+ // Check auth
+ if (!Authorizations.canReadCompany(req.user, company.id)) {
+ throw new AppAuthError({
+ errorCode: HTTPAuthError.FORBIDDEN,
+ user: req.user,
+ action: Action.READ, entity: Entity.COMPANY,
+ module: MODULE_NAME, method: 'handleUpdateSite',
+ value: company.id
+ });
+ }
// Check
UtilsService.checkIfSiteValid(filteredRequest, req);
// OCPI Company
@@ -601,7 +612,7 @@ export default class SiteService {
const authorizationSiteFilters = await AuthorizationService.checkAndGetSiteAuthorizationFilters(
req.tenant, req.user, { ID: filteredRequest.id });
// Get Site
- const site: Site = await SiteStorage.getSite(
+ const site = await SiteStorage.getSite(
req.user.tenantID, filteredRequest.id, authorizationSiteFilters.filters);
UtilsService.assertObjectExists(action, site, `Site with ID '${filteredRequest.id}' does not exist`,
MODULE_NAME, 'handleUpdateSite', req.user);

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -213,17 +213,7 @@ export default class UserService {
public static async handleDeleteUser(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
const userID = UserSecurity.filterUserByIDRequest(req.query);
- // Check Mandatory fields
- if (!userID) {
- throw new AppError({
- source: Constants.CENTRAL_SERVER,
- errorCode: HTTPError.GENERAL_ERROR,
- message: 'User\'s ID must be provided',
- module: MODULE_NAME, method: 'handleDeleteUser',
- user: req.user,
- action: action
- });
- }
+ UtilsService.assertIdIsProvided(action, userID, MODULE_NAME, 'handleDeleteUser', req.user);
// Check auth
if (!Authorizations.canDeleteUser(req.user, userID)) {
throw new AppAuthError({
@@ -431,17 +421,7 @@ export default class UserService {
let statusHasChanged = false;
// Filter
const filteredRequest = UserSecurity.filterUserUpdateRequest(req.body, req.user);
- // Check Mandatory fields
- if (!filteredRequest.id) {
- throw new AppError({
- source: Constants.CENTRAL_SERVER,
- errorCode: HTTPError.GENERAL_ERROR,
- message: 'User\'s ID must be provided',
- module: MODULE_NAME, method: 'handleUpdateUser',
- user: req.user,
- action: action
- });
- }
+ UtilsService.assertIdIsProvided(action, filteredRequest.id, MODULE_NAME, 'handleUpdateUser', req.user);
// Check auth
if (!Authorizations.canUpdateUser(req.user, filteredRequest.id)) {
throw new AppAuthError({

Renaming in auth service