Commit 884a930d authored by Gladys Forte's avatar Gladys Forte

Merge branch 'dev' of http://42.61.118.105:7990/scm/rms/api-main-service into gladys-develop

parents d1b9d732 5418bf4e
......@@ -10,6 +10,7 @@ from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response
import datetime
from django.db.models.functions import Lower
import copy
VALIDATE_TOKEN_URL = settings.VALIDATE_TOKEN_URL
......@@ -46,16 +47,33 @@ class Helper:
req.status_code,
self._headers)
elif request.method == 'POST':
data = request.data
json_body = json.dumps(data)
data = copy.deepcopy(request.data)
filesBody = {}
if not request.FILES == {}:
for fileKey in request.FILES.keys():
filesBody[fileKey] = data[fileKey]
data.pop(fileKey, None)
# Content type will be set to default
# as MultiPart when files header is
# not empty
headers.pop('Content-Type', None)
json_body = data
else:
json_body = json.dumps(data)
req = requests.post(
final_endpoint,
data=json_body,
headers=headers
headers=headers,
files=filesBody
)
return self._response_data(req.json(),
req.status_code,
self._headers)
req.status_code,
self._headers)
elif request.method == 'PUT':
data = request.data
json_body = json.dumps(data)
......@@ -96,6 +114,7 @@ class Helper:
base_url = endpoint.service.base_url
full_path = request.get_full_path()
final_endpoint = f"{base_url}{full_path}"
# print(final_endpoint)
if endpoint.is_need_auth is True:
# redirect to authenticator service
......
......@@ -9,13 +9,22 @@ from api.utils import (
CustomPagination, BadRequestException,
status_message_response, number_generator, tbl_ordering
)
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.filters import SearchFilter
from django_filters import rest_framework as filters
AUTHENTICATOR_GROUP = settings.AUTHENTICATOR_GROUP
class ApplicationFilterSet(filters.FilterSet):
class Meta:
model = Application
fields = ('__all__')
class ApplicationViewSet(viewsets.ModelViewSet):
http_method_names = [
'get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace'
......@@ -25,6 +34,7 @@ class ApplicationViewSet(viewsets.ModelViewSet):
serializer_class = ApplicationSerializer
pagination_class = CustomPagination
filter_backends = (DjangoFilterBackend, SearchFilter,)
filterset_class = ApplicationFilterSet
search_fields = ('application_no', 'name', 'code')
# filter_class = APIEndpointFilter
......@@ -70,7 +80,7 @@ class ApplicationViewSet(viewsets.ModelViewSet):
)
# table ordering
if 'sort_field' and 'sort_order' in request.query_params:
if 'sort_order' in request.query_params and 'sort_field' in request.query_params:
queryset = tbl_ordering(
queryset, **request.query_params
)
......@@ -91,17 +101,17 @@ class ApplicationViewSet(viewsets.ModelViewSet):
results = []
for item in serializer.data:
# print(item['code'])
ids = item['code']
# ids = item['code']
# headers = {
# 'content-type': 'application/json',
# 'Authorization': request.META['HTTP_AUTHORIZATION']
# }
req = requests.get(f'{AUTHENTICATOR_GROUP}/{ids}/')
groups = req.json()['groups']
# req = requests.get(f'{AUTHENTICATOR_GROUP}/{ids}/')
# groups = req.json()['groups']
modules = req.json()['modules']
item['groups'] = groups
item['modules'] = modules
# modules = req.json()['modules']
# item['groups'] = groups
# item['modules'] = modules
results.append(item)
message = {
......@@ -217,6 +227,12 @@ class ApplicationViewSet(viewsets.ModelViewSet):
def archived(self, request, pk=None):
try:
queryset = Application.objects.filter(deleted_at__isnull=False)
# table ordering
if 'sort_order' in request.query_params and 'sort_field' in request.query_params:
queryset = tbl_ordering(
queryset, **request.query_params
)
queryset = self.filter_queryset(queryset)
if not queryset.exists():
message = status_message_response(
......
......@@ -64,7 +64,7 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
queryset = self.queryset.filter(deleted_at__exact=None)
# table ordering
if 'sort_field' and 'sort_order' in request.query_params:
if 'sort_order' in request.query_params and 'sort_field' in request.query_params:
queryset = tbl_ordering(
queryset, **request.query_params
)
......@@ -199,6 +199,12 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
def archived(self, request, pk=None):
try:
queryset = APIEndpoint.objects.filter(deleted_at__isnull=False)
# table ordering
if 'sort_order' in request.query_params and 'sort_field' in request.query_params:
queryset = tbl_ordering(
queryset, **request.query_params
)
queryset = self.filter_queryset(queryset)
if not queryset.exists():
message = status_message_response(
......
......@@ -65,7 +65,7 @@ class APIServiceViewSet(viewsets.ModelViewSet):
queryset = self.queryset.filter(deleted_at__exact=None)
# table ordering
if 'sort_field' and 'sort_order' in request.query_params:
if 'sort_order' in request.query_params and 'sort_field' in request.query_params:
queryset = tbl_ordering(
queryset, **request.query_params
)
......@@ -201,6 +201,12 @@ class APIServiceViewSet(viewsets.ModelViewSet):
def archived(self, request, pk=None):
try:
queryset = self.queryset.filter(deleted_at__isnull=False)
# table ordering
if 'sort_order' in request.query_params and 'sort_field' in request.query_params:
queryset = tbl_ordering(
queryset, **request.query_params
)
queryset = self.filter_queryset(queryset)
if not queryset.exists():
......
version: '3'
services:
rms_main:
build: .
command: python manage.py runserver 0.0.0.0:8000
container_name: rms_main-container
volumes:
- .:/code
ports:
- 7010:8000
networks:
rms_main_network:
ipv4_address: 172.169.70.10
networks:
rms_main_network:
driver: bridge
ipam:
config:
- subnet: 172.17.0.0/16
[PRODUCTION]
DATABASE_ENGINE = django.db.backends.mysql
DATABASE_NAME = maindb
DATABASE_NAME = authenticatordb
DATABASE_USER = root
DATABASE_PASSWORD =
DATABASE_HOST =
DATABASE_PORT =
DATABASE_PASSWORD =
DATABASE_HOST =
DATABASE_PORT =
[UAT]
DATABASE_ENGINE = django.db.backends.mysql
DATABASE_NAME = maindb
DATABASE_USER = root
DATABASE_PASSWORD =
DATABASE_HOST =
DATABASE_PORT =
DATABASE_NAME = devrms_main_db
DATABASE_USER = oneberry
DATABASE_PASSWORD = 0N3Berryt!r
DATABASE_HOST = 52.74.129.178
DATABASE_PORT = 3306
[LOCAL]
DATABASE_ENGINE = django.db.backends.mysql
DATABASE_NAME = maindb
DATABASE_NAME = authenticatordb
DATABASE_USER = root
DATABASE_PASSWORD =
DATABASE_HOST =
DATABASE_PASSWORD =
DATABASE_HOST =
DATABASE_PORT =
[SETTINGS]
CONFIG = config.settings.local
CONFIG = config.settings.uat
[SERVICE]
AUTHENTICATOR_IP = 10.0.75.1:8000
AUTHENTICATOR_IP = 172.17.0.1:7011
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