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
9f666061
Commit
9f666061
authored
Sep 09, 2019
by
John Red Medrano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added user management, added new folder management and master on applicationlayer
parent
85b131ff
Changes
29
Hide whitespace changes
Inline
Side-by-side
Showing
29 changed files
with
739 additions
and
39 deletions
+739
-39
app/applicationlayer/management/account/serializer.py
app/applicationlayer/management/account/serializer.py
+12
-0
app/applicationlayer/management/account/table_filters.py
app/applicationlayer/management/account/table_filters.py
+17
-0
app/applicationlayer/management/account/views.py
app/applicationlayer/management/account/views.py
+101
-0
app/applicationlayer/management/application/table_filters.py
app/applicationlayer/management/application/table_filters.py
+6
-6
app/applicationlayer/management/application/views.py
app/applicationlayer/management/application/views.py
+4
-3
app/applicationlayer/management/company/views.py
app/applicationlayer/management/company/views.py
+8
-4
app/applicationlayer/management/department/views.py
app/applicationlayer/management/department/views.py
+6
-3
app/applicationlayer/management/module/views.py
app/applicationlayer/management/module/views.py
+7
-4
app/applicationlayer/management/user/serializers.py
app/applicationlayer/management/user/serializers.py
+5
-4
app/applicationlayer/management/user/views.py
app/applicationlayer/management/user/views.py
+8
-7
app/applicationlayer/master/company/serializer.py
app/applicationlayer/master/company/serializer.py
+8
-0
app/applicationlayer/master/company/views.py
app/applicationlayer/master/company/views.py
+42
-0
app/applicationlayer/master/department/serializer.py
app/applicationlayer/master/department/serializer.py
+11
-0
app/applicationlayer/master/department/views.py
app/applicationlayer/master/department/views.py
+44
-0
app/applicationlayer/master/urls.py
app/applicationlayer/master/urls.py
+16
-0
app/applicationlayer/master/user_type/views.py
app/applicationlayer/master/user_type/views.py
+43
-0
app/applicationlayer/urls.py
app/applicationlayer/urls.py
+7
-3
app/businesslayer/company/serializer.py
app/businesslayer/company/serializer.py
+8
-0
app/businesslayer/company/table_filters.py
app/businesslayer/company/table_filters.py
+0
-0
app/businesslayer/company/views.py
app/businesslayer/company/views.py
+42
-0
app/businesslayer/department/serializer.py
app/businesslayer/department/serializer.py
+11
-0
app/businesslayer/department/table_filters.py
app/businesslayer/department/table_filters.py
+17
-0
app/businesslayer/department/views.py
app/businesslayer/department/views.py
+44
-0
app/businesslayer/urls.py
app/businesslayer/urls.py
+16
-0
app/businesslayer/user_type/views.py
app/businesslayer/user_type/views.py
+36
-0
app/entities/migrations/0014_application_app_code.py
app/entities/migrations/0014_application_app_code.py
+19
-0
app/entities/models.py
app/entities/models.py
+1
-0
app/helper/decorators.py
app/helper/decorators.py
+198
-0
config/urls.py
config/urls.py
+2
-5
No files found.
app/applicationlayer/management/account/serializer.py
0 → 100644
View file @
9f666061
from
rest_framework
import
serializers
from
app.entities.models
import
User
import
ast
class
UserSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
User
fields
=
'__all__'
read_only_fields
=
(
'created'
,
'createdby'
,
'modified'
,
'modifiedby'
,
'code'
,
)
app/applicationlayer/management/account/table_filters.py
0 → 100644
View file @
9f666061
from
django_filters
import
rest_framework
as
filters
from
django.db.models
import
Count
from
app.entities.models
import
User
from
django.db.models
import
Q
class
UserFilterSet
(
filters
.
FilterSet
):
# search = filters.CharFilter(method='search_bar', label='search')
# def search_bar(self, queryset, name, value):
# return queryset.filter(
# Q(username__icontains=value) |
# Q(first_name__icontains=value) |
# Q(last_name__icontains=value))
class
Meta
:
model
=
User
fields
=
'__all__'
app/applicationlayer/management/account/views.py
0 → 100644
View file @
9f666061
from
app.entities
import
enums
from
django.db
import
transaction
from
app.helper.decorators
import
rms
,
error_safe
from
rest_framework
import
viewsets
,
status
from
rest_framework.response
import
Response
from
django.forms.models
import
model_to_dict
from
rest_framework.filters
import
SearchFilter
,
OrderingFilter
from
django_filters
import
rest_framework
as
filters
from
app.entities.models
import
User
,
EntityLog
from
app.applicationlayer.utils
import
(
CustomPagination
,
status_message_response
,
log_save
)
from
django_filters.rest_framework
import
DjangoFilterBackend
from
app.applicationlayer.management.account
import
serializer
from
app.applicationlayer.management.account.table_filters
import
UserFilterSet
class
UserViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
User
.
objects
.
all
()
serializer_class
=
serializer
.
UserSerializer
pagination_class
=
CustomPagination
filter_backends
=
(
DjangoFilterBackend
,
SearchFilter
,
OrderingFilter
)
filterset_class
=
UserFilterSet
ordering_fields
=
'__all__'
search_fields
=
(
'name'
,)
# @check.user_type
@
rms
.
user_create
@
transaction
.
atomic
def
create
(
self
,
request
,
*
args
,
**
kwargs
):
serializer
=
self
.
get_serializer
(
data
=
request
.
data
)
serializer
.
is_valid
(
raise_exception
=
True
)
self
.
perform_create
(
serializer
)
message
=
status_message_response
(
201
,
'success'
,
'New Users created'
,
serializer
.
data
)
return
Response
(
message
)
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
queryset
=
self
.
filter_queryset
(
self
.
get_queryset
())
page
=
self
.
paginate_queryset
(
queryset
)
if
page
is
not
None
:
serializer
=
self
.
get_serializer
(
page
,
many
=
True
)
message
=
status_message_response
(
200
,
'success'
,
'list of Users found'
,
serializer
.
data
)
return
self
.
get_paginated_response
(
message
)
serializer
=
self
.
get_serializer
(
queryset
,
many
=
True
)
return
Response
(
serializer
.
data
)
@
error_safe
@
transaction
.
atomic
def
destroy
(
self
,
request
,
*
args
,
**
kwargs
):
instance
=
self
.
get_object
()
new_instance
=
model_to_dict
(
instance
)
self
.
perform_destroy
(
instance
)
log_save
(
enums
.
LogEnum
.
DELETED
.
value
,
enums
.
LogEntitiesEnum
.
USER
.
value
,
new_instance
[
'id'
],
new_instance
,
''
)
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
@
transaction
.
atomic
def
update
(
self
,
request
,
*
args
,
**
kwargs
):
partial
=
kwargs
.
pop
(
'partial'
,
False
)
instance
=
self
.
get_object
()
serializer
=
self
.
get_serializer
(
instance
,
data
=
request
.
data
,
partial
=
partial
)
serializer
.
is_valid
(
raise_exception
=
True
)
old_instance
=
model_to_dict
(
instance
)
self
.
perform_update
(
serializer
)
new_instance
=
serializer
.
data
log_save
(
enums
.
LogEnum
.
UPDATE
.
value
,
enums
.
LogEntitiesEnum
.
USER
.
value
,
new_instance
[
'id'
],
old_instance
,
new_instance
)
return
Response
(
serializer
.
data
)
app/applicationlayer/management/application/table_filters.py
View file @
9f666061
...
...
@@ -5,12 +5,12 @@ from django.db.models import Q
class
ApplicationFilterSet
(
filters
.
FilterSet
):
#
search = filters.CharFilter(method='search_bar', label='search')
#
def search_bar(self, queryset, name, value):
#
return queryset.filter(
#
Q(username__icontains=value) |
#
Q(first_name__icontains=value) |
#
Q(last_name__icontains=value))
#
search = filters.CharFilter(method='search_bar', label='search')
#
def search_bar(self, queryset, name, value):
#
return queryset.filter(
#
Q(username__icontains=value) |
#
Q(first_name__icontains=value) |
#
Q(last_name__icontains=value))
class
Meta
:
model
=
Application
...
...
app/applicationlayer/management/application/views.py
View file @
9f666061
...
...
@@ -4,7 +4,7 @@ from app.helper import decorators
from
rest_framework
import
viewsets
,
status
from
rest_framework.response
import
Response
from
django.forms.models
import
model_to_dict
from
rest_framework.filters
import
SearchFilter
from
rest_framework.filters
import
SearchFilter
,
OrderingFilter
from
django_filters
import
rest_framework
as
filters
from
app.entities.models
import
Application
,
EntityLog
from
app.applicationlayer.utils
import
(
...
...
@@ -19,9 +19,10 @@ class ApplicationViewSet(viewsets.ModelViewSet):
queryset
=
Application
.
objects
.
all
()
serializer_class
=
serializer
.
ApplicationSerializer
pagination_class
=
CustomPagination
filter_backends
=
(
DjangoFilterBackend
,)
filter_backends
=
(
DjangoFilterBackend
,
SearchFilter
,
OrderingFilter
)
filterset_class
=
ApplicationFilterSet
# search_fields = ('name',)
ordering_fields
=
'__all__'
search_fields
=
(
'name'
,)
@
transaction
.
atomic
def
create
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
app/applicationlayer/management/company/views.py
View file @
9f666061
...
...
@@ -3,7 +3,7 @@ from django.db import transaction
from
rest_framework
import
viewsets
,
status
from
rest_framework.response
import
Response
from
django.forms.models
import
model_to_dict
from
rest_framework.filters
import
SearchFilter
from
rest_framework.filters
import
SearchFilter
,
OrderingFilter
from
django_filters
import
rest_framework
as
filters
from
app.entities.models
import
Company
,
EntityLog
from
app.applicationlayer.utils
import
(
...
...
@@ -19,10 +19,12 @@ class CompanyViewSet(viewsets.ModelViewSet):
queryset
=
Company
.
objects
.
all
()
serializer_class
=
serializer
.
CompanySerializer
pagination_class
=
CustomPagination
filter_backends
=
(
DjangoFilterBackend
,
SearchFilter
,)
filter_backends
=
(
DjangoFilterBackend
,
SearchFilter
,
OrderingFilter
)
filterset_class
=
CompanyFilterSet
# search_fields = ('name',)
ordering_fields
=
'__all__'
search_fields
=
(
'name'
,)
@
decorators
.
rms
.
company_crate
@
transaction
.
atomic
def
create
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
@@ -39,10 +41,12 @@ class CompanyViewSet(viewsets.ModelViewSet):
message
)
# @decorators.rms.company_list
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
print
(
self
.
queryset
)
queryset
=
self
.
filter_queryset
(
self
.
get_queryset
())
page
=
self
.
paginate_queryset
(
queryset
)
print
(
self
.
queryset
)
if
page
is
not
None
:
serializer
=
self
.
get_serializer
(
page
,
many
=
True
)
...
...
app/applicationlayer/management/department/views.py
View file @
9f666061
...
...
@@ -3,7 +3,7 @@ from django.db import transaction
from
rest_framework
import
viewsets
,
status
from
rest_framework.response
import
Response
from
django.forms.models
import
model_to_dict
from
rest_framework.filters
import
SearchFilter
from
rest_framework.filters
import
SearchFilter
,
OrderingFilter
from
django_filters
import
rest_framework
as
filters
from
app.entities.models
import
Department
,
EntityLog
from
app.applicationlayer.utils
import
(
...
...
@@ -19,10 +19,12 @@ class DepartmentViewSet(viewsets.ModelViewSet):
queryset
=
Department
.
objects
.
all
()
serializer_class
=
serializer
.
DepartmentSerializer
pagination_class
=
CustomPagination
filter_backends
=
(
DjangoFilterBackend
,
SearchFilter
,)
filter_backends
=
(
DjangoFilterBackend
,
SearchFilter
,
OrderingFilter
)
filterset_class
=
DepartmentFilterSet
# search_fields = ('name',)
ordering_fields
=
'__all__'
search_fields
=
(
'name'
,)
@
decorators
.
rms
.
department_crate
@
transaction
.
atomic
def
create
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
@@ -39,6 +41,7 @@ class DepartmentViewSet(viewsets.ModelViewSet):
message
)
# @decorators.rms.department_list
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
queryset
=
self
.
filter_queryset
(
self
.
get_queryset
())
...
...
app/applicationlayer/management/module/views.py
View file @
9f666061
...
...
@@ -3,7 +3,7 @@ from django.db import transaction
from
rest_framework
import
viewsets
,
status
from
rest_framework.response
import
Response
from
django.forms.models
import
model_to_dict
from
rest_framework.filters
import
SearchFilter
from
rest_framework.filters
import
SearchFilter
,
OrderingFilter
from
django_filters
import
rest_framework
as
filters
from
app.entities.models
import
Module
,
EntityLog
from
app.applicationlayer.utils
import
(
...
...
@@ -14,15 +14,17 @@ from app.applicationlayer.management.module import serializer
from
app.applicationlayer.management.module.table_filters
import
ModuleFilterSet
from
app.helper
import
decorators
from
django.db.models
import
F
from
app.helper
import
decorators
class
ModuleViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
Module
.
objects
.
order_by
(
'parent'
,
'sort_id'
)
queryset
=
Module
.
objects
.
order_by
(
'
application'
,
'
parent'
,
'sort_id'
)
serializer_class
=
serializer
.
ModuleSerializer
pagination_class
=
CustomPagination
filter_backends
=
(
DjangoFilterBackend
,
SearchFilter
,)
filter_backends
=
(
DjangoFilterBackend
,
SearchFilter
,
OrderingFilter
)
filterset_class
=
ModuleFilterSet
# search_fields = ('name',)
ordering_fields
=
'__all__'
search_fields
=
(
'name'
,)
@
transaction
.
atomic
def
create
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
@@ -152,6 +154,7 @@ class ModuleViewSet(viewsets.ModelViewSet):
return
Response
(
message
)
@
decorators
.
error_safe
@
transaction
.
atomic
def
destroy
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
app/applicationlayer/management/user/serializers.py
View file @
9f666061
...
...
@@ -75,13 +75,14 @@ class UserManagementRetreiveSerializer(serializers.ModelSerializer):
app
=
user
.
application
.
all
()
list_app
=
[]
for
data
in
app
:
if
user
.
user_type
==
'USR'
and
data
.
name
==
'RMS'
:
print
(
data
)
if
user
.
user_type
.
upper
()
==
'USR'
and
data
.
app_code
.
upper
()
==
'RMS'
:
pass
else
:
remove
=
[
'Module
'
,
'Company'
,
'Department'
,
'Application
'
]
remove
=
[
'Module
s'
,
'Companies'
,
'Department
'
]
if
user
.
user_type
==
'SU'
:
mod
=
data
.
modules
.
all
()
.
values
(
'name'
)
mod
=
data
.
modules
.
all
()
.
values
(
'name'
,
'app_code'
)
else
:
mod
=
data
.
modules
.
exclude
(
name__in
=
remove
)
.
values
(
"id"
,
'name'
,
'parent'
...
...
@@ -101,8 +102,8 @@ class UserManagementRetreiveSerializer(serializers.ModelSerializer):
# list_mod.append(body)
app_body
=
{}
app_body
[
'app_code'
]
=
data
.
app_code
app_body
[
'name'
]
=
data
.
name
# app_body['modules'] = list_mod
app_body
[
'modules'
]
=
mod
list_app
.
append
(
app_body
)
return
list_app
...
...
app/applicationlayer/management/user/views.py
View file @
9f666061
...
...
@@ -2,7 +2,7 @@ import copy
import
json
from
app.entities
import
enums
from
app.businesslayer
import
logger
# from app.businesslayer import log_save
from
django.forms.models
import
model_to_dict
from
django.shortcuts
import
render
...
...
@@ -15,7 +15,7 @@ from app.helper import decorators
from
rest_framework
import
viewsets
,
status
from
rest_framework.decorators
import
action
from
app.applicationlayer
import
table_filters
from
app.applicationlayer
.management.user
import
table_filters
from
django_filters.rest_framework
import
DjangoFilterBackend
from
app.applicationlayer
import
paginators
...
...
@@ -49,8 +49,9 @@ class UsersManagementViewSet(viewsets.ModelViewSet):
@
decorators
.
error_safe
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
print
(
request
.
data
[
'department__name'
])
self
.
serializer_class
=
serializers
.
UserManagementRetreiveSerializer
self
.
queryset
=
QuerySetHelper
.
Sort
(
self
)
#
self.queryset = QuerySetHelper.Sort(self)
return
super
(
UsersManagementViewSet
,
self
)
.
list
(
request
)
@
decorators
.
error_safe
...
...
@@ -75,7 +76,7 @@ class UsersManagementViewSet(viewsets.ModelViewSet):
createdUser
.
save
()
# LOG ADD
log
ger
.
log_save
(
log
_save
.
log_save
(
enums
.
LogEnum
.
ADD
.
value
,
enums
.
LogEntitiesEnum
.
USER
.
value
,
model_to_dict
(
createdUser
))
...
...
@@ -90,7 +91,7 @@ class UsersManagementViewSet(viewsets.ModelViewSet):
fromObj
=
copy
.
copy
(
serializer
.
instance
)
serializer
.
save
()
toObj
=
copy
.
copy
(
serializer
.
instance
)
log
ger
.
log_save
(
log
_save
.
log_save
(
enums
.
LogEnum
.
UPDATE
.
value
,
enums
.
LogEntitiesEnum
.
USER
.
value
,
model_to_dict
(
fromObj
),
...
...
@@ -142,7 +143,7 @@ class UsersManagementViewSet(viewsets.ModelViewSet):
fromObj
=
copy
.
copy
(
existingUser
)
existingUser
.
save
()
toObj
=
copy
.
copy
(
existingUser
)
log
ger
.
log_save
(
log
_save
.
log_save
(
enums
.
LogEnum
.
UPDATE
.
value
,
enums
.
LogEntitiesEnum
.
ROBOT
.
value
,
model_to_dict
(
fromObj
),
...
...
@@ -180,7 +181,7 @@ class UsersManagementViewSet(viewsets.ModelViewSet):
fromObj
=
copy
.
copy
(
existingUser
)
existingUser
.
save
()
toObj
=
copy
.
copy
(
existingUser
)
log
ger
.
log_save
(
log
_save
.
log_save
(
enums
.
LogEnum
.
UPDATE
.
value
,
enums
.
LogEntitiesEnum
.
ROBOT
.
value
,
model_to_dict
(
fromObj
),
...
...
app/applicationlayer/master/company/serializer.py
0 → 100644
View file @
9f666061
from
rest_framework
import
serializers
from
app.entities.models
import
Company
class
AdminCompanySerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Company
fields
=
'__all__'
app/applicationlayer/master/company/views.py
0 → 100644
View file @
9f666061
from
app.helper.decorators
import
rms
from
app.entities.models
import
Company
from
rest_framework
import
viewsets
,
status
from
rest_framework.response
import
Response
from
django_filters
import
rest_framework
as
filters
from
django_filters.rest_framework
import
DjangoFilterBackend
from
app.applicationlayer.management.company
import
serializer
from
rest_framework.filters
import
SearchFilter
,
OrderingFilter
from
app.applicationlayer.master.company.serializer
import
AdminCompanySerializer
from
app.applicationlayer.utils
import
CustomPagination
,
status_message_response
from
app.applicationlayer.management.company.table_filters
import
CompanyFilterSet
class
AdminCompanyViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
Company
.
objects
.
all
()
serializer_class
=
AdminCompanySerializer
pagination_class
=
CustomPagination
filter_backends
=
(
DjangoFilterBackend
,
SearchFilter
,
OrderingFilter
)
filterset_class
=
CompanyFilterSet
ordering_fields
=
'__all__'
search_fields
=
(
'name'
,)
http_method_names
=
[
'get'
]
@
rms
.
company_list
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
queryset
=
self
.
filter_queryset
(
self
.
get_queryset
())
page
=
self
.
paginate_queryset
(
queryset
)
if
page
is
not
None
:
serializer
=
self
.
get_serializer
(
page
,
many
=
True
)
message
=
status_message_response
(
200
,
'success'
,
'list of Company found'
,
serializer
.
data
)
return
self
.
get_paginated_response
(
message
)
serializer
=
self
.
get_serializer
(
queryset
,
many
=
True
)
return
Response
(
serializer
.
data
)
app/applicationlayer/master/department/serializer.py
0 → 100644
View file @
9f666061
from
rest_framework
import
serializers
from
app.entities.models
import
Department
class
AdminDepartmentSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Department
fields
=
'__all__'
read_only_fields
=
(
'created'
,
'createdby'
,
'modified'
,
'modifiedby'
,
'code'
,
)
app/applicationlayer/master/department/views.py
0 → 100644
View file @
9f666061
from
rest_framework
import
viewsets
,
status
from
rest_framework.response
import
Response
from
django.forms.models
import
model_to_dict
from
rest_framework.filters
import
SearchFilter
,
OrderingFilter
from
django_filters
import
rest_framework
as
filters
from
app.entities.models
import
Department
from
app.applicationlayer.utils
import
(
CustomPagination
,
status_message_response
)
from
django_filters.rest_framework
import
DjangoFilterBackend
from
app.applicationlayer.master.department
import
serializer
from
app.applicationlayer.management.department.table_filters
import
DepartmentFilterSet
from
app.helper.decorators
import
rms
class
AdminDepartmentViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
Department
.
objects
.
all
()
serializer_class
=
serializer
.
AdminDepartmentSerializer
pagination_class
=
CustomPagination
filter_backends
=
(
DjangoFilterBackend
,
SearchFilter
,
OrderingFilter
)
filterset_class
=
DepartmentFilterSet
ordering_fields
=
'__all__'
search_fields
=
(
'name'
,)
@
rms
.
department_list
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
queryset
=
self
.
filter_queryset
(
self
.
get_queryset
())
page
=
self
.
paginate_queryset
(
queryset
)
if
page
is
not
None
:
serializer
=
self
.
get_serializer
(
page
,
many
=
True
)
message
=
status_message_response
(
200
,
'success'
,
'list of Department found'
,
serializer
.
data
)
return
self
.
get_paginated_response
(
message
)
serializer
=
self
.
get_serializer
(
queryset
,
many
=
True
)
return
Response
(
serializer
.
data
)
app/applicationlayer/master/urls.py
0 → 100644
View file @
9f666061
from
django.urls
import
path
,
include
from
rest_framework
import
routers
from
django.conf.urls
import
url
from
app.applicationlayer.master.company.views
import
AdminCompanyViewSet
from
app.applicationlayer.master.department.views
import
AdminDepartmentViewSet
from
app.applicationlayer.master.user_type.views
import
UserTypeViewSet
router
=
routers
.
DefaultRouter
()
router
.
register
(
r'companies'
,
AdminCompanyViewSet
)
router
.
register
(
r'departments'
,
AdminDepartmentViewSet
)
# router.register(r'user-types', UserTypeViewSet)
urlpatterns
=
[
path
(
''
,
include
(
router
.
urls
)),
url
(
r'^user-types/$'
,
UserTypeViewSet
.
as_view
(),
name
=
"user-types"
),
]
\ No newline at end of file
app/applicationlayer/master/user_type/views.py
0 → 100644
View file @
9f666061
from
rest_framework.views
import
APIView
from
rest_framework.response
import
Response
from
app.entities
import
enums
class
UserTypeViewSet
(
APIView
):
def
get
(
self
,
request
,
format
=
None
):
enums_super
=
enums
.
UserTypeEnum
.
SUPER_USER
.
value
enums_OUA
=
enums
.
UserTypeEnum
.
OVERALL_USER_ADMIN
.
value
enums_company
=
enums
.
UserTypeEnum
.
COMPANY_USER_ADMIN
.
value
enums_department
=
enums
.
UserTypeEnum
.
DEPARTMENT_USER_ADMIN
.
value
enums_user
=
enums
.
UserTypeEnum
.
USER
.
value
data
=
{
"code"
:
"200"
,
"status"
:
"success"
,
"message"
:
"list of user types"
,
"results"
:
[
{
'Super user'
:
enums_super
,
'Overall user admin'
:
enums_OUA
,
"Company user admin"
:
enums_company
,
"Department user admin"
:
enums_department
,
"user"
:
enums_user
}
]
}
if
self
.
request
.
user
.
user_type
==
enums_OUA
:
del
data
[
'Super user'
]
del
data
[
'Overall user admin'
]
elif
self
.
request
.
user
.
user_type
==
enums_company
:
del
data
[
'Super user'
]
del
data
[
'Overall user admin'
]
del
data
[
'Company user admin'
]
elif
self
.
request
.
user
.
user_type
==
enums_department
:
del
data
[
'Super User'
]
del
data
[
'Overall user admin'
]
del
data
[
'Company user admin'
]
del
data
[
'Department user admin'
]
return
Response
(
data
)
app/applicationlayer/urls.py
View file @
9f666061
from
django.urls
import
path
,
include
from
rest_framework
import
routers
from
django.conf.urls
import
url
from
app.applicationlayer.management.application.views
import
ApplicationViewSet
from
app.applicationlayer.management.company.views
import
CompanyViewSet
from
app.applicationlayer.management.department.views
import
DepartmentViewSet
from
app.applicationlayer.management.module.views
import
ModuleViewSet
# from app.applicationlayer.management.user.views import UsersManagementViewSet
from
app.applicationlayer.management.account.views
import
UserViewSet
from
app.businesslayer.company.views
import
AdminCompanyViewSet
from
app.applicationlayer.management.notification.views
import
NotificationsViewset
from
app.applicationlayer.management.changerequest
import
views
as
crviews
...
...
@@ -15,7 +19,8 @@ router.register(r'applications', ApplicationViewSet)
router
.
register
(
r'companies'
,
CompanyViewSet
)
router
.
register
(
r'departments'
,
DepartmentViewSet
)
router
.
register
(
r'modules'
,
ModuleViewSet
)
# router.register(r'users', UsersManagementViewSet)
router
.
register
(
r'users'
,
UserViewSet
)
router
.
register
(
r'notifications'
,
NotificationsViewset
)
router
.
register
(
r'template'
,
crviews
.
ChangeRequestTemplatesViewset
)
...
...
@@ -33,7 +38,6 @@ router.register(r'template-details', crviews.ChangeRequestTemplateDetailsViewset
urlpatterns
=
(
path
(
''
,
include
(
router
.
urls
)),
path
(
'template-post/'
,
crviews
.
ChangeRequestTemplatePost
.
as_view
()),
path
(
'form-post/'
,
crviews
.
ChangeRequestFormPost
.
as_view
()),
)
app/businesslayer/company/serializer.py
0 → 100644
View file @
9f666061
from
rest_framework
import
serializers
from
app.entities.models
import
Company
class
AdminCompanySerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Company
fields
=
'__all__'
app/businesslayer/company/table_filters.py
0 → 100644
View file @
9f666061
app/businesslayer/company/views.py
0 → 100644
View file @
9f666061
from
rest_framework.filters
import
SearchFilter
,
OrderingFilter
from
django_filters
import
rest_framework
as
filters
from
app.entities.models
import
Company
from
rest_framework
import
viewsets
,
status
from
app.businesslayer.company.serializer
import
AdminCompanySerializer
from
app.applicationlayer.utils
import
CustomPagination
,
status_message_response
from
django_filters.rest_framework
import
DjangoFilterBackend
from
app.applicationlayer.management.company
import
serializer
from
app.applicationlayer.management.company.table_filters
import
CompanyFilterSet
from
app.helper.decorators
import
rms
from
rest_framework.response
import
Response
class
AdminCompanyViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
Company
.
objects
.
all
()
serializer_class
=
AdminCompanySerializer
pagination_class
=
CustomPagination
filter_backends
=
(
DjangoFilterBackend
,
SearchFilter
,
OrderingFilter
)
filterset_class
=
CompanyFilterSet
ordering_fields
=
'__all__'
search_fields
=
(
'name'
,)
http_method_names
=
[
'get'
]
@
rms
.
company_list
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
queryset
=
self
.
filter_queryset
(
self
.
get_queryset
())
page
=
self
.
paginate_queryset
(
queryset
)
if
page
is
not
None
:
serializer
=
self
.
get_serializer
(
page
,
many
=
True
)
message
=
status_message_response
(
200
,
'success'
,
'list of Company found'
,
serializer
.
data
)
return
self
.
get_paginated_response
(
message
)
serializer
=
self
.
get_serializer
(
queryset
,
many
=
True
)
return
Response
(
serializer
.
data
)
app/businesslayer/department/serializer.py
0 → 100644
View file @
9f666061
from
rest_framework
import
serializers
from
app.entities.models
import
Department
class
AdminDepartmentSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Department
fields
=
'__all__'
read_only_fields
=
(
'created'
,
'createdby'
,
'modified'
,
'modifiedby'
,
'code'
,
)
app/businesslayer/department/table_filters.py
0 → 100644
View file @
9f666061
from
django_filters
import
rest_framework
as
filters
from
django.db.models
import
Count
from
app.entities.models
import
Department
from
django.db.models
import
Q
class
AdminDepartmentFilterSet
(
filters
.
FilterSet
):
# search = filters.CharFilter(method='search_bar', label='search')
# def search_bar(self, queryset, name, value):
# return queryset.filter(
# Q(username__icontains=value) |
# Q(first_name__icontains=value) |
# Q(last_name__icontains=value))
class
Meta
:
model
=
Department
fields
=
'__all__'
app/businesslayer/department/views.py
0 → 100644
View file @
9f666061
from
rest_framework
import
viewsets
,
status
from
rest_framework.response
import
Response
from
django.forms.models
import
model_to_dict
from
rest_framework.filters
import
SearchFilter
,
OrderingFilter
from
django_filters
import
rest_framework
as
filters
from
app.entities.models
import
Department
from
app.applicationlayer.utils
import
(
CustomPagination
,
status_message_response
)
from
django_filters.rest_framework
import
DjangoFilterBackend
from
app.businesslayer.department
import
serializer
from
app.businesslayer.department.table_filters
import
AdminDepartmentFilterSet
from
app.helper.decorators
import
rms
class
AdminDepartmentViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
Department
.
objects
.
all
()
serializer_class
=
serializer
.
AdminDepartmentSerializer
pagination_class
=
CustomPagination
filter_backends
=
(
DjangoFilterBackend
,
SearchFilter
,
OrderingFilter
)
filterset_class
=
AdminDepartmentFilterSet
ordering_fields
=
'__all__'
search_fields
=
(
'name'
,)
@
rms
.
department_list
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
queryset
=
self
.
filter_queryset
(
self
.
get_queryset
())
page
=
self
.
paginate_queryset
(
queryset
)
if
page
is
not
None
:
serializer
=
self
.
get_serializer
(
page
,
many
=
True
)
message
=
status_message_response
(
200
,
'success'
,
'list of Department found'
,
serializer
.
data
)
return
self
.
get_paginated_response
(
message
)
serializer
=
self
.
get_serializer
(
queryset
,
many
=
True
)
return
Response
(
serializer
.
data
)
app/businesslayer/urls.py
0 → 100644
View file @
9f666061
from
django.urls
import
path
,
include
from
rest_framework
import
routers
from
django.conf.urls
import
url
from
app.businesslayer.company.views
import
AdminCompanyViewSet
from
app.businesslayer.department.views
import
AdminDepartmentViewSet
from
app.businesslayer.user_type.views
import
UserTypeViewSet
router
=
routers
.
DefaultRouter
()
router
.
register
(
r'companies'
,
AdminCompanyViewSet
)
router
.
register
(
r'departments'
,
AdminDepartmentViewSet
)
# router.register(r'user-types', UserTypeViewSet)
urlpatterns
=
[
path
(
''
,
include
(
router
.
urls
)),
url
(
r'^user-types/$'
,
UserTypeViewSet
.
as_view
(),
name
=
"user-types"
),
]
app/businesslayer/user_type/views.py
0 → 100644
View file @
9f666061
from
rest_framework.views
import
APIView
from
rest_framework.response
import
Response
from
app.entities
import
enums
class
UserTypeViewSet
(
APIView
):
def
get
(
self
,
request
,
format
=
None
):
enums_super
=
enums
.
UserTypeEnum
.
SUPER_USER
.
value
enums_OUA
=
enums
.
UserTypeEnum
.
OVERALL_USER_ADMIN
.
value
enums_company
=
enums
.
UserTypeEnum
.
COMPANY_USER_ADMIN
.
value
enums_department
=
enums
.
UserTypeEnum
.
DEPARTMENT_USER_ADMIN
.
value
enums_user
=
enums
.
UserTypeEnum
.
USER
.
value
data
=
{
'Super user'
:
enums_super
,
'Overall user admin'
:
enums_OUA
,
"Company user admin"
:
enums_company
,
"Department user admin"
:
enums_department
,
"user"
:
enums_user
}
if
self
.
request
.
user
.
user_type
==
enums_OUA
:
del
data
[
'Super user'
]
del
data
[
'Overall user admin'
]
elif
self
.
request
.
user
.
user_type
==
enums_company
:
del
data
[
'Super user'
]
del
data
[
'Overall user admin'
]
del
data
[
'Company user admin'
]
elif
self
.
request
.
user
.
user_type
==
enums_department
:
del
data
[
'Super User'
]
del
data
[
'Overall user admin'
]
del
data
[
'Company user admin'
]
del
data
[
'Department user admin'
]
return
Response
(
data
)
app/entities/migrations/0014_application_app_code.py
0 → 100644
View file @
9f666061
# Generated by Django 2.2 on 2019-09-09 14:17
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'entities'
,
'0013_changerequesthistory'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'application'
,
name
=
'app_code'
,
field
=
models
.
CharField
(
default
=
1
,
max_length
=
255
,
unique
=
True
),
preserve_default
=
False
,
),
]
app/entities/models.py
View file @
9f666061
...
...
@@ -26,6 +26,7 @@ class Application(AuditClass):
max_length
=
255
)
name
=
models
.
CharField
(
unique
=
True
,
max_length
=
255
)
app_code
=
models
.
CharField
(
unique
=
True
,
max_length
=
255
)
class
Meta
:
db_table
=
'applications'
...
...
app/helper/decorators.py
View file @
9f666061
from
rest_framework.response
import
Response
from
rest_framework
import
status
import
json
from
rest_framework.exceptions
import
ParseError
from
functools
import
wraps
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
def
error_safe
(
function
):
...
...
@@ -25,3 +31,195 @@ def error_safe(function):
wrap
.
__doc__
=
function
.
__doc__
wrap
.
__name__
=
function
.
__name__
return
wrap
class
rms
:
# variables
enums_super
=
enums
.
UserTypeEnum
.
SUPER_USER
.
value
enums_OUA
=
enums
.
UserTypeEnum
.
OVERALL_USER_ADMIN
.
value
enums_company
=
enums
.
UserTypeEnum
.
COMPANY_USER_ADMIN
.
value
enums_department
=
enums
.
UserTypeEnum
.
DEPARTMENT_USER_ADMIN
.
value
enums_user
=
enums
.
UserTypeEnum
.
USER
.
value
access_error
=
"Logged user is not allowed to access this endpoint."
department_error
=
'Department should be the same with the logged user'
company_error
=
'Company should be the same with the logged user'
def
user
(
self
):
return
self
.
request
.
user
def
user_type
(
self
):
return
rms
.
user
(
self
)
.
user_type
# @staticmethod
# def user_delete(function):
# @wraps(function)
# def wrapper(self, request, *args, **kwargs):
# return function(self, request, *args, **kwargs)
# return wrapper
@
staticmethod
def
user_create
(
function
):
@
wraps
(
function
)
def
wrapper
(
self
,
request
,
*
args
,
**
kwargs
):
if
rms
.
user_type
(
self
)
==
rms
.
enums_user
:
raise
ParseError
(
rms
.
access_error
)
elif
rms
.
user_type
(
self
)
==
rms
.
enums_department
:
print
(
request
.
data
)
if
request
.
data
[
'department'
]
!=
rms
.
user
(
self
)
.
department
.
id
:
raise
ParseError
(
rms
.
department_error
)
elif
rms
.
user_type
(
self
)
==
rms
.
enums_company
:
user_company
=
rms
.
user
(
self
)
.
department
.
company
request_department
=
Department
.
objects
.
filter
(
Q
(
id
=
request
.
data
[
'department'
])
&
Q
(
company
=
user_company
)
)
if
not
request_department
:
raise
ParseError
(
rms
.
company_error
)
return
function
(
self
,
request
,
*
args
,
**
kwargs
)
return
wrapper
@
staticmethod
def
company_crate
(
function
):
@
wraps
(
function
)
def
wrapper
(
self
,
request
,
*
args
,
**
kwargs
):
if
rms
.
user
(
self
)
!=
rms
.
enums_super
:
raise
ParseError
(
rms
.
access_error
)
return
function
(
self
,
request
,
*
args
,
**
kwargs
)
return
wrapper
@
staticmethod
def
department_crate
(
function
):
@
wraps
(
function
)
def
wrapper
(
self
,
request
,
*
args
,
**
kwargs
):
if
rms
.
user
(
self
)
!=
rms
.
enums_super
or
rms
.
user
(
self
)
!=
rms
.
enums_company
:
raise
ParseError
(
rms
.
rms_access_error
)
return
function
(
self
,
request
,
*
args
,
**
kwargs
)
return
wrapper
@
staticmethod
def
application_crate
(
function
):
@
wraps
(
function
)
def
wrapper
(
self
,
request
,
*
args
,
**
kwargs
):
if
rms
.
user
(
self
)
!=
rms
.
enums_super
:
raise
ParseError
(
rms
.
access_error
)
return
function
(
self
,
request
,
*
args
,
**
kwargs
)
return
wrapper
@
staticmethod
def
company_list
(
function
):
@
wraps
(
function
)
def
wrapper
(
self
,
request
,
*
args
,
**
kwargs
):
if
rms
.
user_type
(
self
)
==
rms
.
enums_company
:
id
=
rms
.
user
(
self
)
.
department
.
company
.
id
self
.
queryset
=
self
.
queryset
.
filter
(
id
=
id
)
elif
rms
.
user_type
(
self
)
==
rms
.
enums_super
:
pass
elif
rms
.
user_type
(
self
)
==
rms
.
enums_OUA
:
pass
else
:
raise
ParseError
(
rms
.
access_error
)
return
function
(
self
,
request
,
*
args
,
**
kwargs
)
return
wrapper
@
staticmethod
def
department_list
(
function
):
@
wraps
(
function
)
def
wrapper
(
self
,
request
,
*
args
,
**
kwargs
):
if
rms
.
user_type
(
self
)
==
rms
.
enums_department
:
id
=
rms
.
user
(
self
)
.
department
.
id
self
.
queryset
=
self
.
queryset
.
filter
(
id
=
id
)
elif
rms
.
user_type
(
self
)
==
rms
.
enums_company
:
pass
elif
rms
.
user_type
(
self
)
==
rms
.
enums_super
:
pass
else
:
raise
ParseError
(
rms
.
access_error
)
return
function
(
self
,
request
,
*
args
,
**
kwargs
)
return
wrapper
class
check
:
# @staticmethod
# def logged_user(function):
# @wraps(function)
# def wrapper(self):
# print('ddd')
# test = self.request.user.department
# test2 = self.request.user.department_users
# print(test)
# print(test2)
# # self.queryset = self.queryset.filter(id=self.request.user.id)
# # return self.queryset
# return "self.queryset"
# return wrapper
def
company_department_listing
(
self
,
instance
):
if
self
.
basename
==
'department'
:
id
=
instance
.
department
.
id
elif
self
.
basename
==
'company'
:
id
=
instance
.
department
.
company
.
id
@
staticmethod
def
user_type
(
function
):
@
wraps
(
function
)
def
wrapper
(
self
,
request
,
*
args
,
**
kwargs
):
instance
=
self
.
request
.
user
user_type
=
instance
.
user_type
if
user_type
==
'USR'
:
raise
ParseError
(
'Logged User is not allowed to create an account'
)
elif
user_type
==
enums
.
UserTypeEnum
.
COMPANY_USER_ADMIN
.
value
:
id
=
''
if
self
.
basename
==
'department'
:
id
=
instance
.
department
.
id
elif
self
.
basename
==
'company'
:
id
=
instance
.
department
.
company
.
id
self
.
queryset
=
self
.
queryset
.
filter
(
id
=
id
)
# elif user_type == 'DUA':
# if self.basename == 'department':
# id =
return
function
(
self
,
request
,
*
args
,
**
kwargs
)
return
wrapper
config/urls.py
View file @
9f666061
...
...
@@ -22,12 +22,9 @@ from app.applicationlayer.management.notification import views as notifview
urlpatterns
=
[
# path('admin/', admin.site.urls),
path
(
'api-auth/'
,
include
(
'rest_framework.urls'
)),
path
(
'api/v1/auth/'
,
include
(
'app.accesslayer.urls'
)),
path
(
'api/v1/'
,
include
(
'app.applicationlayer.urls'
)),
path
(
'api/v1/
management/
'
,
include
(
'app.applicationlayer.urls'
)),
path
(
'api/v1/master/'
,
include
(
'app.applicationlayer.master.urls'
)),
url
(
r'^chat/$'
,
notifview
.
index
,
name
=
'index'
),
url
(
r'^chat/(?P<room_name>[^/]+)/$'
,
notifview
.
room
,
name
=
'room'
),
]
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