fix - quota exception in distribution limit & sale licence and visibility free by org
This commit is contained in:
@@ -2,6 +2,7 @@ from rest_framework import viewsets
|
||||
|
||||
from apps.authentication.mixins.region_filter import RegionFilterMixin, get_organization_by_user
|
||||
from apps.authentication.services.service import get_all_org_child
|
||||
from apps.authentication.services.visibility_services import apply_visibility_filter
|
||||
from apps.authorization.services.role_child import get_all_role_child
|
||||
from apps.core.models import MobileTest, SystemConfig
|
||||
from apps.core.serializers import MobileTestSerializer, SystemConfigSerializer
|
||||
@@ -13,7 +14,7 @@ class BaseViewSet(RegionFilterMixin, viewsets.ModelViewSet):
|
||||
It applies region-based filtering automatically to GET (list) requests.
|
||||
"""
|
||||
|
||||
def get_queryset(self, show_my_org: bool = None):
|
||||
def get_queryset(self, show_my_org: bool = None, visibility_by_org_scope: bool = None):
|
||||
queryset = super().get_queryset()
|
||||
request = self.request
|
||||
user = request.user
|
||||
@@ -23,6 +24,11 @@ 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:
|
||||
""" if organization has free visibility by scope, apply visibility filter """
|
||||
queryset = apply_visibility_filter(queryset, org)
|
||||
return queryset
|
||||
|
||||
if user_relation.exists():
|
||||
user_relation = user_relation.first()
|
||||
if not user_relation.role.type.key == 'ADM':
|
||||
|
||||
16
apps/core/visibility_registry.py
Normal file
16
apps/core/visibility_registry.py
Normal file
@@ -0,0 +1,16 @@
|
||||
VISIBILITY_MAP = {
|
||||
'userrelations': 'organization',
|
||||
'organization': 'id',
|
||||
'quota': ['registerer_organization', 'assigned_organizations'],
|
||||
'quotadistribution': ['assigner_organization', 'assigned_organization'],
|
||||
'inventoryentry': 'organization',
|
||||
'inventoryquotasaletransaction': 'organization',
|
||||
'device': 'organization',
|
||||
# 'deviceactivationcode': 'organization',
|
||||
# 'deviceversion': 'organization',
|
||||
# 'posclient': 'organization',
|
||||
# 'deviceassignment': 'organization',
|
||||
# 'stakeholders': 'organization',
|
||||
# 'stakeholdershareamount': 'registering_organization',
|
||||
# 'posfreeproducts': 'organization',
|
||||
}
|
||||
Reference in New Issue
Block a user