Ejemplo n.º 1
0
 def perform_create(self, serializer):
     if settings.PROFILES_ENABLED:
         created = serializer.save(owner_id=get_owner_id(self.request),
                                   shipment_id=self.kwargs['shipment_pk'])
     else:
         created = serializer.save(shipment_id=self.kwargs['shipment_pk'])
     return created
Ejemplo n.º 2
0
 def perform_create(self, serializer):
     if settings.PROFILES_ENABLED:
         created = serializer.save(owner_id=get_owner_id(self.request),
                                   masquerade_id=self.request.user.id)
     else:
         created = serializer.save()
     return created
Ejemplo n.º 3
0
    def get_queryset(self, *args, **kwargs):
        log_metric('transmission.info',
                   tags={
                       'method': 'transaction.get_queryset',
                       'module': __name__
                   })
        LOG.debug('Getting tx details for a transaction hash.')
        queryset = super().get_queryset(*args, **kwargs)
        if settings.PROFILES_ENABLED:
            if 'wallet_id' in self.request.query_params:
                queryset = queryset.filter(
                    Q(shipment__owner_id=get_owner_id(self.request))
                    | Q(shipment__shipper_wallet_id=self.request.query_params.
                        get('wallet_id'))
                    | Q(shipment__moderator_wallet_id=self.request.
                        query_params.get('wallet_id'))
                    | Q(shipment__carrier_wallet_id=self.request.query_params.
                        get('wallet_id')))
            else:
                permission_link = self.request.query_params.get(
                    'permission_link', None)
                if permission_link:
                    try:
                        permission_link_obj = PermissionLink.objects.get(
                            pk=permission_link)
                    except ObjectDoesNotExist:
                        LOG.warning(
                            f'User: {self.request.user}, is trying to access a shipment\'s transactions '
                            f'with permission link: {permission_link}')
                        raise PermissionDenied('No permission link found.')
                    queryset = queryset.filter(
                        shipment_owner_access_filter(self.request)
                        | Q(shipment__pk=permission_link_obj.shipment.pk))

        return queryset
Ejemplo n.º 4
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.initial_data = self.initial_data.copy()
        self.initial_data.update(
            shipment_id=self.context['view'].kwargs['shipment_pk'])

        if settings.PROFILES_ENABLED:
            self.initial_data.update(
                owner_id=get_owner_id(self.context['request']))
Ejemplo n.º 5
0
 def perform_create(self, serializer):
     if settings.PROFILES_ENABLED:
         background_data_hash_interval = self.request.user.token.get(
             'background_data_hash_interval',
             settings.DEFAULT_BACKGROUND_DATA_HASH_INTERVAL)
         manual_update_hash_interval = self.request.user.token.get(
             'manual_update_hash_interval',
             settings.DEFAULT_MANUAL_UPDATE_HASH_INTERVAL)
         created = serializer.save(
             owner_id=get_owner_id(self.request),
             updated_by=self.request.user.id,
             background_data_hash_interval=background_data_hash_interval,
             manual_update_hash_interval=manual_update_hash_interval)
     else:
         created = serializer.save(background_data_hash_interval=settings.
                                   DEFAULT_BACKGROUND_DATA_HASH_INTERVAL,
                                   manual_update_hash_interval=settings.
                                   DEFAULT_MANUAL_UPDATE_HASH_INTERVAL)
     return created
Ejemplo n.º 6
0
    def get_queryset(self, *args, **kwargs):
        queryset = super().get_queryset(*args, **kwargs)

        # Get latest tracking point for each shipment
        queryset = queryset.filter(id__in=TrackingData.objects.order_by(
            'shipment_id', '-timestamp').distinct('shipment_id').values('id'))

        if settings.PROFILES_ENABLED:
            # Filter by owner or wallet id or access request
            queryset_filter = Q(shipment__owner_id=get_owner_id(self.request))
            queryset_filter = queryset_filter | shipment_list_wallets_filter(
                self.request, nested=True)
            queryset_filter = queryset_filter | Q(
                shipment_id__in=self.request.user.access_request_shipments)

            queryset = queryset.filter(queryset_filter)

        queryset = self._parse_customer_fields_queries(queryset)

        return queryset
Ejemplo n.º 7
0
 def get_queryset(self):
     queryset = self.queryset
     if settings.PROFILES_ENABLED:
         queryset = queryset.filter(shipment__owner_id=get_owner_id(self.request))
     return queryset
Ejemplo n.º 8
0
 def perform_create(self, serializer):
     return serializer.save(owner_id=get_owner_id(self.request))