From e4469cc445092d0fe4aad3b2e8a7da7924f9351b Mon Sep 17 00:00:00 2001 From: Nathan Cheval Date: Fri, 20 Oct 2023 15:50:21 +0200 Subject: [PATCH 1/4] Add missing column in structure sql file --- instance/sql/structure.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/instance/sql/structure.sql b/instance/sql/structure.sql index caa50d64e4..4aea9913d0 100755 --- a/instance/sql/structure.sql +++ b/instance/sql/structure.sql @@ -266,6 +266,7 @@ CREATE TABLE "splitter_pages" ( "document_id" INTEGER, "thumbnail" VARCHAR(255), "source_page" INTEGER, + "display_order" INTEGER, "rotation" INTEGER DEFAULT 0, "status" VARCHAR(255) DEFAULT 'NEW' ); From 04f3b85203e02e8bb8446c934e25abc8c16693b4 Mon Sep 17 00:00:00 2001 From: Nathan Cheval Date: Fri, 20 Oct 2023 16:00:16 +0200 Subject: [PATCH 2/4] Fix accounts tests --- src/backend/tests/rest/test_accounts.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/tests/rest/test_accounts.py b/src/backend/tests/rest/test_accounts.py index 9d62ab3732..43c2c7a8f4 100755 --- a/src/backend/tests/rest/test_accounts.py +++ b/src/backend/tests/rest/test_accounts.py @@ -56,7 +56,8 @@ def create_customer(self): "siret": "1234567891011", "siren": "123456789", "company_number": "123", - "address_id": 1 + "address_id": 1, + "module": 'verifier' } return self.app.post(f'/{CUSTOM_ID}/ws/accounts/customers/create', From 4b961979a86354cb2b27fd051ed4d06c88eef6a7 Mon Sep 17 00:00:00 2001 From: Nathan Cheval Date: Fri, 20 Oct 2023 16:01:07 +0200 Subject: [PATCH 3/4] Add mailcollect and history rest validators --- src/backend/controllers/mailcollect.py | 8 +- src/backend/functions.py | 5 +- src/backend/models/mailcollect.py | 5 +- src/backend/process/find_name.py | 0 src/backend/rest/history.py | 42 ++++++++- src/backend/rest/locale.py | 1 + src/backend/rest/mailcollect.py | 91 ++++++++++++++----- .../mailcollect/mailcollect.component.ts | 1 - .../notifications/notifications.service.ts | 4 +- 9 files changed, 122 insertions(+), 35 deletions(-) mode change 100644 => 100755 src/backend/process/find_name.py diff --git a/src/backend/controllers/mailcollect.py b/src/backend/controllers/mailcollect.py index fc9356e97c..e3917d9332 100755 --- a/src/backend/controllers/mailcollect.py +++ b/src/backend/controllers/mailcollect.py @@ -73,12 +73,10 @@ def create_process(args): 'ip': request.remote_addr, 'submodule': 'create_mailcollect_process', 'user_info': request.environ['user_info'], - 'desc': gettext('CREATE_MAILCOLLECT_PROCESS', process=args['column']['name']) + 'desc': gettext('CREATE_MAILCOLLECT_PROCESS', process=args['columns']['name']) }) - response = { - "process": process - } - return response, 200 + + return {"process": process}, 200 response = { "errors": gettext("CREATE_PROCESS_ERROR"), diff --git a/src/backend/functions.py b/src/backend/functions.py index d7e9541d43..2826f71846 100755 --- a/src/backend/functions.py +++ b/src/backend/functions.py @@ -50,11 +50,12 @@ def rest_validator(data, required_fields): if field['mandatory']: if field['id'] not in data or not data[field['id']]: return False, gettext('NO_DATA_OR_DATA_MISSING') + if not isinstance(data[field['id']], field['type']): if field['type'] == int: try: int(data[field['id']]) - return True, '' + continue except (TypeError, ValueError): return False, error_message return False, error_message @@ -63,7 +64,7 @@ def rest_validator(data, required_fields): if field['type'] == int: try: int(data[field['id']]) - return True, '' + continue except (TypeError, ValueError): return False, error_message return False, error_message diff --git a/src/backend/models/mailcollect.py b/src/backend/models/mailcollect.py index ed424f3a54..fb6b6cb65f 100755 --- a/src/backend/models/mailcollect.py +++ b/src/backend/models/mailcollect.py @@ -32,12 +32,13 @@ def retrieve_processes(args): if not _vars[0]: return {}, _vars[1] database = _vars[0] + error = None processes = database.select({ 'select': ['*'] if 'select' not in args else args['select'], 'table': ['mailcollect'], - 'where': ['1=%s'] if 'where' not in args else args['where'], - 'data': ['1'] if 'data' not in args else args['data'], + 'where': ['status <> %s'] if 'where' not in args else args['where'], + 'data': ['DEL'] if 'data' not in args else args['data'], 'order_by': ['id ASC'], 'limit': str(args['limit']) if 'limit' in args else 'ALL', 'offset': str(args['offset']) if 'offset' in args else 0 diff --git a/src/backend/process/find_name.py b/src/backend/process/find_name.py old mode 100644 new mode 100755 diff --git a/src/backend/rest/history.py b/src/backend/rest/history.py index c7f16b6d76..be42b2006b 100755 --- a/src/backend/rest/history.py +++ b/src/backend/rest/history.py @@ -16,9 +16,10 @@ # @dev : Nathan Cheval -from flask import Blueprint, request, make_response, jsonify from flask_babel import gettext +from flask import Blueprint, request, make_response, jsonify +from src.backend.functions import rest_validator from src.backend.import_controllers import auth, history, privileges bp = Blueprint('history', __name__, url_prefix='/ws/') @@ -26,6 +27,20 @@ @bp.route('history/add', methods=['POST']) def add_history(): + check, message = rest_validator(request.json, [ + {'id': 'desc', 'type': str, 'mandatory': True}, + {'id': 'module', 'type': str, 'mandatory': True}, + {'id': 'user_id', 'type': int, 'mandatory': True}, + {'id': 'user_info', 'type': str, 'mandatory': True}, + {'id': 'submodule', 'type': str, 'mandatory': True} + ]) + + if not check: + return make_response({ + "errors": gettext('BAD_REQUEST'), + "message": message + }, 400) + data = request.json data['ip'] = request.remote_addr res = history.add_history(data) @@ -38,6 +53,21 @@ def get_history(): if not privileges.has_privileges(request.environ['user_id'], ['history | statistics']): return jsonify({'errors': gettext('UNAUTHORIZED_ROUTE'), 'message': '/history/list'}), 403 + check, message = rest_validator(request.args, [ + {'id': 'user', 'type': str, 'mandatory': False}, + {'id': 'year', 'type': int, 'mandatory': False}, + {'id': 'limit', 'type': int, 'mandatory': False}, + {'id': 'offset', 'type': int, 'mandatory': False}, + {'id': 'module', 'type': str, 'mandatory': False}, + {'id': 'submodule', 'type': str, 'mandatory': False} + ]) + + if not check: + return make_response({ + "errors": gettext('BAD_REQUEST'), + "message": message + }, 400) + _history = history.get_history(request.args) return make_response(jsonify(_history[0])), _history[1] @@ -48,6 +78,16 @@ def get_history_submodules(): if not privileges.has_privileges(request.environ['user_id'], ['history']): return jsonify({'errors': gettext('UNAUTHORIZED_ROUTE'), 'message': '/history/submodules'}), 403 + check, message = rest_validator(request.args, [ + {'id': 'module', 'type': str, 'mandatory': False} + ]) + + if not check: + return make_response({ + "errors": gettext('BAD_REQUEST'), + "message": message + }, 400) + _history = history.get_history_submodules(request.args) return make_response(jsonify(_history[0])), _history[1] diff --git a/src/backend/rest/locale.py b/src/backend/rest/locale.py index 64d5bf9cbf..b875a3182f 100755 --- a/src/backend/rest/locale.py +++ b/src/backend/rest/locale.py @@ -60,6 +60,7 @@ def get_current_lang(): _vars = create_classes_from_custom_id(custom_id) configurations = _vars[10] languages = _vars[11] + current_lang = configurations['locale'] angular_moment_lang = '' babel_lang = '' diff --git a/src/backend/rest/mailcollect.py b/src/backend/rest/mailcollect.py index aa014377da..00eff3b62d 100755 --- a/src/backend/rest/mailcollect.py +++ b/src/backend/rest/mailcollect.py @@ -16,6 +16,7 @@ # @dev : Nathan Cheval from flask_babel import gettext +from src.backend.functions import rest_validator from flask import Blueprint, jsonify, make_response, request from src.backend.import_controllers import mailcollect, auth, privileges @@ -28,13 +29,7 @@ def retrieve_processes(): if not privileges.has_privileges(request.environ['user_id'], ['settings', 'mailcollect']): return jsonify({'errors': gettext('UNAUTHORIZED_ROUTE'), 'message': '/mailcollect/getProcesses'}), 403 - args = { - 'select': ['*'], - 'where': ['status <> %s'], - 'data': ['DEL'] - } - - res = mailcollect.retrieve_processes(args) + res = mailcollect.retrieve_processes({}) return make_response(jsonify(res[0])), res[1] @@ -44,8 +39,21 @@ def retrieve_folders(): if not privileges.has_privileges(request.environ['user_id'], ['settings', 'mailcollect']): return jsonify({'errors': gettext('UNAUTHORIZED_ROUTE'), 'message': '/mailcollect/retrieveFolders'}), 403 - args = request.json - res = mailcollect.retrieve_folders(args) + check, message = rest_validator(request.json, [ + {'id': 'port', 'type': int, 'mandatory': True}, + {'id': 'login', 'type': str, 'mandatory': True}, + {'id': 'hostname', 'type': str, 'mandatory': True}, + {'id': 'password', 'type': str, 'mandatory': True}, + {'id': 'secured_connection', 'type': bool, 'mandatory': False} + ]) + + if not check: + return make_response({ + "errors": gettext('BAD_REQUEST'), + "message": message + }, 400) + + res = mailcollect.retrieve_folders(request.json) return make_response(jsonify(res[0])), res[1] @@ -54,14 +62,33 @@ def retrieve_folders(): def update_process(process_name): if not privileges.has_privileges(request.environ['user_id'], ['settings', 'mailcollect']): return jsonify({'errors': gettext('UNAUTHORIZED_ROUTE'), - 'message': f'/mailcollect/updateProcesses/{process_name}'}), 403 - - data = request.json - args = { - 'set': data, - 'process_name': process_name - } - res = mailcollect.update_process(args) + 'message': f'/mailcollect/updateProcess/{process_name}'}), 403 + + check, message = rest_validator(request.json, [ + {'id': 'name', 'type': str, 'mandatory': True}, + {'id': 'port', 'type': int, 'mandatory': True}, + {'id': 'login', 'type': str, 'mandatory': True}, + {'id': 'enabled', 'type': bool, 'mandatory': True}, + {'id': 'hostname', 'type': str, 'mandatory': True}, + {'id': 'password', 'type': str, 'mandatory': True}, + {'id': 'is_splitter', 'type': bool, 'mandatory': False}, + {'id': 'folder_trash', 'type': str, 'mandatory': False}, + {'id': 'folder_to_crawl', 'type': str, 'mandatory': True}, + {'id': 'verifier_form_id', 'type': str, 'mandatory': False}, + {'id': 'folder_destination', 'type': str, 'mandatory': True}, + {'id': 'secured_connection', 'type': bool, 'mandatory': False}, + {'id': 'action_after_process', 'type': str, 'mandatory': True}, + {'id': 'verifier_customer_id', 'type': str, 'mandatory': False}, + {'id': 'splitter_technical_workflow_id', 'type': int, 'mandatory': False} + ]) + + if not check: + return make_response({ + "errors": gettext('BAD_REQUEST'), + "message": message + }, 400) + + res = mailcollect.update_process({'set': request.json, 'process_name': process_name}) return make_response(jsonify(res[0])), res[1] @@ -71,11 +98,31 @@ def create_process(): if not privileges.has_privileges(request.environ['user_id'], ['settings', 'mailcollect']): return jsonify({'errors': gettext('UNAUTHORIZED_ROUTE'), 'message': '/mailcollect/createProcess'}), 403 - data = request.json - args = { - 'columns': data - } - res = mailcollect.create_process(args) + check, message = rest_validator(request.json, [ + {'id': 'name', 'type': str, 'mandatory': True}, + {'id': 'port', 'type': int, 'mandatory': True}, + {'id': 'login', 'type': str, 'mandatory': True}, + {'id': 'enabled', 'type': bool, 'mandatory': False}, + {'id': 'hostname', 'type': str, 'mandatory': True}, + {'id': 'password', 'type': str, 'mandatory': True}, + {'id': 'is_splitter', 'type': bool, 'mandatory': False}, + {'id': 'folder_trash', 'type': str, 'mandatory': False}, + {'id': 'folder_to_crawl', 'type': str, 'mandatory': True}, + {'id': 'verifier_form_id', 'type': str, 'mandatory': False}, + {'id': 'folder_destination', 'type': str, 'mandatory': True}, + {'id': 'secured_connection', 'type': bool, 'mandatory': False}, + {'id': 'action_after_process', 'type': str, 'mandatory': True}, + {'id': 'verifier_customer_id', 'type': str, 'mandatory': False}, + {'id': 'splitter_technical_workflow_id', 'type': int, 'mandatory': False} + ]) + + if not check: + return make_response({ + "errors": gettext('BAD_REQUEST'), + "message": message + }, 400) + + res = mailcollect.create_process({'columns': request.json}) return make_response(jsonify(res[0])), res[1] diff --git a/src/frontend/app/settings/general/mailcollect/mailcollect.component.ts b/src/frontend/app/settings/general/mailcollect/mailcollect.component.ts index 20f796c065..414324504e 100755 --- a/src/frontend/app/settings/general/mailcollect/mailcollect.component.ts +++ b/src/frontend/app/settings/general/mailcollect/mailcollect.component.ts @@ -216,7 +216,6 @@ export class MailCollectComponent implements OnInit { public router: Router, private http: HttpClient, private dialog: MatDialog, - private route: ActivatedRoute, private authService: AuthService, private translate: TranslateService, private notify: NotificationService, diff --git a/src/frontend/services/notifications/notifications.service.ts b/src/frontend/services/notifications/notifications.service.ts index f82e150bed..f04c4f50ec 100755 --- a/src/frontend/services/notifications/notifications.service.ts +++ b/src/frontend/services/notifications/notifications.service.ts @@ -53,13 +53,13 @@ export class NotificationService { return; } this.oldErrorMessage = message; - const duration = this.getMessageDuration(message, 4000); + const duration = this.getMessageDuration(message, 6000); message = message.replace("", 'string'); message = message.replace("", 'integer'); message = message.replace("", 'boolean'); message = message.replace("", 'dict'); message = message.replace("", 'list'); - this.toastr.error(message, '', {timeOut: duration, enableHtml: true, progressBar: true}); + this.toastr.error(message, '', {timeOut: duration, enableHtml: true}); } handleErrors(err: any, route = '') { From 111cfccfc1cce8ff04064be77c3ccc199ea8721b Mon Sep 17 00:00:00 2001 From: Brich Oussama Date: Fri, 20 Oct 2023 16:18:05 +0200 Subject: [PATCH 4/4] Add missing column to sql structure --- instance/sql/structure.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/instance/sql/structure.sql b/instance/sql/structure.sql index caa50d64e4..4aea9913d0 100755 --- a/instance/sql/structure.sql +++ b/instance/sql/structure.sql @@ -266,6 +266,7 @@ CREATE TABLE "splitter_pages" ( "document_id" INTEGER, "thumbnail" VARCHAR(255), "source_page" INTEGER, + "display_order" INTEGER, "rotation" INTEGER DEFAULT 0, "status" VARCHAR(255) DEFAULT 'NEW' );