From 971f3f6c92304f1537ccddcbeff2bff4954769de Mon Sep 17 00:00:00 2001 From: bobbyvish Date: Tue, 21 May 2024 19:02:26 +0530 Subject: [PATCH 1/3] conf(production):structure setting of production server and app verion api --- module_auth/api/urls.py | 1 + module_auth/api/views.py | 6 +++--- module_iam/models.py | 4 ++-- module_project/settings/production.py | 20 +++++++++---------- module_project/wsgi.py | 5 ----- .../module_support/thank_you_support.html | 2 +- 6 files changed, 16 insertions(+), 22 deletions(-) diff --git a/module_auth/api/urls.py b/module_auth/api/urls.py index 1dada83..0fdf38b 100644 --- a/module_auth/api/urls.py +++ b/module_auth/api/urls.py @@ -19,5 +19,6 @@ urlpatterns = [ path('apple-signin/', views.AppleSignin.as_view(), name='apple_signin'), path('version-check/', views.VersionCheck.as_view(), name='version_check'), + path('app-version/', views.VersionCheck.as_view(), name='version_check'), ] diff --git a/module_auth/api/views.py b/module_auth/api/views.py index 5d33a00..fcd68df 100644 --- a/module_auth/api/views.py +++ b/module_auth/api/views.py @@ -374,14 +374,14 @@ class VersionCheck(APIView): model = AppVersion def get(self, request, *args, **kwargs): - app_version = request.GET.get('appVersion') + # app_version = request.GET.get('appVersion') device_type = request.GET.get('deviceType') - if not app_version or not device_type: + if not device_type: return ApiResponse.error(message=constants.FAILURE, errors="App version and device type is required") # Query the database to retrieve the upgrade flags based on the app version try: - version = self.model.objects.get(version=app_version) + version = self.model.objects.filter(device_type=device_type).last() except self.model.DoesNotExist: version = None diff --git a/module_iam/models.py b/module_iam/models.py index 1b16eca..ff7cba1 100644 --- a/module_iam/models.py +++ b/module_iam/models.py @@ -449,10 +449,10 @@ class IAmPrincipalBiometric(BaseModel): class AppVersion(models.Model): DEVICE_CHOICES = [ - ('apple', 'apple'), + ('ios', 'ios'), ('android', 'android'), ] - device_type = models.CharField(max_length=10, choices=DEVICE_CHOICES, verbose_name='Device Type (apple / android)') + device_type = models.CharField(max_length=10, choices=DEVICE_CHOICES, verbose_name='Device Type (ios / android)') version = models.CharField(max_length=5, validators=[RegexValidator(r'^\d+\.\d+\.\d+$')], verbose_name='Version') force_upgrade = models.BooleanField(default=False, verbose_name='Force Upgrade', help_text='Indicates whether a force upgrade is needed for this app version.') recommend_upgrade = models.BooleanField(default=False, verbose_name='Recommend Upgrade', help_text='Indicates whether a recommend upgrade is needed for this app version.') diff --git a/module_project/settings/production.py b/module_project/settings/production.py index 1ab9f5b..e11deca 100644 --- a/module_project/settings/production.py +++ b/module_project/settings/production.py @@ -4,19 +4,18 @@ import os import colorlog from logging.handlers import TimedRotatingFileHandler -DEBUG = False - -ALLOWED_HOSTS = [] +# DEBUG = True +ALLOWED_HOSTS = ["admin.eatwithdigest.com"] # CORS_ALLOWED_ORIGINS = [ -# # "http://127.0.0.1:3000", +# "http://127.0.0.1:3000", # ] -# CORS_ORIGIN_ALLOW_ALL = True +CORS_ORIGIN_ALLOW_ALL = True -# CORS_ORIGIN_WHITELIST = ("",) +# CORS_ORIGIN_WHITELIST = ("http://localhost:3000",) LOGGING_DIR = os.path.join( @@ -29,7 +28,7 @@ if not os.path.exists(LOGGING_DIR): LOGGING_LEVEL = env.str( "LOG_LEVEL", "INFO" -) # Set your desired log level (e.g., DEBUG, INFO, WARNING, ERROR) +) # Set your desired log level (e.g., DEBUG, INFO, WARNING, ERROR) in the env file LOGGING = { @@ -70,8 +69,7 @@ LOGGING = { }, } - -BASE_DOMAIN = "" +BASE_DOMAIN = "https://admin.eatwithdigest.com" # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.2/howto/static-files/ @@ -80,8 +78,8 @@ BASE_DOMAIN = "" MEDIA_URL = "/media/" MEDIA_ROOT = os.path.join(BASE_DIR, "media") -# STATIC_ROOT = os.path.join(BASE_DIR, "static") +STATIC_ROOT = os.path.join(BASE_DIR, "static") STATIC_URL = "/static/" -STATICFILES_DIRS = [BASE_DIR.joinpath("static")] +# STATICFILES_DIRS = [BASE_DIR.joinpath("static")] diff --git a/module_project/wsgi.py b/module_project/wsgi.py index 016ce1a..713dee0 100644 --- a/module_project/wsgi.py +++ b/module_project/wsgi.py @@ -8,11 +8,6 @@ https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ """ import os -import sys - -sys.path.append('/var/www/testing_django/testing') -sys.path.append('/var/www/testing_django/testing/testing') -sys.path.append('/var/www/testing_django/testing/venv/lib/python3.11/site-packages') from django.core.wsgi import get_wsgi_application diff --git a/templates/module_support/thank_you_support.html b/templates/module_support/thank_you_support.html index faa0143..a62686c 100644 --- a/templates/module_support/thank_you_support.html +++ b/templates/module_support/thank_you_support.html @@ -56,7 +56,7 @@

Your Message:

{{ message }}

We will respond to your inquiry as soon as possible.

-

In the meantime, you may find answers to frequently asked questions on our Help Center: [link to Help Center]

+

In the meantime, you may find answers to frequently asked questions on our Help Center: eatwithdigest.com

Sincerely,

The Digest Team

From 585c863f660da7637d1cc8d9535a20d78980313e Mon Sep 17 00:00:00 2001 From: bobbyvish Date: Tue, 21 May 2024 19:40:57 +0530 Subject: [PATCH 2/3] fix(app version):changes in logic --- module_auth/api/serializers.py | 7 ++++- module_auth/api/urls.py | 1 - module_auth/api/views.py | 28 ++++++------------- .../0010_alter_appversion_device_type.py | 18 ++++++++++++ module_project/settings/production.py | 2 +- 5 files changed, 33 insertions(+), 23 deletions(-) create mode 100644 module_iam/migrations/0010_alter_appversion_device_type.py diff --git a/module_auth/api/serializers.py b/module_auth/api/serializers.py index d0f189a..85365ed 100644 --- a/module_auth/api/serializers.py +++ b/module_auth/api/serializers.py @@ -3,7 +3,7 @@ from django.contrib.auth.hashers import make_password from rest_framework import serializers from rest_framework.validators import UniqueValidator -from module_iam.models import IAmPrincipal +from module_iam.models import AppVersion, IAmPrincipal from module_project import constants # class BasePasswordSerializer(serializers.Serializer): @@ -107,3 +107,8 @@ class PasswordResetSerializer(serializers.ModelSerializer): instance.password = make_password(new_password) instance.save() return instance + +class AppVersionSerializer(serializers.ModelSerializer): + class Meta: + model = AppVersion + fields = "__all__" \ No newline at end of file diff --git a/module_auth/api/urls.py b/module_auth/api/urls.py index 0fdf38b..1dada83 100644 --- a/module_auth/api/urls.py +++ b/module_auth/api/urls.py @@ -19,6 +19,5 @@ urlpatterns = [ path('apple-signin/', views.AppleSignin.as_view(), name='apple_signin'), path('version-check/', views.VersionCheck.as_view(), name='version_check'), - path('app-version/', views.VersionCheck.as_view(), name='version_check'), ] diff --git a/module_auth/api/views.py b/module_auth/api/views.py index fcd68df..904e5d7 100644 --- a/module_auth/api/views.py +++ b/module_auth/api/views.py @@ -15,7 +15,7 @@ from module_project import constants from module_project.service import EmailService, SMSService from module_project.utils import ApiResponse -from .serializers import (LoginSerializer, OtpVerificationSerializer, +from .serializers import (AppVersionSerializer, LoginSerializer, OtpVerificationSerializer, PasswordResetSerializer, RegistrationSerializer) from .utils import (AuthService, GoogleAuthService, authticate_with_otp_and_passsword, blacklist_token, @@ -369,30 +369,18 @@ class AppleSignin(APIView): class VersionCheck(APIView): - authentication_classes = [] - permission_classes = [] + authentication_classes = [JWTAuthentication] + permission_classes = [IsAuthenticated] model = AppVersion def get(self, request, *args, **kwargs): - # app_version = request.GET.get('appVersion') + print("app version is called") device_type = request.GET.get('deviceType') if not device_type: - return ApiResponse.error(message=constants.FAILURE, errors="App version and device type is required") + return ApiResponse.error(message=constants.FAILURE, errors="device type is required") # Query the database to retrieve the upgrade flags based on the app version - try: - version = self.model.objects.filter(device_type=device_type).last() - except self.model.DoesNotExist: - version = None + version = self.model.objects.filter(device_type=device_type).last() + version_data = AppVersionSerializer(version) - if version: - upgrade_flags = { - 'forceUpgrade': version.force_upgrade, - 'recommendUpgrade': version.recommend_upgrade, - } - else: - upgrade_flags = { - 'forceUpgrade': False, - 'recommendUpgrade': False, - } - return ApiResponse.success(message=constants.SUCCESS, data=upgrade_flags) \ No newline at end of file + return ApiResponse.success(message=constants.SUCCESS, data=version_data.data) \ No newline at end of file diff --git a/module_iam/migrations/0010_alter_appversion_device_type.py b/module_iam/migrations/0010_alter_appversion_device_type.py new file mode 100644 index 0000000..bce3291 --- /dev/null +++ b/module_iam/migrations/0010_alter_appversion_device_type.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.2 on 2024-05-21 14:09 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('module_iam', '0009_alter_appversion_device_type_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='appversion', + name='device_type', + field=models.CharField(choices=[('ios', 'ios'), ('android', 'android')], max_length=10, verbose_name='Device Type (ios / android)'), + ), + ] diff --git a/module_project/settings/production.py b/module_project/settings/production.py index e11deca..37a9932 100644 --- a/module_project/settings/production.py +++ b/module_project/settings/production.py @@ -4,7 +4,7 @@ import os import colorlog from logging.handlers import TimedRotatingFileHandler -# DEBUG = True +DEBUG = False ALLOWED_HOSTS = ["admin.eatwithdigest.com"] # CORS_ALLOWED_ORIGINS = [ From be1ae7262a12710cd6f03cbedb0d6edaa344f5ec Mon Sep 17 00:00:00 2001 From: bobbyvish Date: Thu, 23 May 2024 12:13:26 +0530 Subject: [PATCH 3/3] refactor(app version): updated serializer --- module_auth/api/serializers.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/module_auth/api/serializers.py b/module_auth/api/serializers.py index 85365ed..61a1ad4 100644 --- a/module_auth/api/serializers.py +++ b/module_auth/api/serializers.py @@ -111,4 +111,9 @@ class PasswordResetSerializer(serializers.ModelSerializer): class AppVersionSerializer(serializers.ModelSerializer): class Meta: model = AppVersion - fields = "__all__" \ No newline at end of file + fields = [ + "device_type", + "version", + "force_upgrade", + "recommend_upgrade", + ] \ No newline at end of file