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
28887d40
Commit
28887d40
authored
Nov 11, 2019
by
Gladys Forte
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
restrictions delegations
parent
93a076f9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
33 deletions
+94
-33
app/applicationlayer/management/delegation/views.py
app/applicationlayer/management/delegation/views.py
+74
-32
app/entities/migrations/0036_auto_20191111_1549.py
app/entities/migrations/0036_auto_20191111_1549.py
+18
-0
app/entities/models.py
app/entities/models.py
+2
-1
No files found.
app/applicationlayer/management/delegation/views.py
View file @
28887d40
...
@@ -5,7 +5,7 @@ from rest_framework.response import Response
...
@@ -5,7 +5,7 @@ from rest_framework.response import Response
from
app.applicationlayer.utils
import
model_to_dict
from
app.applicationlayer.utils
import
model_to_dict
from
rest_framework.filters
import
SearchFilter
,
OrderingFilter
from
rest_framework.filters
import
SearchFilter
,
OrderingFilter
from
django_filters
import
rest_framework
as
filters
from
django_filters
import
rest_framework
as
filters
from
app.entities.models
import
Delegation
from
app.entities.models
import
Delegation
,
Department
from
app.applicationlayer.utils
import
(
from
app.applicationlayer.utils
import
(
CustomPagination
,
status_message_response
,
log_save
CustomPagination
,
status_message_response
,
log_save
)
)
...
@@ -67,16 +67,20 @@ class DelegationViewSet(viewsets.ModelViewSet):
...
@@ -67,16 +67,20 @@ class DelegationViewSet(viewsets.ModelViewSet):
instance
=
self
.
get_object
()
instance
=
self
.
get_object
()
new_instance
=
model_to_dict
(
instance
)
new_instance
=
model_to_dict
(
instance
)
exist_in_dept
=
instance
.
departments
.
all
()
# restrictions
# restrictions
if
(
new_instance
[
'name'
]
.
lower
()
==
'head of department'
or
if
not
exist_in_dept
.
count
()
>
0
:
print
(
exist_in_dept
)
if
not
(
new_instance
[
'name'
]
.
lower
()
==
'head of department'
or
new_instance
[
'name'
]
.
lower
()
==
'sd/od'
or
new_instance
[
'name'
]
.
lower
()
==
'sd/od'
or
new_instance
[
'name'
]
.
lower
()
==
'change control board'
or
new_instance
[
'name'
]
.
lower
()
==
'change control board'
or
new_instance
[
'name'
]
.
lower
()
==
'approver'
or
new_instance
[
'name'
]
.
lower
()
==
'approver'
or
new_instance
[
'name'
]
.
lower
()
==
'vendor/implementor'
or
new_instance
[
'name'
]
.
lower
()
==
'vendor/implementor'
or
new_instance
[
'name'
]
.
lower
()
==
'requestor'
):
new_instance
[
'name'
]
.
lower
()
==
'requestor'
):
print
(
"hello"
)
self
.
perform_destroy
(
instance
)
self
.
perform_destroy
(
instance
)
log_save
(
log_save
(
...
@@ -87,7 +91,27 @@ class DelegationViewSet(viewsets.ModelViewSet):
...
@@ -87,7 +91,27 @@ class DelegationViewSet(viewsets.ModelViewSet):
''
''
)
)
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
message
=
{
'code'
:
200
,
'status'
:
'success'
,
'message'
:
'Delegation Successfully deleted'
}
return
Response
(
message
,
status
=
status
.
HTTP_200_OK
)
else
:
message
=
{
'code'
:
400
,
'status'
:
'failed'
,
'message'
:
'Default delegation cannot delete'
}
return
Response
(
message
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
else
:
message
=
{
'code'
:
400
,
'status'
:
'failed'
,
'message'
:
'Cannot delete this delegation due to existing record in department'
}
return
Response
(
message
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
@
transaction
.
atomic
@
transaction
.
atomic
def
update
(
self
,
request
,
*
args
,
**
kwargs
):
def
update
(
self
,
request
,
*
args
,
**
kwargs
):
...
@@ -98,6 +122,15 @@ class DelegationViewSet(viewsets.ModelViewSet):
...
@@ -98,6 +122,15 @@ class DelegationViewSet(viewsets.ModelViewSet):
serializer
.
is_valid
(
raise_exception
=
True
)
serializer
.
is_valid
(
raise_exception
=
True
)
old_instance
=
model_to_dict
(
instance
)
old_instance
=
model_to_dict
(
instance
)
# restrictions
if
not
(
new_instance
[
'name'
]
.
lower
()
==
'head of department'
or
new_instance
[
'name'
]
.
lower
()
==
'sd/od'
or
new_instance
[
'name'
]
.
lower
()
==
'change control board'
or
new_instance
[
'name'
]
.
lower
()
==
'approver'
or
new_instance
[
'name'
]
.
lower
()
==
'vendor/implementor'
or
new_instance
[
'name'
]
.
lower
()
==
'requestor'
):
self
.
perform_update
(
serializer
)
self
.
perform_update
(
serializer
)
new_instance
=
serializer
.
data
new_instance
=
serializer
.
data
...
@@ -110,3 +143,12 @@ class DelegationViewSet(viewsets.ModelViewSet):
...
@@ -110,3 +143,12 @@ class DelegationViewSet(viewsets.ModelViewSet):
)
)
return
Response
(
serializer
.
data
)
return
Response
(
serializer
.
data
)
else
:
message
=
{
'code'
:
400
,
'status'
:
'failed'
,
'message'
:
'Default delegation cannot edit'
}
return
Response
(
message
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
app/entities/migrations/0036_auto_20191111_1549.py
0 → 100644
View file @
28887d40
# Generated by Django 2.2 on 2019-11-11 15:49
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'entities'
,
'0035_changerequesttemplateapprovers_is_default'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'department'
,
name
=
'delegation'
,
field
=
models
.
ManyToManyField
(
related_name
=
'departments'
,
to
=
'entities.Delegation'
),
),
]
app/entities/models.py
View file @
28887d40
...
@@ -149,7 +149,8 @@ class Department(AuditClass):
...
@@ -149,7 +149,8 @@ class Department(AuditClass):
)
)
name
=
models
.
CharField
(
max_length
=
255
)
name
=
models
.
CharField
(
max_length
=
255
)
delegation
=
models
.
ManyToManyField
(
delegation
=
models
.
ManyToManyField
(
Delegation
Delegation
,
related_name
=
'departments'
)
)
class
Meta
:
class
Meta
:
...
...
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