sonar issue

This commit is contained in:
jain
2023-07-11 11:52:07 +05:30
parent c0f20f732d
commit 41761f22e8
6 changed files with 33 additions and 29 deletions

View File

@ -2,9 +2,16 @@
from django.contrib import admin from django.contrib import admin
"""Import django app""" """Import django app"""
from .models import UserEmailOtp, UserPhoneOtp, DefaultTaskImages, UserNotification from .models import UserEmailOtp, UserPhoneOtp, DefaultTaskImages, UserNotification, UserDelete
# Register your models here. # Register your models here.
@admin.register(UserDelete)
class UserDeleteAdmin(admin.ModelAdmin):
"""User profile admin"""
list_display = ['user', 'old_email', 'd_email']
def __str__(self):
return self.user
@admin.register(UserNotification) @admin.register(UserNotification)
class UserNotificationAdmin(admin.ModelAdmin): class UserNotificationAdmin(admin.ModelAdmin):
"""User profile admin""" """User profile admin"""

View File

@ -10,7 +10,7 @@ from junior.models import Junior
from account.models import UserEmailOtp, DefaultTaskImages, UserDelete, UserNotification, UserPhoneOtp from account.models import UserEmailOtp, DefaultTaskImages, UserDelete, UserNotification, UserPhoneOtp
from base.constants import GUARDIAN, JUNIOR, SUPERUSER from base.constants import GUARDIAN, JUNIOR, SUPERUSER
from base.messages import ERROR_CODE_REQUIRED, ERROR_CODE, SUCCESS_CODE, STATUS_CODE_ERROR from base.messages import ERROR_CODE_REQUIRED, ERROR_CODE, SUCCESS_CODE, STATUS_CODE_ERROR
from .utils import junior_account_update, guardian_account_update
class GoogleLoginSerializer(serializers.Serializer): class GoogleLoginSerializer(serializers.Serializer):
"""google login serializer""" """google login serializer"""
@ -236,25 +236,11 @@ class UserDeleteSerializer(serializers.ModelSerializer):
if user_tb and user_tb.check_password(passwd): if user_tb and user_tb.check_password(passwd):
user_type_data = UserEmailOtp.objects.filter(email=user.email).last() user_type_data = UserEmailOtp.objects.filter(email=user.email).last()
if user_type == '1' and user_type_data.user_type == '1': if user_type == '1' and user_type_data.user_type == '1':
junior_data = Junior.objects.filter(auth__email=user_tb.email).first() junior_account_update(user_tb)
if junior_data:
junior_data.is_active = False
junior_data.is_verified = False
junior_data.guardian_code = '{}'
junior_data.save()
elif user_type == '2' and user_type_data.user_type == '2': elif user_type == '2' and user_type_data.user_type == '2':
guardian_data = Guardian.objects.filter(user__email=user_tb.email).first() guardian_account_update(user_tb)
if guardian_data:
guardian_data.is_active = False
guardian_data.is_verified = False
guardian_data.save()
jun_data = Junior.objects.filter(guardian_code__icontains=str(guardian_data.guardian_code))
for data in jun_data:
data.guardian_code.remove(guardian_data.guardian_code)
data.save()
else: else:
raise serializers.ValidationError({"details":ERROR_CODE['2030'],"code":"400", "status":"failed"}) raise serializers.ValidationError({"details":ERROR_CODE['2030'],"code":"400", "status":"failed"})
user_tb.email = str(random_num) + str('@D_') + '{}'.format(user_tb.username).lower() user_tb.email = str(random_num) + str('@D_') + '{}'.format(user_tb.username).lower()
user_tb.username = str(random_num) + str('@D_') + '{}'.format(user_tb.username).lower() user_tb.username = str(random_num) + str('@D_') + '{}'.format(user_tb.username).lower()
user_tb.password = 'None' user_tb.password = 'None'
@ -295,5 +281,6 @@ class UpdateUserNotificationSerializer(serializers.ModelSerializer):
class UserPhoneOtpSerializer(serializers.ModelSerializer): class UserPhoneOtpSerializer(serializers.ModelSerializer):
"""User Phone serializers""" """User Phone serializers"""
class Meta(object): class Meta(object):
"""Meta info"""
model = UserPhoneOtp model = UserPhoneOtp
fields = '__all__' fields = '__all__'

View File

@ -10,7 +10,28 @@ from datetime import datetime
from calendar import timegm from calendar import timegm
from uuid import uuid4 from uuid import uuid4
import secrets import secrets
from junior.models import Junior
from guardian.models import Guardian
def junior_account_update(user_tb):
"""junior account delete"""
junior_data = Junior.objects.filter(auth__email=user_tb.email).first()
if junior_data:
junior_data.is_active = False
junior_data.is_verified = False
junior_data.guardian_code = '{}'
junior_data.save()
def guardian_account_update(user_tb):
"""update guardian account after delete the user account"""
guardian_data = Guardian.objects.filter(user__email=user_tb.email).first()
if guardian_data:
guardian_data.is_active = False
guardian_data.is_verified = False
guardian_data.save()
jun_data = Junior.objects.filter(guardian_code__icontains=str(guardian_data.guardian_code))
for data in jun_data:
data.guardian_code.remove(guardian_data.guardian_code)
data.save()
def send_otp_email(recipient_email, otp): def send_otp_email(recipient_email, otp):
"""Send otp on email with template""" """Send otp on email with template"""
from_email = settings.EMAIL_FROM_ADDRESS from_email = settings.EMAIL_FROM_ADDRESS

View File

@ -109,8 +109,6 @@ class SigninWithApple(views.APIView):
def post(self, request): def post(self, request):
token = request.data.get("access_token") token = request.data.get("access_token")
user_type = request.data.get("user_type") user_type = request.data.get("user_type")
if not token:
return custom_error_response(ERROR_CODE['2027'], response_status=status.HTTP_400_BAD_REQUEST)
try: try:
decoded_data = jwt.decode(token, options={"verify_signature": False}) decoded_data = jwt.decode(token, options={"verify_signature": False})
user_data = {"email": decoded_data.get('email'), "username": decoded_data.get('email'), "is_active": True} user_data = {"email": decoded_data.get('email'), "username": decoded_data.get('email'), "is_active": True}

View File

@ -95,12 +95,8 @@ class CreateGuardianSerializer(serializers.ModelSerializer):
"""Save first and last name of guardian""" """Save first and last name of guardian"""
if self.context.get('first_name') != '' and self.context.get('first_name') is not None: if self.context.get('first_name') != '' and self.context.get('first_name') is not None:
user.first_name = self.context.get('first_name') user.first_name = self.context.get('first_name')
else:
user.first_name = user.first_name
if self.context.get('last_name') != '' and self.context.get('last_name') is not None: if self.context.get('last_name') != '' and self.context.get('last_name') is not None:
user.last_name = self.context.get('last_name') user.last_name = self.context.get('last_name')
else:
user.last_name = user.last_name
user.save() user.save()
"""Create guardian data""" """Create guardian data"""
guardian, created = Guardian.objects.get_or_create(user=self.context['user']) guardian, created = Guardian.objects.get_or_create(user=self.context['user'])

View File

@ -59,19 +59,14 @@ class CreateJuniorSerializer(serializers.ModelSerializer):
def create(self, validated_data): def create(self, validated_data):
"""Create junior profile""" """Create junior profile"""
image = validated_data.get('image', None)
guardian_code = validated_data.get('guardian_code',None) guardian_code = validated_data.get('guardian_code',None)
user = User.objects.filter(username=self.context['user']).last() user = User.objects.filter(username=self.context['user']).last()
if user: if user:
"""Save first and last name of junior""" """Save first and last name of junior"""
if self.context.get('first_name') != '' and self.context.get('first_name') is not None: if self.context.get('first_name') != '' and self.context.get('first_name') is not None:
user.first_name = self.context.get('first_name') user.first_name = self.context.get('first_name')
else:
user.first_name = user.first_name
if self.context.get('last_name') != '' and self.context.get('last_name') is not None: if self.context.get('last_name') != '' and self.context.get('last_name') is not None:
user.last_name = self.context.get('last_name') user.last_name = self.context.get('last_name')
else:
user.last_name = user.last_name
user.save() user.save()
"""Create junior data""" """Create junior data"""
junior, created = Junior.objects.get_or_create(auth=self.context['user']) junior, created = Junior.objects.get_or_create(auth=self.context['user'])