From 47f9dc646ba1c89e8e550b22cb71b73bd31097d9 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Sun, 2 Nov 2025 12:29:43 +0330 Subject: [PATCH] fix - change get_queryset flag --- apps/authentication/api/v1/api.py | 6 +++++- apps/authentication/api/v1/serializers/serializer.py | 3 ++- apps/authorization/api/v1/api.py | 11 +++++++++-- apps/core/api.py | 2 +- .../web/api/v1/viewsets/quota_distribution_api.py | 6 ++++-- logs/django_requests.log | 4 ++++ 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/apps/authentication/api/v1/api.py b/apps/authentication/api/v1/api.py index de0e8c3..3e39d37 100644 --- a/apps/authentication/api/v1/api.py +++ b/apps/authentication/api/v1/api.py @@ -256,7 +256,11 @@ class OrganizationViewSet(BaseViewSet, SoftDeleteMixin, ModelViewSet, DynamicSea def list(self, request, *args, **kwargs): """ all organization """ - queryset = self.get_queryset(visibility_by_org_scope=True) + org = get_organization_by_user(request.user) + + queryset = self.get_queryset( + visibility_by_org_scope=True + ) if org.free_visibility_by_scope else self.get_queryset() query = self.filter_query(queryset) diff --git a/apps/authentication/api/v1/serializers/serializer.py b/apps/authentication/api/v1/serializers/serializer.py index 8f1612b..2e49014 100644 --- a/apps/authentication/api/v1/serializers/serializer.py +++ b/apps/authentication/api/v1/serializers/serializer.py @@ -224,7 +224,8 @@ class OrganizationSerializer(serializers.ModelSerializer): 'parent_organization', 'national_unique_id', 'company_code', - 'field_of_activity' + 'field_of_activity', + 'free_visibility_by_scope' ] extra_kwargs = {} diff --git a/apps/authorization/api/v1/api.py b/apps/authorization/api/v1/api.py index 30fc60e..aa0d295 100644 --- a/apps/authorization/api/v1/api.py +++ b/apps/authorization/api/v1/api.py @@ -24,6 +24,7 @@ from apps.core.api import BaseViewSet from apps.core.exceptions import ConflictException from apps.core.mixins.search_mixin import DynamicSearchMixin from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin +from common.helpers import get_organization_by_user class RoleViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSet): @@ -164,10 +165,16 @@ class UserRelationViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSet, D def list(self, request, *args, **kwargs): role_param = self.request.query_params.get('role') # noqa + org = get_organization_by_user(request.user) + + queryset = self.get_queryset( + visibility_by_org_scope=True + ) if org.free_visibility_by_scope else self.get_queryset() + if role_param != '': - queryset = self.get_queryset(visibility_by_org_scope=True).filter(role_id=int(role_param)) + queryset = queryset.filter(role_id=int(role_param)) else: - queryset = self.get_queryset(visibility_by_org_scope=True).order_by('-create_date') + queryset = queryset.order_by('-create_date') queryset = self.filter_queryset(queryset) # noqa diff --git a/apps/core/api.py b/apps/core/api.py index 232d6c3..889de96 100644 --- a/apps/core/api.py +++ b/apps/core/api.py @@ -24,7 +24,7 @@ class BaseViewSet(RegionFilterMixin, viewsets.ModelViewSet): if self.request.method.lower() == 'get' and not self.kwargs.get('pk'): queryset = self.filter_by_region(queryset, org=True) - if visibility_by_org_scope and org.free_visibility_by_scope: + if visibility_by_org_scope: """ if organization has free visibility by scope, apply visibility filter """ queryset = apply_visibility_filter(queryset, org) return queryset diff --git a/apps/product/web/api/v1/viewsets/quota_distribution_api.py b/apps/product/web/api/v1/viewsets/quota_distribution_api.py index 1b594a5..5207c15 100644 --- a/apps/product/web/api/v1/viewsets/quota_distribution_api.py +++ b/apps/product/web/api/v1/viewsets/quota_distribution_api.py @@ -6,6 +6,7 @@ from rest_framework.decorators import action from rest_framework.exceptions import APIException from rest_framework.response import Response +from apps.core.api import BaseViewSet from apps.core.mixins.search_mixin import DynamicSearchMixin from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin from apps.core.pagination import CustomPageNumberPagination @@ -28,7 +29,7 @@ def delete(queryset, pk): obj.delete() -class QuotaDistributionViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin): +class QuotaDistributionViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin): """ quota distribution apis """ queryset = product_models.QuotaDistribution.objects.all() @@ -94,7 +95,8 @@ class QuotaDistributionViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSe def my_distributions(self, request): """ list of my distributions """ - queryset = self.filter_query(self.queryset) # return by search param or all objects + queryset = self.filter_query( + self.get_queryset(visibility_by_org_scope=True)) # return by search param or all objects organization = get_organization_by_user(request.user) query = self.request.query_params diff --git a/logs/django_requests.log b/logs/django_requests.log index 2dcfcc5..1ff033d 100644 --- a/logs/django_requests.log +++ b/logs/django_requests.log @@ -672,3 +672,7 @@ AssertionError: .validate() should return the validated data [2025-11-02 11:53:41,310] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\api.py changed, reloading. [2025-11-02 11:53:43,395] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader [2025-11-02 12:01:41,047] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\core\api.py changed, reloading. +[2025-11-02 12:01:44,122] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-02 12:28:52,726] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\api.py changed, reloading. +[2025-11-02 12:28:55,700] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-02 12:29:03,247] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\product\web\api\v1\viewsets\quota_distribution_api.py changed, reloading.