new feature: customer panel accsess

This commit is contained in:
javad committed 2024-01-24 13:50:53 +03:30
1 parent 5052bde49a
commit e983e0cc43
12 files changed
+175 -4

No files matched your search

+6 -1
View File
@@ -3,7 +3,12 @@
<component name="ChangeListManager">
<list default="true" id="87c5db51-3e89-4a98-9bbb-121c9c52ab3c" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/apps/cuser/cuser_model.py" beforeDir="false" afterPath="$PROJECT_DIR$/apps/cuser/cuser_model.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/apps/cuser/models.py" beforeDir="false" afterPath="$PROJECT_DIR$/apps/cuser/models.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/apps/customer/services.py" beforeDir="false" afterPath="$PROJECT_DIR$/apps/customer/services.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/apps/customer/urls.py" beforeDir="false" afterPath="$PROJECT_DIR$/apps/customer/urls.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/apps/customer/views/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/apps/customer/views/__init__.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/apps/customer/views/customer.py" beforeDir="false" afterPath="$PROJECT_DIR$/apps/customer/views/customer.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -91,7 +96,7 @@
<workItem from="1697269439761" duration="66295000" />
<workItem from="1702900258020" duration="63755000" />
<workItem from="1704088148329" duration="105568000" />
<workItem from="1704951046597" duration="82861000" />
<workItem from="1704951046597" duration="99812000" />
</task>
<servers />
</component>
+1 -1
View File
@@ -43,4 +43,4 @@ class CUser(BaseModel, AbstractBaseUser, PermissionsMixin):
]
def __str__(self):
return str(self.username)
return f'{self.name_family} - {self.username}'
@@ -0,0 +1,18 @@
# Generated by Django 4.2.1 on 2024-01-24 06:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('cuser', '0010_alter_cuserrole_unique_together'),
]
operations = [
migrations.AddField(
model_name='cuserrole',
name='customer_panel',
field=models.BooleanField(blank=True, default=None, null=True),
),
]
+2 -1
View File
@@ -25,6 +25,7 @@ class CuserRole(BaseModel):
title = models.CharField(max_length=30, null=True, blank=True)
mobile = models.PositiveBigIntegerField(null=False, blank=False)
mobile_verify = models.BooleanField(default=False)
customer_panel = models.BooleanField(default=None, blank=True, null=True)
sys_ws = models.ForeignKey(WorkspaceModel, on_delete=models.CASCADE, null=True, blank=True, default=None)
uuid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
@@ -34,7 +35,7 @@ class CuserRole(BaseModel):
unique_together = ('cuser', 'role_type', 'sys_ws', )
def __str__(self):
return f'{str(self.cuser) } - { str(self.id) }'
return f'{str(self.name_family) } - { str(self.role_type.role_name) }'
class SmsOpt(BaseModel):
+54 -1
View File
@@ -6,10 +6,62 @@ from apps.customer.models import (
)
from apps.reminder.models import Reminder as ReminderModel
from apps.workspace.models import Workspace as WorkspaceModel
from apps.cuser.models import CuserRole as CuserRoleModel
from rest_framework import exceptions
from utils.get_user_workspace import get_user_workspace, get_user_workspace_uuid
from utils.get_cuser_role import get_cuser_role
from django.db import transaction
from django.contrib.auth import get_user_model
import uuid
import random
CUser = get_user_model()
@transaction.atomic
def customer_panel_access(request, mobile: int, customer_id: int, status: bool) -> CuserRoleModel:
try:
workspace = get_user_workspace(request)
customer = CustomerModel.objects.get(id=customer_id, sys_ws=workspace)
try:
cuser_obj = CUser.objects.get(mobile=mobile)
except CUser.DoesNotExist:
cuser_obj = CUser.objects.create_user(
username=uuid.uuid4(),
mobile=mobile,
name_family=customer.name_family,
password=f"{random.randint(10000, 900000)}!@#{random.randint(10000, 9000000)}",
is_active=True,
)
try:
cuser_role_obj = CuserRoleModel.objects.get(cuser=cuser_obj, role_type_id=3)
cuser_role_obj.customer_panel = status
cuser_role_obj.save()
except CuserRoleModel.DoesNotExist:
cuser_role_obj = CuserRoleModel.objects.create(
cuser=cuser_obj,
role_type_id=3,
name_family=customer.name_family,
mobile=mobile,
mobile_verify=True,
is_active=True,
customer_panel=status,
sys_ws=workspace
)
if cuser_role_obj:
customer.cuser_role = cuser_role_obj
customer.save()
return cuser_role_obj
else:
raise Exception
except Exception as exp:
message = f'Error Create or Update Customer panel accsess: {exp}'
raise exceptions.ValidationError({'error': message})
def create_responsible_group(name: str, workspace: WorkspaceModel):
@@ -232,4 +284,5 @@ def customer_note_delete(request, customer_id: int, note_id: int) -> CustomerNot
except Exception as exp:
message = f'Error Delete Customer Note: {exp}'
raise exceptions.ValidationError({'error': message})
raise exceptions.ValidationError({'error': message})
+3
View File
@@ -36,4 +36,7 @@ urlpatterns = [
path('v2/create/', CustomerCreateApiV2.as_view(), name='customer_create_v2'),
path('form-item/', CustomerFormItemApi.as_view(), name='customer-form-item'),
path('customer-panel/', CustomerPanelApi.as_view(), name='customer-panel'),
]
+1
View File
@@ -7,3 +7,4 @@ from .customer import *
from .form_item import *
from .customer_summary import *
from .customer_note import *
from .customer_panel import *
+8
View File
@@ -22,6 +22,14 @@ class CustomerRetrieveApi(APIView):
permission_classes = (IsAuthenticated, custom_permissions.WorkspaceOperatorPermission)
class OutputSerializer(serializers.ModelSerializer):
cuser_role = inline_serializer(fields={
'id': serializers.IntegerField(required=False),
'cuser': inline_serializer(fields={
'id': serializers.IntegerField(),
'mobile': serializers.IntegerField(),
}),
'customer_panel': serializers.BooleanField(required=False)
})
class Meta:
model = CustomerModel
fields = '__all__'
+27
View File
@@ -0,0 +1,27 @@
from rest_framework.views import APIView
from rest_framework import status
from rest_framework.response import Response
from rest_framework import serializers
from apps.customer.services import customer_panel_access
from rest_framework.permissions import IsAuthenticated
from utils import custom_permissions
class CustomerPanelApi(APIView):
permission_classes = (IsAuthenticated, custom_permissions.WorkspaceOperatorPermission)
class InputSerializer(serializers.Serializer):
mobile = serializers.IntegerField(required=True)
customer_id = serializers.IntegerField(required=True)
status = serializers.BooleanField(required=True)
def post(self, request):
serializer = self.InputSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
cuser_role = customer_panel_access(request=request, **serializer.validated_data)
return Response(data={'cuser_role_id': cuser_role.id}, status=status.HTTP_200_OK)
@@ -0,0 +1,19 @@
# Generated by Django 4.2.1 on 2024-01-24 06:07
from django.db import migrations, models
import uuid
class Migration(migrations.Migration):
dependencies = [
('jwt_auth', '0073_alter_cuserroleloginopt_uuid'),
]
operations = [
migrations.AlterField(
model_name='cuserroleloginopt',
name='uuid',
field=models.UUIDField(default=uuid.UUID('27b41338-1021-4d24-8bcc-daa29fac3415'), unique=True),
),
]
@@ -0,0 +1,18 @@
# Generated by Django 4.2.1 on 2024-01-24 06:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('lead', '0027_alter_lead_status'),
]
operations = [
migrations.AlterField(
model_name='lead',
name='status',
field=models.CharField(blank=True, choices=[('FA', 'FAIL'), ('SU', 'OK'), ('UN', 'unknown')], default='UN', max_length=2, null=True),
),
]
@@ -0,0 +1,18 @@
# Generated by Django 4.2.1 on 2024-01-24 06:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('reminder', '0023_alter_reminder_type'),
]
operations = [
migrations.AlterField(
model_name='reminder',
name='type',
field=models.CharField(choices=[('CU', 'CUSTOMER'), ('UN', 'UNKNOWN'), ('NO', 'NOTE'), ('LE', 'LEAD')], default='UN', max_length=2),
),
]