Commit 85672b37 authored by Gladys Forte's avatar Gladys Forte

Validation Routing Table Form

parent 89d1097b
...@@ -1184,6 +1184,40 @@ class ChangeRequestFormPost(APIView): ...@@ -1184,6 +1184,40 @@ class ChangeRequestFormPost(APIView):
try: try:
frm_approvers = form_header['frm_approvers'] frm_approvers = form_header['frm_approvers']
# Routing Validations
result = change_request_template.validation_superuser_department(frm_approvers)
if result is True:
message = {
'code': 400,
'status': 'failed',
'message': 'Please remove Super User Department into routing table',
}
return Response(message,
status=status.HTTP_400_BAD_REQUEST)
# Check if Vendor and Requestor are existing on routing table
if len(frm_approvers) < 2:
message = {
'code': 400,
'status': 'failed',
'message': 'Please make sure to add an Approver, Vendor and Requestor into routing table',
}
return Response(message,
status=status.HTTP_400_BAD_REQUEST)
else:
result = change_request_template.validation_existing_vendor_requestor(frm_approvers)
if result is False:
message = {
'code': 400,
'status': 'failed',
'message': 'Please add Vendor/Implementor and Requestor into routing table',
}
return Response(message,
status=status.HTTP_400_BAD_REQUEST)
# Do not allow adding an approver for the same level # Do not allow adding an approver for the same level
validation_result = change_request_template.validation_approver_same_level(frm_approvers) validation_result = change_request_template.validation_approver_same_level(frm_approvers)
if validation_result is not None: if validation_result is not None:
...@@ -1196,7 +1230,7 @@ class ChangeRequestFormPost(APIView): ...@@ -1196,7 +1230,7 @@ class ChangeRequestFormPost(APIView):
status=status.HTTP_400_BAD_REQUEST) status=status.HTTP_400_BAD_REQUEST)
# Restrict a requestor to submit a CR without atleast 1 approver # Restrict a requestor to submit a CR without atleast 1 approver
counter = change_request.validation_existing_approver(frm_approvers) counter = change_request_template.validation_existing_approver(frm_approvers)
if form_header['status'].lower() == 'pending' and counter == 0: if form_header['status'].lower() == 'pending' and counter == 0:
message = { message = {
......
...@@ -766,22 +766,3 @@ def cr_routing_actions(approver_instance, current_user, move_to_level): ...@@ -766,22 +766,3 @@ def cr_routing_actions(approver_instance, current_user, move_to_level):
reset_autoemail_tables(form_code) reset_autoemail_tables(form_code)
return True return True
def validation_existing_approver(approvers):
counter = 0
for approver in approvers:
# count all delegation not equal to Requestor and Vendor
if approver['delegation'] not in ['DELEGATION-20191119-0000002', 'DELEGATION-20191119-0000001']:
counter = counter + 1
return counter
return counter
...@@ -106,6 +106,42 @@ def tmp_add_edit_delete(tmp_request_body, ...@@ -106,6 +106,42 @@ def tmp_add_edit_delete(tmp_request_body,
return True return True
# Check if superuser department included in routing table
def validation_superuser_department(approvers):
for approver in approvers:
if approver['delegation'] == 'DEPARTMENT-20190923-0000001':
return True
else:
return False
# Check if routing table has Vendor and Requestor
def validation_existing_vendor_requestor(approvers):
approvers_data = sorted(approvers,
key=itemgetter('level'))[-2:]
if (approvers_data[0]['delegation'] == 'DELEGATION-20191119-0000002' and
approvers_data[1]['delegation'] == 'DELEGATION-20191119-0000001'):
return True
else:
return False
# Check if routing table has atleast 1 approver
def validation_existing_approver(approvers):
counter = 0
for approver in approvers:
# count all delegation not equal to Requestor and Vendor
if approver['delegation'] not in ['DELEGATION-20191119-0000002',
'DELEGATION-20191119-0000001']:
counter = counter + 1
return counter
return counter
# Check if a user has multiple same level in routing table
def validation_approver_same_level(approvers): def validation_approver_same_level(approvers):
data_list_appr = [] data_list_appr = []
...@@ -131,4 +167,3 @@ def validation_approver_same_level(approvers): ...@@ -131,4 +167,3 @@ def validation_approver_same_level(approvers):
return user_name return user_name
return None return None
...@@ -46,7 +46,6 @@ INSTALLED_APPS = [ ...@@ -46,7 +46,6 @@ INSTALLED_APPS = [
'app.accesslayer', 'app.accesslayer',
'app.entities', 'app.entities',
'channels', 'channels',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
......
...@@ -14,8 +14,8 @@ CHANNEL_LAYERS = { ...@@ -14,8 +14,8 @@ CHANNEL_LAYERS = {
'default': { 'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer', 'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': { 'CONFIG': {
# "hosts": [('172.17.0.1', 6379)], "hosts": [('172.17.0.1', 6379)],
"hosts": [('127.0.0.1', 6379)], # "hosts": [('127.0.0.1', 6379)],
}, },
}, },
} }
......
...@@ -14,8 +14,8 @@ CHANNEL_LAYERS = { ...@@ -14,8 +14,8 @@ CHANNEL_LAYERS = {
'default': { 'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer', 'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': { 'CONFIG': {
# "hosts": [('172.17.0.1', 6379)], "hosts": [('172.17.0.1', 6379)],
"hosts": [('127.0.0.1', 6379)], # "hosts": [('127.0.0.1', 6379)],
}, },
}, },
} }
......
...@@ -13,8 +13,8 @@ CHANNEL_LAYERS = { ...@@ -13,8 +13,8 @@ CHANNEL_LAYERS = {
'default': { 'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer', 'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': { 'CONFIG': {
# "hosts": [('172.17.0.1', 6379)], "hosts": [('172.17.0.1', 6379)],
"hosts": [('127.0.0.1', 6379)], # "hosts": [('127.0.0.1', 6379)],
}, },
}, },
} }
......
...@@ -13,8 +13,8 @@ CHANNEL_LAYERS = { ...@@ -13,8 +13,8 @@ CHANNEL_LAYERS = {
'default': { 'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer', 'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': { 'CONFIG': {
# "hosts": [('172.17.0.1', 6379)], "hosts": [('172.17.0.1', 6379)],
"hosts": [('127.0.0.1', 6379)], # "hosts": [('127.0.0.1', 6379)],
}, },
}, },
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment