Commit 64b19f4c authored by Gladys Forte's avatar Gladys Forte

Merge pull request #738 in RMS/api-main-service from core-dev-gladys to RMSv2

* commit '1c63ccdb':
  validation form
  Validation Routing Table Form
parents 5f7947e6 1c63ccdb
......@@ -1182,8 +1182,41 @@ class ChangeRequestFormPost(APIView):
def post(self, request):
form_header = request.data
try:
# restrict superuser department
if (form_header['requested_by_department'] == 'DEPARTMENT-20190923-0000001' or
form_header['requested_to_department'] == 'DEPARTMENT-20190923-0000001'):
message = {
'code': 400,
'status': 'failed',
'message': 'Superuser department cannot be selected',
}
return Response(message,
status=status.HTTP_400_BAD_REQUEST)
frm_approvers = form_header['frm_approvers']
# 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
validation_result = change_request_template.validation_approver_same_level(frm_approvers)
if validation_result is not None:
......@@ -1196,7 +1229,7 @@ class ChangeRequestFormPost(APIView):
status=status.HTTP_400_BAD_REQUEST)
# 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:
message = {
......
......@@ -766,22 +766,3 @@ def cr_routing_actions(approver_instance, current_user, move_to_level):
reset_autoemail_tables(form_code)
return True
\ No newline at end of file
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,32 @@ def tmp_add_edit_delete(tmp_request_body,
return True
# 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):
data_list_appr = []
......@@ -131,4 +157,3 @@ def validation_approver_same_level(approvers):
return user_name
return None
......@@ -46,7 +46,6 @@ INSTALLED_APPS = [
'app.accesslayer',
'app.entities',
'channels',
]
MIDDLEWARE = [
......
......@@ -14,8 +14,8 @@ CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
# "hosts": [('172.17.0.1', 6379)],
"hosts": [('127.0.0.1', 6379)],
"hosts": [('172.17.0.1', 6379)],
# "hosts": [('127.0.0.1', 6379)],
},
},
}
......
......@@ -14,8 +14,8 @@ CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
# "hosts": [('172.17.0.1', 6379)],
"hosts": [('127.0.0.1', 6379)],
"hosts": [('172.17.0.1', 6379)],
# "hosts": [('127.0.0.1', 6379)],
},
},
}
......
......@@ -13,8 +13,8 @@ CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
# "hosts": [('172.17.0.1', 6379)],
"hosts": [('127.0.0.1', 6379)],
"hosts": [('172.17.0.1', 6379)],
# "hosts": [('127.0.0.1', 6379)],
},
},
}
......
......@@ -13,8 +13,8 @@ CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
# "hosts": [('172.17.0.1', 6379)],
"hosts": [('127.0.0.1', 6379)],
"hosts": [('172.17.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