sonar issues fixed

This commit is contained in:
jain
2023-07-17 11:58:04 +05:30
parent 32e52e17f4
commit cfc36735d6
10 changed files with 190 additions and 71 deletions

View File

@ -8,9 +8,13 @@ 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
multiple device simultaneously"""
# Custom middleware
# when user login with
# multiple device simultaneously
# It restricted login in
# multiple devices only
# user can login in single
# device at a time"""
class CustomMiddleware(object):
"""Custom middleware"""
def __init__(self, get_response):

View File

@ -1,10 +1,20 @@
"""Account serializer"""
"""Django Imoprt"""
"""Django Import"""
import random
from rest_framework import serializers
from django.contrib.auth.models import User
from rest_framework_simplejwt.tokens import RefreshToken
"""App import"""
# Import guardian's model,
# Import junior's model,
# Import account's model,
# Import constant from
# base package,
# Import messages from
# base package,
# Import some functions
# from utils file"""
from guardian.models import Guardian
from junior.models import Junior
from account.models import UserEmailOtp, DefaultTaskImages, UserDelete, UserNotification, UserPhoneOtp
@ -12,6 +22,25 @@ from base.constants import GUARDIAN, JUNIOR, SUPERUSER
from base.messages import ERROR_CODE_REQUIRED, ERROR_CODE, SUCCESS_CODE, STATUS_CODE_ERROR
from .utils import delete_user_account_condition_social, delete_user_account_condition
# In this serializer file
# define google login serializer
# update junior profile,
# update guardian profile,
# super admin serializer,
# reset password,
# forgot password,
# change password,
# basic junior serializer,
# basic guardian serializer,
# user delete account serializer,
# user notification serializer,
# update user notification serializer,
# default task's images serializer,
# upload default task's images serializer,
# email verification serializer,
# phone otp serializer
class GoogleLoginSerializer(serializers.Serializer):
"""google login serializer"""
access_token = serializers.CharField(max_length=5000, required=True)
@ -89,6 +118,7 @@ class ChangePasswordSerializer(serializers.Serializer):
def create(self, validated_data):
new_password = validated_data.pop('new_password')
current_password = validated_data.pop('current_password')
"""Check new password is different from current password"""
if new_password == current_password:
raise serializers.ValidationError({"details": ERROR_CODE['2026']})
user_details = User.objects.filter(email=self.context).last()

View File

@ -3,7 +3,27 @@
from django.urls import path, include
"""Third party import"""
from rest_framework import routers
"""Import view functions"""
# Import view functions
# UserLogin views,
# SendPhoneOtp views,
# UserPhoneVerification views,
# UserEmailVerification views,
# ReSendEmailOtp views,
# ForgotPasswordAPIView views,
# ResetPasswordAPIView views,
# ChangePasswordAPIView views,
# UpdateProfileImage views,
# GoogleLoginViewSet views,
# SigninWithApple views,
# ProfileAPIViewSet views,
# UploadImageAPIViewSet views,
# DefaultImageAPIViewSet views,
# DeleteUserProfileAPIViewSet views,
# UserNotificationAPIViewSet views,
# UpdateUserNotificationAPIViewSet views,
# SendSupportEmail views,
# LogoutAPIView views,
# AccessTokenAPIView views"""
from .views import (UserLogin, SendPhoneOtp, UserPhoneVerification, UserEmailVerification, ReSendEmailOtp,
ForgotPasswordAPIView, ResetPasswordAPIView, ChangePasswordAPIView, UpdateProfileImage,
GoogleLoginViewSet, SigninWithApple, ProfileAPIViewSet, UploadImageAPIViewSet,

View File

@ -12,12 +12,37 @@ from calendar import timegm
from uuid import uuid4
import secrets
from rest_framework import serializers
# Django App Import
# Import models from junior App,
# Import models from guardian App,
# Import models from account App,
# Import messages from base package"""
from junior.models import Junior
from guardian.models import Guardian
from account.models import UserDelete
from base.messages import ERROR_CODE
# Define delete
# user account condition,
# Define delete
# user account
# condition for social
# login account,
# Update junior account,
# Update guardian account,
# Define custom email for otp verification,
# Define support email for user's query,
# Define custom success response,
# Define custom error response,
# Generate access token,
# refresh token by using jwt,
# Define function for generating
# guardian code, junior code,
# referral code,
# Define function for generating
# alphanumeric code
def delete_user_account_condition(user, user_type_data, user_type, user_tb, data, random_num):
"""delete user account"""
if user_type == '1' and user_type_data == '1':
@ -28,10 +53,10 @@ def delete_user_account_condition(user, user_type_data, user_type, user_tb, data
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.username = str(random_num) + str('@D_') + '{}'.format(user_tb.username).lower()
user_tb.password = 'None'
d_email = user_tb.email
o_mail = user.email
user_tb.save()
"""create object in user delete model"""
instance = UserDelete.objects.create(user=user_tb, d_email=d_email, old_email=o_mail,
is_active=True, reason=data)
@ -47,10 +72,10 @@ def delete_user_account_condition_social(user, user_type,user_tb, data, random_n
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.username = str(random_num) + str('@D_') + '{}'.format(user_tb.username).lower()
user_tb.password = 'None'
dummy_email = user_tb.email
old_mail = user.email
user_tb.save()
"""create object in user delete model"""
instance_data = UserDelete.objects.create(user=user_tb, d_email=dummy_email, old_email=old_mail,
is_active=True, reason=data)
@ -72,6 +97,7 @@ def guardian_account_update(user_tb):
guardian_data.is_verified = False
guardian_data.save()
jun_data = Junior.objects.filter(guardian_code__icontains=str(guardian_data.guardian_code))
"""Disassociate relation between guardian and junior"""
for data in jun_data:
data.guardian_code.remove(guardian_data.guardian_code)
data.save()
@ -79,6 +105,7 @@ def send_otp_email(recipient_email, otp):
"""Send otp on email with template"""
from_email = settings.EMAIL_FROM_ADDRESS
recipient_list = [recipient_email]
"""Send otp on email"""
send_templated_mail(
template_name='email_otp_verification.email',
from_email=from_email,
@ -93,6 +120,7 @@ def send_support_email(name, sender, subject, message):
"""Send otp on email with template"""
to_email = [settings.EMAIL_FROM_ADDRESS]
from_email = settings.DEFAULT_ADDRESS
"""Send support email to zod bank support team"""
send_templated_mail(
template_name='support_mail.email',
from_email=from_email,

View File

@ -6,31 +6,22 @@ import os
# GOOGLE_URL used for interact with google server to verify user existence.
#GOOGLE_URL = "https://www.googleapis.com/plus/v1/"
# Define Code prefix word
# for guardian code,
# junior code,
# referral code"""
ZOD = 'ZOD'
JUN = 'JUN'
GRD = 'GRD'
# Define number variable
# from zero to
# twenty and
# some standard
# number"""
NUMBER = {
'point_zero': 0.0,
'zero': 0,
'one': 1,
'two': 2,
'three': 3,
'four': 4,
'five': 5,
'six': 6,
'seven': 7,
'eight': 8,
'nine': 9,
'ten': 10,
'eleven': 11,
'twelve': 12,
'thirteen': 13,
'fourteen': 14,
'fifteen': 15,
'sixteen': 16,
'seventeen': 17,
'eighteen': 18,
'nineteen': 19,
'point_zero': 0.0, 'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7,
'eight': 8, 'nine': 9, 'ten': 10, 'eleven': 11, 'twelve': 12, 'thirteen': 13, 'fourteen': 14, 'fifteen': 15,
'sixteen': 16, 'seventeen': 17, 'eighteen': 18, 'nineteen': 19,
'twenty_four': 24,
'twenty_one': 21,
'twenty_two': 22,
@ -108,6 +99,9 @@ RELATIONSHIP = (
('1', 'parent'),
('2', 'legal_guardian')
)
"""
Define task status
in a number"""
PENDING = 1
IN_PROGRESS = 2
REJECTED = 3

View File

@ -20,21 +20,21 @@ router = routers.SimpleRouter()
# filter-task"""
"""Sign up API"""
router.register('sign-up', SignupViewset, basename='sign-up')
"""Create guardian profile API"""
# Create guardian profile API"""
router.register('create-guardian-profile', UpdateGuardianProfile, basename='update-guardian-profile')
"""Create Task API"""
# Create Task API"""
router.register('create-task', CreateTaskAPIView, basename='create-task')
"""All Task list API"""
# All Task list API"""
router.register('all-task-list', AllTaskListAPIView, basename='all-task-list')
"""Task list bases on the status API"""
# Task list bases on the status API"""
router.register('task-list', TaskListAPIView, basename='task-list')
"""Leaderboard API"""
# Leaderboard API"""
router.register('top-junior', TopJuniorListAPIView, basename='top-junior')
"""Search Task list on the bases of status, due date, and task title API"""
# Search Task list on the bases of status, due date, and task title API"""
router.register('filter-task', SearchTaskListAPIView, basename='filter-task')
"""Approve junior API"""
# Approve junior API"""
router.register('approve-junior', ApproveJuniorAPIView, basename='approve-junior')
"""Define Url pattern"""
# Define Url pattern"""
urlpatterns = [
path('api/v1/', include(router.urls)),
]

View File

@ -6,6 +6,14 @@ from django.conf import settings
"""Import tempfile"""
import tempfile
# Define upload image on
# ali baba cloud
# firstly save image
# in temporary file
# then check bucket name
# then upload on ali baba
# bucket and reform the image url"""
def upload_image_to_alibaba(image, filename):
"""upload image on oss alibaba bucket"""
# Save the image object to a temporary file

View File

@ -10,45 +10,66 @@ from base.constants import GENDERS, SIGNUP_METHODS, RELATIONSHIP
"""Define User model"""
User = get_user_model()
# Create your models here.
# Define junior model with
# various fields like
# phone, country code,
# country name,
# gender,
# date of birth,
# profile image,
# relationship type of the guardian
# signup method,
# guardian code,
# junior code,
# referral code,
# referral code that used by the junior
# is invited junior
# profile is active or not
# profile is complete or not
# passcode
# junior is verified or not
"""Define junior points model"""
# points of the junior
# position of the junior
class Junior(models.Model):
"""Junior model"""
auth = models.ForeignKey(User, on_delete=models.CASCADE, related_name='junior_profile', verbose_name='Email')
"""Contact details"""
# Contact details"""
phone = models.CharField(max_length=31, null=True, blank=True, default=None)
country_code = models.IntegerField(blank=True, null=True)
"""country name of the guardian"""
# country name of the guardian"""
country_name = models.CharField(max_length=100, null=True, blank=True, default=None)
"""Personal info"""
# Personal info"""
gender = models.CharField(max_length=10, choices=GENDERS, null=True, blank=True, default=None)
"""Date of birth"""
# Date of birth"""
dob = models.DateField(max_length=15, null=True, blank=True, default=None)
"""Image of the junior"""
# Image of the junior"""
image = models.URLField(null=True, blank=True, default=None)
"""relationship"""
# relationship"""
relationship = models.CharField(max_length=31, choices=RELATIONSHIP, null=True, blank=True,
default='1')
"""Sign up method"""
# Sign up method"""
signup_method = models.CharField(max_length=31, choices=SIGNUP_METHODS, default='1')
"""Codes"""
# Codes"""
junior_code = models.CharField(max_length=10, null=True, blank=True, default=None)
"""Guardian Codes"""
# Guardian Codes"""
guardian_code = ArrayField(models.CharField(max_length=10, null=True, blank=True, default=None),null=True)
"""Referral code"""
# Referral code"""
referral_code = models.CharField(max_length=10, null=True, blank=True, default=None)
"""Referral code that is used by junior while signup"""
# Referral code that is used by junior while signup"""
referral_code_used = models.CharField(max_length=10, null=True, blank=True, default=None)
"""invited junior"""
# invited junior"""
is_invited = models.BooleanField(default=False)
"""Profile activity"""
# Profile activity"""
is_active = models.BooleanField(default=True)
"""junior profile is complete or not"""
# junior profile is complete or not"""
is_complete_profile = models.BooleanField(default=False)
"""passcode of the junior profile"""
# passcode of the junior profile"""
passcode = models.IntegerField(null=True, blank=True, default=None)
"""junior is verified or not"""
# junior is verified or not"""
is_verified = models.BooleanField(default=False)
"""Profile created and updated time"""
# Profile created and updated time"""
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
@ -56,7 +77,7 @@ class Junior(models.Model):
""" Meta class """
db_table = 'junior'
verbose_name = 'Junior'
"""another name of the model"""
# another name of the model"""
verbose_name_plural = 'Junior'
def __str__(self):
@ -66,11 +87,11 @@ class Junior(models.Model):
class JuniorPoints(models.Model):
"""Junior model"""
junior = models.OneToOneField(Junior, on_delete=models.CASCADE, related_name='junior_points')
"""Contact details"""
# Contact details"""
total_task_points = models.IntegerField(blank=True, null=True, default=0)
"""position of the junior"""
# position of the junior"""
position = models.IntegerField(blank=True, null=True, default=99999)
"""Profile created and updated time"""
# Profile created and updated time"""
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
@ -78,7 +99,7 @@ class JuniorPoints(models.Model):
""" Meta class """
db_table = 'junior_task_points'
verbose_name = 'Junior Task Points'
"""another name of the model"""
# another name of the model"""
verbose_name_plural = 'Junior Task Points'
def __str__(self):

View File

@ -8,21 +8,29 @@ from rest_framework import routers
"""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
# Create junior profile API, validate junior profile,
# junior list,
# add junior list, invited junior,
# filter-junior,
# remove junior"""
"""API End points with router"""
"""Create junior profile API"""
router.register('create-junior-profile', UpdateJuniorProfile, basename='profile-update')
"""validate guardian code API"""
# validate guardian code API"""
router.register('validate-guardian-code', ValidateGuardianCode, basename='validate-guardian-code')
"""junior list API"""
# junior list API"""
router.register('junior-list', JuniorListAPIView, basename='junior-list')
"""Add junior list API"""
# Add junior list API"""
router.register('add-junior', AddJuniorAPIView, basename='add-junior')
"""Invited junior list API"""
# Invited junior list API"""
router.register('invited-junior', InvitedJuniorAPIView, basename='invited-junior')
"""Filter junior list API"""
# Filter junior list API"""
router.register('filter-junior', FilterJuniorAPIView, basename='filter-junior')
"""Define url pattern"""
# Define url pattern"""
urlpatterns = [
path('api/v1/', include(router.urls)),
path('api/v1/remove-junior/', RemoveJuniorAPIView.as_view())

View File

@ -4,14 +4,20 @@ from django.conf import settings
"""Third party Django app"""
from templated_email import send_templated_mail
# junior notification
# email for sending email
# when guardian create junior profile
# guardian get email when junior send
# request for approving the profile and
# being part of the zod bank and access the platform
# define junior notification email
# junior approval email
def junior_notification_email(recipient_email, full_name, email, password):
"""Notification email"""
from_email = settings.EMAIL_FROM_ADDRESS
"""recipient email"""
# recipient email"""
recipient_list = [recipient_email]
"""use send template mail for sending email"""
# use send template mail for sending email"""
send_templated_mail(
template_name='junior_notification_email.email',
from_email=from_email,
@ -29,7 +35,7 @@ def junior_approval_mail(guardian, full_name):
"""junior approval mail"""
from_email = settings.EMAIL_FROM_ADDRESS
recipient_list = [guardian]
"""use send tempolate mail for sending email"""
# use send template mail for sending email"""
send_templated_mail(
template_name='junior_approval_mail.email',
from_email=from_email,