diff --git a/accounts/api/urls.py b/accounts/api/urls.py index a17289e..602634a 100644 --- a/accounts/api/urls.py +++ b/accounts/api/urls.py @@ -37,6 +37,7 @@ urlpatterns = [ views.SoftDeletePrincipalAPIView.as_view(), name="delete_account", ), + path('version-check/', views.VersionCheck.as_view(), name='version_check'), diff --git a/accounts/api/views.py b/accounts/api/views.py index 21f73d1..f8b323a 100644 --- a/accounts/api/views.py +++ b/accounts/api/views.py @@ -15,6 +15,7 @@ from django.views.decorators.http import require_http_methods # from .authenticate import authticate_with_otp_and_passsword from accounts.models import ( + AppVersion, IAmPrincipal, IAmPrincipalOtp, IAmPrincipalSource, @@ -933,3 +934,29 @@ class SoftDeletePrincipalAPIView(APIView): message=constants.SUCCESS, data="Account has been successfully deleted.", ) + + +class VersionCheck(APIView): + authentication_classes = [] + permission_classes = [] + + def get(self, request, *args, **kwargs): + app_version = request.GET.get("appVersion") + + # Query the database to retrieve the upgrade flags based on the app version + try: + version = AppVersion.objects.get(version=app_version) + except AppVersion.DoesNotExist: + version = None + + 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) diff --git a/accounts/migrations/0005_appversion.py b/accounts/migrations/0005_appversion.py new file mode 100644 index 0000000..f8f426c --- /dev/null +++ b/accounts/migrations/0005_appversion.py @@ -0,0 +1,56 @@ +# Generated by Django 5.0.2 on 2024-03-26 07:05 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("accounts", "0004_alter_iamprincipallocation_latitude_and_more"), + ] + + operations = [ + migrations.CreateModel( + name="AppVersion", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "version", + models.CharField( + max_length=10, + validators=[ + django.core.validators.RegexValidator( + "^\\d+\\.\\d+\\.\\d+$" + ) + ], + ), + ), + ( + "force_upgrade", + models.BooleanField( + default=False, + help_text="Indicates whether a force upgrade is needed for this app version.", + ), + ), + ( + "recommend_upgrade", + models.BooleanField( + default=False, + help_text="Indicates whether a recommend upgrade is needed for this app version.", + ), + ), + ], + options={ + "db_table": "app_version", + }, + ), + ] diff --git a/accounts/models.py b/accounts/models.py index 443b0e9..308d442 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -446,5 +446,26 @@ class IAmPrincipalLocation(BaseModel): # class Meta: # db_table = "iam_principal_kyc_details" + # def __str__(self): # return f"KYC Information for {self.principal.email}" + + +class AppVersion(models.Model): + version = models.CharField( + max_length=10, validators=[RegexValidator(r"^\d+\.\d+\.\d+$")] + ) + force_upgrade = models.BooleanField( + default=False, + help_text="Indicates whether a force upgrade is needed for this app version.", + ) + recommend_upgrade = models.BooleanField( + default=False, + help_text="Indicates whether a recommend upgrade is needed for this app version.", + ) + + class Meta: + db_table = "app_version" + + def __str__(self): + return self.version