Commit 76797e6c authored by John Red Medrano's avatar John Red Medrano

Merge pull request #316 in RMS/api-main-service from red-develop to RMSv2

* commit '7bc59974':
  added environment for statung cors, fixed current user
  code refactor on class rms at decorators
parents 745ac852 7bc59974
...@@ -25,6 +25,8 @@ class ApplicationViewSet(viewsets.ModelViewSet): ...@@ -25,6 +25,8 @@ class ApplicationViewSet(viewsets.ModelViewSet):
ordering_fields = '__all__' ordering_fields = '__all__'
search_fields = ('name', 'code') search_fields = ('name', 'code')
@decorators.rms.application_crate
@transaction.atomic @transaction.atomic
def create(self, request, *args, **kwargs): def create(self, request, *args, **kwargs):
...@@ -79,6 +81,7 @@ class ApplicationViewSet(viewsets.ModelViewSet): ...@@ -79,6 +81,7 @@ class ApplicationViewSet(viewsets.ModelViewSet):
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
@decorators.rms.application_crate
@transaction.atomic @transaction.atomic
def update(self, request, *args, **kwargs): def update(self, request, *args, **kwargs):
......
...@@ -79,6 +79,7 @@ class CompanyViewSet(viewsets.ModelViewSet): ...@@ -79,6 +79,7 @@ class CompanyViewSet(viewsets.ModelViewSet):
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
@decorators.rms.company_crate
@transaction.atomic @transaction.atomic
def update(self, request, *args, **kwargs): def update(self, request, *args, **kwargs):
......
...@@ -33,6 +33,7 @@ class ModuleViewSet(viewsets.ModelViewSet): ...@@ -33,6 +33,7 @@ class ModuleViewSet(viewsets.ModelViewSet):
'code', 'component', 'sort_id' 'code', 'component', 'sort_id'
) )
@decorators.rms.module_crate
@transaction.atomic @transaction.atomic
def create(self, request, *args, **kwargs): def create(self, request, *args, **kwargs):
...@@ -84,7 +85,7 @@ class ModuleViewSet(viewsets.ModelViewSet): ...@@ -84,7 +85,7 @@ class ModuleViewSet(viewsets.ModelViewSet):
serializer = self.get_serializer(queryset, many=True) serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data) return Response(serializer.data)
@decorators.rms.application_crate
@transaction.atomic @transaction.atomic
def update(self, request, *args, **kwargs): def update(self, request, *args, **kwargs):
partial = kwargs.pop('partial', False) partial = kwargs.pop('partial', False)
......
...@@ -115,17 +115,23 @@ class UserManagementRetreiveSerializer(serializers.ModelSerializer): ...@@ -115,17 +115,23 @@ class UserManagementRetreiveSerializer(serializers.ModelSerializer):
if user.user_type.upper() == enums.UserTypeEnum.USER.value: if user.user_type.upper() == enums.UserTypeEnum.USER.value:
app = user.application.exclude(id=1) app = user.application.exclude(id=1)
else: else:
rms = models.Application.objects.filter(id=1)
app = user.application.all() app = user.application.all()
app = app.union(app, rms)
list_app = [] list_app = []
for data in app: for data in app.order_by('id'):
mod = data.modules.all() if data.id != 1:
mod = data.modules.all()
if user.user_type.upper() != enums.UserTypeEnum.USER.value: if user.user_type.upper() != enums.UserTypeEnum.USER.value:
if user.user_type.upper() != enums.UserTypeEnum.USER.value: if user.user_type.upper() != enums.UserTypeEnum.USER.value:
user_module = models.Module.objects.filter( user_module = models.Module.objects.filter(
name__icontains="user" name__icontains="user"
) )
mod = mod.union(mod, user_module) if data.id != 1:
mod = mod.union(mod, user_module)
else:
mod = user_module
mod = mod.order_by("parent", "sort_id") mod = mod.order_by("parent", "sort_id")
mod = ModuleSerializer(data=mod, many=True) mod = ModuleSerializer(data=mod, many=True)
......
...@@ -51,22 +51,11 @@ class rms: ...@@ -51,22 +51,11 @@ class rms:
def user_type(self): def user_type(self):
return rms.user(self).user_type return rms.user(self).user_type
# @staticmethod def superuser_create(self):
# def user_delete(function): if rms.user_type(self) != rms.enums_super:
# @wraps(function) raise ParseError(rms.access_error)
# def wrapper(self, request, *args, **kwargs): else:
return True
# return function(self, request, *args, **kwargs)
# return wrapper
@staticmethod
def admin_permission(function):
@wraps(function)
def wrapper(self, request, *args, **kwargs):
if rms.user_type(self) == rms.enums_user:
raise ParseError(access_error)
return function(self, request, *args, **kwargs)
return wrapper
@staticmethod @staticmethod
def user_create(function): def user_create(function):
...@@ -102,7 +91,8 @@ class rms: ...@@ -102,7 +91,8 @@ class rms:
rms.access_error rms.access_error
) )
elif rms.user_type(self) == rms.enums_department: elif rms.user_type(self) == rms.enums_department:
if request.user.department.code != rms.user(self).department.code: instance = self.get_object()
if rms.user(self).department.code != instance.department.code:
raise ParseError( raise ParseError(
rms.department_error rms.department_error
) )
...@@ -122,10 +112,7 @@ class rms: ...@@ -122,10 +112,7 @@ class rms:
def company_crate(function): def company_crate(function):
@wraps(function) @wraps(function)
def wrapper(self, request, *args, **kwargs): def wrapper(self, request, *args, **kwargs):
if rms.user_type(self) != rms.enums_super: rms.superuser_create(self)
raise ParseError(
rms.access_error
)
return function(self, request, *args, **kwargs) return function(self, request, *args, **kwargs)
return wrapper return wrapper
...@@ -133,16 +120,7 @@ class rms: ...@@ -133,16 +120,7 @@ class rms:
def department_crate(function): def department_crate(function):
@wraps(function) @wraps(function)
def wrapper(self, request, *args, **kwargs): def wrapper(self, request, *args, **kwargs):
# if rms.user_type(self) == rms.enums_super: rms.superuser_create(self)
# pass
# elif rms.user_type(self) != rms.enums_super or rms.user_type(self) != rms.enums_company:
# raise ParseError(
# rms.access_error
# )
if rms.user_type(self) != rms.enums_super:
raise ParseError(
rms.access_error
)
return function(self, request, *args, **kwargs) return function(self, request, *args, **kwargs)
return wrapper return wrapper
...@@ -150,10 +128,15 @@ class rms: ...@@ -150,10 +128,15 @@ class rms:
def application_crate(function): def application_crate(function):
@wraps(function) @wraps(function)
def wrapper(self, request, *args, **kwargs): def wrapper(self, request, *args, **kwargs):
if rms.user_type(self) != rms.enums_super: rms.superuser_create(self)
raise ParseError( return function(self, request, *args, **kwargs)
rms.access_error return wrapper
)
@staticmethod
def module_crate(function):
@wraps(function)
def wrapper(self, request, *args, **kwargs):
rms.superuser_create(self)
return function(self, request, *args, **kwargs) return function(self, request, *args, **kwargs)
return wrapper return wrapper
......
...@@ -128,7 +128,7 @@ STATIC_ROOT = os.path.join(BASE_DIR, "static") ...@@ -128,7 +128,7 @@ STATIC_ROOT = os.path.join(BASE_DIR, "static")
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/' MEDIA_URL = '/media/'
CORS_ORIGIN_ALLOW_ALL = True # CORS_ORIGIN_ALLOW_ALL = True
REST_SESSION_LOGIN = True REST_SESSION_LOGIN = True
......
...@@ -4,6 +4,7 @@ import configparser ...@@ -4,6 +4,7 @@ import configparser
DEBUG = True DEBUG = True
ALLOWED_HOSTS = ['*'] ALLOWED_HOSTS = ['*']
# CORS_ORIGIN_ALLOW_ALL = True
config = configparser.ConfigParser() config = configparser.ConfigParser()
config_file = os.path.join('./', 'env.ini') config_file = os.path.join('./', 'env.ini')
...@@ -52,3 +53,5 @@ VENDOR_REJECT_MESSAGE = config['NOTIFICATION_EMAIL']['VENDOR_REJECT_MESSAGE'] ...@@ -52,3 +53,5 @@ VENDOR_REJECT_MESSAGE = config['NOTIFICATION_EMAIL']['VENDOR_REJECT_MESSAGE']
CATCH_EMAIL = config['DEV']['CATCH_EMAIL'] CATCH_EMAIL = config['DEV']['CATCH_EMAIL']
CR_FRONT_LINK = config['DEV']['CR_LINK'] CR_FRONT_LINK = config['DEV']['CR_LINK']
CORS_ORIGIN_ALLOW_ALL = True
...@@ -50,3 +50,5 @@ VENDOR_REJECT_MESSAGE = config['NOTIFICATION_EMAIL']['VENDOR_REJECT_MESSAGE'] ...@@ -50,3 +50,5 @@ VENDOR_REJECT_MESSAGE = config['NOTIFICATION_EMAIL']['VENDOR_REJECT_MESSAGE']
CATCH_EMAIL = config['LOCAL']['CATCH_EMAIL'] CATCH_EMAIL = config['LOCAL']['CATCH_EMAIL']
CR_FRONT_LINK = config['LOCAL']['CR_LINK'] CR_FRONT_LINK = config['LOCAL']['CR_LINK']
CORS_ORIGIN_ALLOW_ALL = True
\ No newline at end of file
...@@ -4,6 +4,7 @@ import configparser ...@@ -4,6 +4,7 @@ import configparser
DEBUG = False DEBUG = False
ALLOWED_HOSTS = ['*'] ALLOWED_HOSTS = ['*']
CORS_ORIGIN_ALLOW_ALL = True
config = configparser.ConfigParser() config = configparser.ConfigParser()
config_file = os.path.join('./', 'env.ini') config_file = os.path.join('./', 'env.ini')
...@@ -52,3 +53,4 @@ VENDOR_REJECT_MESSAGE = config['NOTIFICATION_EMAIL']['VENDOR_REJECT_MESSAGE'] ...@@ -52,3 +53,4 @@ VENDOR_REJECT_MESSAGE = config['NOTIFICATION_EMAIL']['VENDOR_REJECT_MESSAGE']
CATCH_EMAIL = config['PRODUCTION']['CATCH_EMAIL'] CATCH_EMAIL = config['PRODUCTION']['CATCH_EMAIL']
CR_FRONT_LINK = config['PRODUCTION']['CR_LINK'] CR_FRONT_LINK = config['PRODUCTION']['CR_LINK']
CORS_ORIGIN_ALLOW_ALL = config['PRODUCTION']['CORS_ORIGIN_ALLOW_ALL']
...@@ -52,3 +52,4 @@ VENDOR_REJECT_MESSAGE = config['NOTIFICATION_EMAIL']['VENDOR_REJECT_MESSAGE'] ...@@ -52,3 +52,4 @@ VENDOR_REJECT_MESSAGE = config['NOTIFICATION_EMAIL']['VENDOR_REJECT_MESSAGE']
CATCH_EMAIL = config['STAGING']['CATCH_EMAIL'] CATCH_EMAIL = config['STAGING']['CATCH_EMAIL']
CR_FRONT_LINK = config['STAGING']['CR_LINK'] CR_FRONT_LINK = config['STAGING']['CR_LINK']
CORS_ORIGIN_ALLOW_ALL = config['STAGING']['CORS_ORIGIN_ALLOW_ALL']
...@@ -12,6 +12,7 @@ USER_DEFAULT_PASSWORD = ...@@ -12,6 +12,7 @@ USER_DEFAULT_PASSWORD =
CATCH_EMAIL = gladys@tirsolutions.com CATCH_EMAIL = gladys@tirsolutions.com
CR_LINK = http://stagingrms.oneberrysystem.com/cms/change-request/form/view CR_LINK = http://stagingrms.oneberrysystem.com/cms/change-request/form/view
REALTIMESERVER_IP = 127.0.0.1:8000 REALTIMESERVER_IP = 127.0.0.1:8000
CORS_ORIGIN_ALLOW_ALL = False
[UAT] [UAT]
DATABASE_ENGINE = django.db.backends.mysql DATABASE_ENGINE = django.db.backends.mysql
...@@ -27,6 +28,7 @@ USER_DEFAULT_PASSWORD = ...@@ -27,6 +28,7 @@ USER_DEFAULT_PASSWORD =
CATCH_EMAIL = gladys@tirsolutions.com CATCH_EMAIL = gladys@tirsolutions.com
CR_LINK = http://stagingrms.oneberrysystem.com/cms/change-request/form/view CR_LINK = http://stagingrms.oneberrysystem.com/cms/change-request/form/view
REALTIMESERVER_IP = 127.0.0.1:8000 REALTIMESERVER_IP = 127.0.0.1:8000
CORS_ORIGIN_ALLOW_ALL = False
[DEV] [DEV]
DATABASE_ENGINE = django.db.backends.mysql DATABASE_ENGINE = django.db.backends.mysql
...@@ -42,6 +44,7 @@ USER_DEFAULT_PASSWORD = ...@@ -42,6 +44,7 @@ USER_DEFAULT_PASSWORD =
CATCH_EMAIL = gladys@tirsolutions.com CATCH_EMAIL = gladys@tirsolutions.com
CR_LINK = http://devweb.rmsv2.oneberrysystem.com/cms/change-request/form/view CR_LINK = http://devweb.rmsv2.oneberrysystem.com/cms/change-request/form/view
REALTIMESERVER_IP = 127.0.0.1:8000 REALTIMESERVER_IP = 127.0.0.1:8000
CORS_ORIGIN_ALLOW_ALL = True
[STAGING] [STAGING]
...@@ -58,6 +61,7 @@ USER_DEFAULT_PASSWORD = password ...@@ -58,6 +61,7 @@ USER_DEFAULT_PASSWORD = password
CATCH_EMAIL = gladys@tirsolutions.com CATCH_EMAIL = gladys@tirsolutions.com
CR_LINK = http://stagingrms.oneberrysystem.com/cms/change-request/form/view CR_LINK = http://stagingrms.oneberrysystem.com/cms/change-request/form/view
REALTIMESERVER_IP = 127.0.0.1:8000 REALTIMESERVER_IP = 127.0.0.1:8000
CORS_ORIGIN_ALLOW_ALL = False
[LOCAL] [LOCAL]
...@@ -74,6 +78,7 @@ USER_DEFAULT_PASSWORD = password ...@@ -74,6 +78,7 @@ USER_DEFAULT_PASSWORD = password
CATCH_EMAIL = gladys@tirsolutions.com CATCH_EMAIL = gladys@tirsolutions.com
CR_LINK = http://localhost:8000/cms/change-request/form/view CR_LINK = http://localhost:8000/cms/change-request/form/view
REALTIMESERVER_IP = 127.0.0.1:8000 REALTIMESERVER_IP = 127.0.0.1:8000
CORS_ORIGIN_ALLOW_ALL = True
[SETTINGS] [SETTINGS]
CONFIG = config.settings.staging CONFIG = config.settings.staging
......
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