T2026-01-032 #18
@@ -1783,14 +1783,23 @@ class EjecutarComandoView(APIView):
|
|||||||
View para ejecutar el comando de microservicios desde una petición HTTP.
|
View para ejecutar el comando de microservicios desde una petición HTTP.
|
||||||
"""
|
"""
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
# organizacion_id = request.data.get('organizacion_id', None)
|
|
||||||
|
# Obtener organizacion_id del request (si se envía)
|
||||||
|
organizacion_id_request = request.data.get('organizacionid', None)
|
||||||
procesamiento = request.data.get('procesamiento', None)
|
procesamiento = request.data.get('procesamiento', None)
|
||||||
todos = request.data.get('todos', False)
|
todos = request.data.get('todos', False)
|
||||||
|
|
||||||
if not self.request.user.is_authenticated or not hasattr(self.request.user, 'organizacion'):
|
if not self.request.user.is_authenticated or not hasattr(self.request.user, 'organizacion'):
|
||||||
raise ValueError("Usuario no autenticado o sin organización")
|
raise ValueError("Usuario no autenticado o sin organización")
|
||||||
|
|
||||||
organizacion_id = self.request.user.organizacion.id
|
if organizacion_id_request is None:
|
||||||
|
return Response(
|
||||||
|
{"error": 'No se proporcionó la organización a ejecutar el proceso.'},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST
|
||||||
|
)
|
||||||
|
|
||||||
|
# organizacion_id = self.request.user.organizacion.id
|
||||||
|
organizacion_id = organizacion_id_request
|
||||||
nombre_organizacion = self.request.user.organizacion.nombre
|
nombre_organizacion = self.request.user.organizacion.nombre
|
||||||
|
|
||||||
if procesamiento is None and todos == False:
|
if procesamiento is None and todos == False:
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ class TaskFilter(filters.FilterSet):
|
|||||||
timestamp_gte = filters.DateTimeFilter(field_name='timestamp', lookup_expr='gte')
|
timestamp_gte = filters.DateTimeFilter(field_name='timestamp', lookup_expr='gte')
|
||||||
timestamp_lte = filters.DateTimeFilter(field_name='timestamp', lookup_expr='lte')
|
timestamp_lte = filters.DateTimeFilter(field_name='timestamp', lookup_expr='lte')
|
||||||
status = filters.CharFilter(field_name='status')
|
status = filters.CharFilter(field_name='status')
|
||||||
|
organizacion = filters.UUIDFilter(field_name='organizacion__id') # Cambiado a relación directa
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Task
|
model = Task
|
||||||
fields = ['servicio', 'pedimento_app', 'pedimento', 'timestamp_gte', 'timestamp_lte', 'status']
|
fields = ['servicio', 'pedimento_app', 'pedimento', 'timestamp_gte', 'timestamp_lte', 'status', 'organizacion']
|
||||||
@@ -4,6 +4,7 @@ from django_filters.rest_framework import DjangoFilterBackend
|
|||||||
from rest_framework.pagination import PageNumberPagination
|
from rest_framework.pagination import PageNumberPagination
|
||||||
|
|
||||||
from api.logger.mixins import LoggingMixin
|
from api.logger.mixins import LoggingMixin
|
||||||
|
from mixins.filtrado_organizacion import OrganizacionFiltradaMixin, ProcesosPorOrganizacionMixin
|
||||||
from .models import Task
|
from .models import Task
|
||||||
from .serializers import TaskSerializer
|
from .serializers import TaskSerializer
|
||||||
from .filters import TaskFilter
|
from .filters import TaskFilter
|
||||||
@@ -22,7 +23,7 @@ class TaskPagination(PageNumberPagination):
|
|||||||
page_size_query_param = 'page_size'
|
page_size_query_param = 'page_size'
|
||||||
max_page_size = 100
|
max_page_size = 100
|
||||||
|
|
||||||
class TaskViewSet(LoggingMixin,viewsets.ModelViewSet):
|
class TaskViewSet(LoggingMixin,viewsets.ModelViewSet,OrganizacionFiltradaMixin):
|
||||||
permission_classes = [IsAuthenticated & (IsSameOrganization | IsSameOrganizationAndAdmin | IsSameOrganizationDeveloper | IsSuperUser)]
|
permission_classes = [IsAuthenticated & (IsSameOrganization | IsSameOrganizationAndAdmin | IsSameOrganizationDeveloper | IsSuperUser)]
|
||||||
queryset = Task.objects.select_related('pedimento', 'servicio').all()
|
queryset = Task.objects.select_related('pedimento', 'servicio').all()
|
||||||
serializer_class = TaskSerializer
|
serializer_class = TaskSerializer
|
||||||
@@ -33,3 +34,18 @@ class TaskViewSet(LoggingMixin,viewsets.ModelViewSet):
|
|||||||
ordering = ['-timestamp'] # ordenamiento por defecto, más reciente primero
|
ordering = ['-timestamp'] # ordenamiento por defecto, más reciente primero
|
||||||
|
|
||||||
my_tags = ['tasks']
|
my_tags = ['tasks']
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
|
||||||
|
"""
|
||||||
|
Filtra las tareas según la organización del usuario.
|
||||||
|
Superusuarios pueden ver todas las tareas.
|
||||||
|
"""
|
||||||
|
queryset = self.get_queryset_filtrado_por_organizacion() # Tambien filtra por importador
|
||||||
|
# if user.is_superuser:
|
||||||
|
# return self.queryset
|
||||||
|
# # return self.queryset.filter(organizacion_id=user.organizacion.id)
|
||||||
|
# else:
|
||||||
|
# return self.queryset.filter(organizacion_id=user.organizacion.id)
|
||||||
|
return queryset
|
||||||
|
|
||||||
Reference in New Issue
Block a user