Added user-assign-sites schema validation
ADD
src/assets/server/rest/v1/schemas/user/user-assign-sites.json
+{
+ "title": "Assign sites to a User",
+ "type": "object",
+ "definitions": {
+ "userID": {
+ "$ref": "common.json#/definitions/id"
+ },
+ "siteIDs": {
+ "type": "array",
+ "items": {
+ "$ref": "common.json#/definitions/id"
+ }
+ }
+ },
+ "required": [
+ "userID"
+ ]
+}

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -94,7 +94,7 @@ export default class UserService {
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.ORGANIZATION,
Action.UPDATE, Entity.SITES, 'SiteService', 'handleAssignSitesToUser');
// Filter request
- const filteredRequest = UserSecurity.filterAssignSitesToUserRequest(req.body);
+ const filteredRequest = UserValidator.getInstance().validateUserAssignToSites(req.body);
// Check and Get User
const user = await UtilsService.checkAndGetUserAuthorization(
req.tenant, req.user, filteredRequest.userID, Action.READ, action);

MODIFY
src/server/rest/v1/validator/UserValidator.ts
src/server/rest/v1/validator/UserValidator.ts
import User, { ImportedUser } from '../../../../types/User';
+import { HttpUserAssignSitesRequest } from '../../../../types/requests/HttpUserRequest';
import Schema from '../../../../types/validator/Schema';
import SchemaValidator from './SchemaValidator';
import UserToken from '../../../../types/UserToken';
@@ -10,11 +11,13 @@ export default class UserValidator extends SchemaValidator {
private static instance: UserValidator|null = null;
private importedUserCreation: Schema;
private userCreate: Schema;
+ private userAssignSites: Schema;
private constructor() {
super('UserValidator');
this.importedUserCreation = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/user/imported-user-create-req.json`, 'utf8'));
this.userCreate = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/user/user-create.json`, 'utf8'));
+ this.userAssignSites = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/user/user-assign-sites.json`, 'utf8'));
}
public static getInstance(): UserValidator {
@@ -33,4 +36,9 @@ export default class UserValidator extends SchemaValidator {
user.password = user.passwords.password;
return user;
}
+
+ validateUserAssignToSites(data: HttpUserAssignSitesRequest): HttpUserAssignSitesRequest {
+ this.validate(this.userAssignSites, data);
+ return data;
+ }
}

Added user-assign-sites schema validation