Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
R
red-ci-cd
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
red-group-test
red-ci-cd
Commits
ed98e131
Commit
ed98e131
authored
Jan 31, 2020
by
Gladys Forte
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
using decorator
parent
b2262f80
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
103 additions
and
43 deletions
+103
-43
app/applicationlayer/cms/template/header/views.py
app/applicationlayer/cms/template/header/views.py
+45
-43
app/helper/decorators.py
app/helper/decorators.py
+58
-0
No files found.
app/applicationlayer/cms/template/header/views.py
View file @
ed98e131
...
...
@@ -35,6 +35,7 @@ from app.applicationlayer.cms.template.attachment.serializers import ChangeReque
from
app.applicationlayer.cms.template.header.serializers
import
ChangeRequestTemplatesSerializer
from
app.applicationlayer.cms.template.header.serializers
import
ChangeRequestTemplatesSerializerList
from
app.applicationlayer.cms.template.header.table_filters
import
HeaderFilterSet
from
app.helper.decorators
import
*
# from django_filters import rest_framework as filters
...
...
@@ -341,55 +342,56 @@ class ChangeRequestTemplatesViewset(viewsets.ModelViewSet):
class
ChangeRequestTemplatePost
(
APIView
):
@
TemplateValidation
@
transaction
.
atomic
()
def
post
(
self
,
request
):
template_header
=
request
.
data
try
:
# restrict superuser department
if
(
template_header
[
'created_by_department'
]
==
'DEPARTMENT-20190923-0000001'
or
template_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
)
tmp_approvers
=
template_header
[
'tmp_approvers'
]
# Check if Vendor and Requestor are existing on routing table
if
len
(
tmp_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
=
validation_existing_vendor_requestor
(
tmp_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
=
validation_approver_same_level
(
tmp_approvers
)
if
validation_result
is
not
None
:
message
=
{
'code'
:
400
,
'status'
:
'failed'
,
'message'
:
validation_result
+
' is already existing for the same level of approval.'
,
}
return
Response
(
message
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
#
if (template_header['created_by_department'] == 'DEPARTMENT-20190923-0000001' or
#
template_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)
#
tmp_approvers = template_header['tmp_approvers']
#
#
Check if Vendor and Requestor are existing on routing table
#
if len(tmp_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 = validation_existing_vendor_requestor(tmp_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 = validation_approver_same_level(tmp_approvers)
#
if validation_result is not None:
#
message = {
#
'code': 400,
#
'status': 'failed',
#
'message': validation_result + ' is already existing for the same level of approval.',
#
}
#
return Response(message,
#
status=status.HTTP_400_BAD_REQUEST)
data_list_approver
=
[]
data_list_stake
=
[]
...
...
app/helper/decorators.py
View file @
ed98e131
...
...
@@ -7,6 +7,11 @@ from rest_framework.authtoken.models import Token
from
app.entities.models
import
User
,
Department
,
Company
from
app.entities
import
enums
from
django.db.models
import
Q
from
app.businesslayer.changerequest.change_request_template
import
(
tmp_add_edit_delete
,
validation_approver_same_level
,
validation_existing_vendor_requestor
)
def
error_safe
(
function
):
...
...
@@ -218,3 +223,56 @@ class rms:
return
function
(
self
,
request
,
*
args
,
**
kwargs
)
return
wrapper
def
TemplateValidation
(
function
):
@
wraps
(
function
)
def
wrapper
(
self
,
request
,
*
args
,
**
kwargs
):
template_header
=
request
.
data
if
(
template_header
[
'created_by_department'
]
==
'DEPARTMENT-20190923-0000001'
or
template_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
)
tmp_approvers
=
template_header
[
'tmp_approvers'
]
# Check if Vendor and Requestor are existing on routing table
if
len
(
tmp_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
=
validation_existing_vendor_requestor
(
tmp_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
=
validation_approver_same_level
(
tmp_approvers
)
if
validation_result
is
not
None
:
message
=
{
'code'
:
400
,
'status'
:
'failed'
,
'message'
:
validation_result
+
' is already existing for the same level of approval.'
,
}
return
Response
(
message
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
return
function
(
self
,
request
,
*
args
,
**
kwargs
)
return
wrapper
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment