Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new release #516

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion accounts/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
AttachmentsSerializer,
OrganizationSerializer,
ProfileSerializer,
UserSerializer
)
from contacts.serializer import ContactSerializer
from leads.serializer import LeadSerializer
Expand All @@ -18,7 +19,7 @@ class Meta:


class AccountSerializer(serializers.ModelSerializer):
created_by = ProfileSerializer()
created_by = UserSerializer()
lead = LeadSerializer()
org = OrganizationSerializer()
tags = TagsSerailizer(read_only=True, many=True)
Expand Down
34 changes: 23 additions & 11 deletions accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
from accounts.tasks import send_email, send_email_to_assigned_user
from cases.serializer import CaseSerializer
from common.models import Attachments, Comment, Profile
from leads.models import Lead
from leads.serializer import LeadSerializer

# from common.custom_auth import JSONWebTokenAuthentication
from common.external_auth import CustomDualAuthentication
from common.serializer import (
AttachmentsSerializer,
CommentSerializer,
Expand All @@ -55,7 +57,7 @@


class AccountsListView(APIView, LimitOffsetPagination):
# authentication_classes = (JSONWebTokenAuthentication,)
authentication_classes = (CustomDualAuthentication,)
permission_classes = (IsAuthenticated,)
model = Account
serializer_class = AccountReadSerializer
Expand All @@ -65,7 +67,7 @@ def get_context_data(self, **kwargs):
queryset = self.model.objects.filter(org=self.request.profile.org).order_by("-id")
if self.request.profile.role != "ADMIN" and not self.request.profile.is_admin:
queryset = queryset.filter(
Q(created_by=self.request.profile) | Q(assigned_to=self.request.profile)
Q(created_by=self.request.profile.user.user) | Q(assigned_to=self.request.profile)
).distinct()

if params:
Expand All @@ -77,7 +79,7 @@ def get_context_data(self, **kwargs):
queryset = queryset.filter(industry__icontains=params.get("industry"))
if params.get("tags"):
queryset = queryset.filter(
tags__in=json.loads(params.get("tags"))
tags__in=params.get("tags")
).distinct()

context = {}
Expand Down Expand Up @@ -136,6 +138,12 @@ def get_context_data(self, **kwargs):
"id", "user__email"
)
context["users"] = users
leads = Lead.objects.filter(org=self.request.profile.org).exclude(
Q(status="converted") | Q(status="closed")
)
context["users"] = users
context["leads"] = LeadSerializer(leads, many=True).data
context["status"] = ["open","close"]
return context

@extend_schema(tags=["Accounts"], parameters=swagger_params1.account_get_params)
Expand Down Expand Up @@ -207,7 +215,7 @@ def post(self, request, *args, **kwargs):


class AccountDetailView(APIView):
# authentication_classes = (JSONWebTokenAuthentication,)
authentication_classes = (CustomDualAuthentication,)
permission_classes = (IsAuthenticated,)
serializer_class = AccountReadSerializer

Expand All @@ -226,7 +234,6 @@ def put(self, request, pk, format=None):
serializer = AccountCreateSerializer(
account_object, data=data, request_obj=request, account=True
)
serializer.data['org'] = request.profile.org

if serializer.is_valid():
if (
Expand Down Expand Up @@ -285,7 +292,7 @@ def put(self, request, pk, format=None):

if self.request.FILES.get("account_attachment"):
attachment = Attachments()
attachment.created_by = self.request.profile
attachment.created_by = self.request.profile.user
attachment.file_name = self.request.FILES.get("account_attachment").name
attachment.account = account_object
attachment.attachment = self.request.FILES.get("account_attachment")
Expand Down Expand Up @@ -375,6 +382,9 @@ def get(self, request, pk, format=None):
users_mention = []
else:
users_mention = []
leads = Lead.objects.filter(org=self.request.profile.org).exclude(
Q(status="converted") | Q(status="closed")
)
context.update(
{
"attachments": AttachmentsSerializer(
Expand Down Expand Up @@ -419,6 +429,8 @@ def get(self, request, pk, format=None):
self.account.sent_email.all(), many=True
).data,
"users_mention": users_mention,
"leads" : LeadSerializer(leads, many=True).data,
"status" : ["open","close"]
}
)
return Response(context)
Expand Down Expand Up @@ -460,7 +472,7 @@ def post(self, request, pk, **kwargs):

if self.request.FILES.get("account_attachment"):
attachment = Attachments()
attachment.created_by = self.request.profile
attachment.created_by = self.request.profile.user
attachment.file_name = self.request.FILES.get("account_attachment").name
attachment.account = self.account_obj
attachment.attachment = self.request.FILES.get("account_attachment")
Expand All @@ -484,7 +496,7 @@ def post(self, request, pk, **kwargs):

class AccountCommentView(APIView):
model = Comment
# authentication_classes = (JSONWebTokenAuthentication,)
authentication_classes = (CustomDualAuthentication,)
permission_classes = (IsAuthenticated,)
serializer_class = AccountCommentEditSwaggerSerializer

Expand Down Expand Up @@ -546,7 +558,7 @@ def delete(self, request, pk, format=None):

class AccountAttachmentView(APIView):
model = Attachments
# authentication_classes = (JSONWebTokenAuthentication,)
authentication_classes = (CustomDualAuthentication,)
permission_classes = (IsAuthenticated,)
serializer_class = AccountDetailEditSwaggerSerializer

Expand All @@ -573,7 +585,7 @@ def delete(self, request, pk, format=None):


class AccountCreateMailView(APIView):
# authentication_classes = (JSONWebTokenAuthentication,)
authentication_classes = (CustomDualAuthentication,)
permission_classes = (IsAuthenticated,)
model = Account
serializer_class = EmailWriteSerializer
Expand Down
21 changes: 21 additions & 0 deletions cases/migrations/0003_alter_case_created_by.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 4.2.1 on 2023-10-31 12:42

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('cases', '0002_initial'),
]

operations = [
migrations.AlterField(
model_name='case',
name='created_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created_by', to=settings.AUTH_USER_MODEL, verbose_name='Created By'),
),
]
6 changes: 3 additions & 3 deletions cases/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class Case(BaseModel):
closed_on = models.DateField()
description = models.TextField(blank=True, null=True)
assigned_to = models.ManyToManyField(Profile, related_name="case_assigned_users")
created_by = models.ForeignKey(
Profile, related_name="case_created_by", on_delete=models.SET_NULL, null=True
)
# created_by = models.ForeignKey(
# Profile, related_name="case_created_by", on_delete=models.SET_NULL, null=True
# )
is_active = models.BooleanField(default=False)
teams = models.ManyToManyField(Teams, related_name="cases_teams")
org = models.ForeignKey(
Expand Down
4 changes: 2 additions & 2 deletions cases/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from accounts.serializer import AccountSerializer
from cases.models import Case
from common.serializer import OrganizationSerializer, ProfileSerializer
from common.serializer import OrganizationSerializer, ProfileSerializer,UserSerializer
from contacts.serializer import ContactSerializer
from teams.serializer import TeamsSerializer

Expand All @@ -11,7 +11,7 @@ class CaseSerializer(serializers.ModelSerializer):
account = AccountSerializer()
contacts = ContactSerializer(read_only=True, many=True)
assigned_to = ProfileSerializer(read_only=True, many=True)
created_by = ProfileSerializer(read_only=True)
created_by = UserSerializer(read_only=True)
teams = TeamsSerializer(read_only=True, many=True)
org = OrganizationSerializer()

Expand Down
36 changes: 18 additions & 18 deletions cases/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from cases.tasks import send_email_to_assigned_user
from common.models import Attachments, Comment, Profile

# from common.custom_auth import JSONWebTokenAuthentication
from common.external_auth import CustomDualAuthentication
from common.serializer import AttachmentsSerializer, CommentSerializer
from common.utils import CASE_TYPE, PRIORITY_CHOICE, STATUS_CHOICE
from contacts.models import Contact
Expand All @@ -25,7 +25,7 @@


class CaseListView(APIView, LimitOffsetPagination):
# authentication_classes = (JSONWebTokenAuthentication,)
authentication_classes = (CustomDualAuthentication,)
permission_classes = (IsAuthenticated,)
model = Case

Expand All @@ -37,13 +37,13 @@ def get_context_data(self, **kwargs):
profiles = Profile.objects.filter(is_active=True, org=self.request.profile.org)
if self.request.profile.role != "ADMIN" and not self.request.profile.is_admin:
queryset = queryset.filter(
Q(created_by=self.request.profile) | Q(assigned_to=self.request.profile)
Q(created_by=self.request.profile.user) | Q(assigned_to=self.request.profile)
).distinct()
accounts = accounts.filter(
Q(created_by=self.request.profile) | Q(assigned_to=self.request.profile)
Q(created_by=self.request.profile.user) | Q(assigned_to=self.request.profile)
).distinct()
contacts = contacts.filter(
Q(created_by=self.request.profile) | Q(assigned_to=self.request.profile)
Q(created_by=self.request.profile.user) | Q(assigned_to=self.request.profile)
).distinct()
profiles = profiles.filter(role="ADMIN")

Expand Down Expand Up @@ -97,26 +97,26 @@ def post(self, request, *args, **kwargs):
serializer = CaseCreateSerializer(data=params, request_obj=request)
if serializer.is_valid():
cases_obj = serializer.save(
created_by=request.profile,
created_by=request.profile.user,
org=request.profile.org,
closed_on=params.get("closed_on"),
case_type=params.get("case_type"),
)

if params.get("contacts"):
contacts_list = json.loads(params.get("contacts"))
contacts_list = params.get("contacts")
contacts = Contact.objects.filter(id__in=contacts_list, org=request.profile.org)
if contacts:
cases_obj.contacts.add(*contacts)

if params.get("teams"):
teams_list = json.loads(params.get("teams"))
teams_list = params.get("teams")
teams = Teams.objects.filter(id__in=teams_list, org=request.profile.org)
if teams.exists():
cases_obj.teams.add(*teams)

if params.get("assigned_to"):
assinged_to_list = json.loads(params.get("assigned_to"))
assinged_to_list = params.get("assigned_to")
profiles = Profile.objects.filter(
id__in=assinged_to_list, org=request.profile.org, is_active=True
)
Expand All @@ -125,7 +125,7 @@ def post(self, request, *args, **kwargs):

if self.request.FILES.get("case_attachment"):
attachment = Attachments()
attachment.created_by = self.request.profile
attachment.created_by = self.request.profile.user
attachment.file_name = self.request.FILES.get("case_attachment").name
attachment.cases = cases_obj
attachment.attachment = self.request.FILES.get("case_attachment")
Expand All @@ -148,7 +148,7 @@ def post(self, request, *args, **kwargs):


class CaseDetailView(APIView):
# authentication_classes = (JSONWebTokenAuthentication,)
authentication_classes = (CustomDualAuthentication,)
permission_classes = (IsAuthenticated,)
model = Case

Expand Down Expand Up @@ -194,21 +194,21 @@ def put(self, request, pk, format=None):
)
cases_object.contacts.clear()
if params.get("contacts"):
contacts_list = json.loads(params.get("contacts"))
contacts_list = params.get("contacts")
contacts = Contact.objects.filter(id__in=contacts_list, org=request.profile.org)
if contacts:
cases_object.contacts.add(*contacts)

cases_object.teams.clear()
if params.get("teams"):
teams_list = json.loads(params.get("teams"))
teams_list = params.get("teams")
teams = Teams.objects.filter(id__in=teams_list, org=request.profile.org)
if teams.exists():
cases_object.teams.add(*teams)

cases_object.assigned_to.clear()
if params.get("assigned_to"):
assinged_to_list = json.loads(params.get("assigned_to"))
assinged_to_list = params.get("assigned_to")
profiles = Profile.objects.filter(
id__in=assinged_to_list, org=request.profile.org, is_active=True
)
Expand All @@ -217,7 +217,7 @@ def put(self, request, pk, format=None):

if self.request.FILES.get("case_attachment"):
attachment = Attachments()
attachment.created_by = self.request.profile
attachment.created_by = self.request.profile.user
attachment.file_name = self.request.FILES.get("case_attachment").name
attachment.case = cases_object
attachment.attachment = self.request.FILES.get("case_attachment")
Expand Down Expand Up @@ -366,7 +366,7 @@ def post(self, request, pk, **kwargs):

if self.request.FILES.get("case_attachment"):
attachment = Attachments()
attachment.created_by = self.request.profile
attachment.created_by = self.request.profile.user
attachment.file_name = self.request.FILES.get("case_attachment").name
attachment.case = self.cases_obj
attachment.attachment = self.request.FILES.get("case_attachment")
Expand All @@ -387,7 +387,7 @@ def post(self, request, pk, **kwargs):

class CaseCommentView(APIView):
model = Comment
# authentication_classes = (JSONWebTokenAuthentication,)
authentication_classes = (CustomDualAuthentication,)
permission_classes = (IsAuthenticated,)

def get_object(self, pk):
Expand Down Expand Up @@ -450,7 +450,7 @@ def delete(self, request, pk, format=None):

class CaseAttachmentView(APIView):
model = Attachments
# authentication_classes = (JSONWebTokenAuthentication,)
authentication_classes = (CustomDualAuthentication,)
permission_classes = (IsAuthenticated,)

@extend_schema(
Expand Down
Loading
Loading