Skip to content

Commit

Permalink
Merge pull request #1134 from edissyum/dev_v3
Browse files Browse the repository at this point in the history
3.0.5
  • Loading branch information
Brich40 authored Oct 20, 2023
2 parents c3fcfd8 + ff69756 commit 41c4ea5
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 36 deletions.
1 change: 1 addition & 0 deletions instance/sql/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
Expand Down
8 changes: 3 additions & 5 deletions src/backend/controllers/mailcollect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
5 changes: 3 additions & 2 deletions src/backend/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/backend/models/mailcollect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Empty file modified src/backend/process/find_name.py
100644 → 100755
Empty file.
42 changes: 41 additions & 1 deletion src/backend/rest/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,31 @@
# @dev : Nathan Cheval <[email protected]>


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/')


@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)
Expand All @@ -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]

Expand All @@ -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]

Expand Down
1 change: 1 addition & 0 deletions src/backend/rest/locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand Down
91 changes: 69 additions & 22 deletions src/backend/rest/mailcollect.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# @dev : Nathan Cheval <[email protected]>

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

Expand All @@ -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]


Expand All @@ -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]


Expand All @@ -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]


Expand All @@ -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]


Expand Down
3 changes: 2 additions & 1 deletion src/backend/tests/rest/test_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/services/notifications/notifications.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("<class 'str'>", 'string');
message = message.replace("<class 'int'>", 'integer');
message = message.replace("<class 'bool'>", 'boolean');
message = message.replace("<class 'dict'>", 'dict');
message = message.replace("<class 'list'>", 'list');
this.toastr.error(message, '', {timeOut: duration, enableHtml: true, progressBar: true});
this.toastr.error(message, '', {timeOut: duration, enableHtml: true});
}

handleErrors(err: any, route = '') {
Expand Down

0 comments on commit 41c4ea5

Please sign in to comment.