From 6ee82319252686d212ce8efa469ea4ba4b9f2505 Mon Sep 17 00:00:00 2001 From: Ashwin Date: Mon, 23 Oct 2023 13:35:09 +0530 Subject: [PATCH] new release --- accounts/urls.py | 8 +++---- accounts/views.py | 17 ++++++++++++++- cases/urls.py | 6 +++--- common/middleware/get_company.py | 36 +++++++++++++++++--------------- events/urls.py | 6 +++--- invoices/api_urls.py | 6 +++--- opportunity/urls.py | 6 +++--- tasks/urls.py | 6 +++--- 8 files changed, 54 insertions(+), 37 deletions(-) diff --git a/accounts/urls.py b/accounts/urls.py index a6f7090cd..6815dc80c 100644 --- a/accounts/urls.py +++ b/accounts/urls.py @@ -6,8 +6,8 @@ urlpatterns = [ path("", views.AccountsListView.as_view()), - path("/", views.AccountDetailView.as_view()), - path("/create_mail/", views.AccountCreateMailView.as_view()), - path("comment//", views.AccountCommentView.as_view()), - path("attachment//", views.AccountAttachmentView.as_view()), + path("/", views.AccountDetailView.as_view()), + path("/create_mail/", views.AccountCreateMailView.as_view()), + path("comment//", views.AccountCommentView.as_view()), + path("attachment//", views.AccountAttachmentView.as_view()), ] diff --git a/accounts/views.py b/accounts/views.py index b8e42086e..210d6ee62 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -26,6 +26,7 @@ AccountCommentEditSwaggerSerializer, EmailWriteSerializer ) +from teams.serializer import TeamsSerializer from accounts.tasks import send_email, send_email_to_assigned_user from cases.serializer import CaseSerializer from common.models import Attachments, Comment, Profile @@ -113,17 +114,28 @@ def get_context_data(self, **kwargs): offset = 0 accounts_close = AccountSerializer(results_accounts_close, many=True).data + contacts = Contact.objects.filter(org=self.request.profile.org).values( + "id", "first_name" + ) + context["contacts"] = contacts context["closed_accounts"] = { "offset": offset, "close_accounts": accounts_close, } + context["teams"] = TeamsSerializer( + Teams.objects.filter(org=self.request.profile.org), many=True + ).data + context["countries"] = COUNTRIES context["industries"] = INDCHOICES tags = Tags.objects.all() tags = TagsSerailizer(tags, many=True).data context["tags"] = tags - + users = Profile.objects.filter(is_active=True, org=self.request.profile.org).values( + "id", "user__email" + ) + context["users"] = users return context @extend_schema(tags=["Accounts"], parameters=swagger_params1.account_get_params) @@ -386,6 +398,9 @@ def get(self, request, pk, format=None): "cases": CaseSerializer( self.account.accounts_cases.all(), many=True ).data, + "teams" : TeamsSerializer( + Teams.objects.filter(org=self.request.profile.org), many=True + ).data, "stages": STAGES, "sources": SOURCES, "countries": COUNTRIES, diff --git a/cases/urls.py b/cases/urls.py index 30ef3e7f0..2467a6eba 100644 --- a/cases/urls.py +++ b/cases/urls.py @@ -6,7 +6,7 @@ urlpatterns = [ path("", views.CaseListView.as_view()), - path("/", views.CaseDetailView.as_view()), - path("comment//", views.CaseCommentView.as_view()), - path("attachment//", views.CaseAttachmentView.as_view()), + path("/", views.CaseDetailView.as_view()), + path("comment//", views.CaseCommentView.as_view()), + path("attachment//", views.CaseAttachmentView.as_view()), ] diff --git a/common/middleware/get_company.py b/common/middleware/get_company.py index ba66ea107..9e33a94ed 100644 --- a/common/middleware/get_company.py +++ b/common/middleware/get_company.py @@ -1,7 +1,7 @@ import jwt from django.conf import settings from django.contrib.auth import logout -from django.core.exceptions import ValidationError +from django.core.exceptions import ValidationError,PermissionDenied from rest_framework import status from rest_framework.response import Response from crum import get_current_user @@ -44,19 +44,21 @@ def __call__(self, request): return self.get_response(request) def process_request(self, request): - - request.profile = None - user_id = None - # here I am getting the the jwt token passing in header - if request.headers.get("Authorization"): - token1 = request.headers.get("Authorization") - token = token1.split(" ")[1] # getting the token value - decoded = jwt.decode(token, (settings.SECRET_KEY), algorithms=[settings.JWT_ALGO]) - user_id = decoded['user_id'] - if user_id is not None: - if request.headers.get("org"): - profile = Profile.objects.get( - user_id=user_id, org=request.headers.get("org"), is_active=True - ) - if profile: - request.profile = profile + try : + request.profile = None + user_id = None + # here I am getting the the jwt token passing in header + if request.headers.get("Authorization"): + token1 = request.headers.get("Authorization") + token = token1.split(" ")[1] # getting the token value + decoded = jwt.decode(token, (settings.SECRET_KEY), algorithms=[settings.JWT_ALGO]) + user_id = decoded['user_id'] + if user_id is not None: + if request.headers.get("org"): + profile = Profile.objects.get( + user_id=user_id, org=request.headers.get("org"), is_active=True + ) + if profile: + request.profile = profile + except : + raise PermissionDenied() diff --git a/events/urls.py b/events/urls.py index 61eec0817..d2a27ac61 100644 --- a/events/urls.py +++ b/events/urls.py @@ -6,7 +6,7 @@ urlpatterns = [ path("", views.EventListView.as_view()), - path("/", views.EventDetailView.as_view()), - path("comment//", views.EventCommentView.as_view()), - path("attachment//", views.EventAttachmentView.as_view()), + path("/", views.EventDetailView.as_view()), + path("comment//", views.EventCommentView.as_view()), + path("attachment//", views.EventAttachmentView.as_view()), ] diff --git a/invoices/api_urls.py b/invoices/api_urls.py index 48cde5236..1a3c66d33 100644 --- a/invoices/api_urls.py +++ b/invoices/api_urls.py @@ -6,7 +6,7 @@ urlpatterns = [ path("", api_views.InvoiceListView.as_view()), - path("/", api_views.InvoiceDetailView.as_view()), - path("comment//", api_views.InvoiceCommentView.as_view()), - path("attachment//", api_views.InvoiceAttachmentView.as_view()), + path("/", api_views.InvoiceDetailView.as_view()), + path("comment//", api_views.InvoiceCommentView.as_view()), + path("attachment//", api_views.InvoiceAttachmentView.as_view()), ] diff --git a/opportunity/urls.py b/opportunity/urls.py index 19cd4916b..182931a54 100644 --- a/opportunity/urls.py +++ b/opportunity/urls.py @@ -6,7 +6,7 @@ urlpatterns = [ path("", views.OpportunityListView.as_view()), - path("/", views.OpportunityDetailView.as_view()), - path("comment//", views.OpportunityCommentView.as_view()), - path("attachment//", views.OpportunityAttachmentView.as_view()), + path("/", views.OpportunityDetailView.as_view()), + path("comment//", views.OpportunityCommentView.as_view()), + path("attachment//", views.OpportunityAttachmentView.as_view()), ] diff --git a/tasks/urls.py b/tasks/urls.py index e186dce47..4367773c3 100644 --- a/tasks/urls.py +++ b/tasks/urls.py @@ -6,7 +6,7 @@ urlpatterns = [ path("", views.TaskListView.as_view()), - path("/", views.TaskDetailView.as_view()), - path("comment//", views.TaskCommentView.as_view()), - path("attachment//", views.TaskAttachmentView.as_view()), + path("/", views.TaskDetailView.as_view()), + path("comment//", views.TaskCommentView.as_view()), + path("attachment//", views.TaskAttachmentView.as_view()), ]