Tag-delete validation + removed security class + postman update
MODIFY
postman/EVSE.postman_collection.json
postman/EVSE.postman_collection.json
"response": []
},
{
- "name": "FE-UserImage",
+ "name": "FE-Tags",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "exec": [
+ "var responseJson = JSON.parse(responseBody);",
+ "postman.setEnvironmentVariable(\"tag\", responseJson[\"result\"][0][\"id\"]);"
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
+ "request": {
+ "auth": {
+ "type": "bearer",
+ "bearer": [
+ {
+ "key": "token",
+ "value": "{{token}}",
+ "type": "string"
+ }
+ ]
+ },
+ "method": "GET",
+ "header": [],
+ "url": {
+ "raw": "{{base_url}}/v1/api/tags",
+ "host": [
+ "{{base_url}}"
+ ],
+ "path": [
+ "v1",
+ "api",
+ "tags"
+ ]
+ }
+ },
+ "response": []
+ },
+ {
+ "name": "FE-Tag",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "exec": [
+ ""
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
+ "request": {
+ "auth": {
+ "type": "bearer",
+ "bearer": [
+ {
+ "key": "token",
+ "value": "{{token}}",
+ "type": "string"
+ }
+ ]
+ },
+ "method": "GET",
+ "header": [],
+ "url": {
+ "raw": "{{base_url}}/v1/api/tags/{{tag}}",
+ "host": [
+ "{{base_url}}"
+ ],
+ "path": [
+ "v1",
+ "api",
+ "tags",
+ "{{tag}}"
+ ]
+ }
+ },
+ "response": []
+ },
+ {
+ "name": "FE-TagExport",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "exec": [
+ ""
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
+ "request": {
+ "auth": {
+ "type": "bearer",
+ "bearer": [
+ {
+ "key": "token",
+ "value": "{{token}}",
+ "type": "string"
+ }
+ ]
+ },
+ "method": "GET",
+ "header": [],
+ "url": {
+ "raw": "{{base_url}}/v1/api/tags/action/export?Active",
+ "host": [
+ "{{base_url}}"
+ ],
+ "path": [
+ "v1",
+ "api",
+ "tags",
+ "action",
+ "export"
+ ],
+ "query": [
+ {
+ "key": "Active",
+ "value": null
+ },
+ {
+ "key": "Issuer",
+ "value": null,
+ "disabled": true
+ },
+ {
+ "key": "UserID",
+ "value": null,
+ "description": "Pipe separated user ids",
+ "disabled": true
+ },
+ {
+ "key": "Search",
+ "value": null,
+ "disabled": true
+ },
+ {
+ "key": "SortFields",
+ "value": null,
+ "disabled": true
+ },
+ {
+ "key": "Skip",
+ "value": null,
+ "disabled": true
+ },
+ {
+ "key": "OnlyRecordCount",
+ "value": null,
+ "disabled": true
+ },
+ {
+ "key": "ProjectFields",
+ "value": null,
+ "disabled": true
+ }
+ ]
+ }
+ },
+ "response": []
+ },
+ {
+ "name": "FE-TagCreate",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "exec": [
+ "var responseJson = JSON.parse(responseBody);",
+ "postman.setEnvironmentVariable(\"tag\", responseJson[\"id\"]);"
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
+ "request": {
+ "auth": {
+ "type": "bearer",
+ "bearer": [
+ {
+ "key": "token",
+ "value": "{{token}}",
+ "type": "string"
+ }
+ ]
+ },
+ "method": "POST",
+ "header": [],
+ "body": {
+ "mode": "raw",
+ "raw": "{\n \"id\": \"ABCD987654\",\n \"visualID\": \"######\",\n \"description\": \"Postman tag\",\n \"active\": true,\n \"issuer\": true,\n \"default\": false,\n \"userID\": \"{{userID}}\"\n}",
+ "options": {
+ "raw": {
+ "language": "json"
+ }
+ }
+ },
+ "url": {
+ "raw": "{{base_url}}/v1/api/tags/",
+ "host": [
+ "{{base_url}}"
+ ],
+ "path": [
+ "v1",
+ "api",
+ "tags",
+ ""
+ ]
+ }
+ },
+ "response": []
+ },
+ {
+ "name": "FE-TagImport",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "exec": [
+ ""
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
+ "request": {
+ "auth": {
+ "type": "bearer",
+ "bearer": [
+ {
+ "key": "token",
+ "value": "{{token}}",
+ "type": "string"
+ }
+ ]
+ },
+ "method": "POST",
+ "header": [],
+ "body": {
+ "mode": "file",
+ "file": {},
+ "options": {
+ "raw": {
+ "language": "text"
+ }
+ }
+ },
+ "url": {
+ "raw": "{{base_url}}/v1/api/tags/action/import",
+ "host": [
+ "{{base_url}}"
+ ],
+ "path": [
+ "v1",
+ "api",
+ "tags",
+ "action",
+ "import"
+ ]
+ }
+ },
+ "response": []
+ },
+ {
+ "name": "FE-TagUpdate",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "exec": [
+ ""
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
+ "request": {
+ "auth": {
+ "type": "bearer",
+ "bearer": [
+ {
+ "key": "token",
+ "value": "{{token}}",
+ "type": "string"
+ }
+ ]
+ },
+ "method": "PUT",
+ "header": [],
+ "body": {
+ "mode": "raw",
+ "raw": "{\n \"id\": \"ABCDE1234679\",\n \"visualID\": \"New visual ID\",\n \"description\": \"Postman tag\",\n \"active\": true,\n \"issuer\": true,\n \"default\": false,\n \"userID\": \"{{userID}}\"\n}",
+ "options": {
+ "raw": {
+ "language": "json"
+ }
+ }
+ },
+ "url": {
+ "raw": "{{base_url}}/v1/api/tags/{{tag}}",
+ "host": [
+ "{{base_url}}"
+ ],
+ "path": [
+ "v1",
+ "api",
+ "tags",
+ "{{tag}}"
+ ]
+ }
+ },
+ "response": []
+ },
+ {
+ "name": "FE-TagDelete",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "exec": [
+ ""
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
+ "request": {
+ "auth": {
+ "type": "bearer",
+ "bearer": [
+ {
+ "key": "token",
+ "value": "{{token}}",
+ "type": "string"
+ }
+ ]
+ },
+ "method": "DELETE",
+ "header": [],
+ "body": {
+ "mode": "raw",
+ "raw": "{\n \"id\": \"ABCDE1234679\",\n \"visualID\": \"New visual ID\",\n \"description\": \"Postman tag\",\n \"active\": true,\n \"issuer\": true,\n \"default\": false,\n \"userID\": \"{{userID}}\"\n}",
+ "options": {
+ "raw": {
+ "language": "json"
+ }
+ }
+ },
+ "url": {
+ "raw": "{{base_url}}/v1/api/tags/{{tag}}",
+ "host": [
+ "{{base_url}}"
+ ],
+ "path": [
+ "v1",
+ "api",
+ "tags",
+ "{{tag}}"
+ ]
+ }
+ },
+ "response": []
+ },
+ {
+ "name": "FE-UserImage Copy",
"request": {
"auth": {
"type": "bearer",

MODIFY
src/server/rest/v1/service/TagService.ts
src/server/rest/v1/service/TagService.ts
@@ -26,7 +26,6 @@ import { OCPITokenWhitelist } from '../../../../types/ocpi/OCPIToken';
import OCPIUtils from '../../../ocpi/OCPIUtils';
import { ServerAction } from '../../../../types/Server';
import { StatusCodes } from 'http-status-codes';
-import TagSecurity from './security/TagSecurity';
import TagStorage from '../../../../storage/mongodb/TagStorage';
import TagValidator from '../validator/TagValidator';
import Tenant from '../../../../types/Tenant';
@@ -73,7 +72,7 @@ export default class TagService {
public static async handleDeleteTag(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = TagSecurity.filterTagRequestByID(req.query);
+ const filteredRequest = TagValidator.getInstance().validateTagGetByID(req.query);
// Delete
await TagService.deleteTags(req.tenant, action, req.user, [filteredRequest.ID]);
// Return
@@ -115,7 +114,7 @@ export default class TagService {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.TAG_VISUAL_ID_ALREADY_EXIST_ERROR,
- message: `Tag with visual ID '${filteredRequest.id}' already exists`,
+ message: `Tag with visual ID '${filteredRequest.visualID}' already exists`,
module: MODULE_NAME, method: 'handleCreateTag',
user: req.user,
action: action

DELETE
src/server/rest/v1/service/security/TagSecurity.ts
-import { HttpTagRequest, HttpTagsRequest } from '../../../../../types/requests/HttpTagRequest';
-
-import Tag from '../../../../../types/Tag';
-import UserToken from '../../../../../types/UserToken';
-import Utils from '../../../../../utils/Utils';
-import UtilsSecurity from './UtilsSecurity';
-import sanitize from 'mongo-sanitize';
-
-export default class TagSecurity {
-
- public static filterTagsRequest(request: any): HttpTagsRequest {
- const filteredRequest = {
- Search: sanitize(request.Search),
- UserID: sanitize(request.UserID),
- Issuer: Utils.objectHasProperty(request, 'Issuer') ? UtilsSecurity.filterBoolean(request.Issuer) : null,
- Active: Utils.objectHasProperty(request, 'Active') ? UtilsSecurity.filterBoolean(request.Active) : null,
- WithUser: Utils.objectHasProperty(request, 'WithUser') ? UtilsSecurity.filterBoolean(request.WithUser) : null,
- } as HttpTagsRequest;
- UtilsSecurity.filterSkipAndLimit(request, filteredRequest);
- UtilsSecurity.filterSort(request, filteredRequest);
- UtilsSecurity.filterProject(request, filteredRequest);
- return filteredRequest;
- }
-
- public static filterTagRequestByIDs(request: any): string[] {
- return request.tagsIDs.map(sanitize);
- }
-
- public static filterTagUpdateRequest(request: any, loggedUser: UserToken): Partial<Tag> {
- return TagSecurity.filterTagRequest(request, loggedUser);
- }
-
- public static filterTagCreateRequest(request: any, loggedUser: UserToken): Partial<Tag> {
- return TagSecurity.filterTagRequest(request, loggedUser);
- }
-
- public static filterTagRequest(tag: Tag, loggedUser: UserToken): Tag {
- let filteredTag: Tag;
- if (tag) {
- filteredTag = {
- id: sanitize(tag.id),
- visualID: sanitize(tag.visualID),
- description: sanitize(tag.description),
- active: UtilsSecurity.filterBoolean(tag.active),
- issuer: UtilsSecurity.filterBoolean(tag.issuer),
- default: UtilsSecurity.filterBoolean(tag.default),
- userID: sanitize(tag.userID)
- } as Tag;
- }
- return filteredTag;
- }
-
- public static filterTagRequestByID(request: any): HttpTagRequest {
- const filteredRequest: HttpTagRequest = {
- ID: sanitize(request.ID)
- };
- UtilsSecurity.filterProject(request, filteredRequest);
- return filteredRequest;
- }
-}

Tag-delete validation + removed security class + postman update