From 32e52e17f4b5cb9daae5ed5af978e37af8abc278 Mon Sep 17 00:00:00 2001 From: jain Date: Sat, 15 Jul 2023 23:07:12 +0530 Subject: [PATCH] sonar issue --- account/admin.py | 3 +++ account/custom_middleware.py | 10 +++++----- base/messages.py | 2 ++ guardian/urls.py | 18 +++++++++--------- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/account/admin.py b/account/admin.py index b67b88a..cf3ff23 100644 --- a/account/admin.py +++ b/account/admin.py @@ -19,6 +19,7 @@ class UserNotificationAdmin(admin.ModelAdmin): list_display = ['user', 'push_notification', 'email_notification', 'sms_notification'] def __str__(self): + """Return image url""" return self.image_url @admin.register(DefaultTaskImages) class DefaultTaskImagesAdmin(admin.ModelAdmin): @@ -26,6 +27,7 @@ class DefaultTaskImagesAdmin(admin.ModelAdmin): list_display = ['task_name', 'image_url'] def __str__(self): + """Return image url""" return self.image_url @admin.register(UserEmailOtp) @@ -43,4 +45,5 @@ class UserDeviceDetailsAdmin(admin.ModelAdmin): list_display = ['user', 'device_id'] def __str__(self): + """Return user email""" return self.user.email diff --git a/account/custom_middleware.py b/account/custom_middleware.py index 3bd5e60..7c4dc32 100644 --- a/account/custom_middleware.py +++ b/account/custom_middleware.py @@ -8,10 +8,10 @@ from account.utils import custom_error_response from account.models import UserDeviceDetails from base.messages import ERROR_CODE, SUCCESS_CODE -"""Custom middleware -when user login with +"""Custom middleware +when user login with multiple device simultaneously""" -class CustomMiddleware: +class CustomMiddleware(object): """Custom middleware""" def __init__(self, get_response): """response""" @@ -21,11 +21,11 @@ class CustomMiddleware: # Code to be executed before the view is called response = self.get_response(request) # Code to be executed after the view is called - device_id = request.META['HTTP_DEVICE_ID'] + device_id = request.META.get('HTTP_DEVICE_ID') if request.user.is_authenticated: """device details""" device_details = UserDeviceDetails.objects.filter(user=request.user, device_id=device_id).last() - if not device_details: + if device_id and not device_details: custom_error = custom_error_response(ERROR_CODE['2037'], response_status=status.HTTP_404_NOT_FOUND) response = Response(custom_error.data, status=status.HTTP_404_NOT_FOUND) # Set content type header to "application/json" diff --git a/base/messages.py b/base/messages.py index 02b0e34..e3399ed 100644 --- a/base/messages.py +++ b/base/messages.py @@ -58,8 +58,10 @@ ERROR_CODE = { "2032": "Failed to send email", "2033": "Missing required fields", "2034": "Junior is not associated", + # image size "2035": "Image should not be 0 kb", "2036": "Choose valid user", + # log in multiple device msg "2037": "You are already log in another device" } """Success message code""" diff --git a/guardian/urls.py b/guardian/urls.py index 14398f2..4a1c644 100644 --- a/guardian/urls.py +++ b/guardian/urls.py @@ -9,15 +9,15 @@ from rest_framework import routers """Define Router""" router = routers.SimpleRouter() -"""API End points with router -in this file -we define various api end point -that is covered in this guardian -section API:- like -sign-up, create guardian profile, -create-task, -all task list, top junior, -filter-task""" +# API End points with router +# in this file +# we define various api end point +# that is covered in this guardian +# section API:- like +# sign-up, create guardian profile, +# create-task, +# all task list, top junior, +# filter-task""" """Sign up API""" router.register('sign-up', SignupViewset, basename='sign-up') """Create guardian profile API"""