Exemple #1
0
 def get_queryset(self):
     """
     Filter projects by current user.
     """
     user = self.request.user
     qs = Instance.for_user(user)
     if 'archived' in self.request.query_params:
         return qs
     return qs.filter(only_current())
Exemple #2
0
 def get_queryset(self):
     """
     Filter projects by current user.
     """
     user = self.request.user
     qs = Instance.for_user(user)
     if 'archived' not in self.request.query_params:
         qs = qs.filter(only_current())
     logger.info(
         "DEBUG- User %s querying for instances, available IDs are:%s" %
         (user, qs.values_list('id', flat=True)))
     return qs
Exemple #3
0
    def get_queryset(self):
        request_user = self.request.user
        if request_user.is_staff or request_user.is_superuser:
            instances_qs = Instance.objects.all()
        elif request_user.is_authenticated():
            instances_qs = Instance.for_user(request_user)
        else:
            raise exceptions.NotAuthenticated()
        query_params = self.request.query_params
        query = self.get_filter_query(query_params)

        queryset = instances_qs.filter(query)
        return queryset
Exemple #4
0
 def _validate_ias_event(self, entity_id, payload):
     allocation_source_name = payload.get('allocation_source_name', '')
     instance_id = payload.get('instance_id', '')
     user = self._get_request_user()
     if entity_id != user.username:
         raise serializers.ValidationError(
             "Expected entity ID to be the Username: %s, Received: %s" %
             (user.username, entity_id))
     if not user:
         raise serializers.ValidationError("Request user was not found")
     allocation_source = AllocationSource.for_user(user=user).filter(
         name=allocation_source_name).first()
     instance = Instance.for_user(user=user).filter(
         provider_alias=instance_id).first()
     if not allocation_source:
         raise serializers.ValidationError(
             "AllocationSource with name=%s DoesNotExist" %
             allocation_source_name)
     if not instance:
         raise serializers.ValidationError(
             "Instance with provider_alias=%s DoesNotExist" % instance_id)
     return True