mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 16:44:54 +00:00
sonar fixes
This commit is contained in:
@ -17,6 +17,8 @@ from guardian.models import Guardian
|
|||||||
# multiple devices only
|
# multiple devices only
|
||||||
# user can login in single
|
# user can login in single
|
||||||
# device at a time"""
|
# device at a time"""
|
||||||
|
# force update
|
||||||
|
# use 308 status code for force update
|
||||||
|
|
||||||
def custom_response(custom_error, response_status = status.HTTP_404_NOT_FOUND):
|
def custom_response(custom_error, response_status = status.HTTP_404_NOT_FOUND):
|
||||||
"""custom response"""
|
"""custom response"""
|
||||||
|
|||||||
@ -123,7 +123,7 @@ class ChangePasswordSerializer(serializers.Serializer):
|
|||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
"""
|
"""
|
||||||
|
change password
|
||||||
"""
|
"""
|
||||||
new_password = validated_data.pop('new_password')
|
new_password = validated_data.pop('new_password')
|
||||||
current_password = validated_data.pop('current_password')
|
current_password = validated_data.pop('current_password')
|
||||||
@ -392,7 +392,8 @@ class UserPhoneOtpSerializer(serializers.ModelSerializer):
|
|||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
class ForceUpdateSerializer(serializers.ModelSerializer):
|
class ForceUpdateSerializer(serializers.ModelSerializer):
|
||||||
# ForceUpdate Serializer
|
""" ForceUpdate Serializer
|
||||||
|
"""
|
||||||
|
|
||||||
class Meta(object):
|
class Meta(object):
|
||||||
""" meta info """
|
""" meta info """
|
||||||
|
|||||||
@ -101,13 +101,16 @@ ERROR_CODE = {
|
|||||||
"2072": "You can not approve or reject this task because junior does not exist in the system",
|
"2072": "You can not approve or reject this task because junior does not exist in the system",
|
||||||
"2073": "You can not approve or reject this junior because junior does not exist in the system",
|
"2073": "You can not approve or reject this junior because junior does not exist in the system",
|
||||||
"2074": "You can not complete this task because you does not exist in the system",
|
"2074": "You can not complete this task because you does not exist in the system",
|
||||||
|
# deactivate account
|
||||||
"2075": "Your account is deactivated. Please contact with admin",
|
"2075": "Your account is deactivated. Please contact with admin",
|
||||||
"2076": "This junior already associate with you",
|
"2076": "This junior already associate with you",
|
||||||
"2077": "You can not add guardian",
|
"2077": "You can not add guardian",
|
||||||
"2078": "This junior is not associate with you",
|
"2078": "This junior is not associate with you",
|
||||||
|
# force update
|
||||||
"2079": "Please update your app version for enjoying uninterrupted services",
|
"2079": "Please update your app version for enjoying uninterrupted services",
|
||||||
"2080": "Can not add App version",
|
"2080": "Can not add App version",
|
||||||
"2081": "You can not add more than 3 guardian",
|
"2081": "You can not add more than 3 guardian",
|
||||||
|
# guardian code not exist
|
||||||
"2082": "Guardian code does not exist"
|
"2082": "Guardian code does not exist"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,6 +36,7 @@ from django.utils.translation import gettext as _
|
|||||||
|
|
||||||
# In this serializer file
|
# In this serializer file
|
||||||
# define user serializer,
|
# define user serializer,
|
||||||
|
# define password validation
|
||||||
# create guardian serializer,
|
# create guardian serializer,
|
||||||
# task serializer,
|
# task serializer,
|
||||||
# guardian serializer,
|
# guardian serializer,
|
||||||
@ -47,6 +48,7 @@ from django.utils.translation import gettext as _
|
|||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
class PasswordValidator:
|
class PasswordValidator:
|
||||||
|
"""Password validation"""
|
||||||
def __init__(self, min_length=8, max_length=None, require_uppercase=True, require_numbers=True):
|
def __init__(self, min_length=8, max_length=None, require_uppercase=True, require_numbers=True):
|
||||||
self.min_length = min_length
|
self.min_length = min_length
|
||||||
self.max_length = max_length
|
self.max_length = max_length
|
||||||
@ -57,6 +59,7 @@ class PasswordValidator:
|
|||||||
self.enforce_password_policy(value)
|
self.enforce_password_policy(value)
|
||||||
|
|
||||||
def enforce_password_policy(self, password):
|
def enforce_password_policy(self, password):
|
||||||
|
# add validation for password
|
||||||
special_characters = "!@#$%^&*()_-+=<>?/[]{}|"
|
special_characters = "!@#$%^&*()_-+=<>?/[]{}|"
|
||||||
if len(password) < self.min_length:
|
if len(password) < self.min_length:
|
||||||
raise serializers.ValidationError(
|
raise serializers.ValidationError(
|
||||||
@ -64,16 +67,20 @@ class PasswordValidator:
|
|||||||
)
|
)
|
||||||
|
|
||||||
if self.max_length is not None and len(password) > self.max_length:
|
if self.max_length is not None and len(password) > self.max_length:
|
||||||
|
# must be 8 character
|
||||||
raise serializers.ValidationError(
|
raise serializers.ValidationError(
|
||||||
_("Password must be at most %(max_length)d characters long.") % {'max_length': self.max_length}
|
_("Password must be at most %(max_length)d characters long.") % {'max_length': self.max_length}
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.require_uppercase and not any(char.isupper() for char in password):
|
if self.require_uppercase and not any(char.isupper() for char in password):
|
||||||
|
# must contain upper case letter
|
||||||
raise serializers.ValidationError(_("Password must contain at least one uppercase letter."))
|
raise serializers.ValidationError(_("Password must contain at least one uppercase letter."))
|
||||||
|
|
||||||
if self.require_numbers and not any(char.isdigit() for char in password):
|
if self.require_numbers and not any(char.isdigit() for char in password):
|
||||||
|
# must contain digit
|
||||||
raise serializers.ValidationError(_("Password must contain at least one digit."))
|
raise serializers.ValidationError(_("Password must contain at least one digit."))
|
||||||
if self.require_numbers and not any(char in special_characters for char in password):
|
if self.require_numbers and not any(char in special_characters for char in password):
|
||||||
|
# must contain special character
|
||||||
raise serializers.ValidationError(_("Password must contain at least one special character."))
|
raise serializers.ValidationError(_("Password must contain at least one special character."))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -288,7 +288,8 @@ class ApproveJuniorAPIView(viewsets.ModelViewSet):
|
|||||||
if request.data['action'] == '1':
|
if request.data['action'] == '1':
|
||||||
# use ApproveJuniorSerializer serializer
|
# use ApproveJuniorSerializer serializer
|
||||||
serializer = ApproveJuniorSerializer(context={"guardian_code": guardian.guardian_code,
|
serializer = ApproveJuniorSerializer(context={"guardian_code": guardian.guardian_code,
|
||||||
"junior": junior_queryset, "action": request.data['action']},
|
"junior": junior_queryset,
|
||||||
|
"action": request.data['action']},
|
||||||
data=request.data)
|
data=request.data)
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
# save serializer
|
# save serializer
|
||||||
|
|||||||
@ -523,18 +523,18 @@ class RemoveGuardianCodeSerializer(serializers.ModelSerializer):
|
|||||||
return instance
|
return instance
|
||||||
|
|
||||||
class FAQSerializer(serializers.ModelSerializer):
|
class FAQSerializer(serializers.ModelSerializer):
|
||||||
# FAQ Serializer
|
"""FAQ Serializer"""
|
||||||
|
|
||||||
class Meta(object):
|
class Meta(object):
|
||||||
# meta info
|
"""meta info"""
|
||||||
model = FAQ
|
model = FAQ
|
||||||
fields = ('id', 'question', 'description')
|
fields = ('id', 'question', 'description')
|
||||||
|
|
||||||
class CreateArticleCardSerializer(serializers.ModelSerializer):
|
class CreateArticleCardSerializer(serializers.ModelSerializer):
|
||||||
# Article card Serializer
|
"""Article card Serializer"""
|
||||||
|
|
||||||
class Meta(object):
|
class Meta(object):
|
||||||
# meta info
|
"""meta info"""
|
||||||
model = ArticleCard
|
model = ArticleCard
|
||||||
fields = ('id', 'article')
|
fields = ('id', 'article')
|
||||||
|
|
||||||
|
|||||||
@ -266,10 +266,10 @@ class FilterJuniorAPIView(viewsets.ModelViewSet):
|
|||||||
manual_parameters=[
|
manual_parameters=[
|
||||||
# Example of a query parameter
|
# Example of a query parameter
|
||||||
openapi.Parameter(
|
openapi.Parameter(
|
||||||
'title', # Query parameter name
|
'title',
|
||||||
openapi.IN_QUERY, # Parameter location
|
openapi.IN_QUERY,
|
||||||
description='title of the name',
|
description='title of the name',
|
||||||
type=openapi.TYPE_STRING, # Parameter type
|
type=openapi.TYPE_STRING,
|
||||||
),
|
),
|
||||||
# Add more parameters as needed
|
# Add more parameters as needed
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user